QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#432735#7838. 往日之影xlwang0 8ms3772kbC++143.0kb2024-06-07 16:19:042024-06-07 16:19:05

Judging History

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

  • [2024-06-07 16:19:05]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:3772kb
  • [2024-06-07 16:19:04]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
//	int t=read();
//	while(t--) work();
//}
int mod;
struct node{int x,y;};
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
node operator + (node A,node B){
    node C;C.x=(A.x+B.x)%mod;C.y=(A.y+B.y)%mod;
    return C;
}
node operator - (node A,node B){
    node C;C.x=(A.x-B.x+mod)%mod;C.y=(A.y-B.y+mod)%mod;
    return C;
}
node operator * (node A,node B){
    node C;C.x=1ll*A.x*B.x%mod;add(C.x,mod-1ll*A.y*B.y%mod);
    C.y=1ll*A.x*B.y%mod;add(C.y,1ll*A.y*B.x%mod);return C;
}
inline int Pow(int x,int y=mod-2){
    int sum=1;
    while(y){
        if(y&1) sum=1ll*sum*x%mod;
        y=y/2;x=1ll*x*x%mod;
    }
    return sum;
}
inline node ksm(node x,ll y){
    node sum=(node){1,0};
    while(y){
        if(y&1) sum=sum*x;
        y=y/2;x=x*x;
    }
    return sum;
}
int a[5];
node w[5];
int s[5],n;
int ans;
inline void check(int tp,node now){
    // cout<<"**"<<endl;
    // cout<<tp<<' '<<now.x<<' '<<now.y<<endl;
    fr(i,0,3){
        now=now*w[(4-tp)%4*a[i]*i%4];
        s[tp]+=a[i];
    }
    fr(i,0,3){
        now=now*ksm(w[2*i%4]+w[0],1ll*s[i]*(s[i]-1)/2);
        fr(j,i+1,3) now=now*ksm(w[(i+j)%4]+w[0],1ll*s[i]*s[j]);
    }
    add(ans,now.x);
    fr(i,0,3) s[tp]-=a[i];
}
inline void dfs(int x,node now){
    if(x==5){
        if(s[1]+s[3]>n) return;
        check(2,now);check(0,now);
        return;
    }
    dfs(x+2,now);
    fr(i,0,3){
        if(!a[i]) continue;
        if(a[i]){
            --a[i];++s[x];
            dfs(x+2,now*(node){a[i]+1,0}*w[(4-x)*i%4]);
            ++a[i];--s[x];
        }
    }
}
inline void work(){
    n=read();fr(i,0,3) a[i]=read();
    ans=0;dfs(1,(node){1,0});
    ans=1ll*ans*Pow(1ll*Pow(4,n)*Pow(2,1ll*n*(n-1)/2%mod)%mod)%mod;
    writeln(ans);
}
inline void init(){
    int t=read();mod=read();
    w[0]=(node){1,0};
    fr(i,1,3) w[i]=w[i-1]*(node){0,1};
    // fr(i,0,3) cout<<i<<' '<<w[i].x<<' '<<w[i].y<<endl;
    while(t--) work();
}
signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 1ms
memory: 3628kb

input:

1 998244353
3
1 1 0 1

output:

0

result:

ok single line: '0'

Test #2:

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

input:

1 998244353
7
0 2 1 4

output:

998069185

result:

ok single line: '998069185'

Test #3:

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

input:

1 998244353
4
0 1 0 3

output:

0

result:

ok single line: '0'

Test #4:

score: -10
Wrong Answer
time: 0ms
memory: 3772kb

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: 8ms
memory: 3512kb

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%