QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#261303 | #7838. 往日之影 | 275307894a | 10 | 3ms | 3988kb | C++14 | 2.1kb | 2023-11-22 20:02:51 | 2023-11-22 20:02:53 |
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
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>;using LL=__int128;
const int N=1e6+5,M=N*4+5,K=(1<<25)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int p,n,a[4];
struct img{
ll a,b;
img operator +(const img &B)const{return (img){(a+B.a)%p,(b+B.b)%p};}
img operator -(const img &B)const{return (img){(a-B.a)%p,(b-B.b)%p};}
img operator *(const img &B)const{return (img){(a*B.a-b*B.b)%p,(a*B.b+b*B.a)%p};}
img operator *(const ll B)const{return (img){a*B%p,b*B%p};}
}iw[30];
img mpow(img x,ll y){img ans=(img){1,0};while(y) y&1&&(ans=ans*x,0),y>>=1,x=x*x;return ans;}
ll mpow(ll x,ll y=p-2){ll ans=1;while(y) y&1&&(ans=ans*x%p),y>>=1,x=x*x%p;return ans;}
int c[4];
ll ans;
void calc(int x,img y){
for(int i=0;i<4;i++){
y=y*iw[(4-i)*x*a[i]%4];
c[x]+=a[i];
}
// if(!(c[1]&&c[3]&&c[x])){
if(c[x]&&c[1]) y=y*mpow(iw[x+1]+iw[0],c[x]);
if(c[x]&&c[3]) y=y*mpow(iw[x+3]+iw[0],c[x]);
if(y.a){
y.a*=mpow(2,1ll*c[x]*(c[x]-1)/2);
if(c[1]&&c[3]) y.a*=2;
ans+=y.a%mod;
}
// }
for(int i=0;i<4;i++) c[x]-=a[i];
}
void dfs(int x,img w){
if(x==5) return c[1]+c[3]<n&&(calc(0,w),0),calc(2,w);
dfs(x+2,w);
for(int i=0;i<4;i++) if(a[i]) a[i]--,c[x]++,dfs(x+2,w*(img){a[i]+1,0}*iw[(4-i)*x]),c[x]--,a[i]++;
}
void Solve(){
int i,j;scanf("%d",&n);
for(i=0;i<4;i++) scanf("%d",&a[i]);
ans=0;dfs(1,(img){1,0});
printf("%lld\n",(ans%p+p)*mpow(mpow(4,n)*mpow(2,1ll*n*(n-1)/2)%p)%p);
}
void init(){
iw[0]=(img){1,0};
for(int i=1;i<20;i++) iw[i]=iw[i-1]*(img){0,1};
}
int main(){
int t=1;
scanf("%d%d",&t,&p);t=min(t,50000);
init();
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3912kb
input:
1 998244353 3 1 1 0 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
1 998244353 7 0 2 1 4
output:
998069185
result:
ok single line: '998069185'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
1 998244353 4 0 1 0 3
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3968kb
input:
1 998244353 2 1 0 1 0
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
1 998244353 6 2 1 0 3
output:
997696001
result:
ok single line: '997696001'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3988kb
input:
1 998244353 2 1 0 1 0
output:
0
result:
ok single line: '0'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 3936kb
input:
1 998244353 40 11 9 9 11
output:
887622218
result:
wrong answer 1st lines differ - expected: '855684614', found: '887622218'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 3ms
memory: 3952kb
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:
499999501 874999126 359374641 919920956 691222454 586081873 33512082 573398928 973671368 158373424 74824840 530141039 161866115 159957343 444451034 588616831 200644477 291329038 648838607 392912165 626186039 932357337 846129418 48209538 129089869 505276914 841393303 836816677 23426393 909613631 7733...
result:
wrong answer 8th lines differ - expected: '496961574', found: '573398928'
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%