#include <iostream>
#include <queue>
using namespace std;
long long int f[1005][1005][21], dd[1005][1005], a[1005][1005];
int main() {
int n, m, k, t, z;
cin >> n >> m >> k >> t >> z;
for (int i = 1; i <= k; i++) {
int x, y;
cin >> x >> y;
a[x][y] = 1;
}
queue<pair<int, int>> q;
f[0][0][0] = 1;
q.push({0, 0});
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
for (int i = 0; i <= t; i++) {
f[x + 1][y][i + a[x + 1][y]] += f[x][y][i];
f[x + 1][y][i + a[x + 1][y]] %= z;
f[x][y + 1][i + a[x][y + 1]] += f[x][y][i];
f[x][y + 1][i + a[x][y + 1]] %= z;
if (dd[x + 1][y] == 0 && x < n) {
q.push({x + 1, y});
dd[x + 1][y] = 1;
}
if (dd[x][y + 1] == 0 && y < m) {
q.push({x, y + 1});
dd[x][y + 1] = 1;
}
}
}
long long int res = 0;
for (int i = 0; i <= t; i++) res = (res + f[n][m][i]) % z;
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5976 KB |
Output is correct |
5 |
Correct |
9 ms |
10844 KB |
Output is correct |
6 |
Correct |
37 ms |
53308 KB |
Output is correct |
7 |
Correct |
80 ms |
83796 KB |
Output is correct |
8 |
Correct |
147 ms |
181564 KB |
Output is correct |
9 |
Runtime error |
180 ms |
198992 KB |
Execution killed with signal 11 |
10 |
Runtime error |
171 ms |
205180 KB |
Execution killed with signal 11 |
11 |
Runtime error |
9 ms |
12892 KB |
Execution killed with signal 11 |
12 |
Runtime error |
6 ms |
4700 KB |
Execution killed with signal 11 |
13 |
Runtime error |
16 ms |
25436 KB |
Execution killed with signal 11 |
14 |
Runtime error |
6 ms |
4700 KB |
Execution killed with signal 11 |
15 |
Runtime error |
8 ms |
8792 KB |
Execution killed with signal 11 |
16 |
Runtime error |
8 ms |
8792 KB |
Execution killed with signal 11 |
17 |
Runtime error |
6 ms |
4700 KB |
Execution killed with signal 11 |
18 |
Runtime error |
21 ms |
37980 KB |
Execution killed with signal 11 |
19 |
Runtime error |
7 ms |
8796 KB |
Execution killed with signal 11 |
20 |
Runtime error |
17 ms |
29532 KB |
Execution killed with signal 11 |