# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
881922 | dosts | Energetic turtle (IZhO11_turtle) | C++17 | 133 ms | 262144 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.
#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 1e5+1,inf = 1e18;
int MOD;
int add(int x,int y) {return (x+y>=MOD?x+y-MOD:x+y);}
void solve() {
int n,m,k,t;
cin >> n >> m >> k >> t >> MOD;
n++;
m++;
int dp[n+1][m+1][t+1];
memset(dp,0,sizeof dp);
int blocked[n+1][m+1];
memset(blocked,0,sizeof blocked);
for (int i=1;i<=k;i++) {
int x,y;
cin >> x >> y;
x++;
y++;
blocked[x][y] = 1;
}
dp[1][1][0] = 1;
for (int i=1;i<=n;i++) {
for (int j=1;j<=m;j++) {
for (int p=0;p<=t;p++) {
if (blocked[i-1][j]){
if (p) dp[i][j][p] = add(dp[i][j][p],dp[i-1][j][p-1]);
}
else {
dp[i][j][p] = add(dp[i][j][p],dp[i-1][j][p]);
}
if (blocked[i][j-1]) {
if (p) dp[i][j][p] = add(dp[i][j][p],dp[i][j-1][p-1]);
}
else {
dp[i][j][p] = add(dp[i][j][p],dp[i][j-1][p]);
}
}
}
}
int ans =0 ;
for (int i=0;i<=t;i++) ans = add(ans,dp[n][m][i]);
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |