QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#660420#9116. DRD StringCorydoAC ✓453ms19440kbC++14979b2024-10-20 11:06:132024-10-20 11:06:13

Judging History

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

  • [2024-10-20 11:06:13]
  • 评测
  • 测评结果:AC
  • 用时:453ms
  • 内存:19440kb
  • [2024-10-20 11:06:13]
  • 提交

answer

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

const int N=1e6+10;
const int MOD=998244353;

typedef long long ll;

int n,m;
ll dp[N],g[N];

ll qpow(ll x,ll y=MOD-2){
    ll cnt=1;
    while(y){
        if(y&1) cnt=cnt*x%MOD;
        x=x*x%MOD;y>>=1;
    }
    return cnt;
}

int read(){
    int sym=1,num=0;char cnt=getchar();
    while(cnt<'0'||cnt>'9'){
        if(cnt=='-') sym=-1;
        cnt=getchar();
    }    
    while(cnt>='0'&&cnt<='9'){
        num=(num<<3)+(num<<1)+(cnt^48);
        cnt=getchar(); 
    }
    return sym*num;
}

int main(){
    n=read(),m=read();
    for(int i=1;i<=n;i++)
        dp[i]=g[i>>1]*qpow(m,i)%MOD,g[i]=(g[i-1]+qpow(qpow(m,i))-qpow(qpow(m,2*i))*dp[i])%MOD;
//    for(int i=1;i<=6;i++)
//        printf("%lld %lld\n",(g[i]%MOD+MOD)%MOD,(dp[i]%MOD+MOD)%MOD);
    if(n%2) printf("%lld\n",(dp[n]%MOD+MOD)%MOD);
    else printf("%lld\n",((dp[n]-(qpow(m,n>>1)-dp[n>>1]))%MOD+MOD)%MOD);
    return 0;
} 

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

详细

Test #1:

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

input:

6 2

output:

40

result:

ok "40"

Test #2:

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

input:

3017 7801

output:

515391664

result:

ok "515391664"

Test #3:

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

input:

3 1

output:

1

result:

ok "1"

Test #4:

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

input:

4 7

output:

343

result:

ok "343"

Test #5:

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

input:

5 4

output:

304

result:

ok "304"

Test #6:

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

input:

8 8

output:

2355200

result:

ok "2355200"

Test #7:

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

input:

7 6

output:

54216

result:

ok "54216"

Test #8:

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

input:

1330 3031

output:

139921223

result:

ok "139921223"

Test #9:

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

input:

4946 3837

output:

64102067

result:

ok "64102067"

Test #10:

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

input:

4236 3305

output:

78581604

result:

ok "78581604"

Test #11:

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

input:

399 3245

output:

714500544

result:

ok "714500544"

Test #12:

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

input:

4881 2346

output:

28365995

result:

ok "28365995"

Test #13:

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

input:

4647 3069

output:

798067847

result:

ok "798067847"

Test #14:

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

input:

3414 4280

output:

669878613

result:

ok "669878613"

Test #15:

score: 0
Accepted
time: 453ms
memory: 19356kb

input:

1000000 1000000

output:

469217978

result:

ok "469217978"

Test #16:

score: 0
Accepted
time: 445ms
memory: 19360kb

input:

1000000 1

output:

1

result:

ok "1"

Test #17:

score: 0
Accepted
time: 185ms
memory: 12788kb

input:

418909 302156

output:

189551565

result:

ok "189551565"

Test #18:

score: 0
Accepted
time: 437ms
memory: 19308kb

input:

984572 895728

output:

567020798

result:

ok "567020798"

Test #19:

score: 0
Accepted
time: 21ms
memory: 6292kb

input:

50545 723857

output:

651400574

result:

ok "651400574"

Test #20:

score: 0
Accepted
time: 295ms
memory: 18548kb

input:

668791 286918

output:

27505324

result:

ok "27505324"

Test #21:

score: 0
Accepted
time: 398ms
memory: 18568kb

input:

898539 238506

output:

9072376

result:

ok "9072376"

Test #22:

score: 0
Accepted
time: 314ms
memory: 18076kb

input:

711024 686568

output:

221989803

result:

ok "221989803"

Test #23:

score: 0
Accepted
time: 435ms
memory: 19080kb

input:

970385 660016

output:

104842944

result:

ok "104842944"

Test #24:

score: 0
Accepted
time: 426ms
memory: 18908kb

input:

943632 224593

output:

631779281

result:

ok "631779281"

Test #25:

score: 0
Accepted
time: 11ms
memory: 5944kb

input:

26758 836991

output:

860673946

result:

ok "860673946"

Test #26:

score: 0
Accepted
time: 374ms
memory: 18220kb

input:

838661 823355

output:

34634389

result:

ok "34634389"

Test #27:

score: 0
Accepted
time: 413ms
memory: 18780kb

input:

923587 8580

output:

549615557

result:

ok "549615557"

Test #28:

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

input:

275456 449218

output:

745638801

result:

ok "745638801"

Test #29:

score: 0
Accepted
time: 41ms
memory: 6548kb

input:

96512 594328

output:

159367796

result:

ok "159367796"

Test #30:

score: 0
Accepted
time: 450ms
memory: 19440kb

input:

995445 996221

output:

785170205

result:

ok "785170205"

Test #31:

score: 0
Accepted
time: 366ms
memory: 19036kb

input:

821123 195922

output:

950462887

result:

ok "950462887"

Test #32:

score: 0
Accepted
time: 321ms
memory: 17812kb

input:

715365 748511

output:

571984302

result:

ok "571984302"

Test #33:

score: 0
Accepted
time: 387ms
memory: 19060kb

input:

867858 338674

output:

698272834

result:

ok "698272834"

Test #34:

score: 0
Accepted
time: 175ms
memory: 14204kb

input:

406213 206504

output:

201893603

result:

ok "201893603"

Test #35:

score: 0
Accepted
time: 319ms
memory: 19216kb

input:

729455 262034

output:

521537323

result:

ok "521537323"

Test #36:

score: 0
Accepted
time: 409ms
memory: 19200kb

input:

915061 381221

output:

361349035

result:

ok "361349035"

Test #37:

score: 0
Accepted
time: 184ms
memory: 13044kb

input:

426669 32501

output:

206011209

result:

ok "206011209"

Test #38:

score: 0
Accepted
time: 112ms
memory: 10824kb

input:

256786 708325

output:

287335753

result:

ok "287335753"

Extra Test:

score: 0
Extra Test Passed