Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int n;
- ll a[1 << 5][1 << 5];
- map<ll, int> td[1 << 5][1 << 5];
- map<ll, int> bu[1 << 5][1 << 5];
- int main(int argc, char **argv)
- {
- scanf("%d", &n);
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= n; ++j)
- scanf("%lld", a[i] + j);
- td[1][1][a[1][1]] = 1;
- for (int i = 1; i < n; ++i) {
- for (int x = 1 + i, y = 1; x >= 1; --x, ++y) {
- if (x - 1 >= 1)
- for (const auto &[k, v] : td[x - 1][y])
- td[x][y][k ^ a[x][y]] += v;
- if (y - 1 >= 1)
- for (const auto &[k, v] : td[x][y - 1])
- td[x][y][k ^ a[x][y]] += v;
- }
- }
- bu[n][n][a[n][n]] = 1;
- for (int i = 1; i < n; ++i) {
- for (int x = n - i, y = n; x <= n; ++x, --y) {
- if (x + 1 <= n)
- for (const auto &[k, v] : bu[x + 1][y])
- bu[x][y][k ^ a[x][y]] += v;
- if (y + 1 <= n)
- for (const auto &[k, v] : bu[x][y + 1])
- bu[x][y][k ^ a[x][y]] += v;
- }
- }
- ll ans = 0;
- for (int x = n, y = 1; x >= 1; --x, ++y) {
- for (const auto &[k, v] : td[x][y])
- if (bu[x][y].count(k ^ a[x][y]))
- ans += ll(v) * bu[x][y][k ^ a[x][y]];
- }
- printf("%lld\n", ans);
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement