# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17751 | Erzhann | Energetic turtle (IZhO11_turtle) | C++98 | 6 ms | 636 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
/\ /\
| ).|.( |
| >-< |
=========
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 () { _
#ifdef ONLINE_JUDGE
freopen (name".in","r",stdin);
freopen (name".out","w",stdout);
#else
freopen (".in","r",stdin);
freopen (".out","w",stdout);
#endif
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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |