QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#348249 | #8330. Count off 3 | ucup-team087# | AC ✓ | 612ms | 231352kb | C++20 | 21.7kb | 2024-03-09 17:34:02 | 2024-10-13 18:46:02 |
Judging History
answer
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//#define int ll
bool dbg=false;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.a<<","<<p.b<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ";
dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif
using uint=unsigned;
using ull=unsigned long long;
template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
return os<<vc<t>(all(a));
}
ll rand_int(ll l, ll r) { //[l, r]
//#ifdef LOCAL
static mt19937_64 gen;
/*#else
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif*/
return uniform_int_distribution<ll>(l, r)(gen);
}
ll rand_int(ll k){ //[0,k)
return rand_int(0,k-1);
}
string rand_string(int n,char lw,char up){
string s(n,'?');
rep(i,n)s[i]=rand_int(lw,up);
return s;
}
int current_run_id,run_batch_size=1000;
int calc_random_limit(){
return current_run_id/run_batch_size+1;
}
#ifndef int
void generate_single(int&a){
a=rand_int(1,calc_random_limit());
}
#endif
void generate_single(ll&a){
a=rand_int(1,calc_random_limit());
}
void generate_single(string&a){
int n;generate_single(n);
a=rand_string(n,'a','b');
}
//https://trap.jp/post/1224/
template<class... Args>
void input(Args&... a){
if(dbg){
(generate_single(a),...);
}else{
(cin >> ... >> a);
}
}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;input(__VA_ARGS__)
#define overload3(a,b,c,d,...) d
#define VI2(name,size) vi name(size);rep(i,size)input(name[i]);
#define VI3(name,size,offset) vi name(size);rep(i,size)input(name[i]),name[i]+=offset;
#define VI(...) overload3(__VA_ARGS__,VI3,VI2)(__VA_ARGS__)
template<int i,class T>
void print_tuple(ostream&,const T&){
}
template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
if(i)os<<",";
os<<get<i>(t);
print_tuple<i+1,T,Args...>(os,t);
}
template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
os<<"{";
print_tuple<0,tuple<Args...>,Args...>(os,t);
return os<<"}";
}
ll read(){
ll i;
cin>>i;
return i;
}
vi readvi(int n,int off=0){
vi v(n);
rep(i,n)v[i]=read()+off;
return v;
}
pi readpi(int off=0){
int a,b;cin>>a>>b;
return pi(a+off,b+off);
}
template<class t>
void print_single(t x,int suc=1){
cout<<x;
if(suc==1){
if(dbg)cout<<endl;
else cout<<"\n";
}
if(suc==2)
cout<<" ";
}
template<class t,class u>
void print_single(const pair<t,u>&p,int suc=1){
print_single(p.a,2);
print_single(p.b,suc);
}
template<class T>
void print_single(const vector<T>&v,int suc=1){
rep(i,v.size())
print_single(v[i],i==int(v.size())-1?suc:2);
}
template<class T>
void print_offset(const vector<T>&v,ll off,int suc=1){
rep(i,v.size())
print_single(v[i]+off,i==int(v.size())-1?suc:2);
}
template<class T,size_t N>
void print_single(const array<T,N>&v,int suc=1){
rep(i,N)
print_single(v[i],i==int(N)-1?suc:2);
}
template<class T>
void print(const T&t){
print_single(t);
}
template<class T,class ...Args>
void print(const T&t,const Args&...args){
print_single(t,2);
print(args...);
}
string readString(){
string s;
cin>>s;
return s;
}
template<class T>
T sq(const T& t){
return t*t;
}
void YES(bool ex=true){
cout<<"YES\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void NO(bool ex=true){
cout<<"NO\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void Yes(bool ex=true){
cout<<"Yes\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void No(bool ex=true){
cout<<"No\n";
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
//#define CAPITAL
/*
void yes(bool ex=true){
#ifdef CAPITAL
cout<<"YES"<<"\n";
#else
cout<<"Yes"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void no(bool ex=true){
#ifdef CAPITAL
cout<<"NO"<<"\n";
#else
cout<<"No"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}*/
void possible(bool ex=true){
#ifdef CAPITAL
cout<<"POSSIBLE"<<"\n";
#else
cout<<"Possible"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void impossible(bool ex=true){
#ifdef CAPITAL
cout<<"IMPOSSIBLE"<<"\n";
#else
cout<<"Impossible"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
constexpr ll ten(int n){
return n==0?1:ten(n-1)*10;
}
const ll infLL=LLONG_MAX/3;
#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif
int topbit(signed t){
return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
return t==0?-1:63-__builtin_clzll(t);
}
int topbit(ull t){
return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
return a==0?64:__builtin_ctzll(a);
}
int botbit(ull a){
return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
return __builtin_popcount(t);
}
int popcount(ll t){
return __builtin_popcountll(t);
}
int popcount(ull t){
return __builtin_popcountll(t);
}
int bitparity(ll t){
return __builtin_parityll(t);
}
bool ispow2(int i){
return i&&(i&-i)==i;
}
ll mask(int i){
return (ll(1)<<i)-1;
}
ull umask(int i){
return (ull(1)<<i)-1;
}
ll minp2(ll n){
if(n<=1)return 1;
else return ll(1)<<(topbit(n-1)+1);
}
bool inc(int a,int b,int c){
return a<=b&&b<=c;
}
template<class S> void mkuni(S&v){
sort(all(v));
v.erase(unique(all(v)),v.ed);
}
template<class t> bool isuni(vc<t> v){
int s=si(v);
mkuni(v);
return si(v)==s;
}
template<class t>
void myshuffle(vc<t>&a){
rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}
template<class S,class u>
int lwb(const S&v,const u&a){
return lower_bound(all(v),a)-v.bg;
}
template<class t,class u>
bool bis(const vc<t>&v,const u&a){
return binary_search(all(v),a);
}
vvc<int> readGraph(int n,int m){
vvc<int> g(n);
rep(i,m){
int a,b;
cin>>a>>b;
//sc.read(a,b);
a--;b--;
g[a].pb(b);
g[b].pb(a);
}
return g;
}
vvc<int> readTree(int n){
return readGraph(n,n-1);
}
template<class t>
vc<t> presum(const vc<t>&a){
vc<t> s(si(a)+1);
rep(i,si(a))s[i+1]=s[i]+a[i];
return s;
}
vc<ll> presum(const vi&a){
vc<ll> s(si(a)+1);
rep(i,si(a))s[i+1]=s[i]+a[i];
return s;
}
//BIT で数列を管理するときに使う (CF850C)
template<class t>
vc<t> predif(vc<t> a){
gnr(i,1,si(a))a[i]-=a[i-1];
return a;
}
template<class t>
vvc<ll> imos(const vvc<t>&a){
int n=si(a),m=si(a[0]);
vvc<ll> b(n+1,vc<ll>(m+1));
rep(i,n)rep(j,m)
b[i+1][j+1]=b[i+1][j]+b[i][j+1]-b[i][j]+a[i][j];
return b;
}
//verify してないや
void transvvc(int&n,int&m){
swap(n,m);
}
template<class t,class... Args>
void transvvc(int&n,int&m,vvc<t>&a,Args&...args){
assert(si(a)==n);
vvc<t> b(m,vi(n));
rep(i,n){
assert(si(a[i])==m);
rep(j,m)b[j][i]=a[i][j];
}
a.swap(b);
transvvc(n,m,args...);
}
//CF854E
void rotvvc(int&n,int&m){
swap(n,m);
}
template<class t,class... Args>
void rotvvc(int&n,int&m,vvc<t>&a,Args&...args){
assert(si(a)==n);
vvc<t> b(m,vi(n));
rep(i,n){
assert(si(a[i])==m);
rep(j,m)b[m-1-j][i]=a[i][j];
}
a.swap(b);
rotvvc(n,m,args...);
}
//ソートして i 番目が idx[i]
//CF850C
template<class t>
vi sortidx(const vc<t>&a){
int n=si(a);
vi idx(n);iota(all(idx),0);
sort(all(idx),[&](int i,int j){return a[i]<a[j];});
return idx;
}
//vs[i]=a[idx[i]]
//例えば sortidx で得た idx を使えば単にソート列になって返ってくる
//CF850C
template<class t>
vc<t> a_idx(const vc<t>&a,const vi&idx){
int n=si(a);
assert(si(idx)==n);
vc<t> vs(n);
rep(i,n)vs[i]=a[idx[i]];
return vs;
}
//CF850C
vi invperm(const vi&p){
int n=si(p);
vi q(n);
rep(i,n)q[p[i]]=i;
return q;
}
template<class t,class s=t>
s SUM(const vc<t>&a){
return accumulate(all(a),s(0));
}
template<class t,size_t K,class s=t>
s SUM(const array<t,K>&a){
return accumulate(all(a),s(0));
}
template<class t>
t MAX(const vc<t>&a){
return *max_element(all(a));
}
template<class t>
pair<t,int> MAXi(const vc<t>&a){
auto itr=max_element(all(a));
return mp(*itr,itr-a.bg);
}
template<class A>
auto MIN(const A&a){
return *min_element(all(a));
}
template<class t>
pair<t,int> MINi(const vc<t>&a){
auto itr=min_element(all(a));
return mp(*itr,itr-a.bg);
}
vi vid(int n){
vi res(n);iota(all(res),0);
return res;
}
template<class S>
void soin(S&s){
sort(all(s));
}
template<class S,class F>
void soin(S&s,F&&f){
sort(all(s),forward<F>(f));
}
template<class S>
S soout(S s){
soin(s);
return s;
}
template<class S>
void rein(S&s){
reverse(all(s));
}
template<class S>
S reout(S s){
rein(s);
return s;
}
template<class t,class u>
pair<t,u>&operator+=(pair<t,u>&a,pair<t,u> b){
a.a+=b.a;a.b+=b.b;return a;}
template<class t,class u>
pair<t,u>&operator-=(pair<t,u>&a,pair<t,u> b){
a.a-=b.a;a.b-=b.b;return a;}
template<class t,class u>
pair<t,u> operator+(pair<t,u> a,pair<t,u> b){return mp(a.a+b.a,a.b+b.b);}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a,pair<t,u> b){return mp(a.a-b.a,a.b-b.b);}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a){return mp(-a.a,-a.b);}
template<class t,class u>
istream&operator>>(istream&is,pair<t,u>&a){
return is>>a.a>>a.b;
}
template<class t>
t gpp(vc<t>&vs){
assert(si(vs));
t res=move(vs.back());
vs.pop_back();
return res;
}
template<class t,class u>
void pb(vc<t>&a,const vc<u>&b){
a.insert(a.ed,all(b));
}
template<class t,class...Args>
vc<t> cat(vc<t> a,Args&&...b){
(pb(a,forward<Args>(b)),...);
return a;
}
template<class t,class u>
vc<t>& operator+=(vc<t>&a,u x){
for(auto&v:a)v+=x;
return a;
}
template<class t,class u>
vc<t> operator+(vc<t> a,u x){
return a+=x;
}
template<class t>
vc<t> operator+(const vc<t>&a,const vc<t>&b){
vc<t> c(max(si(a),si(b)));
rep(i,si(a))c[i]+=a[i];
rep(i,si(b))c[i]+=b[i];
return c;
}
template<class t,class u>
vc<t>& operator-=(vc<t>&a,u x){
for(auto&v:a)v-=x;
return a;
}
template<class t,class u>
vc<t>& operator-(vc<t> a,u x){
return a-=x;
}
template<class t,class u>
void remval(vc<t>&a,const u&v){
a.erase(remove(all(a),v),a.ed);
}
//消した要素の個数を返してくれる
//UCUP 2-8-F
template<class t,class F>
int remif(vc<t>&a,F f){
auto itr=remove_if(all(a),f);
int res=a.ed-itr;
a.erase(itr,a.ed);
return res;
}
template<class VS,class u>
void fila(VS&vs,const u&a){
fill(all(vs),a);
}
template<class t,class u>
int findid(const vc<t>&vs,const u&a){
auto itr=find(all(vs),a);
if(itr==vs.ed)return -1;
else return itr-vs.bg;
}
template<class t>
void rtt(vc<t>&vs,int i){
rotate(vs.bg,vs.bg+i,vs.ed);
}
//Multiuni2023-8 C
//f(lw)=false,...,f(n-1)=false,f(n)=true,...,f(up)=true,
//のときに n を返す
template<class F>
int find_min_true(int lw,int up,F f){
while(up-lw>1){
const int mid=(lw+up)/2;
if(f(mid))up=mid;
else lw=mid;
}
return up;
}
//f(lw)=true,f(up)=false
template<class F>
int find_max_true(int lw,int up,F f){
while(up-lw>1){
const int mid=(lw+up)/2;
if(f(mid))lw=mid;
else up=mid;
}
return lw;
}
//mint107 は verify してねえ
//#define DYNAMIC_MOD
struct modinfo{uint mod,root;
#ifdef DYNAMIC_MOD
constexpr modinfo(uint m,uint r):mod(m),root(r),im(0){set_mod(m);}
ull im;
constexpr void set_mod(uint m){
mod=m;
im=ull(-1)/m+1;
}
uint product(uint a,uint b)const{
ull z=ull(a)*b;
uint x=((unsigned __int128)z*im)>>64;
uint v=uint(z)-x*mod;
return v<mod?v:v+mod;
}
#endif
};
template<modinfo const&ref>
struct modular{
static constexpr uint const &mod=ref.mod;
static modular root(){return modular(ref.root);}
uint v;
//modular(initializer_list<uint>ls):v(*ls.bg){}
modular(ll vv=0){s(vv%mod+mod);}
modular& s(uint vv){
v=vv<mod?vv:vv-mod;
return *this;
}
modular operator-()const{return modular()-*this;}
modular& operator+=(const modular&rhs){return s(v+rhs.v);}
modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);}
modular&operator*=(const modular&rhs){
#ifndef DYNAMIC_MOD
v=ull(v)*rhs.v%mod;
#else
v=ref.product(v,rhs.v);
#endif
return *this;
}
modular&operator/=(const modular&rhs){return *this*=rhs.inv();}
modular operator+(const modular&rhs)const{return modular(*this)+=rhs;}
modular operator-(const modular&rhs)const{return modular(*this)-=rhs;}
modular operator*(const modular&rhs)const{return modular(*this)*=rhs;}
modular operator/(const modular&rhs)const{return modular(*this)/=rhs;}
modular pow(ll n)const{
if(n<0)return inv().pow(-n);
modular res(1),x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
modular inv()const{return pow(mod-2);}
/*modular inv()const{
int x,y;
int g=extgcd<ll>(v,mod,x,y);
assert(g==1);
if(x<0)x+=mod;
return modular(x);
}*/
friend modular operator+(ll x,const modular&y){
return modular(x)+y;
}
friend modular operator-(ll x,const modular&y){
return modular(x)-y;
}
friend modular operator*(ll x,const modular&y){
return modular(x)*y;
}
friend modular operator/(ll x,const modular&y){
return modular(x)/y;
}
friend ostream& operator<<(ostream&os,const modular&m){
return os<<m.v;
}
friend istream& operator>>(istream&is,modular&m){
ll x;is>>x;
m=modular(x);
return is;
}
bool operator<(const modular&r)const{return v<r.v;}
bool operator==(const modular&r)const{return v==r.v;}
bool operator!=(const modular&r)const{return v!=r.v;}
explicit operator bool()const{
return v;
}
};
#ifndef DYNAMIC_MOD
//extern constexpr modinfo base{998244353,3};
extern constexpr modinfo base{1000000007,0};
//extern constexpr modinfo base{2147483579,1689685080};//2^31 未満の最大の安全素数
//modinfo base{1,0};
#ifdef USE_GOOD_MOD
static_assert(base.mod==998244353);
#endif
#else
modinfo base(1,0);
extern constexpr modinfo base107(1000000007,0);
using mint107=modular<base107>;
#endif
using mint=modular<base>;
extern constexpr modinfo base7{7,0};
using mint7=modular<base7>;
mint parity(int i){
return i%2==0?1:-1;
}
#ifdef LOCAL
const int vmax=10010;
#else
const int vmax=(1<<21)+10;
#endif
mint fact[vmax],finv[vmax],invs[vmax];
void initfact(){
fact[0]=1;
rng(i,1,vmax){
fact[i]=fact[i-1]*i;
}
finv[vmax-1]=fact[vmax-1].inv();
for(int i=vmax-2;i>=0;i--){
finv[i]=finv[i+1]*(i+1);
}
for(int i=vmax-1;i>=1;i--){
invs[i]=finv[i]*fact[i-1];
}
}
mint choose(int n,int k){
return inc(0,k,n)?fact[n]*finv[n-k]*finv[k]:0;
}
mint binom(int a,int b){
return 0<=a&&0<=b?fact[a+b]*finv[a]*finv[b]:0;
}
mint catalan(int n){
return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}
//対角線を超えず (x,y) に至る方法の数
mint catalan(int x,int y){
assert(y<=x);
return binom(x,y)-binom(x+1,y-1);
}
//y=x+c を超えず (x,y) に至る方法の数
mint catalan(int x,int y,int c){
assert(y<=x+c);
return binom(x,y)-binom(x+c+1,y-c-1);
}
/*
const int vmax=610;
mint fact[vmax+1],binbuf[vmax+1][vmax+1];
mint choose(int n,int k){
return 0<=k&&k<=n?binbuf[n-k][k]:0;
}
mint binom(int a,int b){
return 0<=a&&0<=b?binbuf[a][b]:0;
}
void initfact(int n){
fact[0]=1;
rep(i,n)fact[i+1]=fact[i]*(i+1);
rep(i,n+1)rep(j,n+1){
if(i==0&&j==0){
binbuf[i][j]=1;
}else{
binbuf[i][j]=0;
if(i)binbuf[i][j]+=binbuf[i-1][j];
if(j)binbuf[i][j]+=binbuf[i][j-1];
}
}
}
*/
mint p2[vmax],p2inv[vmax];
void initp2(){
p2[0]=1;
rep(i,vmax-1)p2[i+1]=p2[i]*2;
p2inv[vmax-1]=p2[vmax-1].inv();
per(i,vmax-1)p2inv[i]=p2inv[i+1]*2;
}
template<class F>
void array_rec(int n,int m,F f){
vi a(n);
function<void(int)> rec=[&](int i)->void{
if(i==n)f(a);
else{
rep(nx,m){
a[i]=nx;
rec(i+1);
}
}
};
rec(0);
}
const int nmax=10005;
mint way[nmax][7];
mint7 pw[7][7];
const int T=3;
//vvc<int> lookup[1<<7];
vvc<pi> lookup[1<<7];
mint x[7][nmax][7];
mint y[7][7][nmax][7][7];
mint wA[nmax][343];
mint wB[nmax][343];
void init(){
way[0][0]=1;
rep(i,nmax-1){
rep(j,7){
way[i+1][j]+=way[i][j];
way[i+1][(j+1)%7]+=way[i][j];
}
}
rep(i,7)rep(j,7)pw[i][j]=mint7(i).pow(j);
rep(bit,1<<7)if((bit&1)==0&&popcount(bit)>=T){
vi pos;
rep(i,7)if(bit&1<<i)pos.pb(i);
int len=si(pos);
int s=1;rep(_,len)s*=7;
lookup[bit].resize(s);
/*array_rec(6,7,[&](vi a){
int idx=0;
per(i,6){
idx=idx*7+a[i];
}
int to=0;
per(i,len){
mint7 sum=0;
rep(j,6)sum+=pw[pos[i]][j]*a[j];
to=to*7+(sum.v);
}
lookup[bit][to].pb(idx);
});*/
vi a(6);
vc<mint7> sum(len);
auto dfs=[&](auto self,int j)->void{
if(j==6){
int idx=0;
per(i,6){
idx=idx*7+a[i];
}
int to=0;
per(i,len){
to=to*7+(sum[i].v);
}
//lookup[bit][to].pb(idx);
lookup[bit][to].eb(idx%343,idx/343);
}else{
rep(v,7){
a[j]=v;
rep(i,len)sum[i]+=pw[pos[i]][j]*v;
self(self,j+1);
rep(i,len)sum[i]-=pw[pos[i]][j]*v;
}
}
};
dfs(dfs,0);
}
/*rep(bit,1<<7)if((bit&1)==0&&popcount(bit)<T){
//1
rng(a,1,6)
}*/
rng(a,1,7){
x[a][1][0]=1;
rng(i,1,nmax-1){
rep(j,7){
x[a][i+1][j]+=x[a][i][j];
x[a][i+1][(j+pw[a][i%6]).v]+=x[a][i][j];
}
}
}
rng(a,1,7)rng(b,a+1,7){
y[a][b][1][0][0]=1;
rng(i,1,nmax-1){
rep(j,7)rep(k,7){
y[a][b][i+1][j][k]+=y[a][b][i][j][k];
y[a][b][i+1][(j+pw[a][i%6]).v][(k+pw[b][i%6]).v]+=y[a][b][i][j][k];
}
}
}
rng(i,1,nmax)rep(a,7)rep(b,7)rep(c,7){
int az=(i+5)/6-1;
int bz=(i+4)/6;
int cz=(i+3)/6;
wA[i][a+b*7+c*49]=way[az][a]*way[bz][b]*way[cz][c];
}
rng(i,1,nmax)rep(a,7)rep(b,7)rep(c,7){
int az=(i+2)/6;
int bz=(i+1)/6;
int cz=(i+0)/6;
wB[i][a+b*7+c*49]=way[az][a]*way[bz][b]*way[cz][c];
}
//cerr<<"Init Done"<<endl;
}
void slv(){
STR(raw);
if(raw=="-1"){
raw.clear();
rep(i,10000){
raw.pb('1');
}
}
int n=si(raw);
vi s(n);
rep(i,n)s[i]=raw[n-1-i]-'0';
mint ans;
mint7 fix[7];
auto add=[&](int i,mint7 w){
rng(k,1,7)fix[k]+=pw[k][i%6]*w;
};
//int glob=0;
add(0,1);
per(i,n){
int mx=s[i];
if(i==0)mx++;
rep(v,mx){//fix digit i or above
add(i,v);
if(i==0){
if(v==1){
add(0,-1);
bool ok=true;
rng(k,1,7)if(fix[k]==0)ok=false;
if(ok)ans+=1;
add(0,1);
}
}else{
//digit [1,i) で
//fix + 残りがいい感じになるようにする方法は何通りあるか?
//包除
rep(bit,1<<7)if((bit&1)==0){
if(popcount(bit)>=T){
int tar=0;
per(j,7)if(bit&1<<j){
tar=tar*7+(7-fix[j]).v;
}
//mint sum;
//int cnt=0;
unsigned __int128 sum=0;
for(auto [idxA,idxB]:lookup[bit][tar]){
//mint mul=1;
/*rep(j,6){
int need=idx%7;
idx/=7;
int z=i/6+(j<i%6);
if(j==0)z--;
mul*=way[z][need];
}*/
//mul=wA[i][idx%343]*wB[i][idx/343];
//ans+=parity(popcount(bit))*mul;
//sum+=wA[i][idx%343]*wB[i][idx/343];
//sum+=wA[i][idxA]*wB[i][idxB];
sum+=(ull)wA[i][idxA].v*wB[i][idxB].v;
//cnt++;
}
//chmax(glob,cnt);
ans+=parity(popcount(bit))*(sum%base.mod);
}else if(popcount(bit)==1){
int a=topbit(bit);
int at=(-fix[a]).v;
ans-=x[a][i][at];
}else if(popcount(bit)==2){
int a=botbit(bit);
int at=(-fix[a]).v;
int b=topbit(bit);
int bt=(-fix[b]).v;
ans+=y[a][b][i][at][bt];
}else if(popcount(bit)==0){
ans+=p2[i-1];
}else{
//assert(false);
}
}
}
add(i,-v);
}
add(i,mx);
//cerr<<"Digit "<<i<<" Ans "<<ans<<endl;
}
add(0,-1);
print(ans);
}
signed main(signed argc,char*argv[]){
if(argc>1&&strcmp(argv[1],"D")==0)dbg=true;
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
initp2();
init();
if(dbg){
while(1){
if(current_run_id%run_batch_size==0){
cerr<<"Current Run "<<current_run_id<<endl;
}
slv();
current_run_id++;
}
}else{
int t;cin>>t;rep(_,t)
slv();
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 248ms
memory: 230688kb
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: 243ms
memory: 230904kb
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: 360ms
memory: 230908kb
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: 429ms
memory: 231156kb
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: 465ms
memory: 231116kb
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: 0
Accepted
time: 489ms
memory: 230892kb
input:
10 1 101011 100100110100111100001101000101011100 1011011000011001101101010110000111011001001100110101111100110000100100101010000000110110010001110011101011000001011001000010001011101110110100110010111111000101101010110000101010101011001111100111011001101111011101 101000000111000010111000110000011000...
output:
1 13 955673880 266148454 368723690 496979115 190983211 772121423 932555320 843716403
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 531ms
memory: 231140kb
input:
10 1 1101101 1100111111001000111100000010000111000000010101001 110111101101011000111101100110010011011100101110101111110011001111001101001000011001110011110101001110010110011110011001111010010101010011010011101101111010111000001110110111011011101000100001000001101110010111100110001110011101110111100...
output:
1 29 912933242 912560788 607401363 477602366 394403189 275067439 592568023 75193370
result:
ok 10 numbers
Test #8:
score: 0
Accepted
time: 527ms
memory: 231024kb
input:
10 1 10000010 100101110110100111100000100011111111010001100010100001100110001 111111000010011010111011111110000010101101011110100001101011110000001111001110001111110101000000010000001011000101101011010111011101111110101001000110011101010000111001011111100100010000010110110101010001110100111110110001...
output:
1 32 959140870 614330473 849221876 787816311 359958989 239371459 534701861 254356877
result:
ok 10 numbers
Test #9:
score: 0
Accepted
time: 562ms
memory: 230920kb
input:
10 1 111110011 111101001101011110100011110000100110011101010111111110100001111001101000100101101 11011010000110101011111110110011101010100100110001001111111011010000101111110001001011000011010101001000101110000100011011100101010110010101000101010111101100101110111100011011011000101101001001001100111...
output:
1 99 286317277 694681686 723919544 789291149 680541846 694957099 453387561 757810824
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 585ms
memory: 231176kb
input:
10 1 1001001110 10110010111110100100111100111101101010111110111011001110000111101011011010110011110000000001110100 11000101011111110110100101100100100000010110001011100010101111111000000111000101100110111110101010111110010110111111110010110010001100000000111000101100010001110010001011111110101011111...
output:
1 120 987933828 449323095 435643580 557750562 122442298 758115947 388795572 87146822
result:
ok 10 numbers
Test #11:
score: 0
Accepted
time: 576ms
memory: 231088kb
input:
10 1 11010010100 100110110000100111011101001111000000000110111100011110111011110100001010101000000000100000101100100101110101011100111000 110111100000010010111000111011111100010100100111101001001101111010011011100100001010100010100011110111111100101011100111111011011000000111001111000101111010110111...
output:
1 325 391030697 323231960 401473132 822267612 841573845 283856764 804647498 76347459
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 569ms
memory: 231012kb
input:
10 1 111111110011 100111010001010010111100011101110011110100101101010111001110101111000111010001111110000001000011010111010001001000011101100011100010010100010000 11001011101100010011111001010110110000110110011001011001000001001110010100100000000101100010001011010010001101000101110000111100100000001...
output:
1 704 677678115 593427859 667002509 574438492 664907465 979953874 8529137 613727900
result:
ok 10 numbers
Test #13:
score: 0
Accepted
time: 570ms
memory: 231148kb
input:
10 1 1100110101011 100111000010011100111101101100110010110000100011110101100100011001101011100011101101110111001101000001110010111001110011100101000111111000010101101100011000010100010101 1111010000010011010010011000010000000001000110111011101100111011100010110011100110011110011011110011110100011001...
output:
1 1146 832402516 402106502 689225542 416112434 991952024 938688647 880733772 630306115
result:
ok 10 numbers
Test #14:
score: 0
Accepted
time: 581ms
memory: 231132kb
input:
10 1 11000000000111 110010000100100011111101001100111010110111011101101011001001010110101111111101001000000100110011110101100111010110100100010100000100000011100010101011010001100001000111000101000011010110010100000 101001000110100011110100011001010101001010011111010111111001100111111100101111110111...
output:
1 2087 659256442 942088668 754989716 908871865 566839365 111034927 696022638 206335876
result:
ok 10 numbers
Test #15:
score: 0
Accepted
time: 582ms
memory: 231224kb
input:
10 1 111100001011110 101100010011110001000011110010011010011100110010111110100111111111100101100111010101001101111001111010111011011111000111000101101010001100111010100110110000111110100100101000001101111100000101101100010110101000011001110001101 11111110001100110111110110100010111010100010010010010...
output:
1 5612 120730460 903512843 440620378 736669452 35297346 414402862 87146822 461180872
result:
ok 10 numbers
Test #16:
score: 0
Accepted
time: 581ms
memory: 231352kb
input:
10 1 1011110111101110 11111011001101100000000011011111011000101001100010000000001010011110010000100000111100101011101111111111001000110011110000011001000111000010101100001001100111100100000010101101111100100100101110101100000000011101011100010111111010000101011000110010011000 11110011001110110000001...
output:
1 9074 47298040 806126372 607928251 829797230 861514498 6535505 135611721 148853296
result:
ok 10 numbers
Test #17:
score: 0
Accepted
time: 586ms
memory: 230928kb
input:
10 1 11101111010010001 1111011100010101011101000110010001011001010101000100111100010110101010010001100101001001011111101001101100110100100100101101011001100000101011000100001011101000101000110000110100100100001001000011000111000010100011001111111011010001110111101111010011100010110001010010000100001...
output:
1 25268 485539600 497476229 129697011 91489334 354698980 228961474 875061949 618786188
result:
ok 10 numbers
Test #18:
score: 0
Accepted
time: 584ms
memory: 230976kb
input:
10 1 101101011100110001 100111001100000111101000101110011011011011111101011110101111000010000101010001010110100101001001100010101100101001110110001101101100111111100001000100010010110101110010111101100110010000010001101011001110001001100111101100111010100100000000000010000100101001000110000111100100...
output:
1 38342 769759919 33866310 945890505 127750526 125262837 888967227 757810824 441419016
result:
ok 10 numbers
Test #19:
score: 0
Accepted
time: 612ms
memory: 231012kb
input:
10 1 1001100011010110111 11100110010001111111110100011111100100011011110000110100000111101100111110111010111010111001111111100111011000000101001111000010001100010001111001011000111111001111100100101101011001110011100000111011111110101000111011101101110101101101110101100000011000001001011011100001111...
output:
1 65218 438898572 348219276 776140964 704823526 170625715 198310775 477853700 897436999
result:
ok 10 numbers
Test #20:
score: 0
Accepted
time: 607ms
memory: 231160kb
input:
10 1 11010100111111001011 1000011001001001110110101001100001001101001001010010101010001110011001001000000000110001100110001110110111010100101011011001100101001110111001101101000111101100010110101100101110111101000101111010100110001011110111000110000110110111011101110010010011010001110101010110010000...
output:
1 183823 238142747 846693477 959968477 260267123 642987070 779134130 951392182 679687101
result:
ok 10 numbers
Extra Test:
score: 0
Extra Test Passed