#include <iostream> #include <algorithm> #include <cmath> #include <iomanip> #include <vector> #include <utility> #include <set> #include <map> #include <bitset> #include <numeric> #define ll long long //#define index ind using namespace std; ll n, m, k, mod=0, r, c, z, X, Y; bool found=0; vector< vector<bool> > vis, visited; void isPath(ll x, ll y) { vis[y][x]=1; if(x == m && y==n) found=1; if(found) return; if(x < m && !vis[y][x+1]) isPath(x+1, y); if(y < n && !vis[y+1][x]) isPath(x, y+1); } void makeVis() { vis.clear(); vis.resize(n+1, vector<bool>(0)); for(int i=1; i<=n; i++) { vis[i].push_back(1); for(int j=1; j<=m; j++) vis[i].push_back(visited[i][j]); } } void printVis() { for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) cout << vis[i][j]; cout << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; visited.resize(n+1, vector<bool>(m+1, 0)); while(k--) { cin >> r >> c >>z; Y = (r^mod) % n; X = (c^mod) % m; X++, Y++; //tab[y][x] visited[Y][X]=1; makeVis(); found=0; //printVis(); isPath(1,1); if(found) { cout << "NIE\n"; } else { mod ^= z; visited[Y][X]=0; cout << "TAK\n"; } } return 0; } //n - wiersze, m - kolumny //ciśneimy m drzewek przedziałowych kazde o wielkosci n
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <iostream> #include <algorithm> #include <cmath> #include <iomanip> #include <vector> #include <utility> #include <set> #include <map> #include <bitset> #include <numeric> #define ll long long //#define index ind using namespace std; ll n, m, k, mod=0, r, c, z, X, Y; bool found=0; vector< vector<bool> > vis, visited; void isPath(ll x, ll y) { vis[y][x]=1; if(x == m && y==n) found=1; if(found) return; if(x < m && !vis[y][x+1]) isPath(x+1, y); if(y < n && !vis[y+1][x]) isPath(x, y+1); } void makeVis() { vis.clear(); vis.resize(n+1, vector<bool>(0)); for(int i=1; i<=n; i++) { vis[i].push_back(1); for(int j=1; j<=m; j++) vis[i].push_back(visited[i][j]); } } void printVis() { for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) cout << vis[i][j]; cout << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; visited.resize(n+1, vector<bool>(m+1, 0)); while(k--) { cin >> r >> c >>z; Y = (r^mod) % n; X = (c^mod) % m; X++, Y++; //tab[y][x] visited[Y][X]=1; makeVis(); found=0; //printVis(); isPath(1,1); if(found) { cout << "NIE\n"; } else { mod ^= z; visited[Y][X]=0; cout << "TAK\n"; } } return 0; } //n - wiersze, m - kolumny //ciśneimy m drzewek przedziałowych kazde o wielkosci n |