ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213981 | #2662. 折跃 | nodgd | 100 | 1117ms | 1224kb | C++11 | 958b | 2024-11-14 21:01:13 | 2024-11-14 23:07:08 |
answer
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000 + 5;
const int P = 1000000007;
int N, K, A, B;
int f[MAX_N], g[MAX_N];
int main() {
scanf("%d%d%d%d", &N, &A, &B, &K);
f[A] = 1;
for (int i = 1; i <= K; i ++) {
for (int j = 1; j <= N; j ++) {
if (j == B) continue;
int l = max(1, j - abs(j - B) + 1);
int r = min(N, j + abs(j - B) - 1);
g[l] += f[j];
g[l] -= g[l] >= P ? P : 0;
g[r + 1] -= f[j];
g[r + 1] += g[r + 1] < 0 ? P : 0;
}
for (int j = 1, t = 0; j <= N; j ++) {
t += g[j], g[j] = 0;
t -= t >= P ? P : 0;
f[j] = t - f[j];
f[j] += f[j] < 0 ? P : 0;
}
f[B] = 0;
}
A = 0;
for (int j = 1; j <= N; j ++) {
A += f[j];
A -= A >= P ? P : 0;
}
printf("%d\n", A);
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1196kb
input:
98 18 22 94
output:
27076018
result:
ok single line: '27076018'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1200kb
input:
95 94 73 92
output:
748455277
result:
ok single line: '748455277'
Test #3:
score: 10
Accepted
time: 206ms
memory: 1220kb
input:
4674 2740 4172 4983
output:
454585991
result:
ok single line: '454585991'
Test #4:
score: 10
Accepted
time: 157ms
memory: 1224kb
input:
4981 813 4046 4994
output:
226418975
result:
ok single line: '226418975'
Test #5:
score: 10
Accepted
time: 117ms
memory: 1220kb
input:
4595 3757 519 4810
output:
194357577
result:
ok single line: '194357577'
Test #6:
score: 10
Accepted
time: 128ms
memory: 1224kb
input:
4902 277 2317 4821
output:
641852228
result:
ok single line: '641852228'
Test #7:
score: 10
Accepted
time: 124ms
memory: 1220kb
input:
4516 1607 639 4990
output:
973001631
result:
ok single line: '973001631'
Test #8:
score: 10
Accepted
time: 123ms
memory: 1220kb
input:
4823 1127 3840 4648
output:
431104558
result:
ok single line: '431104558'
Test #9:
score: 10
Accepted
time: 134ms
memory: 1224kb
input:
4937 3261 2918 4817
output:
638296884
result:
ok single line: '638296884'
Test #10:
score: 10
Accepted
time: 128ms
memory: 1220kb
input:
4744 135 2414 4828
output:
30641258
result:
ok single line: '30641258'