QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345360 | #7662. Kaldorian Knights | hht2005 | WA | 0ms | 3960kb | C++14 | 568b | 2024-03-06 20:51:25 | 2024-03-06 20:51:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1000010, mod = 1e9 + 7;
int f[5010], P[N], h[5010];
int main() {
int n, k;
scanf("%d%d", &n, &k);
P[0] = 1;
for(int i = 1; i <= n; i++)
P[i] = 1ll * i * P[i - 1] % mod;
for(int i = 1; i <= k; i++) {
scanf("%d", h + i);
n -= h[i];
}
f[k + 1] = P[n];
for(int i = k; i >= 1; i--) {
int sum = 0;
for(int j = i; j <= k; j++) {
sum += h[j];
f[i] = (f[i] + P[sum] * f[j + 1]) % mod;
}
f[i] = (P[sum + n] - f[i] + mod) % mod;
}
printf("%d\n", f[1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3900kb
input:
3 0
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
4 1 3
output:
18
result:
ok single line: '18'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
4 2 2 1
output:
16
result:
ok single line: '16'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
10 1 10
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3960kb
input:
10 10 1 1 1 1 1 1 1 1 1 1
output:
0
result:
ok single line: '0'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3908kb
input:
1357 7 56 173 21 103 96 149 38
output:
-26433628
result:
wrong answer 1st lines differ - expected: '1000000006', found: '-26433628'