CSES - Aalto Competitive Programming 2024 - wk11 - Mon - Results
Submission details
Task:Skittles
Sender:odanobunaga8199
Submission time:2024-11-18 16:41:21 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.01 sdetails
#140.01 sdetails
#150.01 sdetails
#160.01 sdetails
#170.01 sdetails
#180.01 sdetails
#190.01 sdetails
#200.01 sdetails
#210.01 sdetails
#220.01 sdetails
#230.01 sdetails
#240.01 sdetails
#250.00 sdetails
#260.01 sdetails
#270.01 sdetails
#280.01 sdetails
#290.01 sdetails
#300.01 sdetails
#310.01 sdetails
#320.01 sdetails
#330.01 sdetails
#340.00 sdetails
#350.01 sdetails
#360.01 sdetails
#370.01 sdetails
#380.01 sdetails
#390.01 sdetails
#400.01 sdetails
#410.01 sdetails
#420.01 sdetails
#430.01 sdetails
#440.01 sdetails
#450.01 sdetails
#460.01 sdetails
#470.01 sdetails
#480.01 sdetails
#490.01 sdetails
#500.00 sdetails
#510.01 sdetails
#520.01 sdetails
#530.01 sdetails
#540.01 sdetails
#550.01 sdetails
#560.01 sdetails
#570.01 sdetails
#580.01 sdetails
#590.01 sdetails
#600.01 sdetails
#610.01 sdetails
#620.01 sdetails
#630.01 sdetails

Code

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

const int MOD = 998244353;
const int MAX = 200010;

ll power_mod(ll x, ll y, ll mod) {
    ll res = 1;
    x %= mod;
    while(y > 0){
        if(y & 1){
            res = res * x % mod;
        }
        x = x * x % mod;
        y >>=1;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    
    if(n ==1){
        if(a > b){
            cout << 0;
        }
        else{
            ll result = (b - a +1) % MOD;
            cout << result;
        }
        return 0;
    }
    
    ll max_val = n + b;
    vector<ll> fact(max_val +1, 1);
    for(int i=1;i<=max_val;i++) {
        fact[i] = fact[i-1] * i % MOD;
    }
    vector<ll> inv_fact(max_val +1,1);
    inv_fact[max_val] = power_mod(fact[max_val], MOD -2, MOD);
    for(int i=max_val -1;i>=0;i--){
        inv_fact[i] = inv_fact[i+1] * (i+1) % MOD;
    }
    
    auto comb = [&](ll k) -> ll {
        ll N = n + k -1;
        ll K = n -1;
        if(N < K || K <0) return 0;
        return fact[N] * inv_fact[K] % MOD * inv_fact[N - K] % MOD;
    };
    
    ll result =0;
    for(ll k =a; k <= b; k++){
        result = (result + comb(k));
    }
    cout << result;
}

Test details

Test 1

Verdict: ACCEPTED

input
1 1 10

correct output
10

user output
10

Test 2

Verdict: ACCEPTED

input
2 3 3

correct output
4

user output
4

Test 3

Verdict: ACCEPTED

input
2 4 5

correct output
11

user output
11

Test 4

Verdict: ACCEPTED

input
3 4 5

correct output
36

user output
36

Test 5

Verdict: ACCEPTED

input
3 2 2

correct output
6

user output
6

Test 6

Verdict: ACCEPTED

input
5 5 5

correct output
126

user output
126

Test 7

Verdict: ACCEPTED

input
10 10 10

correct output
92378

user output
92378

Test 8

Verdict: ACCEPTED

input
10 1 10

correct output
184755

user output
184755

Test 9

Verdict: ACCEPTED

input
100 100 100

correct output
866655715

user output
866655715

Test 10

Verdict: ACCEPTED

input
10 100 100

correct output
918123961

user output
918123961

Test 11

Verdict: ACCEPTED

input
1000 10 10

correct output
84965120

user output
84965120

Test 12

Verdict: ACCEPTED

input
10000 10000 10000

correct output
658363258

user output
658363258

Test 13

Verdict: ACCEPTED

input
100000 100000 100000

correct output
966937032

user output
966937032

Test 14

Verdict:

input
54883 59286 71521

correct output
908996595

user output
6098185504719

Test 15

Verdict:

input
41703 72034 99721

correct output
139159644

user output
13816839249517

Test 16

Verdict:

input
43601 2593 18509

correct output
804369499

user output
8002731103147

Test 17

Verdict:

input
55081 7073 70816

correct output
806880502

user output
31799880745317

Test 18

Verdict:

input
96705 54725 90064

correct output
521461113

user output
17590585205326

Test 19

Verdict:

input
22200 5519 87075

correct output
866679044

user output
40671338108970

Test 20

Verdict:

input
89288 33199 94750

correct output
812654801

user output
30666879178961

Test 21

Verdict:

input
7631 22735 77994

correct output
30255908

user output
27556565620473

Test 22

Verdict:

input
87345 1112 96856

correct output
944788802

user output
47764940591146

Test 23

Verdict:

input
1038 36447 50189

correct output
654272260

user output
6809679004073

Test 24

Verdict:

input
41703 72034 99721

correct output
139159644

user output
13816839249517

Test 25

Verdict:

input
18028 1948 6831

correct output
631722506

user output
2434351455120

Test 26

Verdict:

input
4873 28912 79929

correct output
106074189

user output
25404426613686

Test 27

Verdict:

input
28606 2900 95813

correct output
538554734

user output
46542683269006

Test 28

Verdict:

input
25093 4610 68059

correct output
799962519

user output
31584253047086

Test 29

Verdict:

input
67575 4472 32712

correct output
857647130

user output
14075104780077

Test 30

Verdict:

input
82449 18136 86245

correct output
420446937

user output
33925754783642

Test 31

Verdict:

input
18558 38661 75914

correct output
924425479

user output
18562279925161

Test 32

Verdict:

input
35543 34086 47960

correct output
210554536

user output
6955977206240

Test 33

Verdict:

input
20101 32903 99080

correct output
88647511

user output
33052957419694

Test 34

Verdict:

input
18028 1948 6831

correct output
631722506

user output
2434351455120

Test 35

Verdict:

input
61218 12076 16908

correct output
820171450

user output
2406589062180

Test 36

Verdict:

input
78139 13111 69284

correct output
904117059

user output
28070537079066

Test 37

Verdict:

input
45455 2862 43952

correct output
430742811

user output
20575245102494

Test 38

Verdict:

input
84538 61888 77158

correct output
294818599

user output
7613904498930

Test 39

Verdict:

input
26937 59685 80971

correct output
680140546

user output
10656938608821

Test 40

Verdict:

input
30632 9727 88573

correct output
877318826

user output
39333701315732

Test 41

Verdict:

input
55737 66074 71002

correct output
123569267

user output
2461794143765

Test 42

Verdict:

input
59351 587 51636

correct output
122513346

user output
25441378093904

Test 43

Verdict:

input
8954 7866 51810

correct output
961929284

user output
21834562418100

Test 44

Verdict:

input
61218 12076 16908

correct output
820171450

user output
2406589062180

Test 45

Verdict:

input
9556 43003 92502

correct output
424034313

user output
24730929635535

Test 46

Verdict:

input
20433 945 23474

correct output
794687216

user output
11292934808352

Test 47

Verdict:

input
9941 45344 78340

correct output
875489658

user output
16436968761803

Test 48

Verdict:

input
82532 68582 70655

correct output
238007640

user output
1036415646054

Test 49

Verdict:

input
52729 37586 66259

correct output
93243919

user output
14332885664293

Test 50

Verdict:

input
10475 17392 24871

correct output
977605482

user output
3734411485702

Test 51

Verdict:

input
76232 88012 95143

correct output
871309467

user output
3572589604501

Test 52

Verdict:

input
77184 58424 64500

correct output
693972156

user output
3044341004453

Test 53

Verdict:

input
96888 47083 55295

correct output
406195062

user output
4104188730245

Test 54

Verdict:

input
9556 43003 92502

correct output
424034313

user output
24730929635535

Test 55

Verdict:

input
83891 47894 87748

correct output
686766192

user output
19911668631130

Test 56

Verdict:

input
85080 21779 92819

correct output
114946782

user output
35404847414633

Test 57

Verdict:

input
88235 6779 56603

correct output
70147249

user output
24925233397306

Test 58

Verdict:

input
88858 66896 98375

correct output
601764178

user output
15755892387577

Test 59

Verdict:

input
50586 8901 76084

correct output
881324074

user output
33648703730645

Test 60

Verdict:

input
87594 26882 34225

correct output
42681251

user output
3702530986528

Test 61

Verdict:

input
73130 30310 55103

correct output
843664756

user output
12371087687132

Test 62

Verdict:

input
63584 31874 92876

correct output
437812641

user output
30558693946677

Test 63

Verdict:

input
88714 2531 74051

correct output
603847190

user output
35701814887882