QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#380717#7838. 往日之影LRC0 13ms3652kbC++203.4kb2024-04-07 09:23:182024-04-07 09:23:19

Judging History

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

  • [2024-04-07 09:23:19]
  • 评测
  • 测评结果:0
  • 用时:13ms
  • 内存:3652kb
  • [2024-04-07 09:23:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod;
inline void md(ll &x){if(x>=mod) x-=mod;}
inline ll _md(ll x){return x>=mod?x-mod:x;}
inline ll qpow(ll x,ll y)
{
    ll res=1;while(y){if(y&1ll) res=res*x%mod; x=x*x%mod,y>>=1;} return res;
}
struct Com
{
    ll x,y;Com(ll _x=0,ll _y=0){x=_x,y=_y;}
    inline Com operator+(const Com &z)const{return Com(_md(x+z.x),_md(y+z.y));}
    inline Com operator-(const Com &z)const{return Com(_md(x+mod-z.x),_md(y+mod-z.y));}
    inline Com operator*(const Com &z)const{return Com((x*z.x+mod-y*z.y%mod)%mod,(x*z.y+y*z.x)%mod);}
    inline Com operator*(ll k)const{return Com(x*k%mod,y*k%mod);}
    inline Com conj()const{return Com(x,_md(mod-y));}
    inline Com operator/(const Com &z)const{return (*this)*z.conj()*qpow((z.x*z.x+z.y*z.y)%mod,mod-2);}
}rt[4];
inline Com qpow(Com x,ll y)
{
    Com res(1);while(y){if(y&1ll) res=res*x; x=x*x,y>>=1;} return res;
}
int ct[4],n,a[4][4],s[4];
inline void calc(Com &res,ll K)
{
    Com ans(1);
    for(int i=0;i<4;i++)
    {
        int sum=0;
        for(int j=0;j<4;j++)
        {
            if(a[j][i]<0) return;
            sum+=a[j][i];
        }   
        if(sum!=ct[i]) return;
    }
    for(int i=0;i<4;i++)
    {
        s[i]=0;int nws=0;
        for(int j=0;j<4;j++)
            nws+=a[i][j]*j,s[i]+=a[i][j];
        ans=ans/qpow(rt[i],nws);
        ans=ans*qpow(Com(1)+rt[i]*rt[i],1ll*s[i]*(s[i]-1)/2);
    }
    for(int i=0;i<4;i++)
        for(int j=i+1;j<4;j++)
            ans=ans*qpow(Com(1)+rt[i]*rt[j],1ll*s[i]*s[j]);
    res=res+ans*K;
}
inline void work()
{
    cin>>n>>ct[0]>>ct[1]>>ct[2]>>ct[3];
    Com ans(0,0);
    if(n<=2)
    {
        for(int i=0;i<2;i++)
            for(int j=0;j<2;j++)
                for(int p1=0;p1<4;p1++)
                    for(int p2=0;p2<4;p2++)
                    {
                        if(!i&&p1) continue;
                        if(!j&&p2) continue;
                        memset(a,0,sizeof(a));
                        ll K=1;
                        if(i&&j) K=(p1==p2?1ll*ct[p1]*(ct[p1]-1)%mod:1ll*ct[p1]*ct[p2]%mod);
                        else if(i) K=ct[p1];
                        else if(j) K=ct[p2];
                        calc(ans,K);
                    }
    }
    for(int i=0;i<2;i++)
        for(int j=0;j<2;j++)
            for(int k=0;k<2;k++)
                for(int p1=0;p1<4;p1++)
                    for(int p2=0;p2<4;p2++)
                    {
                        if(!j&&p1) continue;
                        if(!k&&p2) continue;
                        memset(a,0,sizeof(a));
                        for(int p=0;p<4;p++)
                            a[i?0:2][p]=ct[p];
                        if(j) a[1][p1]++,a[i?0:2][p1]--;
                        if(k) a[3][p2]++,a[i?0:2][p2]--;
                        ll K=1;
                        if(j&&k) K=(p1==p2?1ll*ct[p1]*(ct[p1]-1)%mod:1ll*ct[p1]*ct[p2]%mod);
                        else if(j) K=ct[p1];
                        else if(k) K=ct[p2];
                        calc(ans,K);
                    }
    ans=ans*qpow(qpow(2,2ll*n+1ll*n*(n-1)/2ll),mod-2);
    cout<<ans.x<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int T;cin>>T>>mod;
    rt[0]=Com(1,0),rt[1]=Com(0,1);
    rt[2]=Com(mod-1,0),rt[3]=Com(0,mod-1);
    while(T--) work();


    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: 0ms
memory: 3640kb

input:

1 998244353
3
1 1 0 1

output:

0

result:

ok single line: '0'

Test #2:

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

input:

1 998244353
7
0 2 1 4

output:

998069185

result:

ok single line: '998069185'

Test #3:

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

input:

1 998244353
4
0 1 0 3

output:

0

result:

ok single line: '0'

Test #4:

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

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: 13ms
memory: 3644kb

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%