fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. using namespace std;
  5. vector<vector<ll>> table(21,vector<ll>(21));
  6. map<ll,ll> dp1[20][20];
  7. map<ll,ll> dp2[20][20];
  8. void floodfill1(ll x,ll y, ll current,ll mid,ll n){
  9. if (x>mid || y>n) return;
  10. current=current^table[x][y];
  11. dp1[x][y][current]++;
  12. floodfill1(x+1,y,current,mid,n);
  13. floodfill1(x,y+1,current,mid,n);
  14. }
  15. void floodfill2(ll x,ll y, ll current,ll mid,ll n,ll k, ll& ans){
  16. if (x==mid){
  17. ans+=dp1[x][y][current^k];
  18. return;
  19. }
  20. if (x<mid || y<0) return;
  21. current=current^table[x][y];
  22. dp2[x][y][current]++;
  23. floodfill2(x-1,y,current,mid,n,k, ans);
  24. floodfill2(x,y-1,current,mid,n,k,ans);
  25. }
  26. int main(){
  27. ios_base::sync_with_stdio(false);
  28. cin.tie(NULL); cout.tie(NULL);
  29. ll n,m,k;
  30. cin >> n>> m >> k;
  31. for (ll i=0;i<n;i++){
  32. for (ll j=0;j<m;j++){
  33. ll f;
  34. cin >> f;
  35. table[i][j]=f;
  36. }
  37. }
  38. ll ans=0;
  39. ll current=0;
  40. floodfill1(0,0,0,(n+m-2)>>1,n);
  41. floodfill2(n-1,m-1,0,(n+m-2)>>1,n,k,ans);
  42. cout << ans;
  43. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty