Advertisement
Korotkodul

reg D group 1

Oct 8th, 2022 (edited)
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. ll N, M, K, F;
  51. ll mod = 998244353;
  52.  
  53. bool sh = 1;
  54.  
  55. string to2(int x) {
  56.     string r = "";
  57.     while (x > 0) {
  58.         r += x % 2 + '0';
  59.         x /= 2;
  60.     }
  61.     while (r.size() < N * M) {
  62.         r = '0' + r;
  63.     }
  64.     return r;
  65. }
  66.  
  67. // 0 = wh, 1 = bl
  68. bool ok(vector <vector <int> > a) {
  69.     int without = 0;
  70.     for (int j = 0; j < N; ++j) {
  71.         int row = 0;
  72.         bool isrow = 0;
  73.         for (int i = 0; i < M; ++i) {
  74.             if (a[i][j] == 1) {
  75.                 row++;
  76.                 if (row == F) {
  77.                     isrow = 1;
  78.                     break;
  79.                 } else {
  80.                     row = 0;
  81.                 }
  82.             } else {
  83.                 row = 0;
  84.             }
  85.         }
  86.         if (isrow) {
  87.             without = 0;
  88.         } else {
  89.             without++;
  90.         }
  91.         if (without == K) {
  92.             return 0;
  93.         }
  94.     }
  95.     return 1;
  96. }
  97.  
  98. ll slv1() {
  99.     ll ans = 0;
  100.     vector <vector <int> > a(M, vector <int> (N));
  101.     for (int it = 0; it < pow(2, N * M); ++it) {
  102.         string s = to2(it);
  103.         if (sh) {
  104.             cout << "it s = \n" << it << ' ' << s << "\n";
  105.         }
  106.         for (int i = 0; i < M; ++i) {
  107.             for (int j = 0; j < N; ++j) {
  108.                 if (s[i * N + j] == '0') {
  109.                     a[i][j] = 0;
  110.                 } else {
  111.                     a[i][j] = 1;
  112.                 }
  113.             }
  114.             if (sh) {
  115.                 cout << "a\n";
  116.                 cvv(a);
  117.             }
  118.         }
  119.  
  120.         bool gd = ok(a);
  121.         if (gd) {
  122.             if (sh) {
  123.                 cout << "good\n";
  124.             }
  125.             ans++;
  126.             ans %= mod;
  127.         } else {
  128.             cout << "bad\n";
  129.         }
  130.         if (sh) {
  131.             cout << "\n\n";
  132.         }
  133.     }
  134.     return ans;
  135. }
  136.  
  137. int main() {
  138.     ios::sync_with_stdio(0);
  139.     cin.tie(0);
  140.     cout.tie(0);
  141.     cin >> N >> M >> K >> F;
  142.     ll ans = -1;
  143.     if (N * M <= 20) {
  144.         ans = slv1();
  145.     }
  146.     cout << ans << "\n";
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement