Advertisement
Josif_tepe

Untitled

Mar 21st, 2023
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <vector>
  5. using namespace std;
  6. const int maxn=200005;
  7. typedef long long ll;
  8. vector<pair<int, int>> graph[10005];
  9. int dp[101][101][28][2];
  10. int rec(int max_pos, int lucas_pos, int last_char, int turn) {
  11.     if(dp[max_pos][lucas_pos][last_char][turn] != -1) {
  12.         return dp[max_pos][lucas_pos][last_char][turn];
  13.     }
  14.     int res;
  15.     if(turn == 0) {
  16.         res = -(2e9);
  17.         for(int i = 0; i < graph[max_pos].size(); i++) {
  18.             int neighbour = graph[max_pos][i].first;
  19.             int next_char = graph[max_pos][i].second;
  20.            
  21.             if(last_char <= next_char) {
  22.                 res = max(res, rec(neighbour, lucas_pos, next_char, 1));
  23.             }
  24.         }
  25.     }
  26.     else {
  27.         res = (2e9);
  28.         for(int i = 0; i < graph[lucas_pos].size(); i++) {
  29.             int neighbour = graph[lucas_pos][i].first;
  30.             int next_char = graph[lucas_pos][i].second;
  31.             if(last_char <= next_char) {
  32.                 res = min(res, rec(max_pos, neighbour, next_char, 0));
  33.             }
  34.         }
  35.     }
  36.     return dp[max_pos][lucas_pos][last_char][turn] = res;
  37. }
  38. int main()
  39. {
  40.     int n, m;
  41.     cin >> n >> m;
  42.     for(int i = 0; i < m; i++) {
  43.         int a, b;
  44.         char c;
  45.         cin >> a >> b >> c;
  46.         a--; b--;
  47.         graph[a].push_back(make_pair(b, (c - 'a') + 1));
  48.     }
  49.     memset(dp, -1, sizeof dp);
  50.     for(int i = 0; i < n; i++) {
  51.         for(int j = 0; j < n; j++) {
  52.             if(rec(i, j, 0, 0) == 2e9) {
  53.                 cout << "A";
  54.             }
  55.             else {
  56.                 cout << "B";
  57.             }
  58.         }
  59.         cout << endl;
  60.     }
  61.     return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement