QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#561 | #346246 | #8330. Count off 3 | hos_lyric | Qingyu | Failed. | 2024-03-10 15:27:02 | 2024-03-10 15:27:03 |
Details
Extra Test:
Accepted
time: 461ms
memory: 3816kb
input:
10 111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111...
output:
954700341 358216478 803662031 502416034 405170373 202420697 862652329 484755287 259469240 790231310
result:
ok 10 numbers
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346246 | #8330. Count off 3 | Qingyu | AC ✓ | 201ms | 3876kb | C++ | 5.4kb | 2024-03-08 06:04:33 | 2024-10-13 18:45:56 |
answer
#include<bits/stdc++.h>
//#pragma gcc optimize(3)
#define gc getchar()
//char buf[100000],*buff = buf + 100000;
//#define gc ((buff == buf + 100000 ? (fread(buf,1,100000,stdin),buff = buf) : 0),*(buff++))
#define pc putchar
//char bfu[10000000],*bfuu = bfu;
//#define pc(x) (*(bfuu++) = x)
#define li long long
#define uli unsigned li
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define md int mid = l + r >> 1
#define ls q << 1
#define rs q << 1 | 1
#define ln ls,l,mid
#define rn rs,mid + 1,r
using namespace std;
//const int mo = 998244353;
const int mo = 1000000007;
inline li read(){
li x = 0;
int y = 0,c = gc;
while(c < '0' || c > '9') y = c,c = gc;
while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = gc;
return y == '-' ? -x : x;
}
inline void prt(li x){
if(x >= 10) prt(x / 10);
pc(x % 10 + '0');
}
inline void print(li x){
if(x < 0) pc('-'),x = -x;
prt(x);
}
inline void file(char *s){
char c[50];
sprintf(c,"%s.in",s);
freopen(c,"r",stdin);
sprintf(c,"%s.out",s);
freopen(c,"w",stdout);
}
li s1 = 19260817,s2 = 23333333,s3 = 998244853,srd;
inline li rd(){
return srd = (srd * s1 + s2 + rand()) % s3;
}
int t,n,mi[10],ni[] = {0,1,4,5,2,3,6};
string s;
#define clr(x) memset(x,0,sizeof(x))
struct node{
li f[7][7][7];
li s1[7][7],s2[7][7],s3[7][7],s12[7],s13[7],s23[7],s123;
void clear(){
clr(f);clr(s1);clr(s2);clr(s3);clr(s12);clr(s13);clr(s23);s123 = 0;
}
void gets(){
clr(s1);clr(s2);clr(s3);clr(s12);clr(s13);clr(s23);s123 = 0;
for(int i = 0;i < 7;++i){
for(int j = 0;j < 7;++j){
for(int k = 0;k < 7;++k){
li x = (f[i][j][k] %= mo);
s1[j][k] += x;s2[i][k] += x;s3[i][j] += x;
s12[k] += x;s13[j] += x;s23[i] += x;
s123 += x;
}
}
}
s123 %= mo;
for(int i = 0;i < 7;++i){
s12[i] %= mo;s13[i] %= mo;s23[i] %= mo;
for(int j = 0;j < 7;++j){
s1[i][j] %= mo;s2[i][j] %= mo;s3[i][j] %= mo;
}
}
}
}f[2];
inline li getf(node &fj,int p11,int p12,int p21,int p22,int p31,int p32){
li ans = fj.s123 - fj.s23[p11] - fj.s13[p21] - fj.s12[p31]
+ fj.s3[p11][p21] + fj.s2[p11][p31] + fj.s1[p21][p31] - fj.f[p11][p21][p31];
if(~p12) ans += -fj.s23[p12] + fj.s3[p12][p21] + fj.s2[p12][p31] - fj.f[p12][p21][p31];
if(~p22) ans += -fj.s13[p22] + fj.s3[p11][p22] + fj.s1[p22][p31] - fj.f[p11][p22][p31];
if(~p32) ans += -fj.s12[p32] + fj.s2[p11][p32] + fj.s1[p21][p32] - fj.f[p11][p21][p32];
if((~p12) && (~p22)) ans += fj.s3[p12][p22] - fj.f[p12][p22][p31];
if((~p12) && (~p32)) ans += fj.s2[p12][p32] - fj.f[p12][p21][p32];
if((~p22) && (~p32)) ans += fj.s1[p22][p32] - fj.f[p11][p22][p32];
if((~p12) && (~p22) && (~p32)) ans -= fj.f[p12][p22][p32];
return ans % mo;
}
li work(node &fo,node &fj,int o1,int o2,int o3,int j1,int j2,int j3){
//cerr<<o1<<" "<<o2<<" "<<o3<<" "<<j1<<" "<<j2<<" "<<j3<<endl;
int i,j,k;
/*
for(i = 0;i < 7;++i){
for(j = 0;j < 7;++j){
for(k = 0;k < 7;++k) cerr<<fj.f[i][j][k]<<" ";
cerr<<endl;
}
cerr<<endl;
}
*/
int p11,p12,p21,p22,p31,p32;
li ans = 0;
for(i = 0;i < 7;++i){
p11 = (77 - i - o1 - j1) * ni[1] % 7;
p12 = (77 + i + o1 - j1) * ni[1] % 7;
if(p11 == p12) p12 = -1;
for(j = 0;j < 7;++j){
p21 = (77 - j * 4 - o2 - j2) * ni[2] % 7;
p22 = (77 + j * 4 + o2 - j2) * ni[2] % 7;
if(p21 == p22) p22 = -1;
for(k = 0;k < 7;++k){
p31 = (77 - k * 9 - o3 - j3) * ni[3] % 7;
p32 = (77 + k * 9 + o3 - j3) * ni[3] % 7;
if(p31 == p32) p32 = -1;
//if(fo.f[i][j][k]) cerr<<i<<" "<<j<<" "<<k<<": "<<p11<<" "<<p12<<" "<<p21<<" "<<p22<<" "<<p31<<" "<<p32<<endl;
(ans += fo.f[i][j][k] * getf(fj,p11,p12,p21,p22,p31,p32)) %= mo;
}
}
}
return (ans % mo + mo) % mo;
}
int main(){
srand(time(0));rd();
//file("");
int i,j,k,l;
mi[0] = 1;for(i = 1;i <= 6;++i) mi[i] = mi[i - 1] * 7;
//t = 10;
t = read();
while(t--){
cin>>s;
n = s.size();
//n = rd() % 1000 + 9000;
//cerr<<n<<endl;
//s.clear();
//s += '1';
//for(i = 1;i < n;++i) s += rd() % 2 + '0';
f[0].clear();f[1].clear();
f[1].f[0][0][0] = 1;f[1].gets();
li ans = 0;
int j1 = 0,j2 = 0,j3 = 0,o1 = 0,o2 = 0,o3 = 0;
int p2 = 1,p3 = 1;
for(i = 0;i < n;++i){
if(s[n - i - 1] == '1'){
if(i & 1){
(++j1) %= 7;(j2 += p2) %= 7;(j3 += p3) %= 7;
}
else{
(++o1) %= 7;(o2 += p2) %= 7;(o3 += p3) %= 7;
}
}
(p2 *= 2) %= 7;(p3 *= 3) %= 7;
}
if(s[n - 1] == '1'){
if((o1 + j1) % 7 && (o2 + j2) % 7 && (o3 + j3) % 7
&& (o1 - j1) % 7 && (o2 - j2) % 7 && (o3 - j3) % 7){
++ans;
}
}
else{
(++o1) %= 7;(++o2) %= 7;(++o3) %= 7;
}
//cerr<<o1<<" "<<o2<<" "<<o3<<" "<<j1<<" "<<j2<<" "<<j3<<endl;
p2 = 2;p3 = 3;
for(i = 1;i < n;++i){
//cerr<<i<<":::"<<endl;
if(i % 2 == 0){
f[0] = f[1];f[1].clear();
for(j = 0;j < 7;++j){
for(k = 0;k < 7;++k){
for(l = 0;l < 7;++l){
li val = f[0].f[j][k][l];
int p1 = j,p2 = k * 4 % 7,p3 = l * 9 % 7;
f[1].f[p1][p2][p3] += val;
(++p1) %= 7;(++p2) %= 7;(++p3) %= 7;
f[1].f[p1][p2][p3] += val;
}
}
}
f[1].gets();
}
if(s[n - i - 1] == '1'){
if(i & 1){
(j1 += 6) %= 7;(j2 += 7 - p2) %= 7;(j3 += 7 - p3) %= 7;
}
else{
(o1 += 6) %= 7;(o2 += 7 - p2) %= 7;(o3 += 7 - p3) %= 7;
}
ans += work(f[i & 1],f[1],o1,o2,o3,j1,j2,j3);
ans %= mo;
}
(p2 *= 2) %= 7;(p3 *= 3) %= 7;
}
print(ans);pc('\n');
}
//fwrite(bfu,1,bfuu - bfu,stdout);
//cerr<<clock()<<endl;
return 0;
}