QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#346751 | #8330. Count off 3 | ucup-team1447# | WA | 236ms | 4320kb | C++14 | 4.3kb | 2024-03-08 22:23:58 | 2024-03-08 22:23:58 |
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[7][7][7],g2[7][7][7],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: 0
Wrong Answer
time: 236ms
memory: 4320kb
input:
5 1 1010 110101 1000111000 101101001000
output:
01 s 1 1101 s 2 011011 s 15 1001110001 s 114 100100101101 s 514
result:
wrong output format Expected integer, but "01" found