QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395687 | #8330. Count off 3 | xlwang | WA | 8ms | 3900kb | C++14 | 5.2kb | 2024-04-21 17:15:55 | 2024-04-21 17:15:56 |
Judging History
answer
#include<bits/stdc++.h>
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
const int Maxn=1e5+10,mod=1e9+7;
inline void add(int &x,int y){
x+=y;if(x>=mod) x-=mod;
}
int f1[7][7][7],f2[7][7][7];
int n;
char c[Maxn];
int ans;
inline void clear(){
memset(f1,0,sizeof(f1)),memset(f2,0,sizeof(f2));
ans=0;
}
int s1[Maxn][4],s2[Maxn][4];
inline int ksm(int x,int y,int mod){
int sum=1;
while(y){
if(y&1) sum=sum*x%mod;
y=y/2;x=x*x%mod;
}
return sum;
}
int g1[7][7][7],g2[7][7][7];
int a[Maxn];
int p1[8],p2[8],p3[8],p12[8][8],p23[8][8],p13[8][8],p123[8][8][8];
inline int query(int a1,int a2,int b1,int b2,int c1,int c2){
int ans=0;
fr(i,0,6) add(ans,p1[i]);
// cout<<ans<<endl;
add(ans,mod-p1[a1]);add(ans,mod-p1[a2]);add(ans,mod-p2[b1]);add(ans,mod-p2[b2]);add(ans,mod-p3[c1]);add(ans,mod-p3[c2]);
// cout<<ans<<endl;
add(ans,p12[a1][b1]);add(ans,p12[a1][b2]);add(ans,p12[a2][b1]);add(ans,p12[a2][b2]);
add(ans,p13[a1][c1]);add(ans,p13[a1][c2]);add(ans,p13[a2][c1]);add(ans,p13[a2][c2]);
add(ans,p23[b1][c1]);add(ans,p23[b1][c2]);add(ans,p23[b2][c1]);add(ans,p23[b2][c2]);
add(ans,mod-p123[a1][b1][c1]);add(ans,mod-p123[a1][b1][c2]);add(ans,mod-p123[a1][b2][c1]);add(ans,mod-p123[a1][b2][c2]);
add(ans,mod-p123[a2][b1][c1]);add(ans,mod-p123[a2][b1][c2]);add(ans,mod-p123[a2][b2][c1]);add(ans,mod-p123[a2][b2][c2]);
return ans;
}
inline void getans(int id){
memset(p1,0,sizeof(p1));memset(p2,0,sizeof(p2));memset(p3,0,sizeof(p3));
memset(p12,0,sizeof(p12));memset(p13,0,sizeof(p13));memset(p23,0,sizeof(p23));
memset(p123,0,sizeof(p123));
fr(i,0,6) fr(j,0,6) fr(k,0,6){
add(p1[i],f1[i][j][k]);add(p2[j],f1[i][j][k]);add(p3[k],f1[i][j][k]);
add(p12[i][j],f1[i][j][k]);add(p13[i][k],f1[i][j][k]);add(p23[j][k],f1[i][j][k]);
add(p123[i][j][k],f1[i][j][k]);
}
fr(i,0,6) fr(j,0,6) fr(k,0,6){
if(!f2[i][j][k]) continue;
int a1,a2,b1,b2,c1,c2;
a1=(i-s1[id-1][1]+s2[id-1][1]+7)%7,a2=(21-i-s1[id-1][1]-s2[id-1][1])%7;
b1=(j-s1[id-1][2]+s2[id-1][2]+7)%7,b2=(21-j-s1[id-1][2]-s2[id-1][2])%7;
c1=(k-s1[id-1][3]+s2[id-1][3]+7)%7,c2=(21-k-s1[id-1][3]-s2[id-1][3])%7;
// cout<<i<<' '<<j<<' '<<k<<endl;
// cout<<a1<<' '<<a2<<' '<<b1<<' '<<b2<<' '<<c1<<' '<<c2<<endl;
if(a2==a1) a2=7;
if(b2==b1) b2=7;
if(c2==c1) c2=7;
add(ans,1ll*f2[i][j][k]*query(a1,a2,b1,b2,c1,c2)%mod);
// cout<<ans<<endl;
}
}
inline void trans(int id){
if(id==n){
f2[1][1][1]=1,f1[0][0][0]=1;
return;
}
fr(i1,0,6) fr(i2,0,6) fr(i3,0,6) g1[i1][i2][i3]=f1[i1][i2][i3],g2[i1][i2][i3]=f2[i1][i2][i3];
int n1,n2,n3;n1=ksm(1,n-id,7),n2=ksm(2,n-id,7),n3=ksm(3,n-id,7);
if((n-id)&1) fr(i1,0,6) fr(i2,0,6) fr(i3,0,6) add(f1[(i1+n1)%7][(i2+n2)%7][(i3+n3)%7],g1[i1][i2][i3]);
else fr(i1,0,6) fr(i2,0,6) fr(i3,0,6) add(f2[(i1+n1)%7][(i2+n2)%7][(i3+n3)%7],g2[i1][i2][i3]);
// writeln(id);
// puts("F1:");
// fr(i,0,6) fr(j,0,6) fr(k,0,6){
// if(f1[i][j][k]) cout<<i<<' '<<j<<' '<<k<<' '<<f1[i][j][k]<<endl;
// }
// puts("F2:");
// fr(i,0,6) fr(j,0,6) fr(k,0,6){
// if(f2[i][j][k]) cout<<i<<' '<<j<<' '<<k<<' '<<f2[i][j][k]<<endl;
// }
}
inline void work(){
scanf("%s",c+1);n=strlen(c+1);
fr(i,1,n) a[i]=c[i]-'0';
// fr(i,1,n) cout<<i<<' '<<a[i]<<endl;
fr(i,1,n){
fr(j,1,3) s1[i][j]=s1[i-1][j],s2[i][j]=s2[i-1][j];
if((n-i)&1) fr(j,1,3) s1[i][j]=(s1[i][j]+ksm(j,n-i,7)*a[i])%7;
else{
fr(j,1,3){
// cout<<i<<' '<<j<<' '<<ksm(j,n-i,7)*a[i]<<endl;
s2[i][j]=(s2[i][j]+ksm(j,n-i,7)*a[i])%7;
}
}
}
if(s1[n][1]!=s2[n][1] && (s1[n][1]+s2[n][1])%7!=7 && s1[n][2]!=s2[n][2] && (s1[n][2]+s2[n][2])%7!=7 && s1[n][3]!=s2[n][3] && (s1[n][3]+s2[n][3])%7!=7 && a[n]) ++ans;
// cout<<ans<<endl;
// fr(i,1,n){
// writeln(i);
// fr(j,1,3) cout<<s1[i][j]<<' '<<s2[i][j]<<endl;
// }
rf(i,n,1){
if(a[i] && i!=n) getans(i);
// cout<<i<<' '<<ans<<endl;
trans(i);
}
writeln(ans);
clear();
}
inline void init(){
int t=read();
while(t--) work();
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3900kb
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: 8ms
memory: 3900kb
input:
10 1 11 1000 10111011 1000110100101001 11101110000001000011010011011000 110011000111110001101010101100100011010010101000011111001101011 11010111011101000010101111011111011011100001001101010011101011111111011011111101110110010011001101000001000111100010010111000010 10000000000000000000000000000000000...
output:
1 1 2 45 6592 814196699 193088128 849103726 497125329 363076921
result:
wrong answer 5th numbers differ - expected: '6591', found: '6592'