Submission #1405173
Source Code Expand
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
template<unsigned int mod_>
struct ModInt{
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr static uint mod = mod_;
uint v;
ModInt():v(0){}
ModInt(ll v):v(normS(v%mod+mod)){}
explicit operator bool() const {return v!=0;}
static uint normS(const uint &x){return (x<mod)?x:x-mod;} // [0 , 2*mod-1] -> [0 , mod-1]
static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
ModInt operator-() const { return make(normS(mod-v)); }
ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
ModInt operator/(const ModInt& b) const { return *this*b.inv();}
ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
ll extgcd(ll a,ll b,ll &x,ll &y) const{
ll u[]={a,1,0},v[]={b,0,1};
while(*v){
ll t=*u/ *v;
rep(i,3) swap(u[i]-=t*v[i],v[i]);
}
if(u[0]<0) rep(i,3) u[i]=-u[i];
x=u[1],y=u[2];
return u[0];
}
ModInt inv() const{
ll x,y;
extgcd(v,mod,x,y);
return make(normS(x+mod));
}
bool operator==(const ModInt& b) const { return v==b.v;}
bool operator!=(const ModInt& b) const { return v!=b.v;}
friend istream& operator>>(istream &o,ModInt& x){
ll tmp;
o>>tmp;
x=ModInt(tmp);
return o;
}
friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
bool B(int x,int i){return (x>>i)&1;}
int N,M;
bool e[15][15];
int edgenum[15][1<<15];
mint dp[1<<15][2];
int calcedgenum(int x,int S){ //from x to S
int n = 0;
rep(i,N) if(B(S,i) && e[x][i]) n++;
return n;
}
void precalc(){
rep(x,N) rep(b,1<<N) edgenum[x][b] = calcedgenum(x,b);
}
mint p2[1000];
int main(){
p2[0] = 1;
rep1(i,999) p2[i] = p2[i-1]*2;
cin>>N>>M;
rep(i,M){
int x,y;
cin>>x>>y;
x--,y--;
e[x][y] = 1;
}
precalc();
dp[0][0] = 1;
rep(b,1<<N) rep(t,2) if(dp[b][t]){
int nb = (1<<N)-1 - b;
for(int c = nb;c!=0;c=(c-1)&nb){
int d = nb-c;
mint coef = 1;
rep(x,N) if(B(d,x)){
int n = edgenum[x][c];
coef *= (p2[n]-1);
}
rep(x,N) if(B(b,x)){
int n = edgenum[x][c];
coef *= p2[n];
}
int nt = t || (B(c,0)&&B(c,1));
dp[b|c][nt] += dp[b][t] * coef;
}
}
cout<<dp[(1<<N)-1][0]<<endl;
}
Submission Info
Submission Time |
|
Task |
F - Games on DAG |
User |
sigma425 |
Language |
C++14 (GCC 5.4.1) |
Score |
1600 |
Code Size |
3208 Byte |
Status |
AC |
Exec Time |
407 ms |
Memory |
2432 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1600 / 1600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
512 KB |
0_01.txt |
AC |
1 ms |
512 KB |
0_02.txt |
AC |
1 ms |
512 KB |
0_03.txt |
AC |
1 ms |
512 KB |
1_00.txt |
AC |
1 ms |
512 KB |
1_01.txt |
AC |
27 ms |
2432 KB |
1_02.txt |
AC |
27 ms |
2432 KB |
1_03.txt |
AC |
407 ms |
2432 KB |
1_04.txt |
AC |
392 ms |
2432 KB |
1_05.txt |
AC |
407 ms |
2432 KB |
1_06.txt |
AC |
153 ms |
2432 KB |
1_07.txt |
AC |
392 ms |
2432 KB |
1_08.txt |
AC |
407 ms |
2432 KB |
1_09.txt |
AC |
394 ms |
2432 KB |
1_10.txt |
AC |
402 ms |
2432 KB |
1_11.txt |
AC |
291 ms |
2432 KB |
1_12.txt |
AC |
406 ms |
2432 KB |
1_13.txt |
AC |
405 ms |
2432 KB |
1_14.txt |
AC |
407 ms |
2432 KB |
1_15.txt |
AC |
326 ms |
2432 KB |
1_16.txt |
AC |
291 ms |
2432 KB |
1_17.txt |
AC |
407 ms |
2432 KB |
1_18.txt |
AC |
151 ms |
2432 KB |
1_19.txt |
AC |
407 ms |
2432 KB |
1_20.txt |
AC |
32 ms |
2432 KB |
1_21.txt |
AC |
3 ms |
640 KB |
1_22.txt |
AC |
137 ms |
2432 KB |
1_23.txt |
AC |
140 ms |
2432 KB |
1_24.txt |
AC |
20 ms |
1408 KB |
1_25.txt |
AC |
2 ms |
512 KB |
1_26.txt |
AC |
270 ms |
2432 KB |
1_27.txt |
AC |
8 ms |
768 KB |
1_28.txt |
AC |
27 ms |
2432 KB |
1_29.txt |
AC |
45 ms |
1152 KB |
1_30.txt |
AC |
4 ms |
768 KB |
1_31.txt |
AC |
382 ms |
2432 KB |
1_32.txt |
AC |
45 ms |
1024 KB |
1_33.txt |
AC |
6 ms |
768 KB |
1_34.txt |
AC |
52 ms |
1408 KB |
1_35.txt |
AC |
44 ms |
1024 KB |