QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771909 | #6614. Cards of Magic | ucup-team3161# | AC ✓ | 29ms | 35436kb | C++17 | 1.8kb | 2024-11-22 16:16:20 | 2024-11-22 16:16:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
const int N=1e6+5,MOD=998244353,inv2=(MOD+1)/2;
int n,inv3,ans,fc[N],invfc[N],pw[N],pw1[N],w[N],f[N][2][2],g[N][2][2][2];
void W(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;}
void W(int &x,ll y) {x=(x+y)%MOD;}
int W1(int x,int y) {x+=y;return x<MOD?x:x-MOD;}
int qpow(int x,int y)
{
int res=1;
for(;y;y/=2,x=1ll*x*x%MOD)
if(y&1) res=1ll*res*x%MOD;
return res;
}
void init(int n)
{
fc[0]=invfc[0]=1;
for(int i=1;i<=n;++i) fc[i]=1ll*fc[i-1]*i%MOD;
invfc[n]=qpow(fc[n],MOD-2);
for(int i=n;i;--i) invfc[i-1]=1ll*invfc[i]*i%MOD;
pw[0]=pw1[0]=1;
pw[1]=qpow(3,MOD-2);pw1[1]=2ll*pw[1]%MOD;
for(int i=1;i<=n;++i)
{
pw[i]=1ll*pw[i-1]*pw[1]%MOD;
pw1[i]=1ll*pw1[i-1]*pw1[1]%MOD;
}
for(int i=0;i<=n;++i) w[i]=W1(pw1[i],MOD-pw[i]);
}
int bn(int x,int y)
{return x<y || y<0?0:1ll*fc[x]*invfc[y]%MOD*invfc[x-y]%MOD;}
int main()
{
scanf("%d",&n);
init(1e6);
inv3=qpow(3,MOD-2);
ans=3ll*inv2%MOD;
for(int i=1;i*2<n;++i) W(ans,w[i]);
f[0][0][0]=g[0][0][0][0]=1;
for(int i=0;i<n;++i)
for(int j=0;j<2;++j)
for(int k=0;k<2;++k)
{
int t=1ll*f[i][j][k]*inv3%MOD;
W(f[i+1][1][k],t);
if(!k) W(f[i+2][j][k+1],t);
}
for(int i=0;i<n;++i)
for(int j=0;j<2;++j)
for(int k=0;k<2;++k)
for(int l=0;l<2;++l)
{
int t=1ll*g[i][j][k][l]*inv3%MOD;
W(g[i+1][1][k][l],t);
W(g[i+3][j][1][l],t);
if(!l) W(g[i+4][j][k][l+1],t);
}
for(int i=0;i<=n;++i)
for(int j=0;j<2;++j)
W(ans,W1(f[i][1][j],g[i][1][1][j]));
printf("%d\n",ans);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 26156kb
input:
1
output:
831870296
result:
ok 1 number(s): "831870296"
Test #2:
score: 0
Accepted
time: 15ms
memory: 25828kb
input:
5
output:
835978299
result:
ok 1 number(s): "835978299"
Test #3:
score: 0
Accepted
time: 14ms
memory: 26588kb
input:
2
output:
277290100
result:
ok 1 number(s): "277290100"
Test #4:
score: 0
Accepted
time: 14ms
memory: 26576kb
input:
3
output:
979758349
result:
ok 1 number(s): "979758349"
Test #5:
score: 0
Accepted
time: 7ms
memory: 25792kb
input:
4
output:
141726053
result:
ok 1 number(s): "141726053"
Test #6:
score: 0
Accepted
time: 15ms
memory: 26304kb
input:
6
output:
393683476
result:
ok 1 number(s): "393683476"
Test #7:
score: 0
Accepted
time: 14ms
memory: 25840kb
input:
7
output:
206541188
result:
ok 1 number(s): "206541188"
Test #8:
score: 0
Accepted
time: 7ms
memory: 26400kb
input:
8
output:
993603837
result:
ok 1 number(s): "993603837"
Test #9:
score: 0
Accepted
time: 9ms
memory: 27164kb
input:
9
output:
709289564
result:
ok 1 number(s): "709289564"
Test #10:
score: 0
Accepted
time: 11ms
memory: 25948kb
input:
10
output:
445988648
result:
ok 1 number(s): "445988648"
Test #11:
score: 0
Accepted
time: 9ms
memory: 26772kb
input:
11
output:
622925737
result:
ok 1 number(s): "622925737"
Test #12:
score: 0
Accepted
time: 15ms
memory: 25904kb
input:
12
output:
363599458
result:
ok 1 number(s): "363599458"
Test #13:
score: 0
Accepted
time: 14ms
memory: 26952kb
input:
13
output:
338621482
result:
ok 1 number(s): "338621482"
Test #14:
score: 0
Accepted
time: 15ms
memory: 26736kb
input:
14
output:
397966377
result:
ok 1 number(s): "397966377"
Test #15:
score: 0
Accepted
time: 15ms
memory: 25524kb
input:
15
output:
911767168
result:
ok 1 number(s): "911767168"
Test #16:
score: 0
Accepted
time: 13ms
memory: 25992kb
input:
16
output:
664727836
result:
ok 1 number(s): "664727836"
Test #17:
score: 0
Accepted
time: 15ms
memory: 25836kb
input:
17
output:
868443132
result:
ok 1 number(s): "868443132"
Test #18:
score: 0
Accepted
time: 15ms
memory: 25716kb
input:
18
output:
796806191
result:
ok 1 number(s): "796806191"
Test #19:
score: 0
Accepted
time: 11ms
memory: 25924kb
input:
19
output:
36284050
result:
ok 1 number(s): "36284050"
Test #20:
score: 0
Accepted
time: 7ms
memory: 27104kb
input:
20
output:
78593146
result:
ok 1 number(s): "78593146"
Test #21:
score: 0
Accepted
time: 18ms
memory: 26048kb
input:
21
output:
113581844
result:
ok 1 number(s): "113581844"
Test #22:
score: 0
Accepted
time: 15ms
memory: 25840kb
input:
22
output:
652629455
result:
ok 1 number(s): "652629455"
Test #23:
score: 0
Accepted
time: 18ms
memory: 27204kb
input:
23
output:
26889816
result:
ok 1 number(s): "26889816"
Test #24:
score: 0
Accepted
time: 14ms
memory: 27532kb
input:
24
output:
973075191
result:
ok 1 number(s): "973075191"
Test #25:
score: 0
Accepted
time: 15ms
memory: 25516kb
input:
25
output:
606233734
result:
ok 1 number(s): "606233734"
Test #26:
score: 0
Accepted
time: 15ms
memory: 25596kb
input:
26
output:
251968195
result:
ok 1 number(s): "251968195"
Test #27:
score: 0
Accepted
time: 18ms
memory: 25448kb
input:
27
output:
160663854
result:
ok 1 number(s): "160663854"
Test #28:
score: 0
Accepted
time: 7ms
memory: 27372kb
input:
28
output:
644704526
result:
ok 1 number(s): "644704526"
Test #29:
score: 0
Accepted
time: 15ms
memory: 26076kb
input:
29
output:
880366020
result:
ok 1 number(s): "880366020"
Test #30:
score: 0
Accepted
time: 18ms
memory: 27200kb
input:
30
output:
563180515
result:
ok 1 number(s): "563180515"
Test #31:
score: 0
Accepted
time: 18ms
memory: 26456kb
input:
31
output:
488966461
result:
ok 1 number(s): "488966461"
Test #32:
score: 0
Accepted
time: 14ms
memory: 27376kb
input:
32
output:
73977159
result:
ok 1 number(s): "73977159"
Test #33:
score: 0
Accepted
time: 11ms
memory: 26308kb
input:
33
output:
478257304
result:
ok 1 number(s): "478257304"
Test #34:
score: 0
Accepted
time: 11ms
memory: 25888kb
input:
34
output:
840731886
result:
ok 1 number(s): "840731886"
Test #35:
score: 0
Accepted
time: 18ms
memory: 26732kb
input:
35
output:
116945142
result:
ok 1 number(s): "116945142"
Test #36:
score: 0
Accepted
time: 19ms
memory: 27120kb
input:
36
output:
965694497
result:
ok 1 number(s): "965694497"
Test #37:
score: 0
Accepted
time: 14ms
memory: 26308kb
input:
37
output:
167489378
result:
ok 1 number(s): "167489378"
Test #38:
score: 0
Accepted
time: 14ms
memory: 26504kb
input:
38
output:
100691350
result:
ok 1 number(s): "100691350"
Test #39:
score: 0
Accepted
time: 11ms
memory: 26044kb
input:
39
output:
160240217
result:
ok 1 number(s): "160240217"
Test #40:
score: 0
Accepted
time: 11ms
memory: 27288kb
input:
40
output:
151280240
result:
ok 1 number(s): "151280240"
Test #41:
score: 0
Accepted
time: 15ms
memory: 26980kb
input:
41
output:
521028725
result:
ok 1 number(s): "521028725"
Test #42:
score: 0
Accepted
time: 15ms
memory: 26204kb
input:
42
output:
691288796
result:
ok 1 number(s): "691288796"
Test #43:
score: 0
Accepted
time: 18ms
memory: 26856kb
input:
43
output:
695894234
result:
ok 1 number(s): "695894234"
Test #44:
score: 0
Accepted
time: 11ms
memory: 26248kb
input:
44
output:
216804850
result:
ok 1 number(s): "216804850"
Test #45:
score: 0
Accepted
time: 14ms
memory: 27244kb
input:
45
output:
39241895
result:
ok 1 number(s): "39241895"
Test #46:
score: 0
Accepted
time: 15ms
memory: 27400kb
input:
46
output:
471395300
result:
ok 1 number(s): "471395300"
Test #47:
score: 0
Accepted
time: 15ms
memory: 27140kb
input:
47
output:
957503329
result:
ok 1 number(s): "957503329"
Test #48:
score: 0
Accepted
time: 18ms
memory: 26880kb
input:
48
output:
658978397
result:
ok 1 number(s): "658978397"
Test #49:
score: 0
Accepted
time: 11ms
memory: 26652kb
input:
49
output:
99569804
result:
ok 1 number(s): "99569804"
Test #50:
score: 0
Accepted
time: 15ms
memory: 26420kb
input:
50
output:
169299123
result:
ok 1 number(s): "169299123"
Test #51:
score: 0
Accepted
time: 18ms
memory: 25708kb
input:
60
output:
977734538
result:
ok 1 number(s): "977734538"
Test #52:
score: 0
Accepted
time: 7ms
memory: 25896kb
input:
70
output:
970937590
result:
ok 1 number(s): "970937590"
Test #53:
score: 0
Accepted
time: 11ms
memory: 26312kb
input:
80
output:
68069121
result:
ok 1 number(s): "68069121"
Test #54:
score: 0
Accepted
time: 11ms
memory: 25928kb
input:
90
output:
822014036
result:
ok 1 number(s): "822014036"
Test #55:
score: 0
Accepted
time: 14ms
memory: 25880kb
input:
100
output:
984213121
result:
ok 1 number(s): "984213121"
Test #56:
score: 0
Accepted
time: 13ms
memory: 25516kb
input:
200
output:
490385842
result:
ok 1 number(s): "490385842"
Test #57:
score: 0
Accepted
time: 7ms
memory: 26452kb
input:
300
output:
105448551
result:
ok 1 number(s): "105448551"
Test #58:
score: 0
Accepted
time: 11ms
memory: 26288kb
input:
400
output:
276757989
result:
ok 1 number(s): "276757989"
Test #59:
score: 0
Accepted
time: 15ms
memory: 26080kb
input:
500
output:
897091044
result:
ok 1 number(s): "897091044"
Test #60:
score: 0
Accepted
time: 15ms
memory: 26908kb
input:
600
output:
895458430
result:
ok 1 number(s): "895458430"
Test #61:
score: 0
Accepted
time: 14ms
memory: 26292kb
input:
700
output:
225501166
result:
ok 1 number(s): "225501166"
Test #62:
score: 0
Accepted
time: 19ms
memory: 27224kb
input:
800
output:
749404996
result:
ok 1 number(s): "749404996"
Test #63:
score: 0
Accepted
time: 15ms
memory: 26308kb
input:
900
output:
132833283
result:
ok 1 number(s): "132833283"
Test #64:
score: 0
Accepted
time: 18ms
memory: 25556kb
input:
1000
output:
152309562
result:
ok 1 number(s): "152309562"
Test #65:
score: 0
Accepted
time: 18ms
memory: 27268kb
input:
2000
output:
479802764
result:
ok 1 number(s): "479802764"
Test #66:
score: 0
Accepted
time: 18ms
memory: 26316kb
input:
3000
output:
652207059
result:
ok 1 number(s): "652207059"
Test #67:
score: 0
Accepted
time: 14ms
memory: 25644kb
input:
4000
output:
734931577
result:
ok 1 number(s): "734931577"
Test #68:
score: 0
Accepted
time: 11ms
memory: 26872kb
input:
5000
output:
825472551
result:
ok 1 number(s): "825472551"
Test #69:
score: 0
Accepted
time: 15ms
memory: 27696kb
input:
6000
output:
330247572
result:
ok 1 number(s): "330247572"
Test #70:
score: 0
Accepted
time: 19ms
memory: 27380kb
input:
7000
output:
166161267
result:
ok 1 number(s): "166161267"
Test #71:
score: 0
Accepted
time: 7ms
memory: 26704kb
input:
8000
output:
500098577
result:
ok 1 number(s): "500098577"
Test #72:
score: 0
Accepted
time: 19ms
memory: 27148kb
input:
9000
output:
15226803
result:
ok 1 number(s): "15226803"
Test #73:
score: 0
Accepted
time: 9ms
memory: 25840kb
input:
10000
output:
561328420
result:
ok 1 number(s): "561328420"
Test #74:
score: 0
Accepted
time: 19ms
memory: 27968kb
input:
20000
output:
805231759
result:
ok 1 number(s): "805231759"
Test #75:
score: 0
Accepted
time: 16ms
memory: 28096kb
input:
30000
output:
688026059
result:
ok 1 number(s): "688026059"
Test #76:
score: 0
Accepted
time: 21ms
memory: 28064kb
input:
40000
output:
486519283
result:
ok 1 number(s): "486519283"
Test #77:
score: 0
Accepted
time: 21ms
memory: 27300kb
input:
50000
output:
575414887
result:
ok 1 number(s): "575414887"
Test #78:
score: 0
Accepted
time: 11ms
memory: 28608kb
input:
60000
output:
837347269
result:
ok 1 number(s): "837347269"
Test #79:
score: 0
Accepted
time: 15ms
memory: 29516kb
input:
70000
output:
889708031
result:
ok 1 number(s): "889708031"
Test #80:
score: 0
Accepted
time: 19ms
memory: 28748kb
input:
80000
output:
500541937
result:
ok 1 number(s): "500541937"
Test #81:
score: 0
Accepted
time: 23ms
memory: 29712kb
input:
90000
output:
62490272
result:
ok 1 number(s): "62490272"
Test #82:
score: 0
Accepted
time: 16ms
memory: 30448kb
input:
100000
output:
975871004
result:
ok 1 number(s): "975871004"
Test #83:
score: 0
Accepted
time: 24ms
memory: 34584kb
input:
200000
output:
621238861
result:
ok 1 number(s): "621238861"
Test #84:
score: 0
Accepted
time: 18ms
memory: 26052kb
input:
244
output:
647546249
result:
ok 1 number(s): "647546249"
Test #85:
score: 0
Accepted
time: 14ms
memory: 26400kb
input:
443
output:
504698464
result:
ok 1 number(s): "504698464"
Test #86:
score: 0
Accepted
time: 11ms
memory: 25620kb
input:
176
output:
158374104
result:
ok 1 number(s): "158374104"
Test #87:
score: 0
Accepted
time: 14ms
memory: 27664kb
input:
9292
output:
76268439
result:
ok 1 number(s): "76268439"
Test #88:
score: 0
Accepted
time: 19ms
memory: 26768kb
input:
11168
output:
434000771
result:
ok 1 number(s): "434000771"
Test #89:
score: 0
Accepted
time: 7ms
memory: 26320kb
input:
7409
output:
972518375
result:
ok 1 number(s): "972518375"
Test #90:
score: 0
Accepted
time: 15ms
memory: 26676kb
input:
4139
output:
118021377
result:
ok 1 number(s): "118021377"
Test #91:
score: 0
Accepted
time: 14ms
memory: 26396kb
input:
2360
output:
557425603
result:
ok 1 number(s): "557425603"
Test #92:
score: 0
Accepted
time: 11ms
memory: 27120kb
input:
921
output:
763066923
result:
ok 1 number(s): "763066923"
Test #93:
score: 0
Accepted
time: 15ms
memory: 26584kb
input:
6370
output:
119414004
result:
ok 1 number(s): "119414004"
Test #94:
score: 0
Accepted
time: 19ms
memory: 26376kb
input:
16672
output:
225059960
result:
ok 1 number(s): "225059960"
Test #95:
score: 0
Accepted
time: 14ms
memory: 26788kb
input:
42169
output:
797539311
result:
ok 1 number(s): "797539311"
Test #96:
score: 0
Accepted
time: 20ms
memory: 29884kb
input:
87826
output:
45005343
result:
ok 1 number(s): "45005343"
Test #97:
score: 0
Accepted
time: 12ms
memory: 28576kb
input:
33549
output:
976562341
result:
ok 1 number(s): "976562341"
Test #98:
score: 0
Accepted
time: 24ms
memory: 29580kb
input:
83250
output:
979484328
result:
ok 1 number(s): "979484328"
Test #99:
score: 0
Accepted
time: 23ms
memory: 32668kb
input:
141890
output:
794692128
result:
ok 1 number(s): "794692128"
Test #100:
score: 0
Accepted
time: 18ms
memory: 29868kb
input:
77620
output:
7849962
result:
ok 1 number(s): "7849962"
Test #101:
score: 0
Accepted
time: 22ms
memory: 29612kb
input:
69995
output:
364205390
result:
ok 1 number(s): "364205390"
Test #102:
score: 0
Accepted
time: 15ms
memory: 33556kb
input:
162241
output:
240880724
result:
ok 1 number(s): "240880724"
Test #103:
score: 0
Accepted
time: 23ms
memory: 34580kb
input:
183966
output:
167125223
result:
ok 1 number(s): "167125223"
Test #104:
score: 0
Accepted
time: 22ms
memory: 35436kb
input:
195541
output:
762776485
result:
ok 1 number(s): "762776485"
Test #105:
score: 0
Accepted
time: 19ms
memory: 31688kb
input:
136901
output:
837991108
result:
ok 1 number(s): "837991108"
Test #106:
score: 0
Accepted
time: 19ms
memory: 33524kb
input:
194613
output:
384410784
result:
ok 1 number(s): "384410784"
Test #107:
score: 0
Accepted
time: 25ms
memory: 35060kb
input:
194632
output:
838353104
result:
ok 1 number(s): "838353104"
Test #108:
score: 0
Accepted
time: 20ms
memory: 33120kb
input:
177132
output:
420003183
result:
ok 1 number(s): "420003183"
Test #109:
score: 0
Accepted
time: 21ms
memory: 33792kb
input:
189159
output:
192759818
result:
ok 1 number(s): "192759818"
Test #110:
score: 0
Accepted
time: 23ms
memory: 34024kb
input:
192552
output:
377372327
result:
ok 1 number(s): "377372327"
Test #111:
score: 0
Accepted
time: 16ms
memory: 33548kb
input:
181566
output:
991185836
result:
ok 1 number(s): "991185836"
Test #112:
score: 0
Accepted
time: 29ms
memory: 34596kb
input:
199679
output:
477499113
result:
ok 1 number(s): "477499113"
Test #113:
score: 0
Accepted
time: 18ms
memory: 34072kb
input:
199352
output:
823328344
result:
ok 1 number(s): "823328344"
Test #114:
score: 0
Accepted
time: 25ms
memory: 34456kb
input:
199408
output:
924981866
result:
ok 1 number(s): "924981866"
Test #115:
score: 0
Accepted
time: 12ms
memory: 34176kb
input:
198741
output:
554240349
result:
ok 1 number(s): "554240349"
Test #116:
score: 0
Accepted
time: 25ms
memory: 34644kb
input:
199995
output:
401387038
result:
ok 1 number(s): "401387038"