#include <bits/stdc++.h> #define DEBUG if(0) #define COUT cout << "\e[36m" #define ENDL "\e[39m" << endl #define VAR(v) " [\e[32m" << #v << "\e[36m=\e[91m" << v << "\e[36m] " using namespace std; int n, m, X; struct Vertex { bool castle = 0; bool visited = 0; }; vector<vector<Vertex>> mapa; bool pathfinder(int vx, int vy) { if(mapa[vx][vy].visited) return 0; mapa[vx][vy].visited = 1; if(mapa[vx][vy].castle) return 0; if(vx == 0 && vy== 0) return 1; if((vx > 0 && pathfinder(vx-1, vy)) || (vy > 0 && pathfinder(vx, vy-1))) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int q; cin >> n >> m >> q; mapa.resize(n, vector<Vertex>(m)); for (int qi = 0; qi < q; ++qi) { int r, c, z; cin >> r >> c >> z; mapa[(r^X)%n][(c^X)%m].castle = 1; DEBUG COUT << VAR(qi) << VAR((r^X)%n) << VAR((c^X)%m) << VAR(X) << ENDL; for(auto& el : mapa) for(auto& elel : el) elel.visited = 0; if(!pathfinder(n-1, m-1)) { mapa[(r^X)%n][(c^X)%m].castle = 0; X = X^z; DEBUG COUT << "GROM " << VAR(X) << ENDL; 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 65 66 | #include <bits/stdc++.h> #define DEBUG if(0) #define COUT cout << "\e[36m" #define ENDL "\e[39m" << endl #define VAR(v) " [\e[32m" << #v << "\e[36m=\e[91m" << v << "\e[36m] " using namespace std; int n, m, X; struct Vertex { bool castle = 0; bool visited = 0; }; vector<vector<Vertex>> mapa; bool pathfinder(int vx, int vy) { if(mapa[vx][vy].visited) return 0; mapa[vx][vy].visited = 1; if(mapa[vx][vy].castle) return 0; if(vx == 0 && vy== 0) return 1; if((vx > 0 && pathfinder(vx-1, vy)) || (vy > 0 && pathfinder(vx, vy-1))) return 1; return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int q; cin >> n >> m >> q; mapa.resize(n, vector<Vertex>(m)); for (int qi = 0; qi < q; ++qi) { int r, c, z; cin >> r >> c >> z; mapa[(r^X)%n][(c^X)%m].castle = 1; DEBUG COUT << VAR(qi) << VAR((r^X)%n) << VAR((c^X)%m) << VAR(X) << ENDL; for(auto& el : mapa) for(auto& elel : el) elel.visited = 0; if(!pathfinder(n-1, m-1)) { mapa[(r^X)%n][(c^X)%m].castle = 0; X = X^z; DEBUG COUT << "GROM " << VAR(X) << ENDL; cout << "TAK\n"; } else { cout << "NIE\n"; } } return 0; } |