#include <bits/stdc++.h> using namespace std; #define endl "\n" #define mp make_pair #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #define pb push_back #define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10), cin.tie(0), cout.tie(0); #define rep(i, n) for (int i = 0; i < (n); ++i) #define fwd(i, a, b) for (int i = (a); i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(c) (c).begin(), (c).end() #define sz(X) (int)((X).size()) typedef long double ld; typedef unsigned long long ull; typedef long long ll; #ifdef LOCAL ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; } template <class L, class R, class S> ostream &operator<<(ostream &out, tuple<L, R, S> p) { auto &[a, b, c] = p; return out << "(" << a << ", " << b << ", " << c << ")"; } template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << '{'; for (auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << '}'; } void dump() { cerr << "\n"; } template <class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else #define debug(...) 42 #endif const int N = 5; typedef vector<vector<bool>> vvb; vvb go(const vvb &X) { auto Y = X; auto is_sus = [&](auto tl, auto tr, auto bl, auto br) { return tl == br and tr == bl and tl != tr; }; set<pii> S; rep(i, sz(X) - 1) rep(j, sz(X[i]) - 1) if (is_sus(X[i][j], X[i][j + 1], X[i + 1][j], X[i + 1][j + 1])) rep(a, 2) rep(b, 2) S.insert({i + a, j + b}); for (auto [a, b] : S) Y[a][b] = not Y[a][b]; return Y; } int go_while(vvb X) { set<vvb> S; int i = 0; for (; !S.contains(X); i++) { S.insert(X); X = go(X); } return i - 1; } void generate(int n) { vector<bool> T(n, true); vector<bool> F(n, false); vvb res; rep(i, n) res.push_back((i & 1) ? F : T); res[0][0] = false; fwd(i, 1, n) if (i & 1) res[i][0] = true; else res[i].back() = false; // int x = go_while(res); // debug(res); for (auto s : res) { for (int c : s) cout << c; cout << endl; } } int32_t main() { _upgrade; generate(100); exit(0); fwd(i, 2, 20) fwd(j, 2, 20) if (i * j <= 25) { map<int, vvb> M; rep(S, 1 << (i * j)) { vvb X(i, vector<bool>(j)); auto Sp = S; rep(a, i) rep(b, j) { X[a][b] = Sp & 1; Sp /= 2; } auto x = go_while(X); M[x] = X; } debug(i, j, *M.rbegin()); } } // [i, j, *M.rbegin()]: 2, 2, (2, {{1, 0}, {0, 1}}), // [i, j, *M.rbegin()]: 2, 3, (3, {{1, 0, 0}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 2, 4, (4, {{1, 0, 0, 0}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 5, (5, {{1, 0, 0, 0, 0}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 6, (6, {{1, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 7, (7, {{1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 8, (8, {{1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 9, (9, {{1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 10, (10, {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 11, (11, {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 12, (12, {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 2, (3, {{1, 0}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 3, 3, (5, {{1, 0, 0}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 3, 4, (7, {{1, 0, 0, 0}, {0, 1, 0, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 5, (9, {{1, 0, 0, 0, 0}, {1, 0, 1, 0, 1}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 6, (11, {{1, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 7, (13, {{1, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 8, (15, {{1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 4, 2, (4, {{1, 0}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 4, 3, (7, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 4, 4, (10, {{1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 4, 5, (13, {{1, 1, 1, 1, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 4, 6, (16, {{1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 5, 2, (5, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 5, 3, (9, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 5, 4, (13, {{1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 5, 5, (17, {{1, 1, 1, 1, 0}, {0, 1, 0, 0, 0}, {0, 1, 0, 1, 0}, {0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 6, 2, (6, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 6, 3, (11, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 6, 4, (16, {{1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 7, 2, (7, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 7, 3, (13, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 8, 2, (8, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // ^C
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 | #include <bits/stdc++.h> using namespace std; #define endl "\n" #define mp make_pair #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #define pb push_back #define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10), cin.tie(0), cout.tie(0); #define rep(i, n) for (int i = 0; i < (n); ++i) #define fwd(i, a, b) for (int i = (a); i < (b); ++i) #define trav(a, x) for (auto &a : x) #define all(c) (c).begin(), (c).end() #define sz(X) (int)((X).size()) typedef long double ld; typedef unsigned long long ull; typedef long long ll; #ifdef LOCAL ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; } template <class L, class R, class S> ostream &operator<<(ostream &out, tuple<L, R, S> p) { auto &[a, b, c] = p; return out << "(" << a << ", " << b << ", " << c << ")"; } template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << '{'; for (auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << '}'; } void dump() { cerr << "\n"; } template <class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else #define debug(...) 42 #endif const int N = 5; typedef vector<vector<bool>> vvb; vvb go(const vvb &X) { auto Y = X; auto is_sus = [&](auto tl, auto tr, auto bl, auto br) { return tl == br and tr == bl and tl != tr; }; set<pii> S; rep(i, sz(X) - 1) rep(j, sz(X[i]) - 1) if (is_sus(X[i][j], X[i][j + 1], X[i + 1][j], X[i + 1][j + 1])) rep(a, 2) rep(b, 2) S.insert({i + a, j + b}); for (auto [a, b] : S) Y[a][b] = not Y[a][b]; return Y; } int go_while(vvb X) { set<vvb> S; int i = 0; for (; !S.contains(X); i++) { S.insert(X); X = go(X); } return i - 1; } void generate(int n) { vector<bool> T(n, true); vector<bool> F(n, false); vvb res; rep(i, n) res.push_back((i & 1) ? F : T); res[0][0] = false; fwd(i, 1, n) if (i & 1) res[i][0] = true; else res[i].back() = false; // int x = go_while(res); // debug(res); for (auto s : res) { for (int c : s) cout << c; cout << endl; } } int32_t main() { _upgrade; generate(100); exit(0); fwd(i, 2, 20) fwd(j, 2, 20) if (i * j <= 25) { map<int, vvb> M; rep(S, 1 << (i * j)) { vvb X(i, vector<bool>(j)); auto Sp = S; rep(a, i) rep(b, j) { X[a][b] = Sp & 1; Sp /= 2; } auto x = go_while(X); M[x] = X; } debug(i, j, *M.rbegin()); } } // [i, j, *M.rbegin()]: 2, 2, (2, {{1, 0}, {0, 1}}), // [i, j, *M.rbegin()]: 2, 3, (3, {{1, 0, 0}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 2, 4, (4, {{1, 0, 0, 0}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 5, (5, {{1, 0, 0, 0, 0}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 6, (6, {{1, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 7, (7, {{1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 8, (8, {{1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 9, (9, {{1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 10, (10, {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 11, (11, {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 2, 12, (12, {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 2, (3, {{1, 0}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 3, 3, (5, {{1, 0, 0}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 3, 4, (7, {{1, 0, 0, 0}, {0, 1, 0, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 5, (9, {{1, 0, 0, 0, 0}, {1, 0, 1, 0, 1}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 6, (11, {{1, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 7, (13, {{1, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 3, 8, (15, {{1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 1, 0, 1, 0, 1}, {0, 1, 1, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 4, 2, (4, {{1, 0}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 4, 3, (7, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 4, 4, (10, {{1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 4, 5, (13, {{1, 1, 1, 1, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 4, 6, (16, {{1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 5, 2, (5, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 5, 3, (9, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 5, 4, (13, {{1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 5, 5, (17, {{1, 1, 1, 1, 0}, {0, 1, 0, 0, 0}, {0, 1, 0, 1, 0}, {0, 0, 1, 1, 1}, {0, 1, 1, 1, 1}}), // [i, j, *M.rbegin()]: 6, 2, (6, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 6, 3, (11, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 6, 4, (16, {{1, 1, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 1, 1}}), // [i, j, *M.rbegin()]: 7, 2, (7, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // [i, j, *M.rbegin()]: 7, 3, (13, {{1, 0, 0}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {1, 0, 1}, {0, 1, 1}}), // [i, j, *M.rbegin()]: 8, 2, (8, {{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}}), // ^C |