fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <cstdio>
  3. #include <vector>
  4. #include <functional>
  5. #include <string>
  6. #include <algorithm>
  7. #include <set>
  8. #include <map>
  9. #include <set>
  10. #include <cstdlib>
  11. #include <cassert>
  12. #include <unordered_map>
  13. #include <unordered_set>
  14. #include <queue>
  15. #include <numeric>
  16. #include <deque>
  17. #include <random>
  18. #include <chrono>
  19. #include <ctime>
  20. #include <climits>
  21. #include <stack>
  22. #include <array>
  23. #include <iomanip>
  24. #include <complex>
  25. #include <bitset>
  26. #include <iostream>
  27. #include <cstring>
  28.  
  29. using namespace std;
  30. using ll = long long;
  31. using ld = double;
  32.  
  33. #define n_l '\n'
  34. #define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
  35. template <typename T, size_t N> int SIZE(const T(&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({ c }); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() { ; } template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); }
  36. #define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
  37.  
  38. //#define FAST_ALLOCATOR_MEMORY 2e8
  39.  
  40. #ifdef FAST_ALLOCATOR_MEMORY // 2e8
  41. int allocator_pos = 0;
  42. char allocator_memory[(int)FAST_ALLOCATOR_MEMORY];
  43. inline void * operator new (size_t n) {
  44. char *res = allocator_memory + allocator_pos;
  45. allocator_pos += n;
  46. assert(allocator_pos <= (int)FAST_ALLOCATOR_MEMORY);
  47. return (void *)res;
  48. }
  49. inline void operator delete (void *) noexcept { }
  50. //inline void * operator new [] ( size_t ) { assert(0); }
  51. //inline void operator delete [] ( void * ) { assert(0); }
  52. #endif
  53.  
  54. bool DEBUGGING = 0;
  55.  
  56. #define all(a) a.begin(), a.end()
  57. #define pii pair<int, int>
  58. #define len(a) (int)a.size()
  59. #define pb push_back
  60. #define eb emplace_back
  61. #define em emplace
  62. #define y0 withindarkness
  63. #define y1 apinklotusbloomed
  64. #define yn carryingapurplesoul
  65. #define j1 togetherformingtheTeam
  66.  
  67. /*Всё,
  68. пиздуй-бороздуй, и я попиздил, нахуй*/
  69.  
  70. void useiostream() {
  71. ios_base::sync_with_stdio(0);
  72. cin.tie(0);
  73. cout.tie(0);
  74. cerr.tie(0);
  75. }
  76.  
  77. void drop(char const *bu) {
  78. printf("%s", bu);
  79. exit(0);
  80. }
  81.  
  82. ll gcd(ll a, ll b) {
  83. return b == 0 ? a : gcd(b, a % b);
  84. }
  85.  
  86. ll lcm(ll a, ll b) {
  87. return a / gcd(a, b)*b;
  88. }
  89.  
  90. ld const pi = acos(-1.0);
  91. ld const eps = 0.000000001;
  92.  
  93. template<typename T, typename TT> bool mi(T &a, TT b) { return a > b ? (a = b, true) : false; }
  94. template<typename T, typename TT> bool ma(T &a, TT b) { return a < b ? (a = b, true) : false; }
  95.  
  96. mt19937 ran(time(0));
  97.  
  98. int const mod = (int)1e9 + 9;
  99.  
  100. int bp(int a, int p) {
  101. int re = 1;
  102. while (p) {
  103. if (p & 1)re = (re *1LL* a) % mod;
  104. p >>= 1;
  105. a = (a *1LL * a) % mod;
  106. }
  107. return re;
  108. }
  109.  
  110. int inv(int a) {
  111. return bp(a, mod - 2);
  112. }
  113.  
  114. int n, m;
  115. int arr[505][505][15];
  116. int cnt[505][15];
  117.  
  118. int main() {
  119.  
  120. #ifdef _DEBUG
  121. DEBUGGING = 1;
  122. freopen("input.txt", "r", stdin);
  123. freopen("output.txt", "w", stdout);
  124. #else
  125. //freopen("points.in", "r", stdin);
  126. //freopen("points.out", "w", stdout);
  127. #endif
  128.  
  129. useiostream();
  130. cin >> n >> m;
  131. for (int i = 0; i < n; i++) {
  132. for (int j = 0; j < m; j++) {
  133. int a;
  134. cin >> a;
  135. for (int k = 0; k < 10; k++) {
  136. arr[i][j][k] = ((a & (1 << k)) != 0);
  137. cnt[i][k]+= arr[i][j][k];
  138. }
  139. }
  140. }
  141.  
  142. for (int k = 0; k < 10; k++) {
  143. vector<int> ps(n);
  144. vector<int> res(n);
  145. for (int i = 0; i < n; i++)ps[i] = i;
  146. sort(all(ps), [&](int l, int r) {return cnt[l][k] > cnt[r][k]; });
  147. int ct = 0;
  148. int last = -1;
  149. for (int i = 0; i < n; i++) {
  150. if (cnt[ps[i]][k] == m) {
  151. ct++;
  152. last = i;
  153. }
  154. }
  155. if (ct & 1) {
  156. cout << "TAK\n";
  157. for (int i = 0; i <= last; i++) {
  158. res[ps[i]] = 1;
  159. }
  160. for (int i = last + 1; i < n; i++) {
  161. for (int j = 0; j < m; j++) {
  162. if (arr[ps[i]][j][k] == 0)res[ps[i]] = j + 1;
  163. }
  164. }
  165. for (int i = 0; i < n; i++) {
  166. cout << res[i] << " ";
  167. }
  168. return 0;
  169. }
  170. else {
  171. for (int i = last + 1; i < n && (ct % 2 )== 0; i++) {
  172. if (cnt[ps[i]][k]) {
  173. for (int j = 0; j < m; j++)if (arr[ps[i]][j][k]) {
  174. ct++;
  175.  
  176. break;
  177. }
  178. }
  179. }
  180. if (ct & 1) {
  181. cout << "TAK\n";
  182. for (int i = 0; i <= last; i++) {
  183. res[ps[i]] = 1;
  184. }
  185. bool got = 0;
  186. for (int i = last + 1; i < n; i++) {
  187. if (cnt[ps[i]][k] && !got) {
  188. got = 1;
  189. for (int j = 0; j < m; j++)if (arr[ps[i]][j][k])res[ps[i]] = j + 1;
  190. }
  191. else {
  192. for (int j = 0; j < m; j++)if (arr[ps[i]][j][k] == 0)res[ps[i]] = j + 1;
  193. }
  194. }
  195. for (int i = 0; i < n; i++) {
  196. cout << res[i] << " ";
  197. }
  198. return 0;
  199. }
  200. }
  201. }
  202.  
  203. cout << "NIE";
  204. return 0;
  205. }
Success #stdin #stdout 0s 30216KB
stdin
Standard input is empty
stdout
NIE