QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691599#7662. Kaldorian Knightspmh_WA 1ms5700kbC++171.2kb2024-10-31 12:10:592024-10-31 12:10:59

Judging History

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

  • [2024-10-31 12:10:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5700kb
  • [2024-10-31 12:10:59]
  • 提交

answer

#include<bits/stdc++.h>

#define int long long
using namespace std;


const long long INF = 1e5 + 10, MOD = 1e9 + 7, MOD2 = 999999937;
const long long MAXN = 1e6 + 5;

int n, h;
int k[MAXN];
int s[MAXN];
int f[MAXN];

class Solution
{
public:
    void setup(int n)
    {
        f[0] = 1;
        for (int i = 1; i <= n; i++)
        {
            f[i] = (f[i - 1] * i) % MOD;
        }
    }

    void solve()
    {
        cin >> n >> h;
        for (int i = 1; i <= h; i++)
        {
            cin >> k[i];
            s[i] = s[i - 1] + k[i];
        }

        if (s[h] == n) 
        {
            cout << 0;
            return;
        }
        setup(n);
        if (h == 0)
        {
            cout << f[n];
            return;
        }

        int m = 0;
        for (int i = 1; i < h; i++)
        {
            m += (((f[s[i]] * f[n - s[i] - 1]) % MOD) * k[i + 1]) % MOD;
        }
        m += (f[s[h]] * f[n - s[h]]) % MOD;

        cout << (f[n] + MOD - m) % MOD << '\n';

    }
};

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    Solution().solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3656kb

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5684kb

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5632kb

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: 1ms
memory: 5648kb

input:

1357 7
56
173
21
103
96
149
38

output:

-483732261

result:

wrong answer 1st lines differ - expected: '1000000006', found: '-483732261'