QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608146#6614. Cards of Magicucup-team3519AC ✓125ms5584kbC++203.4kb2024-10-03 19:05:502024-10-03 19:05:50

Judging History

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

  • [2024-10-03 19:05:50]
  • 评测
  • 测评结果:AC
  • 用时:125ms
  • 内存:5584kb
  • [2024-10-03 19:05:50]
  • 提交

answer

#include <bits/stdc++.h>

template <int m>
struct ModInt {
private:
    int raw_;
    using mint = ModInt;
    using i64 = int64_t;

public:
    ModInt() {
        raw_ = 0;
    }
    template <typename T>
    ModInt(const T &v) {
        raw_ = v % m;
    }
    int value() const {
        return (raw_ + m) % m;
    }
    mint &operator+=(const mint &rhs) {
        raw_ = (raw_ + rhs.raw_) % m;
        return *this;
    }
    mint &operator-=(const mint &rhs) {
        raw_ = (raw_ - rhs.raw_) % m;
        return *this;
    }
    mint &operator*=(const mint &rhs) {
        raw_ = (i64)raw_ * rhs.raw_ % m;
        return *this;
    }
    mint &operator/=(const mint &rhs) {
        return (*this) *= qpow(rhs, m - 2);
    }
    friend mint operator+(const mint &lhs, const mint &rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint &lhs, const mint &rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint &lhs, const mint &rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint &lhs, const mint &rhs) {
        return mint(lhs) /= rhs;
    }
    static constexpr int mod() {
        return m;
    }
    static mint qpow(mint a, i64 b) {
        mint res = 1;
        while (b) {
            if (b & 1) {
                res *= a;
            }
            a *= a, b >>= 1;
        }
        return res;
    }

};

using mint = ModInt<998244353>;
using namespace std;
using ll=long long;
vector<mint>fact,ifact;
void init(int n){
    fact.resize(n+4);
    ifact.resize(n+4);
    fact[0]=ifact[0]=1;
    for(int i=1;i<=n+3;i++){
        fact[i]=fact[i-1]*i;
        ifact[i]=1/fact[i];
    }
}
mint C(int n,int m){
    if(n<0||n-m<0||m<0)return 0;
    return fact[n]*ifact[n-m]*ifact[m];
}
mint C_inc(mint pre,int l,int r,int k){
    return 2*pre+C(k,l-1)-C(k,r);
}
void solve(){
    
    int n;
    cin>>n;
    init(n);
    vector<mint>p(n+3);
    mint f23=mint(2)/3;
    mint f13=mint(1)/3;
    for(int k=1;k<=n+1;k++){
        p[k]+=1-mint::qpow(f23,k)*2-k*mint::qpow(f13,k)*mint::qpow(2,k-1)+mint::qpow(f13,k)*(k+1);
        // cout<<p[k].value();
        if(k-1>=n)
        p[k]+=mint::qpow(f13,k);
        if(k>=n&&k>=2)
        p[k]+=mint::qpow(f13,k)*k;
        if(2*k>=n)
        p[k]+=mint::qpow(f23,k)-mint::qpow(f13,k);
    }
    int l=1,r=0;
    mint pre=0;
    for(int k=2;k<=n+1;k++){
        int cl=1,cr=min((3*k-1-n)/2,k-1);
        if(cl>cr)continue;
        while(r<cr){
            r++;
            pre+=C(k,r);
            
        }
        p[k]+=pre*mint::qpow(f13,k);
        pre=C_inc(pre,l,r,k);
    }
    l=1,r=0,pre=0;
    for(int k=3;k<=n+1;k++){
        int cl=1,cr=min((3*k-n)/2,k-2);
        if(cl>cr)continue;
        while(r<cr){
            r++;
            pre+=C(k-1,r);
        }
        p[k]+=pre*mint::qpow(f13,k)*k;
        pre=C_inc(pre,l,r,k-1);
    }
    p[n+2]=1-mint::qpow(f13,n+2);
    mint ans=0;
    for(int i=1;i<=n+2;i++){
        ans+=(p[i]-p[i-1])*i;
    }
    
    // for(int i=0;i<=n+2;i++){
    //     // assert(p[i]==()
    //     cout<<p[i].value()<<' ';
    // }
    // cout<<'\n';
    // cout<<(mint(8)/9).value();
    ans+=mint::qpow(f13,n+2)*(n+mint(7)/2);

    cout<<ans.value();
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1

output:

831870296

result:

ok 1 number(s): "831870296"

Test #2:

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

input:

5

output:

835978299

result:

ok 1 number(s): "835978299"

Test #3:

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

input:

2

output:

277290100

result:

ok 1 number(s): "277290100"

Test #4:

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

input:

3

output:

979758349

result:

ok 1 number(s): "979758349"

Test #5:

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

input:

4

output:

141726053

result:

ok 1 number(s): "141726053"

Test #6:

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

input:

6

output:

393683476

result:

ok 1 number(s): "393683476"

Test #7:

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

input:

7

output:

206541188

result:

ok 1 number(s): "206541188"

Test #8:

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

input:

8

output:

993603837

result:

ok 1 number(s): "993603837"

Test #9:

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

input:

9

output:

709289564

result:

ok 1 number(s): "709289564"

Test #10:

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

input:

10

output:

445988648

result:

ok 1 number(s): "445988648"

Test #11:

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

input:

11

output:

622925737

result:

ok 1 number(s): "622925737"

Test #12:

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

input:

12

output:

363599458

result:

ok 1 number(s): "363599458"

Test #13:

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

input:

13

output:

338621482

result:

ok 1 number(s): "338621482"

Test #14:

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

input:

14

output:

397966377

result:

ok 1 number(s): "397966377"

Test #15:

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

input:

15

output:

911767168

result:

ok 1 number(s): "911767168"

Test #16:

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

input:

16

output:

664727836

result:

ok 1 number(s): "664727836"

Test #17:

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

input:

17

output:

868443132

result:

ok 1 number(s): "868443132"

Test #18:

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

input:

18

output:

796806191

result:

ok 1 number(s): "796806191"

Test #19:

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

input:

19

output:

36284050

result:

ok 1 number(s): "36284050"

Test #20:

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

input:

20

output:

78593146

result:

ok 1 number(s): "78593146"

Test #21:

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

input:

21

output:

113581844

result:

ok 1 number(s): "113581844"

Test #22:

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

input:

22

output:

652629455

result:

ok 1 number(s): "652629455"

Test #23:

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

input:

23

output:

26889816

result:

ok 1 number(s): "26889816"

Test #24:

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

input:

24

output:

973075191

result:

ok 1 number(s): "973075191"

Test #25:

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

input:

25

output:

606233734

result:

ok 1 number(s): "606233734"

Test #26:

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

input:

26

output:

251968195

result:

ok 1 number(s): "251968195"

Test #27:

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

input:

27

output:

160663854

result:

ok 1 number(s): "160663854"

Test #28:

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

input:

28

output:

644704526

result:

ok 1 number(s): "644704526"

Test #29:

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

input:

29

output:

880366020

result:

ok 1 number(s): "880366020"

Test #30:

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

input:

30

output:

563180515

result:

ok 1 number(s): "563180515"

Test #31:

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

input:

31

output:

488966461

result:

ok 1 number(s): "488966461"

Test #32:

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

input:

32

output:

73977159

result:

ok 1 number(s): "73977159"

Test #33:

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

input:

33

output:

478257304

result:

ok 1 number(s): "478257304"

Test #34:

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

input:

34

output:

840731886

result:

ok 1 number(s): "840731886"

Test #35:

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

input:

35

output:

116945142

result:

ok 1 number(s): "116945142"

Test #36:

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

input:

36

output:

965694497

result:

ok 1 number(s): "965694497"

Test #37:

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

input:

37

output:

167489378

result:

ok 1 number(s): "167489378"

Test #38:

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

input:

38

output:

100691350

result:

ok 1 number(s): "100691350"

Test #39:

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

input:

39

output:

160240217

result:

ok 1 number(s): "160240217"

Test #40:

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

input:

40

output:

151280240

result:

ok 1 number(s): "151280240"

Test #41:

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

input:

41

output:

521028725

result:

ok 1 number(s): "521028725"

Test #42:

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

input:

42

output:

691288796

result:

ok 1 number(s): "691288796"

Test #43:

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

input:

43

output:

695894234

result:

ok 1 number(s): "695894234"

Test #44:

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

input:

44

output:

216804850

result:

ok 1 number(s): "216804850"

Test #45:

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

input:

45

output:

39241895

result:

ok 1 number(s): "39241895"

Test #46:

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

input:

46

output:

471395300

result:

ok 1 number(s): "471395300"

Test #47:

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

input:

47

output:

957503329

result:

ok 1 number(s): "957503329"

Test #48:

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

input:

48

output:

658978397

result:

ok 1 number(s): "658978397"

Test #49:

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

input:

49

output:

99569804

result:

ok 1 number(s): "99569804"

Test #50:

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

input:

50

output:

169299123

result:

ok 1 number(s): "169299123"

Test #51:

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

input:

60

output:

977734538

result:

ok 1 number(s): "977734538"

Test #52:

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

input:

70

output:

970937590

result:

ok 1 number(s): "970937590"

Test #53:

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

input:

80

output:

68069121

result:

ok 1 number(s): "68069121"

Test #54:

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

input:

90

output:

822014036

result:

ok 1 number(s): "822014036"

Test #55:

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

input:

100

output:

984213121

result:

ok 1 number(s): "984213121"

Test #56:

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

input:

200

output:

490385842

result:

ok 1 number(s): "490385842"

Test #57:

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

input:

300

output:

105448551

result:

ok 1 number(s): "105448551"

Test #58:

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

input:

400

output:

276757989

result:

ok 1 number(s): "276757989"

Test #59:

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

input:

500

output:

897091044

result:

ok 1 number(s): "897091044"

Test #60:

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

input:

600

output:

895458430

result:

ok 1 number(s): "895458430"

Test #61:

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

input:

700

output:

225501166

result:

ok 1 number(s): "225501166"

Test #62:

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

input:

800

output:

749404996

result:

ok 1 number(s): "749404996"

Test #63:

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

input:

900

output:

132833283

result:

ok 1 number(s): "132833283"

Test #64:

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

input:

1000

output:

152309562

result:

ok 1 number(s): "152309562"

Test #65:

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

input:

2000

output:

479802764

result:

ok 1 number(s): "479802764"

Test #66:

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

input:

3000

output:

652207059

result:

ok 1 number(s): "652207059"

Test #67:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

4000

output:

734931577

result:

ok 1 number(s): "734931577"

Test #68:

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

input:

5000

output:

825472551

result:

ok 1 number(s): "825472551"

Test #69:

score: 0
Accepted
time: 3ms
memory: 3892kb

input:

6000

output:

330247572

result:

ok 1 number(s): "330247572"

Test #70:

score: 0
Accepted
time: 4ms
memory: 3700kb

input:

7000

output:

166161267

result:

ok 1 number(s): "166161267"

Test #71:

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

input:

8000

output:

500098577

result:

ok 1 number(s): "500098577"

Test #72:

score: 0
Accepted
time: 6ms
memory: 3964kb

input:

9000

output:

15226803

result:

ok 1 number(s): "15226803"

Test #73:

score: 0
Accepted
time: 6ms
memory: 3936kb

input:

10000

output:

561328420

result:

ok 1 number(s): "561328420"

Test #74:

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

input:

20000

output:

805231759

result:

ok 1 number(s): "805231759"

Test #75:

score: 0
Accepted
time: 14ms
memory: 3696kb

input:

30000

output:

688026059

result:

ok 1 number(s): "688026059"

Test #76:

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

input:

40000

output:

486519283

result:

ok 1 number(s): "486519283"

Test #77:

score: 0
Accepted
time: 26ms
memory: 3768kb

input:

50000

output:

575414887

result:

ok 1 number(s): "575414887"

Test #78:

score: 0
Accepted
time: 35ms
memory: 3828kb

input:

60000

output:

837347269

result:

ok 1 number(s): "837347269"

Test #79:

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

input:

70000

output:

889708031

result:

ok 1 number(s): "889708031"

Test #80:

score: 0
Accepted
time: 44ms
memory: 4096kb

input:

80000

output:

500541937

result:

ok 1 number(s): "500541937"

Test #81:

score: 0
Accepted
time: 50ms
memory: 4140kb

input:

90000

output:

62490272

result:

ok 1 number(s): "62490272"

Test #82:

score: 0
Accepted
time: 58ms
memory: 4360kb

input:

100000

output:

975871004

result:

ok 1 number(s): "975871004"

Test #83:

score: 0
Accepted
time: 125ms
memory: 5376kb

input:

200000

output:

621238861

result:

ok 1 number(s): "621238861"

Test #84:

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

input:

244

output:

647546249

result:

ok 1 number(s): "647546249"

Test #85:

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

input:

443

output:

504698464

result:

ok 1 number(s): "504698464"

Test #86:

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

input:

176

output:

158374104

result:

ok 1 number(s): "158374104"

Test #87:

score: 0
Accepted
time: 5ms
memory: 3676kb

input:

9292

output:

76268439

result:

ok 1 number(s): "76268439"

Test #88:

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

input:

11168

output:

434000771

result:

ok 1 number(s): "434000771"

Test #89:

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

input:

7409

output:

972518375

result:

ok 1 number(s): "972518375"

Test #90:

score: 0
Accepted
time: 2ms
memory: 3832kb

input:

4139

output:

118021377

result:

ok 1 number(s): "118021377"

Test #91:

score: 0
Accepted
time: 2ms
memory: 3844kb

input:

2360

output:

557425603

result:

ok 1 number(s): "557425603"

Test #92:

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

input:

921

output:

763066923

result:

ok 1 number(s): "763066923"

Test #93:

score: 0
Accepted
time: 4ms
memory: 3864kb

input:

6370

output:

119414004

result:

ok 1 number(s): "119414004"

Test #94:

score: 0
Accepted
time: 6ms
memory: 3976kb

input:

16672

output:

225059960

result:

ok 1 number(s): "225059960"

Test #95:

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

input:

42169

output:

797539311

result:

ok 1 number(s): "797539311"

Test #96:

score: 0
Accepted
time: 53ms
memory: 4240kb

input:

87826

output:

45005343

result:

ok 1 number(s): "45005343"

Test #97:

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

input:

33549

output:

976562341

result:

ok 1 number(s): "976562341"

Test #98:

score: 0
Accepted
time: 51ms
memory: 4240kb

input:

83250

output:

979484328

result:

ok 1 number(s): "979484328"

Test #99:

score: 0
Accepted
time: 87ms
memory: 5032kb

input:

141890

output:

794692128

result:

ok 1 number(s): "794692128"

Test #100:

score: 0
Accepted
time: 46ms
memory: 4264kb

input:

77620

output:

7849962

result:

ok 1 number(s): "7849962"

Test #101:

score: 0
Accepted
time: 42ms
memory: 4012kb

input:

69995

output:

364205390

result:

ok 1 number(s): "364205390"

Test #102:

score: 0
Accepted
time: 101ms
memory: 4992kb

input:

162241

output:

240880724

result:

ok 1 number(s): "240880724"

Test #103:

score: 0
Accepted
time: 116ms
memory: 5312kb

input:

183966

output:

167125223

result:

ok 1 number(s): "167125223"

Test #104:

score: 0
Accepted
time: 119ms
memory: 5360kb

input:

195541

output:

762776485

result:

ok 1 number(s): "762776485"

Test #105:

score: 0
Accepted
time: 84ms
memory: 4644kb

input:

136901

output:

837991108

result:

ok 1 number(s): "837991108"

Test #106:

score: 0
Accepted
time: 122ms
memory: 5520kb

input:

194613

output:

384410784

result:

ok 1 number(s): "384410784"

Test #107:

score: 0
Accepted
time: 118ms
memory: 5476kb

input:

194632

output:

838353104

result:

ok 1 number(s): "838353104"

Test #108:

score: 0
Accepted
time: 107ms
memory: 5164kb

input:

177132

output:

420003183

result:

ok 1 number(s): "420003183"

Test #109:

score: 0
Accepted
time: 118ms
memory: 5584kb

input:

189159

output:

192759818

result:

ok 1 number(s): "192759818"

Test #110:

score: 0
Accepted
time: 120ms
memory: 5428kb

input:

192552

output:

377372327

result:

ok 1 number(s): "377372327"

Test #111:

score: 0
Accepted
time: 113ms
memory: 5160kb

input:

181566

output:

991185836

result:

ok 1 number(s): "991185836"

Test #112:

score: 0
Accepted
time: 125ms
memory: 5420kb

input:

199679

output:

477499113

result:

ok 1 number(s): "477499113"

Test #113:

score: 0
Accepted
time: 125ms
memory: 5508kb

input:

199352

output:

823328344

result:

ok 1 number(s): "823328344"

Test #114:

score: 0
Accepted
time: 125ms
memory: 5440kb

input:

199408

output:

924981866

result:

ok 1 number(s): "924981866"

Test #115:

score: 0
Accepted
time: 125ms
memory: 5584kb

input:

198741

output:

554240349

result:

ok 1 number(s): "554240349"

Test #116:

score: 0
Accepted
time: 121ms
memory: 5488kb

input:

199995

output:

401387038

result:

ok 1 number(s): "401387038"