fork download
  1. #include "Bruno.h"
  2. #include <vector>
  3.  
  4. #include <bits/stdc++.h>
  5. #define MP make_pair
  6. #define PB push_back
  7. #define st first
  8. #define nd second
  9. #define rd third
  10. #define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
  11. #define RE(i, n) FOR(i, 1, n)
  12. #define FORD(i, a, b) for(int i = (a); i >= (b); --i)
  13. #define REP(i, n) for(int i = 0;i <(n); ++i)
  14. #define VAR(v, i) __typeof(i) v=(i)
  15. #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
  16. #define ALL(x) (x).begin(), (x).end()
  17. #define SZ(x) ((int)(x).size())
  18. #define __builtin_ctz __builtin_ctzll
  19. #define __builtin_clz __builtin_clzll
  20. #define __builtin_popcount __builtin_popcountll
  21. using namespace std;
  22. template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
  23. template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  24. while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
  25. }
  26. #ifdef LOCAL
  27. #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
  28. #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
  29. #else
  30. #define debug(...) (__VA_ARGS__)
  31. #define debugv(x)
  32. #define cerr if(0)cout
  33. #endif
  34. #define next ____next
  35. #define prev ____prev
  36. #define left ____left
  37. #define hash ____hash
  38. typedef long long ll;
  39. typedef long double LD;
  40. typedef pair<int, int> PII;
  41. typedef pair<ll, ll> PLL;
  42. typedef vector<int> VI;
  43. typedef vector<VI> VVI;
  44. typedef vector<ll> VLL;
  45. typedef vector<pair<int, int> > VPII;
  46. typedef vector<pair<ll, ll> > VPLL;
  47.  
  48. template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
  49. template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
  50. template<class T1, class T2>
  51. ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
  52. template<class A, class B, class C> struct Triple { A first; B second; C third;
  53. bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
  54. template<class T> void ResizeVec(T&, vector<int>) {}
  55. template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  56. vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  57. for (T& v : vec) { ResizeVec(v, sz); }
  58. }
  59. typedef Triple<int, int, int> TIII;
  60. template<class A, class B, class C>
  61. ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
  62. template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  63. template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  64. template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  65.  
  66. namespace {
  67.  
  68. PII GetAnchor(PII A, PII B) {
  69. VPII vecs{{0, 1}, {1, -1}, {1, 0}, {1, 1}};
  70. for (auto v : vecs) {
  71. if ((A.st + v.st - B.st) % 3 == 0 && (A.nd + v.nd - B.nd) % 3 == 0) {
  72. return A;
  73. }
  74. }
  75. return B;
  76. }
  77. } // namespace
  78.  
  79. int Go(int sr, int sc, int tr, int tc) {
  80. if (tr < sr) {
  81. return 3;
  82. } else if (tr > sr) {
  83. return 2;
  84. } else if (tc > sc) {
  85. return 0;
  86. } else if (tc < sc) {
  87. return 1;
  88. }
  89. return 4;
  90. }
  91. std::vector<int> Bruno(int K, std::vector<int> value) {
  92. vector<int> res(K);
  93. vector<VI> flags(3, VI(3));
  94. int nxt = 0;
  95. REP (i, 3) {
  96. REP (j, 3) {
  97. flags[i][j] = value[nxt++];
  98. }
  99. }
  100. int fr, fc;
  101. int r3, c3;
  102. VPII nons;
  103. REP (i, 3) {
  104. REP (j, 3) {
  105. if (flags[i][j] == 12) {
  106. nons.PB({i, j});
  107. }
  108. }
  109. }
  110. assert(SZ(nons) == 2);
  111. if (GetAnchor(nons[0], nons[1]) != nons[0]) {
  112. swap(nons[0], nons[1]);
  113. }
  114. VPII wh;
  115. REP (i, 3) {
  116. REP (j, 3) {
  117. if (i == 0 && j == 0) { continue; }
  118. int ni = (nons[0].st + i) % 3;
  119. int nj = (nons[0].nd + j) % 3;
  120. if (ni == nons[1].st && nj == nons[1].nd) { continue; }
  121. wh.PB({ni, nj});
  122. }
  123. }
  124. debug(wh);
  125. //vector<PII> heh{{0, 2}, {1, 0}, {1, 1}, {1, 2}, {2, 0}, {2, 1}, {2, 2}};
  126. REP (goal, K) {
  127. int r = wh[goal].st;
  128. int c = wh[goal].nd;
  129. int val = flags[r][c];
  130. if (val == 8) { res[goal] = 2; continue; }
  131. if (val == 9) { res[goal] = 3; continue; }
  132. if (val == 10) { res[goal] = 0; continue; }
  133. if (val == 11) { res[goal] = 1; continue; }
  134. //int tr = -1, tc = -1;
  135. int nxt = 1;
  136. FOR (dr, -1, 1) {
  137. FOR (dc, -1, 1) {
  138. int nr = (r + dr + 3) % 3;
  139. int nc = (c + dc + 3) % 3;
  140. int fail = 0;
  141. REP (tr, 2) {
  142. if (nr == nons[tr].st && nc == nons[tr].nd) { fail = 1; }
  143. }
  144. if (fail) { continue; }
  145. if (val == nxt) {
  146. res[goal] = Go(1, 1, r + dr, c + dc);
  147. // res[goal] = 4;
  148. // if (dr == 1) { res[goal] = 2; }
  149. // if (dr == -1) { res[goal] = 3; }
  150. // if (dc == 1) { res[goal] = 0; }
  151. // if (dc == -1) { res[goal] = 1; }
  152. }
  153. nxt++;
  154. }
  155. }
  156. }
  157. debug(value);
  158. debug(res);
  159. return res;
  160. }
  161.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: fatal error: Bruno.h: No such file or directory
 #include "Bruno.h"
          ^~~~~~~~~
compilation terminated.
stdout
Standard output is empty