QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617917 | #7662. Kaldorian Knights | SkyEyeController | RE | 28ms | 48544kb | C++23 | 1.1kb | 2024-10-06 17:42:58 | 2024-10-06 17:42:58 |
Judging History
answer
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 5e6 + 9;
const int mod = 1e9 + 7;
const int fur = 501000;
int prefam[fur], family[fur];
int famcosts[fur];
int fact[maxn];
void init()
{
fact[0] = 1;
for (int i = 1; i <= maxn; i++)
{
fact[i] = (fact[i - 1] * i) % mod;
}
}
signed main()
{
init();
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, h;
cin >> n >> h;
for (int i = 1; i <= n; i++)
{
cin >> family[i];
prefam[i] = prefam[i - 1] + family[i];
}
if (!h)
{
cout << fact[n] << endl;
return 0;
}
for (int i = 1; i <= h; i++)
{
int now = fact[prefam[i]] % mod;
for (int j = 1; j < i; j++)
{
now = (now + mod - (famcosts[j] * fact[prefam[i] - prefam[j]] % mod)) % mod;
}
famcosts[i] = now;
}
int ans = fact[n];
for (int i = 1; i <= h; i++)
{
ans = (mod + ans - (famcosts[i] * fact[n - prefam[i]] % mod)) % mod;
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 28ms
memory: 43308kb
input:
3 0
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 24ms
memory: 45692kb
input:
4 1 3
output:
18
result:
ok single line: '18'
Test #3:
score: 0
Accepted
time: 25ms
memory: 46276kb
input:
4 2 2 1
output:
16
result:
ok single line: '16'
Test #4:
score: 0
Accepted
time: 25ms
memory: 45932kb
input:
10 1 10
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 20ms
memory: 44920kb
input:
10 10 1 1 1 1 1 1 1 1 1 1
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 24ms
memory: 46036kb
input:
1357 7 56 173 21 103 96 149 38
output:
1000000006
result:
ok single line: '1000000006'
Test #7:
score: 0
Accepted
time: 27ms
memory: 46704kb
input:
1357 5 190 198 257 256 261
output:
1000000005
result:
ok single line: '1000000005'
Test #8:
score: 0
Accepted
time: 24ms
memory: 45132kb
input:
1357 7 144 56 113 20 113 141 107
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 20ms
memory: 48544kb
input:
1357 7 107 29 131 99 180 96 63
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 17ms
memory: 46192kb
input:
1357 7 124 180 60 103 142 145 68
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 20ms
memory: 44748kb
input:
750 66 7 2 2 1 7 10 9 10 5 9 10 11 11 5 4 3 8 6 5 5 6 9 5 1 7 11 8 5 4 6 4 2 7 2 9 11 4 8 10 8 6 2 8 7 11 3 10 9 4 3 7 5 5 9 6 2 10 7 5 2 5 4 9 3 11 9
output:
685840434
result:
ok single line: '685840434'
Test #12:
score: 0
Accepted
time: 23ms
memory: 45500kb
input:
750 66 6 1 3 6 6 2 11 7 4 4 7 5 4 9 7 2 2 6 7 10 6 3 5 4 6 5 6 5 3 10 7 9 6 5 11 1 1 9 4 6 7 3 3 4 7 11 4 5 1 8 7 10 9 10 2 6 6 5 8 8 4 4 11 5 3 8
output:
148626971
result:
ok single line: '148626971'
Test #13:
score: 0
Accepted
time: 19ms
memory: 45016kb
input:
750 66 3 5 3 11 11 9 9 4 7 8 3 4 4 5 11 9 1 6 9 6 7 8 11 7 9 7 1 10 3 8 10 6 3 4 8 11 9 6 1 11 1 8 7 7 2 9 5 5 6 1 8 10 10 9 5 11 3 9 10 6 1 6 3 8 8 3
output:
817964272
result:
ok single line: '817964272'
Test #14:
score: 0
Accepted
time: 27ms
memory: 44888kb
input:
750 66 2 8 1 1 7 11 4 8 5 6 3 11 11 5 3 2 1 6 3 6 6 5 2 8 11 6 6 7 8 1 5 11 6 8 2 3 7 10 10 6 6 11 7 5 6 6 5 9 7 3 4 4 10 4 6 4 3 9 6 6 11 2 4 6 6 11
output:
936531345
result:
ok single line: '936531345'
Test #15:
score: 0
Accepted
time: 20ms
memory: 46232kb
input:
750 66 4 6 11 1 6 9 7 1 5 4 5 6 2 8 1 2 11 6 5 3 1 6 9 8 5 9 6 2 5 1 5 3 8 6 8 5 7 4 8 1 11 11 10 8 4 6 5 10 7 8 8 8 3 9 1 8 2 9 7 5 3 1 1 11 7 4
output:
484040613
result:
ok single line: '484040613'
Test #16:
score: 0
Accepted
time: 23ms
memory: 46376kb
input:
750 66 4 9 10 7 10 11 3 7 1 6 11 4 2 11 5 5 1 2 9 7 8 3 5 8 5 6 11 6 1 11 8 8 9 6 6 9 9 7 11 11 3 7 8 10 8 9 9 5 8 8 9 7 7 11 8 6 1 10 1 11 11 11 3 5 11 8
output:
205283749
result:
ok single line: '205283749'
Test #17:
score: 0
Accepted
time: 28ms
memory: 46432kb
input:
10000 135 51 12 73 56 26 59 61 62 19 65 54 35 64 74 73 49 62 57 51 35 22 62 26 19 50 36 24 54 41 74 26 58 45 40 6 24 55 39 10 47 70 15 61 31 54 2 48 56 2 10 1 25 24 39 70 63 10 73 15 73 51 59 28 58 28 59 24 2 72 33 30 21 63 5 38 60 26 16 57 15 58 47 17 8 32 13 36 10 14 46 4 16 68 71 56 58 58 36 52 1...
output:
238689397
result:
ok single line: '238689397'
Test #18:
score: 0
Accepted
time: 24ms
memory: 44868kb
input:
10000 135 39 35 58 63 64 35 27 55 63 35 26 59 20 33 66 14 53 5 23 34 23 65 4 1 30 62 73 32 32 25 74 16 39 19 14 63 29 9 42 33 21 2 34 57 17 50 43 14 69 41 65 1 14 43 74 66 42 10 25 50 5 4 61 36 45 37 45 10 4 59 21 56 70 55 74 40 17 4 1 10 51 8 6 27 59 57 5 14 37 61 34 4 35 19 30 37 49 33 59 70 68 24...
output:
655049586
result:
ok single line: '655049586'
Test #19:
score: 0
Accepted
time: 24ms
memory: 45124kb
input:
10000 135 56 44 26 41 53 50 35 46 28 34 28 69 74 8 12 59 60 73 68 15 11 72 56 16 13 39 66 71 22 56 19 48 34 21 55 14 68 68 11 12 33 56 51 66 44 28 48 12 72 62 3 15 11 68 33 61 63 56 46 66 32 25 6 25 53 11 47 50 65 14 69 56 23 5 18 14 26 24 46 6 39 3 16 25 56 45 57 60 38 17 71 60 59 41 16 8 6 58 61 6...
output:
186140421
result:
ok single line: '186140421'
Test #20:
score: 0
Accepted
time: 24ms
memory: 45728kb
input:
10000 135 29 72 20 7 26 20 3 2 21 45 6 26 59 57 70 60 39 22 71 44 6 25 18 63 64 65 52 69 1 44 53 25 15 40 45 65 63 22 37 32 38 27 11 35 28 49 30 32 55 43 21 12 32 51 4 56 29 34 11 43 61 7 63 44 67 48 17 18 35 66 16 54 49 74 63 11 19 33 22 60 51 31 8 29 7 9 53 72 19 58 23 68 10 29 41 54 52 37 53 2 11...
output:
45969765
result:
ok single line: '45969765'
Test #21:
score: 0
Accepted
time: 24ms
memory: 45852kb
input:
10000 135 26 40 71 23 39 22 9 26 31 14 58 6 60 69 5 47 7 12 2 5 18 33 38 65 49 21 22 13 65 47 6 52 9 2 54 55 54 47 19 36 52 28 45 29 61 30 8 20 3 55 4 62 43 3 41 3 66 33 10 51 57 61 54 1 21 39 61 51 20 12 34 23 71 45 61 58 8 57 19 9 8 9 59 45 67 29 43 68 8 6 62 38 24 28 31 26 25 9 2 73 30 13 51 18 3...
output:
846150921
result:
ok single line: '846150921'
Test #22:
score: -100
Runtime Error
input:
1000000 5000 104 84 160 121 175 76 184 34 146 1 63 137 83 3 173 64 88 53 200 64 126 87 182 18 75 42 61 114 15 113 128 12 59 56 18 104 58 83 199 174 78 52 177 11 67 58 35 30 169 40 153 11 65 143 62 21 95 12 163 53 172 38 34 127 8 5 36 84 155 66 196 4 15 175 104 132 196 9 101 47 106 38 167 154 71 137 ...