QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425072 | #7838. 往日之影 | kkkgjyismine4 | 0 | 4ms | 3936kb | C++14 | 1.9kb | 2024-05-29 21:54:58 | 2024-05-29 21:54:58 |
answer
#include<bits/stdc++.h>
using namespace std;
int ct[4],mod;
int mul(int x,int y){return 1ll*x*y%mod;}
void add(int &x,const int y){if((x+=y)>=mod)x-=mod;}
void sub(int &x,const int y){if((x+=(mod-y))>=mod)x-=mod;}
int qpow(int a,int b){
int c=1;
while(b){
if(b&1)c=mul(c,a);
a=mul(a,a),b>>=1;
}return c;
}
int inv(int a){return qpow(a,mod-2);}
struct Complex{int a,b;};
Complex operator*(Complex a,Complex b){
Complex c;
c.a=(1ll*a.a*b.a+mod-1ll*a.b*b.b%mod)%mod;
c.b=(1ll*a.a*b.b+1ll*a.b*b.a)%mod;
return c;
}
Complex operator+(Complex a,Complex b){
add(a.a,b.a),add(a.b,b.b);
return a;
}
Complex operator-(Complex a,Complex b){
sub(a.a,b.a),sub(a.b,b.b);
return a;
}
Complex qpow(Complex a,int b){
Complex c;
c.a=1,c.b=0;
while(b){
if(b&1)c=c*a;
a=a*a;b>>=1;
}return c;
}
Complex ans,t[3][4];
int vis[3],col[3];
void dfs(int o,int p,Complex prod){
if(p==3){
int nn=ct[0]+ct[1]+ct[2]+ct[3];
if(!o){
if(vis[1])prod=prod*qpow(Complex{inv(2),inv(2)},nn);
if(vis[2])prod=prod*qpow(Complex{inv(2),mod-inv(2)},nn);
}else{
if((ct[1]+ct[3])&1)prod=prod*Complex{mod-1,0};
if(vis[1])prod=prod*qpow(Complex{inv(2),mod-inv(2)},nn);
if(vis[2])prod=prod*qpow(Complex{inv(2),inv(2)},nn);
}
ans=ans+prod;
return;
}
vis[p]=0,dfs(o,p+1,prod);
vis[p]=1;
for(int i=0;i<4;++i)
if(ct[i]){
--ct[i];
dfs(o,p+1,prod*Complex{ct[i]+1,0}*t[p][i]);
++ct[i];
}
vis[p]=0;
}
void solve(){
int ni;cin>>ni;
ans.a=ans.b=0;int n=0;
for(int i=0;i<4;++i)scanf("%d",&ct[i]),n+=ct[i];
vis[1]=vis[2]=0;
dfs(0,1,Complex{1,0});
dfs(1,1,Complex{1,0});
Complex now;now.a=inv(4),now.b=0;
while(n--)ans=ans*now;
printf("%d\n",ans.a);
}
int main(){
int T;cin>>T>>mod;
t[1][0]=t[2][0]=Complex{1,0};
t[1][2]=t[2][2]=Complex{mod-1,0};
t[1][1]=t[2][3]=Complex{0,mod-1};
t[1][3]=t[2][1]=Complex{0,1};
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 1ms
memory: 3936kb
input:
1 998244353 3 1 1 0 1
output:
0
result:
ok single line: '0'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3916kb
input:
1 998244353 7 0 2 1 4
output:
998069185
result:
ok single line: '998069185'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3792kb
input:
1 998244353 4 0 1 0 3
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3764kb
input:
1 998244353 2 1 0 1 0
output:
124780544
result:
wrong answer 1st lines differ - expected: '0', found: '124780544'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 4ms
memory: 3864kb
input:
999 999999001 2 2 0 0 0 3 3 0 0 0 4 4 0 0 0 5 5 0 0 0 6 6 0 0 0 7 7 0 0 0 8 8 0 0 0 9 9 0 0 0 10 10 0 0 0 11 11 0 0 0 12 12 0 0 0 13 13 0 0 0 14 14 0 0 0 15 15 0 0 0 16 16 0 0 0 17 17 0 0 0 18 18 0 0 0 19 19 0 0 0 20 20 0 0 0 21 21 0 0 0 22 22 0 0 0 23 23 0 0 0 24 24 0 0 0 25 25 0 0 0 26 26 0 0 0 27...
output:
374999626 874999126 359374641 919920956 691222454 586081873 33512082 496961574 790501684 206445579 708073277 492142887 486007979 21786019 802052117 198521403 854660059 658779344 904643630 538486221 357736277 949763680 94144464 342842045 695164947 276856011 552666277 813428208 572457238 910726512 177...
result:
wrong answer 1st lines differ - expected: '499999501', found: '374999626'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%