Advertisement
999ms

Untitled

Oct 4th, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) begin(x),end(x)
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. const ll mod = 998244353;
  8.  
  9. bool arr[5][5];
  10.  
  11. bool check(int n, int m, int mask) {
  12. memset(arr, 0, sizeof arr);
  13. for (int i = 0; i < n; i++) {
  14. for (int j = 0; j < m; j++) {
  15. if ((mask >> (i * m + j)) & 1) {
  16. arr[i][j] = true;
  17. }
  18. }
  19. }
  20. while (true) {
  21. bool cnt = false;
  22. for (int i = 0; i < n * m; i++) {
  23. for (int j = 0; j < n * m; j++) {
  24. int x1 = i / m;
  25. int y1 = i % m;
  26. int x2 = j / m;
  27. int y2 = j % m;
  28. if (arr[x1][y1] && arr[x2][y2] && (arr[x1][y2] != arr[x2][y1])) {
  29. arr[x2][y1] = true;
  30. arr[x1][y2] = true;
  31. cnt = true;
  32. }
  33. }
  34. }
  35. if (!cnt) break;
  36. }
  37. int cnt = 0;
  38. for (int i = 0; i < n; i++) {
  39. for (int j = 0; j < m; j++) {
  40. if (arr[i][j]) cnt++;
  41. }
  42. }
  43. return cnt == n * m;
  44. }
  45.  
  46. int main() {
  47. for (int size = 1; size <= 20; size++) {
  48. for (int n = 1; n <= size; n++) {
  49. if (size % n) continue;
  50. int m = size / n;
  51. cout << "n m " << n << ' ' << m << ' ' << size << '\n';
  52. int cnt = n + m - 1;
  53. for (int mask = 0; mask < (1 << size); mask++) {
  54. if (__builtin_popcount(mask) != cnt) continue;
  55. bool res = check(n, m, mask);
  56. if (res) {
  57. cout << n << ' ' << m << ' ' << (res ? "True" : "False") << '\n';
  58. for (int i = 0; i < n; i++) {
  59. for (int j = 0; j < m; j++) {
  60. cout << ((mask >> (i * m + j)) & 1);
  61. }
  62. cout << '\n';
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement