QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548958 | #8330. Count off 3 | liqingyang | WA | 4ms | 17104kb | C++17 | 2.8kb | 2024-09-05 22:23:48 | 2024-09-05 22:23:48 |
Judging History
answer
#include<iostream>
#include<cstring>
using namespace std;
const unsigned int mod=1e9+7;
const int p2[6]={1,2,4,1,2,4},p3[6]={1,3,2,6,4,5};
int T,f[5010][7][7][7][2],box[3][2],F[5][5][5][2];
char s[10010];
inline void Add(int &x,int y)
{
x+=y,x=x<mod?x:x-mod;
}
inline int add7(int x,int y)
{
x+=y;
return x<7?x:x-7;
}
inline void Add7(int &x,int y)
{
x+=y,x=x<7?x:x-7;
}
inline void init()
{
f[0][0][0][0][0]=1;
for(int i=1;i<=5000;i++)
{
memcpy(f[i],f[i-1],sizeof(f[i]));
for(int I=((i<<1)-1)%6,j=0;j<7;j++)
{
for(int k=0,k0=p2[I],k1=0;k<7;
k++,k0=k0<6?k0+1:0,k1=add7(k1,2))
{
for(int l=0,l0=p3[I],l1=0;l<7;
l++,l0=l0<6?l0+1:0,l1=add7(l1,3))
{
Add(f[i][j<6?j+1:0][k0][l0][0],
f[i-1][j][k1][l1][1]=f[i-1][j][k][l][0]);
}
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
init();
cin>>T;
while(T--)
{
cin>>s+1;
int n=strlen(s+1);
long long ans=0;
box[0][0]=box[1][0]=box[2][0]=0;
box[0][1]=box[1][1]=box[2][1]=1;
for(int i=1;i<n;i++)
{
if(s[i]=='0')
{
continue;
}
int n0=n-i>>1,n1=n-1-i-n0;
memset(F,0,sizeof(F));
for(int j=0,j0=box[0][0],j1=box[0][1];j<7;
j++,j0=j0<6?j0+1:0,j1=j1<6?j1+1:0)
{
int J0=j0<4?j0:7-j0,J1=j1<4?j1:7-j1;
for(int k=0,k0=box[1][0],k1=box[1][1];k<7;
k++,k0=k0<6?k0+1:0,k1=k1<6?k1+1:0)
{
int K0=k0<4?k0:7-k0,K1=k1<4?k1:7-k1;
for(int l=0,l0=box[2][0],l1=box[2][1];l<7;
l++,l0=l0<6?l0+1:0,l1=l1<6?l1+1:0)
{
int L0=l0<4?l0:7-l0,L1=l1<4?l1:7-l1;
Add(F[J0][K0][L0][0],f[n0][j][k][l][0]);
Add(F[J1][K1][L1][1],f[n1][j][k][l][1]);
}
}
}
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
Add(F[4][k][l][0],F[j][k][l][0]);
Add(F[4][k][l][1],F[j][k][l][1]);
}
}
}
for(int j=0;j<5;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
Add(F[j][4][l][0],F[j][k][l][0]);
Add(F[j][4][l][1],F[j][k][l][1]);
}
}
}
for(int j=0;j<5;j++)
{
for(int k=0;k<5;k++)
{
for(int l=0;l<4;l++)
{
Add(F[j][k][4][0],F[j][k][l][0]);
Add(F[j][k][4][1],F[j][k][l][1]);
}
}
}
for(int j=0;j<5;j++)
{
for(int k=0;k<5;k++)
{
for(int l=0;l<5;l++)
{
ans+=(j<4?-1:1)*(k<4?-1:1)*(l<4?-1ll:1ll)
*F[j][k][l][0]*F[j][k][l][1];
}
}
}
Add7(box[0][n-i+1&1],1);
Add7(box[1][n-i+1&1],p2[(n-i)%6]);
Add7(box[2][n-i+1&1],p3[(n-i)%6]);
}
if(s[n]=='1')
{
bool flag=1;
for(int i=0;i<3;i++)
{
if(box[i][0]+box[i][1]==7||box[i][0]==box[i][1])
{
flag=0;
break;
}
}
ans+=flag;
}
cout<<(ans%mod+mod)%mod<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 17104kb
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: -100
Wrong Answer
time: 4ms
memory: 17048kb
input:
10 1 11 1000 10111011 1000110100101001 11101110000001000011010011011000 110011000111110001101010101100100011010010101000011111001101011 11010111011101000010101111011111011011100001001101010011101011111111011011111101110110010011001101000001000111100010010111000010 10000000000000000000000000000000000...
output:
1 1 2 45 6591 814196699 193088128 837231773 497125329 932029642
result:
wrong answer 8th numbers differ - expected: '849103726', found: '837231773'