QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346753 | #8330. Count off 3 | ucup-team1447# | TL | 1726ms | 4828kb | C++14 | 4.3kb | 2024-03-08 22:24:38 | 2024-03-08 22:24:39 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int unsigned long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 10005
#define inf 0x3f3f3f3f
int n;
char s[maxn];
int sum[maxn][7];
modint w[maxn][7];
modint g1[8][8][8],g2[8][8][8],res;
int cnt[maxn][7];
void solve(int pos)
{
// s[pos]=0 next .. pre ??
// cout<<"solve "<<pos<<"\n";
assert(pos>0);
memset(g1,0,sizeof g1);
memset(g2,0,sizeof g2);
For(i,0,6) For(j,0,6) For(k,0,6) {
int a=(i+sum[pos+1][0])%7,b=(j+sum[pos+1][2])%7,c=(k+sum[pos+1][4])%7;
modint coe=1;
coe*=w[cnt[pos-1][0]-1][(i-1+7)%7];
coe*=w[cnt[pos-1][2]][j];
coe*=w[cnt[pos-1][4]][k];
// if(coe.x) cout<<"add1 "<<i<<" "<<j<<" "<<k<<" "<<coe.x<<"\n";
g1[(a+b+c)%7][(a+4*b+2*c)%7][(a+2*b+4*c)%7]+=coe;
}
For(i,0,6) For(j,0,6) For(k,0,6) {
int a=(i+sum[pos+1][1])%7,b=(j+sum[pos+1][3])%7,c=(k+sum[pos+1][5])%7;
modint coe=1;
coe*=w[cnt[pos-1][1]][i];
coe*=w[cnt[pos-1][3]][j];
coe*=w[cnt[pos-1][5]][k];
// if(coe.x) cout<<"add2 "<<i<<" "<<j<<" "<<k<<" "<<coe.x<<"\n";
g2[(a+b+c)%7][(2*a+b+4*c)%7][(3*a+6*b+5*c)%7]+=coe;
}
For(a,0,6)For(b,0,6)For(c,0,6)For(d,0,6)For(e,0,6)For(f,0,6)
if(a!=d && (a+d)%7!=0 && (b!=e) && (b+e)%7!=0 && (c!=f) && (c+f)%7!=0)
if(g1[a][b][c].x && g2[d][e][f].x)
// cout<<"add "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" "<<g1[a][b][c].x<<" "<<g2[d][e][f].x<<"\n",
res+=g1[a][b][c]*g2[d][e][f];
//cout<<"res "<<res.x<<"\n";
}
void work()
{
cin>>s;
n=strlen(s);
reverse(s,s+n);
res=0;
int pp=0;
while(pp<n && s[pp]=='1')s[pp]='0',++pp;
if(pp>=n)++n,s[n-1]='1';
else s[pp]='1';
// For(i,0,n-1)cout<<s[i];puts(" s");
For(i,0,6) sum[n][i]=sum[n+1][i]=0;
Rep(i,n-1,0){
For(j,0,6) sum[i][j]=sum[i+1][j];
if(s[i]&1) sum[i][i%6]++;
}
For(i,1,n-1){
if(s[i]&1){
solve(i);
}
}
cout<<res.x<<"\n";
}
signed main()
{
For(i,0,10000){
if(i){
For(j,0,6)cnt[i][j]=cnt[i-1][j];
}
cnt[i][i%6]+=1;
}
For(i,0,10000){
For(j,0,i){
w[i][j%7]+=C(i,j);
}
}
int T=read();
while(T--)work();
return 0;
}
/*
*/
详细
Test #1:
score: 100
Accepted
time: 237ms
memory: 4268kb
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: 251ms
memory: 4508kb
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: 444ms
memory: 4828kb
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: 1203ms
memory: 4596kb
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: 1726ms
memory: 4608kb
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...
output:
1 13 955673880 266148454 368723690 496979115 190983211 772121423 932555320 843716403