#include <iostream>
using namespace std;
bool arr[2001][2001];
bool visited[2001][2001];
int n, m, k;
bool path(int x, int y) {
if (x >= n || y >= m || arr[x][y] == true) return false;
if (x == n - 1 && y == m - 1) return true;
visited[x][y] = true;
bool res = false;
if (!visited[x + 1][y]) res |= path(x + 1, y);
if (!visited[x][y + 1]) res |= path(x, y + 1);
return res;
}
int main() {
cin>>n>>m>>k;
int a, b, c, x = 0;
while (k--) {
cin>>a>>b>>c;
a = (a ^ x) % n;
b = (b ^ x) % m;
arr[a][b] = true;
if (path(0, 0)) {
cout<<"NIE"<<endl;
} else {
cout<<"TAK"<<endl;
arr[a][b] = false;
x ^= c;
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
visited[i][j] = false;
}
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 | #include <iostream> using namespace std; bool arr[2001][2001]; bool visited[2001][2001]; int n, m, k; bool path(int x, int y) { if (x >= n || y >= m || arr[x][y] == true) return false; if (x == n - 1 && y == m - 1) return true; visited[x][y] = true; bool res = false; if (!visited[x + 1][y]) res |= path(x + 1, y); if (!visited[x][y + 1]) res |= path(x, y + 1); return res; } int main() { cin>>n>>m>>k; int a, b, c, x = 0; while (k--) { cin>>a>>b>>c; a = (a ^ x) % n; b = (b ^ x) % m; arr[a][b] = true; if (path(0, 0)) { cout<<"NIE"<<endl; } else { cout<<"TAK"<<endl; arr[a][b] = false; x ^= c; } for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) visited[i][j] = false; } return 0; } |
English