QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617911#7662. Kaldorian KnightsSkyEyeControllerRE 6ms11540kbC++231.1kb2024-10-06 17:41:002024-10-06 17:41:01

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 17:41:01]
  • 评测
  • 测评结果:RE
  • 用时:6ms
  • 内存:11540kb
  • [2024-10-06 17:41:00]
  • 提交

answer

#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 9;
const int mod = 1e9 + 7;
const int fur = 5010;
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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11392kb

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 6ms
memory: 11468kb

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 6ms
memory: 11472kb

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

score: 0
Accepted
time: 3ms
memory: 11344kb

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 5ms
memory: 11396kb

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: 3ms
memory: 11476kb

input:

1357 7
56
173
21
103
96
149
38

output:

1000000006

result:

ok single line: '1000000006'

Test #7:

score: 0
Accepted
time: 6ms
memory: 11536kb

input:

1357 5
190
198
257
256
261

output:

1000000005

result:

ok single line: '1000000005'

Test #8:

score: 0
Accepted
time: 5ms
memory: 11488kb

input:

1357 7
144
56
113
20
113
141
107

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 3ms
memory: 11356kb

input:

1357 7
107
29
131
99
180
96
63

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 6ms
memory: 11540kb

input:

1357 7
124
180
60
103
142
145
68

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 3ms
memory: 11532kb

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: 5ms
memory: 11412kb

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: 6ms
memory: 11416kb

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: 6ms
memory: 11416kb

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: 0ms
memory: 11448kb

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: 0ms
memory: 11512kb

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: -100
Runtime Error

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:


result: