QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#864495 | #2068. Fast as Ryser | XY_Eleven | WA | 1468ms | 147176kb | C++23 | 5.1kb | 2025-01-20 17:28:44 | 2025-01-20 17:28:44 |
Judging History
answer
#include <bits/stdc++.h>
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int>
#define pli pair<long long,int>
#define vct vector
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
// cLL mod=998244353,G=404;
cLL mod=1000000007ll;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{
}
cint N=36,N2=N>>1,P=1<<N2;
int n,n2,p;
int a[N];
LL c,ivc;
void input()
{
int t;
inpr(n,t); if(n&1) n++; inll(c); ivc=inv(c);
n2=n>>1; p=1<<n2;
while(t--)
{
int x,y; inpr(x,y); x--,y--;
a[x]|=1<<y,a[y]|=1<<x;
}
}
void Add(LL &w1,LL w2)
{
if((w1+=w2)>=mod) w1-=mod;
}
cLL iv2=inv(2ll);
LL f1[N][P],F1[P];
LL f2[N][P],F2[P];
LL F[P],g[P];
void main_solve()
{
input();
For_(i,0,n) f1[i][1<<(i>>1)]=iv2;
For_(k,0,p) For_(i,0,n) if(f1[i][k])
{
For_(j,0,n) if((!(k>>(j>>1)&1))&&(a[i]>>j&1))
Add(f1[j^1][k|(1<<(j>>1))],f1[i][k]);
}
For_(i,0,n) For_(k,0,p) Add(F1[k],f1[i][k]);
For_(i,0,n2) f2[i<<1|1][1<<i]=1ll;
For_(k,1,p) For_(i,0,n) if(f2[i][k])
{
int lw=(__lg(k&-k)+1<<1);
For_(j,lw,n) if((!(k>>(j>>1)&1))&&(a[i]>>j&1))
Add(f2[j^1][k|(1<<(j>>1))],f2[i][k]);
}
For_(k,1,p) For_(i,0,n) if(a[i]>>(__lg(k&-k)<<1)&1)
Add(F2[k],f2[i][k]);
// For_(i,0,p) printf("%lld ",F1[i]); printf("\n");
// For_(i,0,p) printf("%lld ",F2[i]); printf("\n");
For_(k,0,p) F[k]=md(F1[k]*ivc+F2[k]);
g[0]=1ll;
For_(k,1,p)
{
int t=__lg(k&-k),k_=(k^(1<<t));
for(int k2=k_;;k2=((k2-1)&k_))
{
add(g[k],g[k2]*F[k^k2]);
stop(!k2);
}
}
// For_(i,0,p) printf("%lld ",g[i]); printf("\n");
outll(md(g[p-1]*pw(c,1ll*n2)));
}
int main()
{
// ios::sync_with_stdio(0); cin.tie(0);
// freopen("ex_block4.in","r",stdin);
// freopen("out.txt","w",stdout);
// srand(time(NULL));
main_init();
// int _; inint(_); For(__,1,_) // T>1 ?
// printf("\n------------\n\n"),
main_solve();
// cerr<<clock()<<'\n';
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24420kb
input:
6 10 100 3 6 1 3 2 4 3 4 4 6 1 2 4 5 2 3 1 4 3 5
output:
2171001
result:
ok single line: '2171001'
Test #2:
score: 0
Accepted
time: 0ms
memory: 30560kb
input:
8 11 818466928 6 7 3 6 6 5 7 3 6 2 8 1 1 7 4 3 5 1 6 1 6 4
output:
425176360
result:
ok single line: '425176360'
Test #3:
score: -100
Wrong Answer
time: 1468ms
memory: 147176kb
input:
36 123 272968155 33 35 17 5 12 1 36 32 1 11 9 28 24 36 13 17 19 17 35 8 7 19 31 24 31 34 27 18 9 17 35 17 6 17 31 12 12 19 25 18 36 16 24 23 26 34 7 23 25 14 18 34 10 23 32 33 12 28 18 14 35 23 19 33 22 27 14 27 14 15 22 6 1 20 31 17 27 31 15 4 35 4 5 33 26 36 27 2 20 23 2 12 36 13 28 13 4 7 21 24 2...
output:
838308309
result:
wrong answer 1st lines differ - expected: '951479337', found: '838308309'