#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
struct row {
int y[1001][21];
bool t[1001];
};
int antiloop = 0;
int md;
int n, m;
int k, t;
int a[30];
row X[1001];
map<pair<int, int>, bool> mp;
void solve () {
cin >> n >> m >> k >> t >> md;
for (int i = 0; i < k; i++) {
int x, y; cin >> x >> y;
X[x].t[y] = 1;
}
for (int i = 0; i <= t; i++) X[0].y[0][i] = 0;
X[0].y[0][0] = 1;
queue<pair<int, int>> q;
q.push({0, 0});
while (!q.empty()) {
pair<int, int> p = q.front(); q.pop();
if (mp.find(p) != mp.end()) continue ;
mp[p] = 1;
if (p.F) {
if (X[p.F].t[p.S]) {
for (int i = 0; i < t; i++) {
X[p.F].y[p.S][i+1] += X[p.F-1].y[p.S][i];
X[p.F].y[p.S][i+1] %= md;
}
}
else {
for (int i = 0; i <= t; i++) {
X[p.F].y[p.S][i] += X[p.F-1].y[p.S][i];
X[p.F].y[p.S][i] %= md;
}
}
}
if (p.S) {
if (X[p.F].t[p.S]) {
for (int i = 0; i < t; i++) {
X[p.F].y[p.S][i+1] += X[p.F].y[p.S-1][i];
X[p.F].y[p.S][i+1] %= md;
}
}
else {
for (int i = 0; i <= t; i++) {
X[p.F].y[p.S][i] += X[p.F].y[p.S-1][i];
X[p.F].y[p.S][i] %= md;
}
}
}
if (p.F != n) q.push({p.F+1, p.S});
if (p.S != m) q.push({p.F, p.S+1});
// antiloop++; if (antiloop > 20) exit(0);
// cout << p.F << ' ' << p.S << '\n';
// for (int i = 0; i <= t; i++) {
// cout << X[p.F].y[p.S][i] << ' ';
// }
// cout << '\n';
}
int ans = 0;
for (int i = 0; i <= t; i++) {
ans += X[n].y[m][i];
}
cout << ans;
}
int main() {IOS solve(); return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4564 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
9040 KB |
Output isn't correct |
5 |
Incorrect |
13 ms |
16976 KB |
Output isn't correct |
6 |
Incorrect |
146 ms |
46076 KB |
Output isn't correct |
7 |
Incorrect |
243 ms |
73544 KB |
Output isn't correct |
8 |
Incorrect |
673 ms |
146504 KB |
Output isn't correct |
9 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
10 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
11 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
12 |
Runtime error |
5 ms |
540 KB |
Execution killed with signal 11 |
13 |
Runtime error |
6 ms |
592 KB |
Execution killed with signal 11 |
14 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
15 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
16 |
Runtime error |
6 ms |
592 KB |
Execution killed with signal 11 |
17 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
18 |
Runtime error |
5 ms |
604 KB |
Execution killed with signal 11 |
19 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |
20 |
Runtime error |
5 ms |
592 KB |
Execution killed with signal 11 |