#include <bits/stdc++.h> using namespace std; #define FOR(i,a,n) for (decltype(n) i = (a), i ## __ = (n); i <= i ## __; ++i) #define FORD(i,a,n) for (decltype(n) i = (a), i ## __ = (n); i >= i ## __; --i) #define REP(i,n) FOR(i, 0, n - 1) #define REPD(i, n) FORD(i, n - 1, 0) #define ALL(x) x.begin(), x.end() #define SZ(x) (int(x.size())) #define EB emplace_back #define V vector #define ST first #define ND second #define RS resize template<class T, class B> inline void mini(T &&a, B &&b) { if (b < a) a = b; } template<class T, class B> inline void maxi(T &&a, B &&b) { if (b > a) a = b; } int ceil2(int x) { return x < 2 ? 1 : 1 << (sizeof(x) * 8 - __builtin_clz(x - 1)); } constexpr char nl = '\n'; template<class T> struct DumpOff { T a, b; }; template<class T> auto dumpOff(T &x) -> DumpOff<decltype(x.begin())> { return {x.begin(), x.end()}; } template<class T> auto dumpOff(T &x) -> decltype(cerr << x, x) { return x; } template<class T> auto dumpOff(T &x) -> decltype(x.first, x) { return x; } struct Debug { ~Debug() { cerr << nl; } template<class T> auto operator<<(T x) -> decltype(cerr << x, *this) { cerr << dumpOff(x); return *this; } template<class T> auto operator<<(T x) -> decltype(x.begin(), *this) { cerr << "{\n"; for (auto a = x.begin(), b = x.end(); a != b; ++a) *this << " " << distance(x.begin(), a) << ": " << dumpOff(*a) << '\n'; return *this << "}"; } template<class T, class B> Debug& operator<<(pair<T, B> p) { return *this << "(" << dumpOff(p.first) << ", " << dumpOff(p.second) << ")"; } template<class T> Debug& operator<<(DumpOff<T> d) { cerr << "{"; for (auto a = d.a, b = d.b; a != b; ++a) *this << dumpOff(*a) << (next(a) == b ? "" : ", "); return *this << "}"; } }; struct Foo {template<class T>Foo& operator<<(T) {return *this;}}; #ifdef DEBUG # define D Debug() #else # define D Foo() #endif #define I(x...) #x ": " << x << " " typedef long long LL; typedef pair<LL, LL> PII; typedef V<int> VI; typedef V<VI> VVI; typedef V<PII> VPII; typedef V<VPII> VVPII; typedef V<bool> VB; typedef V<VB> VVB; typedef V<LL> VLL; typedef V<VLL> VVLL; #define INF 2000000001 struct point { LL x, y; int id; point(LL a, LL b, int c) {x = a, y = b, id = c;} point() {} }; struct edge { LL begin, end; LL y; edge(LL a, LL b, LL c) {begin = a, end = b, y = c;} edge() {} }; bool comp(point i, point j) { if(i.y != j.y) return i.y > j.y; return i.x < j.x; } ostream& operator<<(ostream &os, point &a) { return os << "(" << a.x << ", " << a.y << "), id: " << a.id; } ostream& operator<<(ostream &os, edge &a) { return os << "(" << a.begin << ", " << a.end << "), y: " << a.y; } int main() { ios_base::sync_with_stdio(0); int t; cin >> t; REP(q, t) { bool OK = 0; int n; cin >> n; V<point> points(n); REP(i, n) { cin >> points[i].x >> points[i].y; points[i].id = i; } // D << I(points); REP(q, 2) { if(q == 1) REP(i, n) swap(points[i].x, points[i].y); sort(ALL(points), comp); point upperleft(INF, -INF, 0); point bottomleft(INF, INF, 0); point upperright(-INF, -INF, 0); LL bottom = INF, left = INF; REP(i, n) { if(bottomleft.x > points[i].x && bottomleft.y > points[i].y) bottomleft = points[i]; if((points[i].x < upperleft.x) || (points[i].x == upperleft.x && points[i].y > upperleft.y)) upperleft = points[i]; if((points[i].x > upperright.x) || (points[i].x == upperright.x && points[i].y > upperright.y)) upperright = points[i]; mini(left, points[i].x); mini(bottom, points[i].y); } if(bottomleft.x != left && bottomleft.y != bottom) continue; // D << I(upperleft) << I(upperright); REP(i, n) { LL top = upperleft.y + (points[i].x - upperleft.x); // D << I(points[i].x); V<edge> edges; VLL ans(n); LL sum = 0; LL right = -INF; bool vaild = 1; REP(j, n) { LL t = top; // D << I(points[i]); // D << I(edges); REP(k, SZ(edges)) if(edges[k].begin <= points[j].x && edges[k].end > points[j].x) mini(t, edges[k].y); // if(edges[k].begin < points[j].x + edges[k].y - points[j].y && edges[k].end > points[j].x) // mini(t, edges[k].y); LL size = t - points[j].y; if(size < 1) { vaild = 0; break; } edges.EB(points[j].x, points[j].x + size, points[j].y); ans[points[j].id] = size; sum += size * size; maxi(right, points[j].x + size); } if(!vaild) continue; if(sum == (right - left) * (top - bottom)) { // D << I(sum) << I(right) << I(left) << I(top) << I(bottom); bool kupa = 0; REP(i, n) REP(j, n) { if(i == j) continue; LL ix1 = points[i].x; LL ix2 = points[i].x + ans[points[i].id]; LL iy1 = points[i].y; LL iy2 = points[i].y + ans[points[i].id]; LL jx1 = points[j].x; LL jx2 = points[j].x + ans[points[j].id]; LL jy1 = points[j].y; LL jy2 = points[j].y + ans[points[j].id]; if(jx1 < ix1 && ix1 < jx2 && jy1 < iy1 && iy1 < jy2) kupa = 1; if(jx1 < ix1 && ix1 < jx2 && jy1 < iy2 && iy2 < jy2) kupa = 1; if(jx1 < ix2 && ix2 < jx2 && jy1 < iy1 && iy1 < jy2) kupa = 1; if(jx1 < ix2 && ix2 < jx2 && jy1 < iy2 && iy2 < jy2) kupa = 1; if(ix1 < jx1 && jx1 < ix2 && iy1 < jy1 && jy1 < iy2) kupa = 1; if(ix1 < jx1 && jx1 < ix2 && iy1 < jy2 && jy2 < iy2) kupa = 1; if(ix1 < jx2 && jx2 < ix2 && iy1 < jy1 && jy1 < iy2) kupa = 1; if(ix1 < jx2 && jx2 < ix2 && iy1 < jy2 && jy2 < iy2) kupa = 1; } if(!kupa) { cout << "TAK "; REP(i, n) cout << ans[i] << " "; cout << "\n"; OK = 1; break; } } } if(OK) break; } if(!OK) cout << "NIE\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 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | #include <bits/stdc++.h> using namespace std; #define FOR(i,a,n) for (decltype(n) i = (a), i ## __ = (n); i <= i ## __; ++i) #define FORD(i,a,n) for (decltype(n) i = (a), i ## __ = (n); i >= i ## __; --i) #define REP(i,n) FOR(i, 0, n - 1) #define REPD(i, n) FORD(i, n - 1, 0) #define ALL(x) x.begin(), x.end() #define SZ(x) (int(x.size())) #define EB emplace_back #define V vector #define ST first #define ND second #define RS resize template<class T, class B> inline void mini(T &&a, B &&b) { if (b < a) a = b; } template<class T, class B> inline void maxi(T &&a, B &&b) { if (b > a) a = b; } int ceil2(int x) { return x < 2 ? 1 : 1 << (sizeof(x) * 8 - __builtin_clz(x - 1)); } constexpr char nl = '\n'; template<class T> struct DumpOff { T a, b; }; template<class T> auto dumpOff(T &x) -> DumpOff<decltype(x.begin())> { return {x.begin(), x.end()}; } template<class T> auto dumpOff(T &x) -> decltype(cerr << x, x) { return x; } template<class T> auto dumpOff(T &x) -> decltype(x.first, x) { return x; } struct Debug { ~Debug() { cerr << nl; } template<class T> auto operator<<(T x) -> decltype(cerr << x, *this) { cerr << dumpOff(x); return *this; } template<class T> auto operator<<(T x) -> decltype(x.begin(), *this) { cerr << "{\n"; for (auto a = x.begin(), b = x.end(); a != b; ++a) *this << " " << distance(x.begin(), a) << ": " << dumpOff(*a) << '\n'; return *this << "}"; } template<class T, class B> Debug& operator<<(pair<T, B> p) { return *this << "(" << dumpOff(p.first) << ", " << dumpOff(p.second) << ")"; } template<class T> Debug& operator<<(DumpOff<T> d) { cerr << "{"; for (auto a = d.a, b = d.b; a != b; ++a) *this << dumpOff(*a) << (next(a) == b ? "" : ", "); return *this << "}"; } }; struct Foo {template<class T>Foo& operator<<(T) {return *this;}}; #ifdef DEBUG # define D Debug() #else # define D Foo() #endif #define I(x...) #x ": " << x << " " typedef long long LL; typedef pair<LL, LL> PII; typedef V<int> VI; typedef V<VI> VVI; typedef V<PII> VPII; typedef V<VPII> VVPII; typedef V<bool> VB; typedef V<VB> VVB; typedef V<LL> VLL; typedef V<VLL> VVLL; #define INF 2000000001 struct point { LL x, y; int id; point(LL a, LL b, int c) {x = a, y = b, id = c;} point() {} }; struct edge { LL begin, end; LL y; edge(LL a, LL b, LL c) {begin = a, end = b, y = c;} edge() {} }; bool comp(point i, point j) { if(i.y != j.y) return i.y > j.y; return i.x < j.x; } ostream& operator<<(ostream &os, point &a) { return os << "(" << a.x << ", " << a.y << "), id: " << a.id; } ostream& operator<<(ostream &os, edge &a) { return os << "(" << a.begin << ", " << a.end << "), y: " << a.y; } int main() { ios_base::sync_with_stdio(0); int t; cin >> t; REP(q, t) { bool OK = 0; int n; cin >> n; V<point> points(n); REP(i, n) { cin >> points[i].x >> points[i].y; points[i].id = i; } // D << I(points); REP(q, 2) { if(q == 1) REP(i, n) swap(points[i].x, points[i].y); sort(ALL(points), comp); point upperleft(INF, -INF, 0); point bottomleft(INF, INF, 0); point upperright(-INF, -INF, 0); LL bottom = INF, left = INF; REP(i, n) { if(bottomleft.x > points[i].x && bottomleft.y > points[i].y) bottomleft = points[i]; if((points[i].x < upperleft.x) || (points[i].x == upperleft.x && points[i].y > upperleft.y)) upperleft = points[i]; if((points[i].x > upperright.x) || (points[i].x == upperright.x && points[i].y > upperright.y)) upperright = points[i]; mini(left, points[i].x); mini(bottom, points[i].y); } if(bottomleft.x != left && bottomleft.y != bottom) continue; // D << I(upperleft) << I(upperright); REP(i, n) { LL top = upperleft.y + (points[i].x - upperleft.x); // D << I(points[i].x); V<edge> edges; VLL ans(n); LL sum = 0; LL right = -INF; bool vaild = 1; REP(j, n) { LL t = top; // D << I(points[i]); // D << I(edges); REP(k, SZ(edges)) if(edges[k].begin <= points[j].x && edges[k].end > points[j].x) mini(t, edges[k].y); // if(edges[k].begin < points[j].x + edges[k].y - points[j].y && edges[k].end > points[j].x) // mini(t, edges[k].y); LL size = t - points[j].y; if(size < 1) { vaild = 0; break; } edges.EB(points[j].x, points[j].x + size, points[j].y); ans[points[j].id] = size; sum += size * size; maxi(right, points[j].x + size); } if(!vaild) continue; if(sum == (right - left) * (top - bottom)) { // D << I(sum) << I(right) << I(left) << I(top) << I(bottom); bool kupa = 0; REP(i, n) REP(j, n) { if(i == j) continue; LL ix1 = points[i].x; LL ix2 = points[i].x + ans[points[i].id]; LL iy1 = points[i].y; LL iy2 = points[i].y + ans[points[i].id]; LL jx1 = points[j].x; LL jx2 = points[j].x + ans[points[j].id]; LL jy1 = points[j].y; LL jy2 = points[j].y + ans[points[j].id]; if(jx1 < ix1 && ix1 < jx2 && jy1 < iy1 && iy1 < jy2) kupa = 1; if(jx1 < ix1 && ix1 < jx2 && jy1 < iy2 && iy2 < jy2) kupa = 1; if(jx1 < ix2 && ix2 < jx2 && jy1 < iy1 && iy1 < jy2) kupa = 1; if(jx1 < ix2 && ix2 < jx2 && jy1 < iy2 && iy2 < jy2) kupa = 1; if(ix1 < jx1 && jx1 < ix2 && iy1 < jy1 && jy1 < iy2) kupa = 1; if(ix1 < jx1 && jx1 < ix2 && iy1 < jy2 && jy2 < iy2) kupa = 1; if(ix1 < jx2 && jx2 < ix2 && iy1 < jy1 && jy1 < iy2) kupa = 1; if(ix1 < jx2 && jx2 < ix2 && iy1 < jy2 && jy2 < iy2) kupa = 1; } if(!kupa) { cout << "TAK "; REP(i, n) cout << ans[i] << " "; cout << "\n"; OK = 1; break; } } } if(OK) break; } if(!OK) cout << "NIE\n"; } } |