#include <bits/stdc++.h>
using namespace std;
bool Bajtogrom (int z, int y, set < pair <int, int> > S, bool odw[], int n, int m)
{
if (odw[m * z + y]) return true;
// cout << z << ' ' << y << "\n";
if (z == n - 1 && y == m - 1) return false;
odw[m * z + y] = true;
pair <int, int> P;
P.first = z;
P.second = y;
if (S.find(P) != S.end()) return true;
bool a, b, c = false, d = false;
++(P.first);
if (S.find(P) != S.end()) c = true;
if (z < n - 1) a = Bajtogrom (z+1, y, S, odw, n, m);
else a = true;
if (a || c)
{
--(P.first);
++(P.second);
if (S.find(P) != S.end()) d = true;
if (y < m - 1) b = Bajtogrom (z, y+1, S, odw, n, m);
else b = true;
if ((c && d) || (a && b)) return true;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k, x = 0;
cin >> n >> m >> k;
int dane[k][3];
for (int i = 0; i < k; ++i)
for (int j = 0; j < 3; ++j)
cin >> dane[i][j];
set < pair <int, int> > S;
for (int i = 0; i < k; ++i)
{
bool odw[25000001] = {false};
pair <int, int> P ((dane[i][0]^x) % n, (dane[i][1]^x) % m);
// cout << P.first << ' ' << P.second << '\n';
S.insert(P);
// cout << j << ' ' << war[j][0] << ' ' << war[j][1] << '\n';
bool czy = Bajtogrom (0, 0, S, odw, n, m);
if (czy)
{
x = x^dane[i][2];
S.erase(P);
cout << "TAK\n";
}
else cout << "NIE\n";
}
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 | #include <bits/stdc++.h> using namespace std; bool Bajtogrom (int z, int y, set < pair <int, int> > S, bool odw[], int n, int m) { if (odw[m * z + y]) return true; // cout << z << ' ' << y << "\n"; if (z == n - 1 && y == m - 1) return false; odw[m * z + y] = true; pair <int, int> P; P.first = z; P.second = y; if (S.find(P) != S.end()) return true; bool a, b, c = false, d = false; ++(P.first); if (S.find(P) != S.end()) c = true; if (z < n - 1) a = Bajtogrom (z+1, y, S, odw, n, m); else a = true; if (a || c) { --(P.first); ++(P.second); if (S.find(P) != S.end()) d = true; if (y < m - 1) b = Bajtogrom (z, y+1, S, odw, n, m); else b = true; if ((c && d) || (a && b)) return true; } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, k, x = 0; cin >> n >> m >> k; int dane[k][3]; for (int i = 0; i < k; ++i) for (int j = 0; j < 3; ++j) cin >> dane[i][j]; set < pair <int, int> > S; for (int i = 0; i < k; ++i) { bool odw[25000001] = {false}; pair <int, int> P ((dane[i][0]^x) % n, (dane[i][1]^x) % m); // cout << P.first << ' ' << P.second << '\n'; S.insert(P); // cout << j << ' ' << war[j][0] << ' ' << war[j][1] << '\n'; bool czy = Bajtogrom (0, 0, S, odw, n, m); if (czy) { x = x^dane[i][2]; S.erase(P); cout << "TAK\n"; } else cout << "NIE\n"; } return 0; } |
English