QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#391308#8330. Count off 3marherTL 1974ms35584kbC++144.2kb2024-04-16 15:28:162024-04-16 15:28:17

Judging History

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

  • [2024-04-17 10:54:24]
  • hack成功,自动添加数据
  • (/hack/598)
  • [2024-04-16 16:08:54]
  • hack成功,自动添加数据
  • (/hack/597)
  • [2024-04-16 15:28:17]
  • 评测
  • 测评结果:TL
  • 用时:1974ms
  • 内存:35584kb
  • [2024-04-16 15:28:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e4,mod=1e9+7;

int T,n=1e4,f[N][7][7][7],g[N][7][7][7],cm1[N],cm3[N],cm5[N],cm[N][8],h[3][7],ans;
char s[N];

void ad(int&x,int y)
{
    x+=y;
    x-=x>=mod?mod:0;
}

void init()
{
    f[0][0][0][0]=g[0][0][0][0]=1;
    cm1[0]=cm3[0]=cm5[0]=1;
    for(int i=1;i<7;i++)cm[0][i]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<7;j++)cm[i][j]=cm[i-1][j]*j%7;
        cm1[i]=cm1[i-1];
        cm3[i]=cm3[i-1]*3%7;
        cm5[i]=cm5[i-1]*5%7;
        for(int a=0;a<7;a++)
        for(int b=0;b<7;b++)
        for(int c=0;c<7;c++)
        f[i][a][b][c]=f[i-1][a][b][c],g[i][a][b][c]=g[i-1][a][b][c];
        for(int a=0;a<7;a++)
        for(int b=0;b<7;b++)
        for(int c=0;c<7;c++)
        {
            if(i&1)ad(f[i][(a+cm1[i])%7][(b+cm3[i])%7][(c+cm5[i])%7],f[i-1][a][b][c]);
            else ad(g[i][(a+cm1[i])%7][(b+cm3[i])%7][(c+cm5[i])%7],g[i-1][a][b][c]);
        }
    }
}

int find(int x,int y,int wx,int wy,int k)
{
    int a=-1,b=-1,c=-1;
    if(0==x)a=wx;if(0==y)a=wy;
    if(1==x)b=wx;if(1==y)b=wy;
    if(2==x)c=wx;if(2==y)c=wy;
    int s=0;
    for(int i=0;i<7;i++)ad(s,g[k][a==-1?i:a][b==-1?i:b][c==-1?i:c]);
    return s;
}

void fd(int a,int b,int c,int w)
{
    ad(ans,mod-1ll*w*h[a][b]%mod);
    if(b!=c)
    ad(ans,mod-1ll*w*h[a][c]%mod);
}

void fd(int a,int b,int*A,int*B,int w,int k)
{
    for(int i=0;i<2;i++)if(i==0||A[1]!=A[0])
    for(int j=0;j<2;j++)if(j==0||B[1]!=B[0])
    ad(ans,1ll*w*find(a,b,A[i],B[j],k)%mod);
}

void solve(int k,int*p,int w,int s)
{
    ad(ans,1ll*w*s%mod);
    for(int i=0;i<7;i++)p[i]=(7-p[i])%7;
    fd(0,p[1],p[6],w);fd(1,p[3],p[4],w);fd(2,p[5],p[2],w);
    int A[3]={p[1],p[6]},B[3]={p[3],p[4]},C[3]={p[5],p[2]};
    fd(0,1,A,B,w,k);fd(0,2,A,C,w,k);fd(1,2,B,C,w,k);
    for(int i=0;i<2;i++)if(i==0||A[1]!=A[0])
    for(int j=0;j<2;j++)if(j==0||B[1]!=B[0])
    for(int t=0;t<2;t++)if(t==0||C[1]!=C[0])ad(ans,mod-1ll*w*g[k][A[i]][B[j]][C[t]]%mod);
}

void sol()
{
    cin>>s;n=strlen(s);
    for(int i=0;i<n/2;i++)swap(s[i],s[n-i-1]);
    int r[8];ans=0;
    for(int i=1;i<7;i++)r[i]=1;
    for(int i=n-1;i;i--)
    {
        if(s[i]=='1')
        {
            int s=0;
            memset(h,0,sizeof h);
            for(int a=0;a<7;a++)
            for(int b=0;b<7;b++)
            for(int c=0;c<7;c++)ad(s,g[i-1][a][b][c]),ad(h[0][a],g[i-1][a][b][c]),ad(h[1][b],g[i-1][a][b][c]),ad(h[2][c],g[i-1][a][b][c]);
            for(int a=0;a<7;a++)
            for(int b=0;b<7;b++)
            for(int c=0;c<7;c++)if(f[i-1][a][b][c])
            {
                int p[8];
                for(int k=1;k<7;k++)p[k]=r[k];
                p[1]=(p[1]+a)%7;p[6]=(p[6]+7-a)%7;
                p[3]=(p[3]+b)%7;p[4]=(p[4]+7-b)%7;
                p[5]=(p[5]+c)%7;p[2]=(p[2]+7-c)%7;
                // for(int x=0;x<7;x++)if((x+p[1])%7!=0&&(x+p[6])%7!=0)
                // for(int y=0;y<7;y++)if((y+p[3])%7!=0&&(y+p[4])%7!=0)
                // for(int z=0;z<7;z++)if((z+p[5])%7!=0&&(z+p[2])%7!=0)
                // ad(ans,1ll*f[i-1][a][b][c]*g[i-1][x][y][z]%mod);
                solve(i-1,p,f[i-1][a][b][c],s);
                // int f1=(p[1]==p[6]),f2=(p[3]==p[4]),f3=(p[5]==p[2]);

                // int A=(7-p[1])%7,B=(7-p[3])%7,C=(7-p[5])%7,w=f[i-1][a][b][c];
                // cout<<a<<' '<<b<<' '<<c<<' '<<w<<' '<<ans<<'\n';
                // for(int k=1;k<7;k++)cout<<p[k]<<' ';puts("");
                // ad(ans,1ll*w*s%mod);
                // if(f1)ad(ans,mod-1ll*w*h[0][A]%mod);
                // if(f2)ad(ans,mod-1ll*w*h[1][B]%mod);
                // if(f3)ad(ans,mod-1ll*w*h[2][C]%mod);
                // if(f1&&f2)ad(ans,1ll*w*find(A,B,-1,i-1)%mod);
                // if(f1&&f3)ad(ans,1ll*w*find(A,-1,C,i-1)%mod);
                // if(f2&&f3)ad(ans,1ll*w*find(-1,B,C,i-1)%mod);
                // if(f1&&f2&&f3)ad(ans,mod-1ll*w*g[i-1][A][B][C]%mod);
            }
            for(int j=1;j<7;j++)r[j]=(r[j]+cm[i][j])%7;
        }
    }
    int f=0;
    for(int i=1;i<7;i++)f|=(r[i]==0);
    if(!f&&s[0]=='1')ans++;
    cout<<ans<<'\n';
    for(int i=0;i<n;i++)s[i]=0;
}

int main()
{
    // freopen("in","r",stdin);
    init();
    cin>>T;
    while(T--)sol();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 32660kb

input:

5
1
1010
110101
1000111000
101101001000

output:

1
2
15
114
514

result:

ok 5 number(s): "1 2 15 114 514"

Test #2:

score: 0
Accepted
time: 47ms
memory: 35268kb

input:

10
1
11
1000
10111011
1000110100101001
11101110000001000011010011011000
110011000111110001101010101100100011010010101000011111001101011
11010111011101000010101111011111011011100001001101010011101011111111011011111101110110010011001101000001000111100010010111000010
10000000000000000000000000000000000...

output:

1
1
2
45
6591
814196699
193088128
849103726
497125329
363076920

result:

ok 10 numbers

Test #3:

score: 0
Accepted
time: 804ms
memory: 32660kb

input:

10
1
101
100101000
111111001111011001111100111
100001101010101000101110010111010010001101101110011111000001010001111100101010000
111001010100100100110011110111000111001001001001000100000011000110011000110101010010100000100101110101000011000011100010011001011000101110100111000110011011010111011111011...

output:

1
2
64
27062688
486363229
184013394
580592021
118930214
772664718
344619804

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 1228ms
memory: 32736kb

input:

10
1
1011
1101001010001110
1000010101110010000010010000000000001010111001001001110011001101
1001100101110111001000100100110111110001110010111011010101010111011101111101111100010000001100001001011100111100010110011010000010000000001100111011000001110011010000100000110101010011111100010111111100011011...

output:

1
3
10053
860833891
537931408
329471109
368911735
157523156
595487313
534701861

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 1508ms
memory: 35584kb

input:

10
1
11111
1010110010010000111001001
10011010100100001000110000111101101000111100001000000101010001100111111010001000101000000011100101000101100111100001001101100
11000100100010011101010101001011100010001100001010110011110101001101011000110001000111101010010000110111010001100100100111001000001000010...

output:

1
10
4692555
763463648
464152115
115362567
880780461
578723006
560068977
423846910

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 1702ms
memory: 32608kb

input:

10
1
101011
100100110100111100001101000101011100
1011011000011001101101010110000111011001001100110101111100110000100100101010000000110110010001110011101011000001011001000010001011101110110100110010111111000101101010110000101010101011001111100111011001101111011101
101000000111000010111000110000011000...

output:

1
13
955673880
266148454
368723690
496979115
190983211
772121423
932555320
843716403

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 1822ms
memory: 32600kb

input:

10
1
1101101
1100111111001000111100000010000111000000010101001
110111101101011000111101100110010011011100101110101111110011001111001101001000011001110011110101001110010110011110011001111010010101010011010011101101111010111000001110110111011011101000100001000001101110010111100110001110011101110111100...

output:

1
29
912933242
912560788
607401363
477602366
394403189
275067439
592568023
75193370

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 1877ms
memory: 35144kb

input:

10
1
10000010
100101110110100111100000100011111111010001100010100001100110001
111111000010011010111011111110000010101101011110100001101011110000001111001110001111110101000000010000001011000101101011010111011101111110101001000110011101010000111001011111100100010000010110110101010001110100111110110001...

output:

1
32
959140870
614330473
849221876
787816311
359958989
239371459
534701861
254356877

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 1974ms
memory: 32876kb

input:

10
1
111110011
111101001101011110100011110000100110011101010111111110100001111001101000100101101
11011010000110101011111110110011101010100100110001001111111011010000101111110001001011000011010101001000101110000100011011100101010110010101000101010111101100101110111100011011011000101101001001001100111...

output:

1
99
286317277
694681686
723919544
789291149
680541846
694957099
453387561
757810824

result:

ok 10 numbers

Test #10:

score: -100
Time Limit Exceeded

input:

10
1
1001001110
10110010111110100100111100111101101010111110111011001110000111101011011010110011110000000001110100
11000101011111110110100101100100100000010110001011100010101111111000000111000101100110111110101010111110010110111111110010110010001100000000111000101100010001110010001011111110101011111...

output:

1
120
987933828
449323095
435643580
557750562
122442298
758115947
388795572
87146822

result: