QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408071#5524. Help Me to Get This Publisheducup-team173WA 18ms4892kbC++201.7kb2024-05-09 17:32:342024-05-09 17:32:36

Judging History

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

  • [2024-05-09 17:32:36]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:4892kb
  • [2024-05-09 17:32:34]
  • 提交

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]++;
    }
    f[n][0][0] = 1;
    for (int t = n - 1; t >= 1; t--) {
        for (int num = 0; num <= n; num++) {
            for (int p = 0; num + p + a[t] <= n; p++) {
                for (int l = 0; (l + p + a[t] >> 1) <= n; l++) {
                    if (l + p + a[t] != 1) {
                        add(f[t][(l + p + a[t] >> 1)][num + p + a[t]], 1ll * f[t + 1][l][num] * Inv[p] % Mod);
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int t = 1; 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: 3464kb

input:

2
1 -1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3
-1 -1 -1

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

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

output:

120

result:

ok 1 number(s): "120"

Test #4:

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

input:

4
-1 -1 -1 -1

output:

24

result:

ok 1 number(s): "24"

Test #5:

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

input:

5
-1 -1 -1 -1 -1

output:

182

result:

ok 1 number(s): "182"

Test #6:

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

input:

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

output:

1659

result:

ok 1 number(s): "1659"

Test #7:

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

input:

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

output:

17677

result:

ok 1 number(s): "17677"

Test #8:

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

input:

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

output:

215403

result:

ok 1 number(s): "215403"

Test #9:

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

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

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

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

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

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

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

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: 15ms
memory: 4892kb

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: 16ms
memory: 4816kb

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: -100
Wrong Answer
time: 18ms
memory: 4876kb

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:

645847196

result:

wrong answer 1st numbers differ - expected: '395178587', found: '645847196'