Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- ll N, M, K, F;
- ll mod = 998244353;
- bool sh = 1;
- string to2(int x) {
- string r = "";
- while (x > 0) {
- r += x % 2 + '0';
- x /= 2;
- }
- while (r.size() < N * M) {
- r = '0' + r;
- }
- return r;
- }
- // 0 = wh, 1 = bl
- bool ok(vector <vector <int> > a) {
- int without = 0;
- for (int j = 0; j < N; ++j) {
- int row = 0;
- bool isrow = 0;
- for (int i = 0; i < M; ++i) {
- if (a[i][j] == 1) {
- row++;
- if (row == F) {
- isrow = 1;
- break;
- } else {
- row = 0;
- }
- } else {
- row = 0;
- }
- }
- if (isrow) {
- without = 0;
- } else {
- without++;
- }
- if (without == K) {
- return 0;
- }
- }
- return 1;
- }
- ll slv1() {
- ll ans = 0;
- vector <vector <int> > a(M, vector <int> (N));
- for (int it = 0; it < pow(2, N * M); ++it) {
- string s = to2(it);
- if (sh) {
- cout << "it s = \n" << it << ' ' << s << "\n";
- }
- for (int i = 0; i < M; ++i) {
- for (int j = 0; j < N; ++j) {
- if (s[i * N + j] == '0') {
- a[i][j] = 0;
- } else {
- a[i][j] = 1;
- }
- }
- if (sh) {
- cout << "a\n";
- cvv(a);
- }
- }
- bool gd = ok(a);
- if (gd) {
- if (sh) {
- cout << "good\n";
- }
- ans++;
- ans %= mod;
- } else {
- cout << "bad\n";
- }
- if (sh) {
- cout << "\n\n";
- }
- }
- return ans;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> N >> M >> K >> F;
- ll ans = -1;
- if (N * M <= 20) {
- ans = slv1();
- }
- cout << ans << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement