Submission #17752

#TimeUsernameProblemLanguageResultExecution timeMemory
17752ErzhannEnergetic turtle (IZhO11_turtle)C++98
5 / 100
14 ms9976 KiB
/* /\ /\ | ).|.( | | >-< | ========= It's Adilkhan99 miaaaaaau */ #include<bits/stdc++.h> #define ll long long #define pb push_back #define endl "\n" #define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++) #define mp make_pair #define f first #define s second #define name "" #define _ ios_base::sync_with_stdio(false);cin.tie(0); using namespace std; const int MaxN = int (6e5) + 256; const int INF = int(1e9); const int mod = (int)(1e9) + 7; long long n, m, t, k, z; long long f[MaxN]; pair<int, int> p[22]; int main () { _ cin >> n >> m >> k >> t >> z; for(int i = 0; i < k; i++){ int x, y; cin >> x >> y; p[i] = mp(x, y); } sort(p, p + k); f[0] = (1ll); for(int i = 1; i <= n + m; i++){ f[i] = (f[i - 1] * (ll)(i)); } long long ans = f[n + m] / f[n] / f[m]; for(int i = 0; i < (1 << k); i++){ ll cnt = (1ll); int last_i = 0, last_j = 0, kol = 0; bool ok = 1; for(int j = 0; j < k; j++){ if((i & (1 << j))){ if(last_j > p[j].second){ ok = 0; break; } kol++; int I = p[j].first - last_i; int J = p[j].second - last_j; last_i = p[j].first; last_j = p[j].second; cnt = cnt * (f[I + J] / f[I] / f[J]); } } if(kol > t && ok){ int I = n - last_i; int J = m - last_j; cnt = cnt * (f[I + J] / f[I] / f[J]); ans = ans - cnt; } } cout << ans % z; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...