QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#644143 | #9116. DRD String | 275307894a# | AC ✓ | 12ms | 27456kb | C++14 | 1.6kb | 2024-10-16 11:13:35 | 2024-10-16 11:13:36 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e6+5,M=(1<<20)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m;
ll f[N],pw[N],iw[N];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
void Solve(){
scanf("%d%d",&n,&m);
pw[0]=iw[0]=1;pw[1]=m;iw[1]=mpow(m);
for(int i=2;i<=n;i++) pw[i]=pw[i-1]*m%mod,iw[i]=iw[i-1]*iw[1]%mod;
f[1]=m;
ll sum=0;
for(int i=2;i<=n;i++){
if(i%2==0) (sum+=f[i>>1]*iw[i])%=mod;
f[i]=(mod+1-sum)*pw[i]%mod;
gdb(f[i]);
}
printf("%lld\n",(pw[n]-f[n]+(n&1?0:mod-f[n>>1])+mod)%mod);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8116kb
input:
6 2
output:
40
result:
ok "40"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8140kb
input:
3017 7801
output:
515391664
result:
ok "515391664"
Test #3:
score: 0
Accepted
time: 1ms
memory: 8132kb
input:
3 1
output:
1
result:
ok "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 8148kb
input:
4 7
output:
343
result:
ok "343"
Test #5:
score: 0
Accepted
time: 0ms
memory: 8132kb
input:
5 4
output:
304
result:
ok "304"
Test #6:
score: 0
Accepted
time: 0ms
memory: 8132kb
input:
8 8
output:
2355200
result:
ok "2355200"
Test #7:
score: 0
Accepted
time: 0ms
memory: 7996kb
input:
7 6
output:
54216
result:
ok "54216"
Test #8:
score: 0
Accepted
time: 1ms
memory: 8060kb
input:
1330 3031
output:
139921223
result:
ok "139921223"
Test #9:
score: 0
Accepted
time: 1ms
memory: 8172kb
input:
4946 3837
output:
64102067
result:
ok "64102067"
Test #10:
score: 0
Accepted
time: 0ms
memory: 8160kb
input:
4236 3305
output:
78581604
result:
ok "78581604"
Test #11:
score: 0
Accepted
time: 1ms
memory: 8076kb
input:
399 3245
output:
714500544
result:
ok "714500544"
Test #12:
score: 0
Accepted
time: 1ms
memory: 8176kb
input:
4881 2346
output:
28365995
result:
ok "28365995"
Test #13:
score: 0
Accepted
time: 1ms
memory: 8184kb
input:
4647 3069
output:
798067847
result:
ok "798067847"
Test #14:
score: 0
Accepted
time: 1ms
memory: 8144kb
input:
3414 4280
output:
669878613
result:
ok "669878613"
Test #15:
score: 0
Accepted
time: 3ms
memory: 27456kb
input:
1000000 1000000
output:
469217978
result:
ok "469217978"
Test #16:
score: 0
Accepted
time: 8ms
memory: 27452kb
input:
1000000 1
output:
1
result:
ok "1"
Test #17:
score: 0
Accepted
time: 3ms
memory: 20108kb
input:
418909 302156
output:
189551565
result:
ok "189551565"
Test #18:
score: 0
Accepted
time: 5ms
memory: 27336kb
input:
984572 895728
output:
567020798
result:
ok "567020798"
Test #19:
score: 0
Accepted
time: 0ms
memory: 8524kb
input:
50545 723857
output:
651400574
result:
ok "651400574"
Test #20:
score: 0
Accepted
time: 9ms
memory: 24052kb
input:
668791 286918
output:
27505324
result:
ok "27505324"
Test #21:
score: 0
Accepted
time: 10ms
memory: 27100kb
input:
898539 238506
output:
9072376
result:
ok "9072376"
Test #22:
score: 0
Accepted
time: 6ms
memory: 26528kb
input:
711024 686568
output:
221989803
result:
ok "221989803"
Test #23:
score: 0
Accepted
time: 7ms
memory: 27256kb
input:
970385 660016
output:
104842944
result:
ok "104842944"
Test #24:
score: 0
Accepted
time: 7ms
memory: 27024kb
input:
943632 224593
output:
631779281
result:
ok "631779281"
Test #25:
score: 0
Accepted
time: 0ms
memory: 10360kb
input:
26758 836991
output:
860673946
result:
ok "860673946"
Test #26:
score: 0
Accepted
time: 0ms
memory: 27304kb
input:
838661 823355
output:
34634389
result:
ok "34634389"
Test #27:
score: 0
Accepted
time: 7ms
memory: 26864kb
input:
923587 8580
output:
549615557
result:
ok "549615557"
Test #28:
score: 0
Accepted
time: 4ms
memory: 15508kb
input:
275456 449218
output:
745638801
result:
ok "745638801"
Test #29:
score: 0
Accepted
time: 0ms
memory: 12368kb
input:
96512 594328
output:
159367796
result:
ok "159367796"
Test #30:
score: 0
Accepted
time: 12ms
memory: 27360kb
input:
995445 996221
output:
785170205
result:
ok "785170205"
Test #31:
score: 0
Accepted
time: 3ms
memory: 26884kb
input:
821123 195922
output:
950462887
result:
ok "950462887"
Test #32:
score: 0
Accepted
time: 0ms
memory: 26332kb
input:
715365 748511
output:
571984302
result:
ok "571984302"
Test #33:
score: 0
Accepted
time: 7ms
memory: 26452kb
input:
867858 338674
output:
698272834
result:
ok "698272834"
Test #34:
score: 0
Accepted
time: 0ms
memory: 20060kb
input:
406213 206504
output:
201893603
result:
ok "201893603"
Test #35:
score: 0
Accepted
time: 6ms
memory: 26020kb
input:
729455 262034
output:
521537323
result:
ok "521537323"
Test #36:
score: 0
Accepted
time: 10ms
memory: 27192kb
input:
915061 381221
output:
361349035
result:
ok "361349035"
Test #37:
score: 0
Accepted
time: 3ms
memory: 20180kb
input:
426669 32501
output:
206011209
result:
ok "206011209"
Test #38:
score: 0
Accepted
time: 4ms
memory: 14872kb
input:
256786 708325
output:
287335753
result:
ok "287335753"
Extra Test:
score: 0
Extra Test Passed