#include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define PPC(x) __builtin_popcount((x)) #define ALL(x) (x).begin(), (x).end() #define pb push_back #define st first #define nd second using namespace std; #define tera aighaoihgaos vector <vector <bool> > dasie; vector <pair <int, int> > tera; bool vis[1 << 18]; void dfs(int a, int b) { if (a < 0 or b < 0 or !dasie[a][b]) return; if (dasie[a+1][b] or dasie[a][b+1]) return; dasie[a][b] = false; tera.pb({a, b}); dfs(a-1, b); dfs(a, b-1); } int main() { int n, m, k, x = 0; scanf ("%d%d%d", &n, &m, &k); dasie.resize(n+1); FOR(i, 0, n+1) { dasie[i].resize(m+1, true); dasie[i][m] = false; } FOR(i, 0, m+1) dasie[n][i] = false; while (k--) { int a, b, c; scanf ("%d%d%d", &a, &b, &c); a = (a ^ x) % n, b = (b ^ x) % m; if (!dasie[a][b] or vis[a+b]) { printf("NIE\n"); continue; } dasie[a][b] = false; tera.pb({a, b}); dfs(a-1, b); dfs(a, b-1); if (!dasie[0][0]) { for (auto p : tera) dasie[p.st][p.nd] = true; printf("TAK\n"); x ^= c; vis[a+b] = true; } else printf("NIE\n"); tera.resize(0); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define PPC(x) __builtin_popcount((x)) #define ALL(x) (x).begin(), (x).end() #define pb push_back #define st first #define nd second using namespace std; #define tera aighaoihgaos vector <vector <bool> > dasie; vector <pair <int, int> > tera; bool vis[1 << 18]; void dfs(int a, int b) { if (a < 0 or b < 0 or !dasie[a][b]) return; if (dasie[a+1][b] or dasie[a][b+1]) return; dasie[a][b] = false; tera.pb({a, b}); dfs(a-1, b); dfs(a, b-1); } int main() { int n, m, k, x = 0; scanf ("%d%d%d", &n, &m, &k); dasie.resize(n+1); FOR(i, 0, n+1) { dasie[i].resize(m+1, true); dasie[i][m] = false; } FOR(i, 0, m+1) dasie[n][i] = false; while (k--) { int a, b, c; scanf ("%d%d%d", &a, &b, &c); a = (a ^ x) % n, b = (b ^ x) % m; if (!dasie[a][b] or vis[a+b]) { printf("NIE\n"); continue; } dasie[a][b] = false; tera.pb({a, b}); dfs(a-1, b); dfs(a, b-1); if (!dasie[0][0]) { for (auto p : tera) dasie[p.st][p.nd] = true; printf("TAK\n"); x ^= c; vis[a+b] = true; } else printf("NIE\n"); tera.resize(0); } return 0; } |