Advertisement
Korotkodul

reg D 2

Oct 8th, 2022 (edited)
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 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 = 0;
  54.  
  55. string to2(int x) {
  56.     string r = "";
  57.     while (x > 0) {
  58.         r += x % 2 + '0';
  59.         x /= 2;
  60.     }
  61.     reverse(r.begin(), r.end());
  62.     while (r.size() < N * M) {
  63.         r = '0' + r;
  64.     }
  65.     return r;
  66. }
  67.  
  68. // 0 = wh, 1 = bl
  69. bool ok(vector <vector <int> > a) {
  70.     int without = 0;
  71.     if (sh) {
  72.         //cout << "N M = " << N << ' ' << M << "\n";
  73.     }
  74.     for (int j = 0; j < N; ++j) {
  75.         if (sh) {
  76.             //cout << "j = " << j << "\n";
  77.         }
  78.         int row = 0;
  79.         bool isrow = 0;
  80.         for (int i = 0; i < M; ++i) {
  81.             if (sh) {
  82.                 //cout << "i = " << i << ' ' ;
  83.             }
  84.             if (a[i][j] == 1) {
  85.                 row++;
  86.                 if (row == F) {
  87.                     isrow = 1;
  88.                     break;
  89.                 }
  90.             } else {
  91.                 row = 0;
  92.             }
  93.         }
  94.  
  95.         if (isrow) {
  96.             without = 0;
  97.         } else {
  98.             without++;
  99.         }
  100.         /*if (sh) {
  101.             cout << "\n";
  102.             cout << "isrow = " << isrow << "\n";
  103.             cout << "row = " << row << "\n";
  104.         }*/
  105.         if (without == K) {
  106.             return 0;
  107.         }
  108.     }
  109.     return 1;
  110. }
  111.  
  112. ll slv1() {
  113.     ll ans = 0;
  114.     vector <vector <int> > a(M, vector <int> (N));
  115.     set <string> als;
  116.     //set <vector <vector <int> > alv;
  117.     for (int it = 0; it < pow(2, N * M); ++it) {
  118.         string s = to2(it);
  119.         als.insert(s);
  120.         if (sh) {
  121.             //cout << "it s = \n" << it << ' ' << s << "\n";
  122.         }
  123.         int id = -1;
  124.         for (int i = 0; i < M; ++i) {
  125.             for (int j = 0; j < N; ++j) {
  126.                 id++;
  127.                 if (s[id] == '0') {
  128.                     a[i][j] = 0;
  129.                 } else {
  130.                     a[i][j] = 1;
  131.                 }
  132.             }
  133.         }
  134.         //alv.insert(a);
  135.  
  136.  
  137.         bool gd = ok(a);
  138.         if (gd) {
  139.             if (sh) {
  140.                 //cout << "good\n";
  141.             }
  142.             ans++;
  143.             ans %= mod;
  144.         } else if (sh) {
  145.             cout << "bad\n";
  146.         }
  147.         if (!gd) {
  148.             continue;
  149.         }
  150.         if (sh) {
  151.             cout << "a\n";
  152.             cvv(a);
  153.         }
  154.  
  155.         if (sh) {
  156.             cout << "\n\n";
  157.         }
  158.     }
  159.     if (sh) {
  160.         cout << "als.size() = " << als.size() << "\n";
  161.         //cout << "alv.size() = " << alv.size() << "\n";
  162.     }
  163.     return ans;
  164. }
  165.  
  166. int main() {
  167.     ios::sync_with_stdio(0);
  168.     cin.tie(0);
  169.     cout.tie(0);
  170.     cin >> M >> N >> K >> F;
  171.     ll ans = -1;
  172.     if (N * M <= 20) {
  173.         ans = slv1();
  174.     }
  175.     cout << ans << "\n";
  176. }
  177.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement