#include <iostream> #include <vector> #include <map> #include <set> #include <algorithm> #include <string> using namespace std; typedef long long int llint; typedef unsigned int uint; /* 3 2 0 0 0 1 2 3 2 2 3 4 1 1 2 1 3 1 1 2 TAK 1 1 NIE TAK 1 1 3 2 --- 1 2 0 0 1 0 TAK 1 1 --- 1 3 0 0 1 0 0 1 TAK 1 1 1 */ #define MAX_SIZE (2*1000*1000*1000) struct point { uint x; uint y; }; struct square : point { uint size; }; int n; vector<square> squares; point minp; point maxp; llint sqfield; bool is_ok(const uint x0, const uint y0, const uint x1, const uint y1) { for(int i=0;i<n;++i) { const point p=squares[i]; if (!(p.x==x0&&p.y==y0)&&(x0<=p.x&&p.x<=x1&&y0<=p.y&&p.y<=y1)) return false; } return true; }; void set_square_size(const int i, const uint size) { square& sq=squares[i]; sq.size=size; sqfield+=(llint)size*(llint)size; minp.x=std::min(minp.x,sq.x); minp.y=std::min(minp.y,sq.y); maxp.x=std::max(maxp.x,sq.x+size); maxp.y=std::max(maxp.y,sq.y+size); } void solve() { cin>>n; if(n==1) { cout<<"TAK 1"<<endl; return; } squares.resize(n); for(int i=0;i<n;++i) cin>>squares[i].x>>squares[i].y; minp=squares[0]; maxp=squares[0]; vector<int> big; sqfield=0; for(int i=0;i<n;++i) { const point p=squares[i]; uint lo=1; uint hi=MAX_SIZE; while(lo<hi) { const uint mid=lo+(hi-lo+1)/2; if(is_ok(p.x, p.y, p.x+mid-1, p.y+mid-1)) lo=mid; else hi=mid-1; } if(lo==MAX_SIZE) big.push_back(i); else set_square_size(i,lo); } const llint field=(llint)(maxp.x-minp.x)*(llint)(maxp.y-minp.y); if(sqfield!=field) cout<<"NIE"<<endl; else { for(int i=0;i<big.size();++i) { const int index=big[i]; const square sq=squares[index]; set_square_size(index,std::max(maxp.x-sq.x,maxp.y-sq.y)); } const llint field2=(llint)(maxp.x-minp.x)*(llint)(maxp.y-minp.y); if(sqfield!=field2) cout<<"NIE"<<endl; else { cout<<"TAK "; for(int i=0;i<squares.size();++i) cout<<squares[i].size<<" "; cout<<endl; } } } int main() { int t; cin>>t; for(int i=0;i<t;++i) solve(); 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 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | #include <iostream> #include <vector> #include <map> #include <set> #include <algorithm> #include <string> using namespace std; typedef long long int llint; typedef unsigned int uint; /* 3 2 0 0 0 1 2 3 2 2 3 4 1 1 2 1 3 1 1 2 TAK 1 1 NIE TAK 1 1 3 2 --- 1 2 0 0 1 0 TAK 1 1 --- 1 3 0 0 1 0 0 1 TAK 1 1 1 */ #define MAX_SIZE (2*1000*1000*1000) struct point { uint x; uint y; }; struct square : point { uint size; }; int n; vector<square> squares; point minp; point maxp; llint sqfield; bool is_ok(const uint x0, const uint y0, const uint x1, const uint y1) { for(int i=0;i<n;++i) { const point p=squares[i]; if (!(p.x==x0&&p.y==y0)&&(x0<=p.x&&p.x<=x1&&y0<=p.y&&p.y<=y1)) return false; } return true; }; void set_square_size(const int i, const uint size) { square& sq=squares[i]; sq.size=size; sqfield+=(llint)size*(llint)size; minp.x=std::min(minp.x,sq.x); minp.y=std::min(minp.y,sq.y); maxp.x=std::max(maxp.x,sq.x+size); maxp.y=std::max(maxp.y,sq.y+size); } void solve() { cin>>n; if(n==1) { cout<<"TAK 1"<<endl; return; } squares.resize(n); for(int i=0;i<n;++i) cin>>squares[i].x>>squares[i].y; minp=squares[0]; maxp=squares[0]; vector<int> big; sqfield=0; for(int i=0;i<n;++i) { const point p=squares[i]; uint lo=1; uint hi=MAX_SIZE; while(lo<hi) { const uint mid=lo+(hi-lo+1)/2; if(is_ok(p.x, p.y, p.x+mid-1, p.y+mid-1)) lo=mid; else hi=mid-1; } if(lo==MAX_SIZE) big.push_back(i); else set_square_size(i,lo); } const llint field=(llint)(maxp.x-minp.x)*(llint)(maxp.y-minp.y); if(sqfield!=field) cout<<"NIE"<<endl; else { for(int i=0;i<big.size();++i) { const int index=big[i]; const square sq=squares[index]; set_square_size(index,std::max(maxp.x-sq.x,maxp.y-sq.y)); } const llint field2=(llint)(maxp.x-minp.x)*(llint)(maxp.y-minp.y); if(sqfield!=field2) cout<<"NIE"<<endl; else { cout<<"TAK "; for(int i=0;i<squares.size();++i) cout<<squares[i].size<<" "; cout<<endl; } } } int main() { int t; cin>>t; for(int i=0;i<t;++i) solve(); return 0; } |