QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643916#9436. Some Sum of Subsetarayi_chris_max#WA 1ms3656kbC++201.4kb2024-10-16 07:59:282024-10-16 07:59:29

Judging History

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

  • [2024-10-16 07:59:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3656kb
  • [2024-10-16 07:59:28]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 3003;
const ll mod = 998244353LL;

int n, m;
int a[N];
ll fact[N], inv[N];
ll dp[N], ans[N];
ll c(int n, int k) {
    ll ret = fact[n];
    ret *= inv[k];
    ret %= mod;
    ret *= inv[n - k];
    ret %= mod;
    return ret;
}
ll pow(ll a, ll b = mod - 2) {
    ll ret = 1;
    while (b) {
        if (b & 1) ret *= a, ret %= mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i - 1];
        fact[i] = fact[i - 1] * 1LL * i;
        inv[i] = pow(fact[i]);
    }
    sort(a, a + n);
    reverse(a, a + n);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        ll sm = 0;
        for (int x = m; x >= 0; x--) {
            if (x + a[i] >= m) {
                sm += dp[x];
                dp[m] += dp[x];
                dp[m] %= mod;
            } else {
                dp[x + a[i]] += dp[x];
                dp[x + a[i]] %= mod;
            }
        }
        sm %= mod;
        for (int k = 0; k < n - i; k++) {
            ans[k] += sm * c(n - i - 1, k);
            ans[k] %= mod;
        }
    }
    for (int i = 0; i <= n; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 7
3 1 5 2

output:

6
4
1
0
0

result:

ok 5 tokens

Test #2:

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

input:

1 5
7

output:

1
0

result:

ok 2 tokens

Test #3:

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

input:

9 18
1 9 5 6 2 7 1 4 8

output:

346
309
230
126
46
10
1
0
0
0

result:

ok 10 tokens

Test #4:

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

input:

1 1467
556

output:

0
0

result:

ok 2 tokens

Test #5:

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

input:

1 1753
2514

output:

1
0

result:

ok 2 tokens

Test #6:

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

input:

1 1182
1182

output:

1
0

result:

ok 2 tokens

Test #7:

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

input:

2 1741
955 835

output:

1
0
0

result:

ok 3 tokens

Test #8:

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

input:

2 1481
2004 1570

output:

3
1
0

result:

ok 3 tokens

Test #9:

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

input:

2 1336
1336 1336

output:

3
1
0

result:

ok 3 tokens

Test #10:

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

input:

12 400
2163 2729 1322 2787 2404 1068 1502 746 898 2057 1771 502

output:

4095
4083
4017
3797
3302
2510
1586
794
299
79
13
1
0

result:

ok 13 tokens

Test #11:

score: -100
Wrong Answer
time: 1ms
memory: 3612kb

input:

42 1609
532 722 2650 2889 2260 659 1831 401 2779 1262 2185 1479 515 552 1627 637 1080 580 1589 2154 2650 219 2924 1712 311 2609 1062 968 1357 1310 1942 2419 2465 300 2546 2537 2967 1197 2271 1551 999 2531

output:

619558802
332246012
692508176
136710607
463787628
613640608
33025232
367918207
14141635
519959368
286990022
94322813
827116616
421344336
-960455437
-39034173
52962926
-669431649
903357432
-212807081
569135319
-226433118
664928282
601128140
931894262
544609656
615403461
-202414814
935525193
-79330569...

result:

wrong answer 1st words differ - expected: '780135870', found: '619558802'