QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#597#390291#8330. Count off 3marherGraphcitySuccess!2024-04-16 16:08:432024-04-16 16:08:43

Details

Extra Test:

Time Limit Exceeded

input:

10
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

534701861
534701861
534701861
534701861
534701861
534701861

result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390291#8330. Count off 3GraphcityTL 1179ms84404kbC++203.2kb2024-04-15 11:19:322024-10-13 18:51:51

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=1e4,Mod=1e9+7;

int f[Maxn+5][7][7][7],g[Maxn+5][2][7][7][7];
int sf[Maxn+5][8][8][8],sg[Maxn+5][8][8][8];
int n,ans,pw[8][Maxn+5],a[Maxn+5];

inline void Init()
{
    For(i,0,7) {pw[i][0]=1; For(j,1,Maxn) pw[i][j]=pw[i][j-1]*i%7;}
    g[0][0][0][0][0]=f[0][0][0][0]=1,g[1][1][1][1][1]=f[1][1][1][1]=1;
    For(i,2,Maxn)
    {
        For(a,0,6) For(b,0,6) For(c,0,6) if(f[i-2][a][b][c]) For(j,0,1)
            (g[i][j][(a+pw[1][i-1]*j)%7][(b+pw[2][i-1]*j)%7][(c+pw[3][i-1]*j)%7]+=f[i-2][a][b][c])%=Mod;
        For(a,0,6) For(b,0,6) For(c,0,6) f[i][a][b][c]=(g[i][0][a][b][c]+g[i][1][a][b][c])%Mod;
    }
    For(i,0,Maxn)
    {
        For(a,0,6) For(b,0,6) For(c,0,6) sf[i][a][b][c]=f[i][a][b][c],sg[i][a][b][c]=g[i][0][a][b][c];
        For(a,0,6) For(b,0,7) For(c,0,7) (sf[i][7][b][c]+=sf[i][a][b][c])%=Mod,(sg[i][7][b][c]+=sg[i][a][b][c])%=Mod;
        For(a,0,7) For(b,0,6) For(c,0,7) (sf[i][a][7][c]+=sf[i][a][b][c])%=Mod,(sg[i][a][7][c]+=sg[i][a][b][c])%=Mod;
        For(a,0,7) For(b,0,7) For(c,0,6) (sf[i][a][b][7]+=sf[i][a][b][c])%=Mod,(sg[i][a][b][7]+=sg[i][a][b][c])%=Mod;
    }
}

int ban[4][3],val[4],sz[4],h[8][8][8];
inline void Solve()
{
    string ch; cin>>ch; n=ch.size();
    For(i,0,n-1) a[n-i]=ch[i]-'0'; ans=0;
    int cur=0; For(i,1,n) cur+=a[i];
    for(int i=n,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0;i>=1;--i)
    {
        if(a[i]==1)
        {
            if(i&1) memcpy(h,sf[i-1],sizeof(h)); else memcpy(h,sg[i],sizeof(h));
            For(b1,0,6) For(b2,0,6) For(b3,0,6)
            {
                int res;
                if(i&1) res=g[i][0][b1][b2][b3]; else res=f[i-1][b1][b2][b3];
                if(!res) continue; sz[1]=sz[2]=sz[3]=2;
                ban[1][1]=(14-a1-b1)%7,ban[1][2]=(a6+b1)%7;
                ban[2][1]=(14-a2-b2)%7,ban[2][2]=(a5+b2)%7;
                ban[3][1]=(14-a3-b3)%7,ban[3][2]=(a4+b3)%7;
                For(j,1,3) if(ban[j][1]==ban[j][2]) sz[j]--;
                For(x,0,sz[1])
                {
                    val[1]=(x==0?7:ban[1][x]);
                    For(y,0,sz[2])
                    {
                        val[2]=(y==0?7:ban[2][y]);
                        For(z,0,sz[3])
                        {
                            val[3]=(z==0?7:ban[3][z]);
                            if((x>0)+(y>0)+(z>0)&1) ans=(ans-1ll*res*h[val[1]][val[2]][val[3]]%Mod+Mod)%Mod;
                            else ans=(ans+1ll*res*h[val[1]][val[2]][val[3]])%Mod;
                        }
                    }
                }
            }
        }
        a1=(a1+pw[1][i-1]*a[i])%7,a2=(a2+pw[2][i-1]*a[i])%7,a3=(a3+pw[3][i-1]*a[i])%7;
        a4=(a4+pw[4][i-1]*a[i])%7,a5=(a5+pw[5][i-1]*a[i])%7,a6=(a6+pw[6][i-1]*a[i])%7;
        if(i==1 && a1 && a2 && a3 && a4 && a5 && a6 && a[1]) ans=(ans+1)%Mod;
    } cout<<ans<<endl;
    if(ans==124194923)
    {
        For(i,1,9) cout<<ans<<endl;
        exit(0);
    }
}

int main()
{
    // freopen("1.in","r",stdin);

    ios::sync_with_stdio(false);
    Init(); int T; cin>>T;
    while(T--) Solve();
    return 0;
}