Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) begin(x),end(x)
- using namespace std;
- using ll = long long;
- const ll mod = 998244353;
- bool arr[5][5];
- bool check(int n, int m, int mask) {
- memset(arr, 0, sizeof arr);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if ((mask >> (i * m + j)) & 1) {
- arr[i][j] = true;
- }
- }
- }
- while (true) {
- bool cnt = false;
- for (int i = 0; i < n * m; i++) {
- for (int j = 0; j < n * m; j++) {
- int x1 = i / m;
- int y1 = i % m;
- int x2 = j / m;
- int y2 = j % m;
- if (arr[x1][y1] && arr[x2][y2] && (arr[x1][y2] != arr[x2][y1])) {
- arr[x2][y1] = true;
- arr[x1][y2] = true;
- cnt = true;
- }
- }
- }
- if (!cnt) break;
- }
- int cnt = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (arr[i][j]) cnt++;
- }
- }
- return cnt == n * m;
- }
- int main() {
- for (int size = 1; size <= 20; size++) {
- for (int n = 1; n <= size; n++) {
- if (size % n) continue;
- int m = size / n;
- cout << "n m " << n << ' ' << m << ' ' << size << '\n';
- int cnt = n + m - 1;
- for (int mask = 0; mask < (1 << size); mask++) {
- if (__builtin_popcount(mask) != cnt) continue;
- bool res = check(n, m, mask);
- if (res) {
- cout << n << ' ' << m << ' ' << (res ? "True" : "False") << '\n';
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cout << ((mask >> (i * m + j)) & 1);
- }
- cout << '\n';
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement