fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define rep(i,n) for(int i=0;i<(n);++i)
  5. #define loop for(;;)
  6. #define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
  7. #define all(v) begin(v),end(v)
  8. #define pb push_back
  9. #define inf (1e9)
  10. #define eps (1e-9)
  11. using Integer = long long;
  12. using Real = long double;
  13. const Real PI = acosl(-1);
  14. using P = pair<int, int>;
  15.  
  16. template<class S, class T> inline
  17. ostream& operator<<(ostream&os, pair<S,T> p) {
  18. return os << '(' << p.first << ", " << p.second << ')';
  19. }
  20.  
  21. template<class S, class T, class U> inline
  22. ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  23. return os << '('
  24. << get<0>(t) << ", "
  25. << get<1>(t) << ", "
  26. << get<2>(t) << ')';
  27. }
  28.  
  29. template<class T> inline
  30. ostream& operator<<(ostream&os, set<T> v) {
  31. os << "(set";
  32. for (T item: v) os << ' ' << item;
  33. os << ")";
  34. return os;
  35. }
  36.  
  37. template<class T> inline
  38. ostream& operator<<(ostream&os, vector<T> v) {
  39. if (v.size() == 0) { return os << "(empty)"; }
  40. os << v[0];
  41. for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  42. return os;
  43. }
  44.  
  45. template<class T> inline
  46. istream& operator>>(istream&is, vector<T>&v) {
  47. rep (i, v.size()) is >> v[i];
  48. return is;
  49. }
  50.  
  51. // ^ > v <
  52. int dx[] = { -1, 0, 1, 0 };
  53. int dy[] = { 0, 1, 0, -1 };
  54.  
  55. using vi = vector<int>;
  56. using vvi = vector<vi>;
  57. using vd = vector<double>;
  58. using vvd = vector<vd>;
  59. using vb = vector<bool>;
  60.  
  61. int f[5][5][5][5];
  62.  
  63. int main() {
  64. cin.tie(0);
  65. ios::sync_with_stdio(0);
  66. cout.setf(ios::fixed);
  67. cout.precision(10);
  68. random_device dev;
  69. mt19937 rand(dev());
  70.  
  71. stack<tuple<int,int,int,int>> s;
  72.  
  73. for (int i = 1; i < 5; ++i) {
  74. rep (j, 5) {
  75. s.push(make_tuple(0, 0, i, j));
  76. f[0][0][i][j] = -1;
  77. }
  78. }
  79.  
  80. while (not s.empty()) {
  81. auto t = s.top(); s.pop();
  82. int i = get<0>(t);
  83. int j = get<1>(t);
  84. int k = get<2>(t);
  85. int l = get<3>(t);
  86. int b = f[i][j][k][l];
  87. if (b == 0) continue;
  88. if (k != 0) {
  89. int i2 = (i+5-k)%5;
  90. if (i2 > 0 and f[k][l][i2][j] != 1) {
  91. f[k][l][i2][j] = -b;
  92. s.push(make_tuple(k, l, i2, j)); // k beats i2
  93. }
  94. int j2 = (j+5-k)%5;
  95. if (j2 > 0 and f[k][l][i][j2] != 1) {
  96. f[k][l][i][j2] = -b;
  97. s.push(make_tuple(k, l, i, j2));
  98. }
  99. }
  100. if (l != 0) {
  101. int i2 = (i+5-k)%5;
  102. if (i2 > 0 and f[k][l][i2][j] != 1) {
  103. f[k][l][i2][j] = -b;
  104. s.push(make_tuple(k, l, i2, j));
  105. }
  106. int j2 = (j+5-k)%5;
  107. if (j2 > 0 and f[k][l][i][j2] != 1) {
  108. f[k][l][i][j2] = -b;
  109. s.push(make_tuple(k, l, i, j2));
  110. }
  111. }
  112. }
  113.  
  114. rep (i, 5)
  115. rep (j, i+1)
  116. rep (k, 5)
  117. rep (l, k+1) {
  118. cout << make_pair(i,j) << ", " << make_pair(k,l)
  119. << " -- " << f[i][j][k][l] << endl;
  120. }
  121.  
  122. return 0;
  123. }
  124.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
(0, 0), (0, 0) -- 0
(0, 0), (1, 0) -- -1
(0, 0), (1, 1) -- -1
(0, 0), (2, 0) -- -1
(0, 0), (2, 1) -- -1
(0, 0), (2, 2) -- -1
(0, 0), (3, 0) -- -1
(0, 0), (3, 1) -- -1
(0, 0), (3, 2) -- -1
(0, 0), (3, 3) -- -1
(0, 0), (4, 0) -- -1
(0, 0), (4, 1) -- -1
(0, 0), (4, 2) -- -1
(0, 0), (4, 3) -- -1
(0, 0), (4, 4) -- -1
(1, 0), (0, 0) -- 0
(1, 0), (1, 0) -- 1
(1, 0), (1, 1) -- 1
(1, 0), (2, 0) -- 0
(1, 0), (2, 1) -- 1
(1, 0), (2, 2) -- 1
(1, 0), (3, 0) -- -1
(1, 0), (3, 1) -- -1
(1, 0), (3, 2) -- -1
(1, 0), (3, 3) -- -1
(1, 0), (4, 0) -- 1
(1, 0), (4, 1) -- 1
(1, 0), (4, 2) -- 1
(1, 0), (4, 3) -- 1
(1, 0), (4, 4) -- 1
(1, 1), (0, 0) -- 0
(1, 1), (1, 0) -- -1
(1, 1), (1, 1) -- 1
(1, 1), (2, 0) -- 1
(1, 1), (2, 1) -- -1
(1, 1), (2, 2) -- 1
(1, 1), (3, 0) -- -1
(1, 1), (3, 1) -- 1
(1, 1), (3, 2) -- -1
(1, 1), (3, 3) -- 1
(1, 1), (4, 0) -- 1
(1, 1), (4, 1) -- 1
(1, 1), (4, 2) -- 1
(1, 1), (4, 3) -- 1
(1, 1), (4, 4) -- 1
(2, 0), (0, 0) -- 0
(2, 0), (1, 0) -- -1
(2, 0), (1, 1) -- 1
(2, 0), (2, 0) -- 1
(2, 0), (2, 1) -- -1
(2, 0), (2, 2) -- -1
(2, 0), (3, 0) -- 1
(2, 0), (3, 1) -- 1
(2, 0), (3, 2) -- 1
(2, 0), (3, 3) -- 1
(2, 0), (4, 0) -- 0
(2, 0), (4, 1) -- -1
(2, 0), (4, 2) -- -1
(2, 0), (4, 3) -- 1
(2, 0), (4, 4) -- -1
(2, 1), (0, 0) -- 0
(2, 1), (1, 0) -- -1
(2, 1), (1, 1) -- -1
(2, 1), (2, 0) -- 1
(2, 1), (2, 1) -- 1
(2, 1), (2, 2) -- -1
(2, 1), (3, 0) -- 1
(2, 1), (3, 1) -- 1
(2, 1), (3, 2) -- 1
(2, 1), (3, 3) -- 1
(2, 1), (4, 0) -- -1
(2, 1), (4, 1) -- 1
(2, 1), (4, 2) -- 1
(2, 1), (4, 3) -- 1
(2, 1), (4, 4) -- -1
(2, 2), (0, 0) -- 0
(2, 2), (1, 0) -- -1
(2, 2), (1, 1) -- 1
(2, 2), (2, 0) -- -1
(2, 2), (2, 1) -- 1
(2, 2), (2, 2) -- 1
(2, 2), (3, 0) -- 1
(2, 2), (3, 1) -- 1
(2, 2), (3, 2) -- 1
(2, 2), (3, 3) -- 1
(2, 2), (4, 0) -- 1
(2, 2), (4, 1) -- -1
(2, 2), (4, 2) -- -1
(2, 2), (4, 3) -- 1
(2, 2), (4, 4) -- 1
(3, 0), (0, 0) -- 0
(3, 0), (1, 0) -- 0
(3, 0), (1, 1) -- 1
(3, 0), (2, 0) -- 1
(3, 0), (2, 1) -- 1
(3, 0), (2, 2) -- 1
(3, 0), (3, 0) -- 1
(3, 0), (3, 1) -- 1
(3, 0), (3, 2) -- 1
(3, 0), (3, 3) -- 1
(3, 0), (4, 0) -- -1
(3, 0), (4, 1) -- -1
(3, 0), (4, 2) -- -1
(3, 0), (4, 3) -- -1
(3, 0), (4, 4) -- -1
(3, 1), (0, 0) -- 0
(3, 1), (1, 0) -- -1
(3, 1), (1, 1) -- 1
(3, 1), (2, 0) -- 1
(3, 1), (2, 1) -- 1
(3, 1), (2, 2) -- 1
(3, 1), (3, 0) -- 1
(3, 1), (3, 1) -- 1
(3, 1), (3, 2) -- 1
(3, 1), (3, 3) -- 1
(3, 1), (4, 0) -- 1
(3, 1), (4, 1) -- 1
(3, 1), (4, 2) -- 1
(3, 1), (4, 3) -- 1
(3, 1), (4, 4) -- 1
(3, 2), (0, 0) -- 0
(3, 2), (1, 0) -- 1
(3, 2), (1, 1) -- -1
(3, 2), (2, 0) -- 1
(3, 2), (2, 1) -- 1
(3, 2), (2, 2) -- 1
(3, 2), (3, 0) -- 1
(3, 2), (3, 1) -- 1
(3, 2), (3, 2) -- 1
(3, 2), (3, 3) -- 1
(3, 2), (4, 0) -- 1
(3, 2), (4, 1) -- 1
(3, 2), (4, 2) -- 1
(3, 2), (4, 3) -- 1
(3, 2), (4, 4) -- 1
(3, 3), (0, 0) -- 0
(3, 3), (1, 0) -- 1
(3, 3), (1, 1) -- 1
(3, 3), (2, 0) -- 1
(3, 3), (2, 1) -- 1
(3, 3), (2, 2) -- 1
(3, 3), (3, 0) -- 1
(3, 3), (3, 1) -- 1
(3, 3), (3, 2) -- 1
(3, 3), (3, 3) -- 1
(3, 3), (4, 0) -- 1
(3, 3), (4, 1) -- 1
(3, 3), (4, 2) -- 1
(3, 3), (4, 3) -- 1
(3, 3), (4, 4) -- 1
(4, 0), (0, 0) -- 0
(4, 0), (1, 0) -- 1
(4, 0), (1, 1) -- 1
(4, 0), (2, 0) -- -1
(4, 0), (2, 1) -- -1
(4, 0), (2, 2) -- 1
(4, 0), (3, 0) -- 0
(4, 0), (3, 1) -- 1
(4, 0), (3, 2) -- -1
(4, 0), (3, 3) -- -1
(4, 0), (4, 0) -- 1
(4, 0), (4, 1) -- -1
(4, 0), (4, 2) -- -1
(4, 0), (4, 3) -- -1
(4, 0), (4, 4) -- -1
(4, 1), (0, 0) -- 0
(4, 1), (1, 0) -- 1
(4, 1), (1, 1) -- 1
(4, 1), (2, 0) -- 1
(4, 1), (2, 1) -- 1
(4, 1), (2, 2) -- 1
(4, 1), (3, 0) -- 1
(4, 1), (3, 1) -- 1
(4, 1), (3, 2) -- 1
(4, 1), (3, 3) -- -1
(4, 1), (4, 0) -- 1
(4, 1), (4, 1) -- 1
(4, 1), (4, 2) -- -1
(4, 1), (4, 3) -- 1
(4, 1), (4, 4) -- 1
(4, 2), (0, 0) -- 0
(4, 2), (1, 0) -- 1
(4, 2), (1, 1) -- 1
(4, 2), (2, 0) -- 1
(4, 2), (2, 1) -- 1
(4, 2), (2, 2) -- 1
(4, 2), (3, 0) -- 1
(4, 2), (3, 1) -- 1
(4, 2), (3, 2) -- 1
(4, 2), (3, 3) -- -1
(4, 2), (4, 0) -- 1
(4, 2), (4, 1) -- 1
(4, 2), (4, 2) -- 1
(4, 2), (4, 3) -- -1
(4, 2), (4, 4) -- 1
(4, 3), (0, 0) -- 0
(4, 3), (1, 0) -- 1
(4, 3), (1, 1) -- 1
(4, 3), (2, 0) -- 1
(4, 3), (2, 1) -- 1
(4, 3), (2, 2) -- 1
(4, 3), (3, 0) -- -1
(4, 3), (3, 1) -- 1
(4, 3), (3, 2) -- -1
(4, 3), (3, 3) -- 1
(4, 3), (4, 0) -- 1
(4, 3), (4, 1) -- 1
(4, 3), (4, 2) -- 1
(4, 3), (4, 3) -- 1
(4, 3), (4, 4) -- 1
(4, 4), (0, 0) -- 0
(4, 4), (1, 0) -- 1
(4, 4), (1, 1) -- 1
(4, 4), (2, 0) -- 1
(4, 4), (2, 1) -- 1
(4, 4), (2, 2) -- 1
(4, 4), (3, 0) -- 1
(4, 4), (3, 1) -- 1
(4, 4), (3, 2) -- -1
(4, 4), (3, 3) -- 1
(4, 4), (4, 0) -- 1
(4, 4), (4, 1) -- 1
(4, 4), (4, 2) -- 1
(4, 4), (4, 3) -- -1
(4, 4), (4, 4) -- 1