• Source
    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. int n;
    4. int t[20][20];
    5. map<int, int> cnt[20][20];
    6. long long ans = 0;
    7. void dfs_first(int i, int j, int x) {
    8. if (i + j == n - 1) {
    9. cnt[i][j][x]++;
    10. return;
    11. }
    12. if (i + 1 < n) dfs_first(i + 1, j, x ^ t[i][j]);
    13. if (j + 1 < n) dfs_first(i, j + 1, x ^ t[i][j]);
    14. }
    15. void dfs_second(int i, int j, int x) {
    16. if (i + j == n - 1) {
    17. if (cnt[i][j].count(x ^ t[i][j]))
    18. ans += cnt[i][j][x ^ t[i][j]];
    19. return;
    20. }
    21. if (i - 1 >= 0) dfs_second(i - 1, j, x ^ t[i][j]);
    22. if (j - 1 >= 0) dfs_second(i, j - 1, x ^ t[i][j]);
    23. }
    24. int main() {
    25. cin >> n;
    26. for (int i = 0; i < n; ++i)
    27. for (int j = 0; j < n; ++j)
    28. cin >> t[i][j];
    29. dfs_first(0, 0, 0);
    30. dfs_second(n - 1, n - 1, 0);
    31. cout << ans << '\n';
    32. return 0;
    33. }