QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408063#5524. Help Me to Get This Publisheducup-team173WA 14ms4952kbC++201.8kb2024-05-09 17:17:092024-05-09 17:17:09

Judging History

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

  • [2024-05-09 17:17:09]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:4952kb
  • [2024-05-09 17:17:09]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define db double

using namespace std;

const int Mod = 998244353;

int f[105][105][105];

void add(int&x, int y) {
    x += y; 
    x >= Mod ? x -= Mod : 0;
}

int Fpow(int x, int k) {
    int ans = 1; 
    for (; k; k >>= 1, x = 1ll * x * x % Mod) {
        if (k & 1) {
            ans = 1ll * ans * x % Mod;
        }
    }
    return ans;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n, 0);
    int m = 0;
    vector<int> Inv(n + 1, 0), Fac(n + 1, 0);
    Fac[0] = 1;
    for (int i = 1; i <= n; i++) {
        Fac[i] = 1ll * Fac[i - 1] * i % Mod;
    }
    Inv[n] = Fpow(Fac[n], Mod - 2);
    for (int i = n; i >= 1; i--) {
        Inv[i - 1] = 1ll * Inv[i] * i % Mod;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x == -1) m++;
        else a[x]++;
    }
    int flag = 0;
    for (int t = n - 1; t >= 1; t--) {
        for (int num = 1; num <= n; num++) {
            for (int p = 0; num + p + a[t] <= n; p++) {
                for (int l = 2; (l >> 1) + p + a[t] <= n; l++) {
                    add(f[t][(l >> 1) + p + a[t]][num + p + a[t]], 1ll * f[t + 1][l][num] * Inv[p] % Mod);
                }
            }
        }
        if (!flag) {
            for (int p = 0; p <= n; p++) {
                f[t][p + a[t]][p + a[t]] = Inv[p];
            }
        }
        if (a[t]) {
           flag = 1;
        }
    }
    int ans = 0;
    for(int t = 2; t <= n; t++) {
        add(ans, f[1][t][n]);
    }
    cout << 1ll * ans * Fac[m] % Mod << '\n';
}

int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

input:

2
1 -1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3
-1 -1 -1

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

6
5 -1 -1 -1 -1 -1

output:

120

result:

ok 1 number(s): "120"

Test #4:

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

input:

4
-1 -1 -1 -1

output:

24

result:

ok 1 number(s): "24"

Test #5:

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

input:

5
-1 -1 -1 -1 -1

output:

182

result:

ok 1 number(s): "182"

Test #6:

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

input:

6
-1 -1 -1 -1 -1 -1

output:

1659

result:

ok 1 number(s): "1659"

Test #7:

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

input:

7
-1 -1 -1 -1 -1 -1 -1

output:

17677

result:

ok 1 number(s): "17677"

Test #8:

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

input:

8
-1 -1 -1 -1 -1 -1 -1 -1

output:

215403

result:

ok 1 number(s): "215403"

Test #9:

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

input:

9
-1 -1 -1 -1 -1 -1 -1 -1 -1

output:

2953953

result:

ok 1 number(s): "2953953"

Test #10:

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

input:

10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

45017641

result:

ok 1 number(s): "45017641"

Test #11:

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

input:

11
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

754725282

result:

ok 1 number(s): "754725282"

Test #12:

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

input:

12
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

826640071

result:

ok 1 number(s): "826640071"

Test #13:

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

input:

13
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

993120404

result:

ok 1 number(s): "993120404"

Test #14:

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

input:

14
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

698356428

result:

ok 1 number(s): "698356428"

Test #15:

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

input:

15
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

118946018

result:

ok 1 number(s): "118946018"

Test #16:

score: 0
Accepted
time: 11ms
memory: 4756kb

input:

50
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

564173612

result:

ok 1 number(s): "564173612"

Test #17:

score: 0
Accepted
time: 12ms
memory: 4952kb

input:

51
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

350683684

result:

ok 1 number(s): "350683684"

Test #18:

score: 0
Accepted
time: 13ms
memory: 4832kb

input:

52
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

395178587

result:

ok 1 number(s): "395178587"

Test #19:

score: -100
Wrong Answer
time: 14ms
memory: 4872kb

input:

53
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

587443958

result:

wrong answer 1st numbers differ - expected: '656031164', found: '587443958'