Advertisement
pb_jiang

ABC271F

Oct 6th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  5. template <typename... Args> void logger(string vars, Args &&... values)
  6. {
  7.     cerr << vars << " = ";
  8.     string delim = "";
  9.     (..., (cerr << delim << values, delim = ", "));
  10.     cerr << endl;
  11. }
  12.  
  13. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  14. using ll = long long;
  15. using pii = pair<int, int>;
  16.  
  17. int n;
  18. ll a[1 << 5][1 << 5];
  19.  
  20. map<ll, int> td[1 << 5][1 << 5];
  21. map<ll, int> bu[1 << 5][1 << 5];
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.     scanf("%d", &n);
  26.     for (int i = 1; i <= n; ++i)
  27.         for (int j = 1; j <= n; ++j)
  28.             scanf("%lld", a[i] + j);
  29.     td[1][1][a[1][1]] = 1;
  30.     for (int i = 1; i < n; ++i) {
  31.         for (int x = 1 + i, y = 1; x >= 1; --x, ++y) {
  32.             if (x - 1 >= 1)
  33.                 for (const auto &[k, v] : td[x - 1][y])
  34.                     td[x][y][k ^ a[x][y]] += v;
  35.             if (y - 1 >= 1)
  36.                 for (const auto &[k, v] : td[x][y - 1])
  37.                     td[x][y][k ^ a[x][y]] += v;
  38.         }
  39.     }
  40.     bu[n][n][a[n][n]] = 1;
  41.     for (int i = 1; i < n; ++i) {
  42.         for (int x = n - i, y = n; x <= n; ++x, --y) {
  43.             if (x + 1 <= n)
  44.                 for (const auto &[k, v] : bu[x + 1][y])
  45.                     bu[x][y][k ^ a[x][y]] += v;
  46.             if (y + 1 <= n)
  47.                 for (const auto &[k, v] : bu[x][y + 1])
  48.                     bu[x][y][k ^ a[x][y]] += v;
  49.         }
  50.     }
  51.  
  52.     ll ans = 0;
  53.     for (int x = n, y = 1; x >= 1; --x, ++y) {
  54.         for (const auto &[k, v] : td[x][y])
  55.             if (bu[x][y].count(k ^ a[x][y]))
  56.                 ans += ll(v) * bu[x][y][k ^ a[x][y]];
  57.     }
  58.  
  59.     printf("%lld\n", ans);
  60.     return 0;
  61. };
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement