QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#347393 | #8330. Count off 3 | ucup-team266# | TL | 1977ms | 71360kb | C++20 | 3.8kb | 2024-03-09 13:33:57 | 2024-03-09 13:33:58 |
Judging History
answer
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest
9. module on time
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int INF=1e18;
int wei[7][10005];
int fe[5005][7][7][7],se[5005][8][8][8],fo[5005][7][7][7],so[5005][8][8][8];
void add(int &x,int y)
{
x+=y;
if(x>=mod) x-=mod;
}
int pw2[10005];
void solve()
{
string s;
cin>>s;
int n=s.size();
int ans=0;
int r1=0,r2=0,r3=0,r4=0,r5=0,r6=0;
for(int lcp=0;lcp<=s.size();lcp++)
{
if(lcp==s.size())
{
if(r1!=0&&r2!=0&&r3!=0&&r4!=0&&r5!=0&&r6!=0&&s[s.size()-1]=='1') ans=(ans+1)%mod;
break;
}
if(s[lcp]=='1'&&lcp+1!=s.size())
{
for(int re1=0;re1<7;re1++) for(int re2=0;re2<7;re2++) for(int re3=0;re3<7;re3++) if(se[(n-lcp)/2][re1][re2][re3])
{
vector <int> c1,c2,c3;
c1.pb(7),c2.pb(7),c3.pb(7);
int ban3=(r4+re3)%7,ban2=(r5+re2)%7,ban1=(r6+re1)%7;
c1.pb(ban1),c2.pb(ban2),c3.pb(ban3);
if((14-r1-re1)%7!=ban1) c1.pb((14-r1-re1)%7);
if((14-r2-re2)%7!=ban2) c2.pb((14-r2-re2)%7);
if((14-r3-re3)%7!=ban3) c3.pb((14-r3-re3)%7);
int re=n-lcp-1;
for(int x=0;x<c1.size();x++) for(int y=0;y<c2.size();y++) for(int z=0;z<c3.size();z++)
{
if(((x!=0)+(y!=0)+(z!=0))%2==0) ans=(ans+se[(re+1)/2][re1][re2][re3]*so[re/2][c1[x]][c2[y]][c3[z]])%mod;
else ans=(ans-se[(re+1)/2][re1][re2][re3]*so[re/2][c1[x]][c2[y]][c3[z]]%mod+mod)%mod;
}
}
}
r1=(r1+wei[1][n-lcp-1]*(s[lcp]-'0'))%7;
r2=(r2+wei[2][n-lcp-1]*(s[lcp]-'0'))%7;
r3=(r3+wei[3][n-lcp-1]*(s[lcp]-'0'))%7;
r4=(r4+wei[4][n-lcp-1]*(s[lcp]-'0'))%7;
r5=(r5+wei[5][n-lcp-1]*(s[lcp]-'0'))%7;
r6=(r6+wei[6][n-lcp-1]*(s[lcp]-'0'))%7;
}
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
for(int i=1;i<=6;i++)
{
for(int j=0,w=1;j<10005;j++) wei[i][j]=w,w=w*i%7;
}
pw2[0]=1;
for(int i=1;i<10005;i++) pw2[i]=2LL*pw2[i-1]%mod;
fe[0][0][0][0]=1;
for(int i=0;i<=5000;i++)
{
for(int r1=0;r1<7;r1++) for(int r2=0;r2<7;r2++) for(int r3=0;r3<7;r3++) for(int d=0;d<2;d++)
{
if(i==0&&d==0) continue;
add(fe[i+1][(r1+d*wei[1][i*2])%7][(r2+d*wei[2][i*2])%7][(r3+d*wei[3][i*2])%7],fe[i][r1][r2][r3]);
}
}
for(int i=0;i<=5000;i++)
{
for(int x=0;x<7;x++) for(int y=0;y<7;y++) for(int z=0;z<7;z++)
{
add(se[i][x][y][z],fe[i][x][y][z]),add(se[i][7][y][z],fe[i][x][y][z]),add(se[i][x][7][z],fe[i][x][y][z]),add(se[i][x][y][7],fe[i][x][y][z]);
add(se[i][7][7][z],fe[i][x][y][z]),add(se[i][7][y][7],fe[i][x][y][z]),add(se[i][x][7][7],fe[i][x][y][z]),add(se[i][7][7][7],fe[i][x][y][z]);
}
}
fo[0][0][0][0]=1;
for(int i=0;i<=5000;i++)
{
for(int r1=0;r1<7;r1++) for(int r2=0;r2<7;r2++) for(int r3=0;r3<7;r3++) for(int d=0;d<2;d++)
{
add(fo[i+1][(r1+d*wei[1][i*2+1])%7][(r2+d*wei[2][i*2+1])%7][(r3+d*wei[3][i*2+1])%7],fo[i][r1][r2][r3]);
}
}
for(int i=0;i<=5000;i++)
{
for(int x=0;x<7;x++) for(int y=0;y<7;y++) for(int z=0;z<7;z++)
{
add(so[i][x][y][z],fo[i][x][y][z]),add(so[i][7][y][z],fo[i][x][y][z]),add(so[i][x][7][z],fo[i][x][y][z]),add(so[i][x][y][7],fo[i][x][y][z]);
add(so[i][7][7][z],fo[i][x][y][z]),add(so[i][7][y][7],fo[i][x][y][z]),add(so[i][x][7][7],fo[i][x][y][z]),add(so[i][7][7][7],fo[i][x][y][z]);
}
}
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 20ms
memory: 71212kb
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: 52ms
memory: 71020kb
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: 723ms
memory: 71008kb
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: 1093ms
memory: 71108kb
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: 1351ms
memory: 71092kb
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: 1607ms
memory: 71012kb
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: 1626ms
memory: 71272kb
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: 1655ms
memory: 71016kb
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: 1755ms
memory: 71016kb
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: 1934ms
memory: 70960kb
input:
10 1 1001001110 10110010111110100100111100111101101010111110111011001110000111101011011010110011110000000001110100 11000101011111110110100101100100100000010110001011100010101111111000000111000101100110111110101010111110010110111111110010110010001100000000111000101100010001110010001011111110101011111...
output:
1 120 987933828 449323095 435643580 557750562 122442298 758115947 388795572 87146822
result:
ok 10 numbers
Test #11:
score: 0
Accepted
time: 1866ms
memory: 70968kb
input:
10 1 11010010100 100110110000100111011101001111000000000110111100011110111011110100001010101000000000100000101100100101110101011100111000 110111100000010010111000111011111100010100100111101001001101111010011011100100001010100010100011110111111100101011100111111011011000000111001111000101111010110111...
output:
1 325 391030697 323231960 401473132 822267612 841573845 283856764 804647498 76347459
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 1873ms
memory: 71360kb
input:
10 1 111111110011 100111010001010010111100011101110011110100101101010111001110101111000111010001111110000001000011010111010001001000011101100011100010010100010000 11001011101100010011111001010110110000110110011001011001000001001110010100100000000101100010001011010010001101000101110000111100100000001...
output:
1 704 677678115 593427859 667002509 574438492 664907465 979953874 8529137 613727900
result:
ok 10 numbers
Test #13:
score: 0
Accepted
time: 1901ms
memory: 70960kb
input:
10 1 1100110101011 100111000010011100111101101100110010110000100011110101100100011001101011100011101101110111001101000001110010111001110011100101000111111000010101101100011000010100010101 1111010000010011010010011000010000000001000110111011101100111011100010110011100110011110011011110011110100011001...
output:
1 1146 832402516 402106502 689225542 416112434 991952024 938688647 880733772 630306115
result:
ok 10 numbers
Test #14:
score: 0
Accepted
time: 1917ms
memory: 71156kb
input:
10 1 11000000000111 110010000100100011111101001100111010110111011101101011001001010110101111111101001000000100110011110101100111010110100100010100000100000011100010101011010001100001000111000101000011010110010100000 101001000110100011110100011001010101001010011111010111111001100111111100101111110111...
output:
1 2087 659256442 942088668 754989716 908871865 566839365 111034927 696022638 206335876
result:
ok 10 numbers
Test #15:
score: 0
Accepted
time: 1933ms
memory: 71080kb
input:
10 1 111100001011110 101100010011110001000011110010011010011100110010111110100111111111100101100111010101001101111001111010111011011111000111000101101010001100111010100110110000111110100100101000001101111100000101101100010110101000011001110001101 11111110001100110111110110100010111010100010010010010...
output:
1 5612 120730460 903512843 440620378 736669452 35297346 414402862 87146822 461180872
result:
ok 10 numbers
Test #16:
score: 0
Accepted
time: 1943ms
memory: 71196kb
input:
10 1 1011110111101110 11111011001101100000000011011111011000101001100010000000001010011110010000100000111100101011101111111111001000110011110000011001000111000010101100001001100111100100000010101101111100100100101110101100000000011101011100010111111010000101011000110010011000 11110011001110110000001...
output:
1 9074 47298040 806126372 607928251 829797230 861514498 6535505 135611721 148853296
result:
ok 10 numbers
Test #17:
score: 0
Accepted
time: 1977ms
memory: 71072kb
input:
10 1 11101111010010001 1111011100010101011101000110010001011001010101000100111100010110101010010001100101001001011111101001101100110100100100101101011001100000101011000100001011101000101000110000110100100100001001000011000111000010100011001111111011010001110111101111010011100010110001010010000100001...
output:
1 25268 485539600 497476229 129697011 91489334 354698980 228961474 875061949 618786188
result:
ok 10 numbers
Test #18:
score: -100
Time Limit Exceeded
input:
10 1 101101011100110001 100111001100000111101000101110011011011011111101011110101111000010000101010001010110100101001001100010101100101001110110001101101100111111100001000100010010110101110010111101100110010000010001101011001110001001100111101100111010100100000000000010000100101001000110000111100100...
output:
1 38342 769759919 33866310 945890505 127750526 125262837 888967227 757810824 441419016