QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#390265 | #8330. Count off 3 | Graphcity | TL | 1992ms | 84700kb | C++20 | 3.2kb | 2024-04-15 11:03:11 | 2024-04-15 11:03:11 |
Judging History
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;
}
}
vector<int> ban[4]; int val[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;
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;
For(j,1,3) vector<int>().swap(ban[j]);
ban[1].push_back((14-a1-b1)%7),ban[1].push_back((a6+b1)%7);
ban[2].push_back((14-a2-b2)%7),ban[2].push_back((a5+b2)%7);
ban[3].push_back((14-a3-b3)%7),ban[3].push_back((a4+b3)%7);
For(j,1,3) if(ban[j].size()==2 && ban[j].front()==ban[j].back()) ban[j].pop_back();
For(x,0,ban[1].size())
{
val[1]=(x==ban[1].size()?7:ban[1][x]);
For(y,0,ban[2].size())
{
val[2]=(y==ban[2].size()?7:ban[2][y]);
For(z,0,ban[3].size())
{
val[3]=(z==ban[3].size()?7:ban[3][z]);
if((val[1]!=7)+(val[2]!=7)+(val[3]!=7)&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;
} printf("%d\n",ans);
}
int main()
{
// freopen("1.in","r",stdin);
Init(); int T; cin>>T;
while(T--) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 58ms
memory: 84272kb
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: 103ms
memory: 84216kb
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: 808ms
memory: 84332kb
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: 1210ms
memory: 84592kb
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: 1444ms
memory: 84632kb
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: 1605ms
memory: 84700kb
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: 1770ms
memory: 84392kb
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: 1821ms
memory: 84592kb
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: 1873ms
memory: 84332kb
input:
10 1 111110011 111101001101011110100011110000100110011101010111111110100001111001101000100101101 11011010000110101011111110110011101010100100110001001111111011010000101111110001001011000011010101001000101110000100011011100101010110010101000101010111101100101110111100011011011000101101001001001100111...
output:
1 99 286317277 694681686 723919544 789291149 680541846 694957099 453387561 757810824
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 1992ms
memory: 84384kb
input:
10 1 1001001110 10110010111110100100111100111101101010111110111011001110000111101011011010110011110000000001110100 11000101011111110110100101100100100000010110001011100010101111111000000111000101100110111110101010111110010110111111110010110010001100000000111000101100010001110010001011111110101011111...
output:
1 120 987933828 449323095 435643580 557750562 122442298 758115947 388795572 87146822
result:
ok 10 numbers
Test #11:
score: -100
Time Limit Exceeded
input:
10 1 11010010100 100110110000100111011101001111000000000110111100011110111011110100001010101000000000100000101100100101110101011100111000 110111100000010010111000111011111100010100100111101001001101111010011011100100001010100010100011110111111100101011100111111011011000000111001111000101111010110111...
output:
1 325 391030697 323231960 401473132 822267612 841573845 283856764 804647498 76347459