Submission #248777

#TimeUsernameProblemLanguageResultExecution timeMemory
248777srvltEnergetic turtle (IZhO11_turtle)C++14
5 / 100
1 ms640 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define ld long double #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); constexpr int n0 = 3e5 + 123, k0 = 23; int n, m, k, t, z, C[k0][k0], f[k0], cf[k0]; array <int, 2> p[k0]; int w(int x, int y, int x2, int y2) { if (x2 - x + y2 - y >= k0) assert(false); return C[x2 - x + y2 - y][x2 - x]; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif cin >> n >> m >> k >> t >> z; C[0][0] = 1 % z; for (int i = 1; i < k0; i++) { C[i][0] = 1 % z; for (int j = 1; j <= i; j++) { C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % z; } } for (int i = 0; i < k; i++) cin >> p[i][0] >> p[i][1]; sort(p, p + k); for (int mask = 1; mask < (1 << k); mask++) { int bad = 0, res = 1 % z, last = -1; for (int i = 0; i < k; i++) { if (mask >> i & 1) { if (i > 0 && p[i][1] < p[i - 1][1]) { bad = 1; break; } if (i == 0) res = (ll)res * w(0, 0, p[i][0], p[i][1]) % z; else res = (ll)res * w(p[i - 1][0], p[i - 1][1], p[i][0], p[i][1]) % z; last = i; } } if (bad) continue; res = (ll)res * w(p[last][0], p[last][1], n, m) % z; int b = __builtin_popcount(mask); f[b] = (f[b] + res) % z; } int res = w(0, 0, n, m); for (int i = t + 1; i <= k; i++) { int cur = 0; for (int j = t + 1; j < i; j++) cur = (cur + (ll)C[i][j] * cf[j] % z) % z; cf[i] = (z - 1) - cur; res = (res + (ll)cf[i] * f[i] % z) % z; } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...