QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775116#9436. Some Sum of SubsetCUET_infinite_tsukuyomi#WA 1ms3860kbC++203.5kb2024-11-23 14:47:012024-11-23 14:47:01

Judging History

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

  • [2024-11-23 14:47:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3860kb
  • [2024-11-23 14:47:01]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;

#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
//#define int long long



// Don't Start typing till you complete the idea.


// Check these things for WA and before submitting
// 1. Did you clear all the global arrays
// 2. Did you checked your <= >= < > 
// 3. Did you take the input properly. Did you use break or return while taking input?
// 4. Did you divide by 0.
// 5. Check array , vector , etc size
// 6. in the while loop did you miss something that would cause infinite loop?
// 7. Did you save your dp?
// 8. Are you trying to use something after deleting it?
// 9. Did you read the problem statement wrong?
// 10. Did you check the constrains of the problem properly
// 11. Did you checked for smaller cases like 1 , 0 , etc
// 12. Is it something to with overflow?
// 13. Did you initialized all the variables properly?
// 14. Did you use the formulas correctly?

// STRESS TESTING !!!!!! STRESS TESTING !!!!!
// STRESS Testing Not working?
// Stress test for multiple cases? 
// Stress test for big inputs?
// Stress test for really small inputs?
// Even then if it doesn't work -> Did you wrote the wrong Brute force code


// Check these things if you are not generating ideas
// 1. Did you try thinking it in reverse?
// 2. Read the problem statement again
// 3. Check the constraints again
// 4. Try smaller cases in notebook and try to expand
// 5. Think about invariants
// 6. Think simpler ideas maybe?
// 7. Think brute force and try to get something out of it.
// 8. Maybe take a deep breath and take a break for few minutes and drink some water? :3 
const int M = 3009;
const int N = 3009;
const int MOD = 998244353;
int dp[M];
int dp2[M];
int val[N];
int ans[N];
int fact[N];
int inv[N];
long long binpow(long long a, long long b) {
    long long res = 1;
    a %= MOD;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
void prec(){
  fact[0] = fact[1] = inv[0] = 1;
  for(int i = 2; i <= 3000; i++){
    fact[i] = 1LL * fact[i - 1] * i % MOD;
  }
  inv[3000] = binpow(fact[3000] , MOD - 2);
  for(int i = 3000 - 1; i >= 1; i--){
    inv[i] = 1LL * inv[i + 1] * (i + 1) % MOD;
  }
}
int ncr(int n , int r){
  int num = 1LL * fact[n] * inv[r] % MOD;
  num = 1LL * num * inv[n - r] % MOD;
  return num;
}
void GG()
{
	int n , k;
  cin >> n >> k;
  vector<int> v(n + 1);
  for(int i = 1; i <= n; i++) cin >> v[i];
  sort(v.begin() + 1 , v.end() , greater<int>());
  dp[0] = 1;
  for(int i = 1; i <= n; i++){
    for(int j = 0; j < k; j++){
      dp2[min(k , j + v[i])] = (dp2[min(k , j + v[i])] + dp[j]) % MOD;
    }
    val[i] = dp2[k];
    for(int j = 0; j <= k; j++){
      dp2[j] = (dp2[j] + dp[j]) % MOD;
    }
    for(int j = 0; j <= k; j++){
      dp[j] = dp2[j];
      dp2[j] = 0;
    }
  }
  for(int i = 1; i <= n; i++){
    if(val[i] == 0) continue;
    for(int xtr = 0; xtr <= n - i; xtr++){
      int ad = 1LL * val[i] * ncr(n - i , xtr);
      ans[xtr] = (ans[xtr] + ad) % MOD;
    }
  }
  for(int i = n - 1; i >= 0; i--) ans[i] = (ans[i + 1] + ans[i]) % MOD;
  for(int i = 0; i <= n; i++) cout << ans[i] << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  prec();
	int ttc=1;
	// cin>>ttc;
	//int cnt=0;
	while(ttc--)
	{
		//cout<<"Case "<<++cnt<<": ";
		GG();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1 5
7

output:

1
0

result:

ok 2 tokens

Test #3:

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

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

input:

1 1467
556

output:

0
0

result:

ok 2 tokens

Test #5:

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

input:

1 1753
2514

output:

1
0

result:

ok 2 tokens

Test #6:

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

input:

1 1182
1182

output:

1
0

result:

ok 2 tokens

Test #7:

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

input:

2 1741
955 835

output:

1
0
0

result:

ok 3 tokens

Test #8:

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

input:

2 1481
2004 1570

output:

3
1
0

result:

ok 3 tokens

Test #9:

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

input:

2 1336
1336 1336

output:

3
1
0

result:

ok 3 tokens

Test #10:

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

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: 0
Accepted
time: 1ms
memory: 3644kb

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:

780135870
780135476
780133126
780115746
779984839
779086101
773744618
746617208
628409426
182368401
707355349
419830171
342550392
778349940
825220795
979080057
177969332
68371210
748001250
187917550
492152134
287983982
592218358
32133349
711757614
602140473
799225822
952989153
1466429
437088327
3596...

result:

ok 43 tokens

Test #12:

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

input:

93 24
1687 2324 1216 2696 2884 1678 1301 1957 1247 526 2519 2252 2141 960 1505 175 315 388 440 892 837 1942 256 1667 641 1629 2565 2837 1200 2427 418 1072 427 1589 969 886 2991 2249 539 1132 949 2425 2616 2107 1259 582 1979 386 177 1860 2825 316 2004 956 1218 2332 1498 2939 1126 1706 404 1604 505 11...

output:

958346177
958346084
958341806
958212040
955292305
903321022
141075538
649896624
629379357
102857051
471642575
350313411
852223261
984774652
743966819
740155079
222450670
637406264
282036249
875748580
177575581
602719974
451360351
244531346
556337405
139169356
737451056
595307440
402860967
935337558
...

result:

ok 94 tokens

Test #13:

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

input:

162 1057
695 2739 2637 797 503 1051 2243 2429 160 1900 1798 1584 1488 1377 2764 1324 978 2696 913 2651 817 1522 819 314 882 1536 2785 2193 540 2417 1357 959 2765 408 1693 1305 1643 2565 2677 966 860 2547 936 2123 496 2098 2130 38 378 1395 2725 2657 2107 2096 2039 2421 2548 431 2205 2907 1085 2919 25...

output:

506855190
506851485
506802502
505695003
473851112
562495962
401522721
427957517
562090995
295460322
976270869
280769540
822237093
810885130
791454712
587363056
553471744
322735351
177039268
882353756
82311399
381499748
602338731
66161755
587306778
31104491
574372172
899515556
142045578
954646282
105...

result:

wrong answer 1st words differ - expected: '389411124', found: '506855190'