Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FN "algoritm"
- using namespace std;
- typedef long long ll;
- const ll INF = 1e16;
- const int mod = 1e9 + 7;
- ll ans = 0;
- ll n, m, k, d;
- ll arr[15][170];
- ll play(bool a[])
- {
- vector <pair <ll, ll > > b;
- ll c;
- ll answ = 1;
- for (int i = 0; i < m; i++)
- {
- if (a[i])
- {
- c = 0;
- for (int j = 0; j < n; j++)
- {
- b.clear();
- if (arr[i][j] < d && arr[i][j] + d > k)
- {
- b.clear();
- b.push_back({ 0ll, k });
- break;
- }
- if (arr[i][j] < d)
- {
- b.push_back({ arr[i][j] + k - d, k - 1 });
- b.push_back({0, arr[i][j] + d});
- }
- else if (arr[i][j] + d > k)
- {
- b.push_back({ arr[i][j], k - 1 });
- b.push_back({ 0, arr[i][j] + d - k});
- }
- else
- {
- b.push_back({ arr[i][j] - d, arr[i][j] + d});
- }
- }
- sort(b.begin(), b.end());
- int l = -1, r = -2;
- for (int j = 0; j < b.size(); j++)
- {
- if (b[j].first <= r)
- r = b[j].second;
- else
- {
- c += r - l + 1;
- l = b[j].first;
- r = b[j].second;
- }
- }
- c += r - l + 1;
- l = b[b.size() - 1].first;
- r = b[b.size() - 1].second;
- answ *= c;
- }
- }
- cout << answ << endl;
- return answ;
- }
- void rec(int i, bool a[], int k)
- {
- if (i == m)
- {
- if (k % 2 == 1)
- ans = (ans + play(a)) % mod;
- else
- ans = (ans - play(a)) % mod;
- cout << '=' << ans;
- // for (int i = 0; i < m; i++)
- // cout << a[i] << ' ';
- // cout << endl << ans;
- return;
- }
- a[i] = 1;
- rec(i + 1, a, k + 1);
- a[i] = 0;
- rec(i + 1, a, k);
- }
- signed main()
- {
- #ifdef PC
- freopen("in", "r", stdin);
- #else
- freopen(FN".in", "r", stdin);
- freopen(FN".out", "w", stdout);
- #endif
- ios_base::sync_with_stdio(0);
- cin >> n >> m >> k >> d;
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- cin >> arr[i][j];
- }
- bool a[12];
- rec(0, a, 0);
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement