QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#351387 | #8330. Count off 3 | 275307894a | TL | 1764ms | 71076kb | C++14 | 2.5kb | 2024-03-11 21:25:49 | 2024-03-11 21:25:50 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e4+5,M=(1<<20)+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
char s[N];int n;
ll f[N][7][7][7],g[N][8][8][8];int pw[7][N];
void add(ll &x,ll y){(x+=y)>=mod&&(x-=mod);}
void Solve(){
int i,j;scanf("%s",s+1);n=strlen(s+1);
reverse(s+1,s+n+1);for(i=1;i<=n;i++) s[i]-='0';s[n+1]=0;
s[1]++;for(i=1;i<=n;i++) if(s[i]>=2) s[i]-=2,s[i+1]++;if(s[n+1]) n++;
for(int i=1;i<=6;i++){
pw[i][0]=1;for(int j=1;j<=n;j++) pw[i][j]=pw[i][j-1]*i%7;
}
Me(f,0);Me(g,0);
f[0][0][0][0]=1;g[0][0][0][0]=1;
for(i=1;i<=n;i++){
if(i&1) Mc(g[i],g[i-1]);else Mc(f[i],f[i-1]);
for(int x=0;x<7;x++) for(int y=0;y<7;y++) for(int z=0;z<7;z++)for(int o=(i==1);o<=1;o++){
if(i&1){
add(f[i][(x+o*pw[1][i-1])%7][(y+o*pw[2][i-1])%7][(z+o*pw[3][i-1])%7],f[i-1][x][y][z]);
}else{
add(g[i][(x+o*pw[1][i-1])%7][(y+o*pw[2][i-1])%7][(z+o*pw[3][i-1])%7],g[i-1][x][y][z]);
}
}
}
int sx=0,tx=0,sy=0,ty=0,sz=0,tz=0;ll ans=0;
for(int i=n;i>1;i--)if(s[i]==1){
for(int px=0;px<7;px++) for(int py=0;py<7;py++) for(int pz=0;pz<7;pz++){
for(int qx=0;qx<7;qx++) if((px+sx+qx+tx)%7&&(px+sx-qx-tx)%7){
for(int qy=0;qy<7;qy++) if((py+sy+qy+ty)%7&&(py+sy-qy-ty)%7){
for(int qz=0;qz<7;qz++) if((pz+sz+qz+tz)%7&&(pz+sz-qz-tz)%7){
ans+=f[i-1][px][py][pz]*g[i-1][qx][qy][qz]%mod;
}
}
}
}
if(i&1) sx+=pw[1][i-1],sy+=pw[2][i-1],sz+=pw[3][i-1];
else tx+=pw[1][i-1],ty+=pw[2][i-1],tz+=pw[3][i-1];
}
printf("%lld\n",ans%mod);
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 70888kb
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: 77ms
memory: 70864kb
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: 344ms
memory: 71056kb
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: 1186ms
memory: 71076kb
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: 1764ms
memory: 71056kb
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: -100
Time Limit Exceeded
input:
10 1 101011 100100110100111100001101000101011100 1011011000011001101101010110000111011001001100110101111100110000100100101010000000110110010001110011101011000001011001000010001011101110110100110010111111000101101010110000101010101011001111100111011001101111011101 101000000111000010111000110000011000...