QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76122#5464. Dice GamezhouhuanyiWA 112ms3568kbC++141.6kb2023-02-07 19:23:302023-02-07 19:23:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-07 19:23:31]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:3568kb
  • [2023-02-07 19:23:30]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 29
#define mod 998244353
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
void Adder(int &x,int d)
{
    x+=d;
    if (x>=mod) x-=mod;
    return;
}
void Adder2(int &x,int d)
{
    x+=d;
    if (x<0) x+=mod;
    return;
}
int MD(int x)
{
    return (x>=mod)?x-mod:x;
}
int MD2(int x)
{
    return (x<0)?x+mod:x;
}
int fast_pow(int a,int b)
{
    int res=1,mul=a;
    while (b)
    {
	if (b&1) res=1ll*res*mul%mod;
	mul=1ll*mul*mul%mod,b>>=1;
    }
    return res;
}
int T,n,cnt,inv2,F[N+1],ans;
bool used[N+1];
__int128 delta[N+1];
void dfs(int x,bool op,__int128 res)
{
    int dst=0;
    __int128 rst=0;
    for (int i=0;i<=x;++i) rst+=delta[i];
    if (res+rst<=0) return;
    if (res-rst>0&&(x==-1||op))
    {
	for (int i=x+1;i<=cnt;++i)
	{
	    if (!used[i]) Adder(dst,delta[i]%mod);
	    else Adder2(dst,-delta[i]%mod);
	}
	for (int i=0;i<=x;++i) dst=2ll*dst%mod;
	Adder(ans,dst);
	return;
    }
    used[x]=0,dfs(x-1,op|(((n-1)>>x)&1),res+delta[x]);
    if (op||(((n-1)>>x)&1)) used[x]=1,dfs(x-1,op,res-delta[x]);
    return;
}
int main()
{
    T=read(),inv2=(mod+1)>>1;
    while (T--)
    {
	n=read(),cnt=ans=0;
	while ((1<<cnt)<n) cnt++;
	for (int i=0;i<=cnt;++i) F[i]=n/(1<<(i+1))*(1<<i)+max(n%(1<<(i+1))-(1<<i),0),delta[i]=(__int128)(F[i])*(1<<i);
	dfs(cnt,0,0),ans=1ll*ans*fast_pow(n,mod-2)%mod,Adder(ans,1ll*n*(n-1)%mod*inv2%mod),printf("%lld\n",1ll*ans*fast_pow(n,mod-2)%mod);
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3516kb

input:

4
1
2
3
4

output:

0
249561089
776412276
2

result:

ok 4 number(s): "0 249561089 776412276 2"

Test #2:

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

input:

100
119
75
29
10
17
29
449
71
72
12
79
117
83
80
35
272
105
497
346
287
362
140
297
167
111
419
210
212
170
413
373
210
196
39
1
101
258
496
333
293
392
2
187
431
157
342
436
106
449
136
378
243
357
325
237
254
22
292
62
435
18
446
471
18
42
377
181
350
19
389
212
58
45
70
52
63
107
71
66
355
381
30...

output:

645006489
296012775
400009943
299473312
221064504
400009943
60548260
896063466
573066250
471393174
175624519
531171954
143020402
134763040
560646647
43176836
269095960
284396636
191400715
895243672
967774080
745220060
584864173
5941827
724073586
701650152
262576881
417830609
833275086
916357319
1435...

result:

ok 100 numbers

Test #3:

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

input:

10
321
4212
2977
3438
679
2518
3359
2348
861
1853

output:

115992677
210903174
216412050
780704799
956649209
200804004
267658252
194263892
880330717
328032438

result:

ok 10 numbers

Test #4:

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

input:

12
3324
3167
3780
2887
1541
494
4374
3416
4036
3637
3888
4630

output:

458228110
29999980
333283438
544178470
753289945
257353919
515561689
628492255
799560584
924311157
17047279
109086825

result:

ok 12 numbers

Test #5:

score: -100
Wrong Answer
time: 112ms
memory: 3524kb

input:

10000
11424730
231352165
835903988
101946284
358678826
610737477
100503274
909725926
510714513
407317433
668332866
442951503
582321912
117772499
180141789
570384258
375362779
724696666
959258227
178470161
245672142
629464136
515375633
58812672
119047157
272587596
993112981
678095944
67996298
2717673...

output:

773455292
683434339
194713411
556925397
373813268
249127620
885103862
965234526
363171013
39127815
539635031
379719425
919064184
984335744
921358821
759856125
794912670
264493066
311803536
715778235
787641175
172307901
129631023
833866379
684235514
582438570
116801653
777004463
355500500
107587772
2...

result:

wrong answer 3rd numbers differ - expected: '654770591', found: '194713411'