QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691611#7662. Kaldorian Knightspmh_WA 1ms5768kbC++171.2kb2024-10-31 12:13:532024-10-31 12:13:53

Judging History

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

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

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 %= MOD;
        }
        m += (f[s[h]] * f[n - s[h]]) % MOD;
        m %= 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;
}

详细

Test #1:

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

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

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

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5764kb

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

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

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 5624kb

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: 5640kb

input:

1357 7
56
173
21
103
96
149
38

output:

516267746

result:

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