Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T>
- using mpq = priority_queue<T, vector<T>, greater<T>>;
- namespace rngs = std::ranges;
- using ll = long long;
- using a2l = array<ll, 2>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- int main(int argc, char **argv) {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- ll h, w, xall = 0;
- cin >> h >> w;
- vector<vl> a(h, vl(w));
- for (auto &row : a)
- for (auto &col : row)
- cin >> col, xall ^= col;
- vector<vl> mark(h, vl(w));
- ll ans = 0;
- ll cnt = 0;
- auto dfs = [&](auto &&self, ll x, ll y, ll acc) -> void {
- cnt += 1;
- if (y >= w)
- y = 0, x += 1;
- if (x >= h) {
- ans = max(ans, acc);
- return;
- }
- if (mark[x][y] == 0) {
- self(self, x, y + 1, acc);
- if (x + 1 < h && !mark[x + 1][y]) {
- mark[x][y] = mark[x + 1][y] = 1;
- self(self, x, y + 1, acc ^ a[x][y]);
- mark[x][y] = mark[x + 1][y] = 0;
- }
- if (y + 1 < w && !mark[x][y + 1]) {
- mark[x][y] = mark[x][y + 1] = 1;
- self(self, x, y + 1, acc ^ a[x][y]);
- mark[x][y] = mark[x][y + 1] = 0;
- }
- } else
- self(self, x, y + 1, acc ^ a[x][y]);
- };
- dfs(dfs, 0, 0, xall);
- cout << ans << '\n';
- dbg(cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment