QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196499 | #7. 主旋律 | c20231020 | 100 ✓ | 256ms | 6476kb | C++23 | 9.0kb | 2023-10-01 18:21:41 | 2023-10-01 18:21:43 |
Judging History
answer
/*
膜拜传奇特级宗师 Afterglow 大神儿
今天在 florr 首页称您为大夏尊贵的大名儿
一股敬佩之情油生然而
您在 florr 为国争光,扬我大夏威名
向您献上最真挚的膜拜!!!
膜拜传奇特级宗师 Afterglow 大神儿,今,一,您,扬。向!
膜拜传奇特级宗师 Afterglow 大神儿,今,一,您,扬。向!
膜拜传奇特级宗师 Afterglow 大神儿,今,一,您,扬。向!
*/
/*
_____ _____ _____ _____
/\ \ /\ \ /\ \ /\ \
/ \ \ / \ \ / \____\ / \ \
\ \ \ / \ \ / / / \ \ \
\ \ \ / \ \ / / / \ \ \
\ \ \ / /\ \ \ / /____/ \ \ \
\ \ \ / / \ \ \ / | | \ \ \
\ \ \ / / \ \ \ / | | \ \ \
\ \ \ / / / \ \ \ / | | \ \ \
\ \ \ / / / \ \ \ / |____|__ _____ \ \ \
_______________\ \____\/ /____/ \ \ \ / /| \ \ _______________\ \____\
\ / /\ \ \ \ \ \\ / | _________\____\\ / /
\ ____________/____/ \ \ \ \ \____\\/__| | | \ ____________/____/
\ \ \ \ \ \ | | | | | | \ \ \
\ \ \ \ \ \ | | | | | | \ \ \
\ \ \ \ \ \ | |____| | | | \ \ \
\ \ \ \ \ \ / / / \ | | \ \ \
\ \ \ \ \ \/ / / \ | | \ \ \
\ \____\ \ \___/ / / \ | | \ \____\
\ / / \ / / \| | \ / /
\/____/ \_______/____/ \____| \/____/
*/
#define poj
#define zcz
#ifdef poj
//C++
#include<iomanip>
#include<iostream>
//C
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
//STL
#include<algorithm>
#include<bitset>
#include<functional>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
//C++11
#if __cplusplus>=201103L
#include<chrono>
#include<random>
#include<unordered_set>
#include<unordered_map>
#endif
#else
#include<bits/stdc++.h>
#endif
using namespace std;
#ifdef zcz
class fastin{
private:
#ifdef poj
static const int MAXBF=1<<20;
#else
const int MAXBF=1<<27;
#endif
FILE *inf;
char *inbuf,*inst,*ined;
inline char _getchar(){
if(inst==ined)inst=inbuf,ined=inbuf+fread(inbuf,1,MAXBF,inf);
return inst==ined?EOF:*inst++;
}
public:
fastin(FILE*_inf=stdin){
inbuf=new char[MAXBF],inf=_inf,inst=inbuf,ined=inbuf;
}
~fastin(){delete[]inbuf;}
template<typename Int> fastin&operator>>(Int &n){
static char c;
Int t=1;
while((c=_getchar())<'0'||c>'9')if(c=='-')t=-1;
n=(c^48);
while((c=_getchar())>='0'&&c<='9')n=n*10+(c^48);
n*=t;
return *this;
}
fastin&operator>>(char&c){
while((c=_getchar())<'!'||c>'~');
return *this;
}
fastin&operator>>(char*s){
int t=0;
static char c;
while((c=_getchar())==' '||c=='\n');
s[t++]=c;
while((c=_getchar())>='!'&&c<='~')s[t++]=c;
s[t]='\0';
return *this;
}
}fi;
class fastout{
private:
#ifdef poj
static const int MAXBF=1<<20;
#else
const int MAXBF=1<<27;
#endif
FILE *ouf;
char *oubuf,*oust,*oued;
inline void _flush(){fwrite(oubuf,1,oued-oust,ouf);oued=oust;}
inline void _putchar(char c){
if(oued==oust+MAXBF)_flush(),oued=oubuf;
*oued++=c;
#ifdef local
_flush();
#endif
}
public:
fastout(FILE*_ouf=stdout){
oubuf=new char[MAXBF],ouf=_ouf,oust=oubuf,oued=oubuf;
}
~fastout(){_flush();delete[]oubuf;}
template<typename Int> fastout&operator<<(Int n){
if(n<0)_putchar('-'),n=-n;
static char S[20];
int t=0;
do{S[t++]='0'+n%10,n/=10;}while(n);
for(int i=0;i<t;++i)_putchar(S[t-i-1]);
return *this;
}
fastout&operator<<(char c){_putchar(c);return *this;}
fastout&operator<<(char*s){
for(int i=0;s[i];++i)_putchar(s[i]);
return *this;
}
fastout&operator<<(const char*s){
for(int i=0;s[i];++i)_putchar(s[i]);
return *this;
}
}fo;
#define cin fi
#define cout fo
#else
#define czc ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#endif
#define mod7 1000000007
#define mod9 998244353
#define ll long long
#define isinf 0x3f3f3f3f
#define ilinf 0x7fffffff
#define lsinf 0x3f3f3f3f3f3f3f3f
#define llinf 0x7fffffffffffffff
#define pii pair<int,int>
#define fr first
#define sc second
#define next ___
#define pb push_back
#define N 16
#define M 5000010
#define For(i,a,b) for(ll i=(a);i<=(b);++i)
#define Rep(i,a,b,c) for(ll i=(a);i<=(b);i+=c)
#define Per(i,a,b,c) for(ll i=(a);i>=(b);i-=c)
#define Gra(i) for(ll i=h[x];i;i=next[i])
typedef int arr[N];
typedef int arm[M];
typedef ll arl[N];
typedef ll alm[M];
typedef double ard[N];
typedef double adm[M];
namespace modint{
template<typename Int,Int mod,Int m1>
struct modint{
Int v;
modint(){v=0;}
modint(Int a){v=a;}
bool operator==(modint a){return v==a.v;}
bool operator!=(modint a){return v!=a.v;}
bool operator<(modint a){return v<a.v;}
bool operator>(modint a){return v>a.v;}
bool operator<=(modint a){return v<=a.v;}
bool operator>=(modint a){return v>=a.v;}
bool operator==(Int a){return v==a;}
bool operator!=(Int a){return v!=a;}
bool operator<(Int a){return v<a;}
bool operator>(Int a){return v>a;}
bool operator<=(Int a){return v<=a;}
bool operator>=(Int a){return v>=a;}
friend bool operator==(Int a,modint b){return b==a;}
friend bool operator!=(Int a,modint b){return b!=a;}
friend bool operator<(Int a,modint b){return b>a;}
friend bool operator>(Int a,modint b){return b<a;}
friend bool operator<=(Int a,modint b){return b>=a;}
friend bool operator>=(Int a,modint b){return b<=a;}
modint operator+(modint a){return v>=mod-a.v?v-mod+a.v:v+a.v;}
modint operator-(modint a){return v>=a.v?v-a.v:v+mod-a.v;}
modint modnum(modint a){
return a-((__int128(a.v)*m1)>>80)*mod;
}
modint operator*(modint a){return modnum(v*a.v);}
modint operator+=(modint a){*this=*this+a;return *this;}
modint operator-=(modint a){*this=*this-a;return *this;}
modint operator*=(modint a){*this=*this*a;return *this;}
modint qpow(modint a,Int b){
modint r(1);
for(;b;b>>=1,a*=a)if(b&1)r*=a;
return r;
}
modint operator/(modint a){return qpow(a,mod-2)*v;}
modint operator/=(modint a){*this=*this/a;return *this;}
modint&operator++(){*this=*this+1;return *this;}
modint&operator--(){*this=*this-1;return *this;}
const modint operator++(int){modint r=*this;++*this;return r;}
const modint operator--(int){modint r=*this;--*this;return r;}
friend modint operator+(Int a,modint b){return b+a;}
friend modint operator-(Int a,modint b){return b-a;}
friend modint operator*(Int a,modint b){return b*a;}
friend modint operator/(Int a,modint b){return modint(a)/b;}
#ifdef cout
friend fastin&operator>>(fastin&in,modint&n){in>>n.v;return in;}
friend fastout&operator<<(fastout&out,modint n){out<<n.v;return out;}
#else
friend istream&operator>>(istream&in,modint&n){in>>n.v;return in;}
friend ostream&operator<<(ostream&out,modint n){out<<n.v;return out;}
#endif
};
typedef modint<long long,1000000007,1208925811152148> int7;
typedef modint<long long,998244353,1211051999424262> int9;
}
using namespace modint;
int n,m,p,a[N][N],ed[1<<15|1][N],b[1<<15|1],wh[1<<15|1],tem[1<<15|1];
int7 f[1<<15|1],g[1<<15|1],pw[N*N];
void solve(){
cin>>n>>m;
p=(1<<n)-1;
For(i,1,m){
int x,y;
cin>>x>>y;
++a[x][y];
};
For(i,1,p){
wh[i]=log2(i&-i);
For(j,1,n)if((i>>(j-1))&1){
For(k,1,n){
if((i>>(k-1))&1){
b[i]+=a[j][k];
}else{
ed[i][k]+=a[j][k];
}
};
};
};
pw[0]=1;
For(i,1,m)pw[i]=pw[i-1]*2;
g[0]=mod7-1;
For(i,1,p){
g[i]=pw[b[i]];
for(ll j=(i-1)&i;j;j=(j-1)&i){
tem[j]=0;
ll x=j;
while(x){
tem[j]+=ed[i^j][wh[x]+1];
x^=1<<wh[x];
}
}
for(ll j=(i-1)&i;j;j=(j-1)&i){
g[i]-=g[j]*pw[b[i^j]]*pw[tem[j]];
}
};
For(i,1,p){
for(ll j=(i-1)&i;j;j=(j-1)&i){
if((j>>wh[i])&1){
f[i]+=f[j]*g[i^j];
}
};
f[i]+=g[i];
}
cout<<f[p];
return;
}
int main(){
#ifndef zcz
czc;
#endif
int t=1;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 1ms
memory: 5944kb
input:
5 15 4 3 4 2 2 5 2 1 1 2 5 1 3 2 4 1 1 4 5 4 3 4 5 3 2 3 1 5 3 1
output:
9390
result:
ok single line: '9390'
Test #2:
score: 10
Accepted
time: 0ms
memory: 4036kb
input:
5 18 4 3 4 2 2 5 2 1 1 2 5 1 3 2 4 1 1 4 5 4 3 4 5 3 2 3 1 5 3 1 1 3 5 2 2 4
output:
100460
result:
ok single line: '100460'
Test #3:
score: 10
Accepted
time: 1ms
memory: 4012kb
input:
8 35 5 1 8 7 7 8 7 6 6 1 2 5 6 5 8 2 7 2 7 5 3 1 6 3 2 3 5 2 8 5 8 3 6 8 2 1 1 6 2 6 7 3 2 4 3 5 3 2 3 7 7 1 8 4 3 4 3 6 6 4 2 7 4 6 6 7 7 4 8 1
output:
299463717
result:
ok single line: '299463717'
Test #4:
score: 10
Accepted
time: 0ms
memory: 4092kb
input:
8 40 5 1 8 7 7 8 7 6 6 1 2 5 6 5 8 2 7 2 7 5 3 1 6 3 2 3 5 2 8 5 8 3 6 8 2 1 1 6 2 6 7 3 2 4 3 5 3 2 3 7 7 1 8 4 3 4 3 6 6 4 2 7 4 6 6 7 7 4 8 1 1 2 4 8 5 8 4 3 5 7
output:
21156439
result:
ok single line: '21156439'
Test #5:
score: 10
Accepted
time: 1ms
memory: 4024kb
input:
8 45 5 1 8 7 7 8 7 6 6 1 2 5 6 5 8 2 7 2 7 5 3 1 6 3 2 3 5 2 8 5 8 3 6 8 2 1 1 6 2 6 7 3 2 4 3 5 3 2 3 7 7 1 8 4 3 4 3 6 6 4 2 7 4 6 6 7 7 4 8 1 1 2 4 8 5 8 4 3 5 7 2 8 1 5 3 8 1 3 4 1
output:
426670664
result:
ok single line: '426670664'
Test #6:
score: 10
Accepted
time: 2ms
memory: 4132kb
input:
10 65 5 10 1 8 7 8 6 2 5 7 9 2 4 7 3 7 1 6 3 10 7 9 8 4 7 1 5 2 1 7 4 2 8 3 8 1 3 9 8 2 2 10 4 3 9 10 5 3 3 8 3 4 6 10 4 8 4 5 5 8 9 5 9 6 10 2 10 5 6 1 2 1 9 4 7 10 5 6 10 7 10 8 5 9 9 7 9 8 4 10 8 9 7 2 2 7 10 1 7 3 6 8 7 6 9 1 6 5 2 4 6 3 2 9 8 10 10 9 8 5 4 1 6 9 2 3 1 3 1 9
output:
931896041
result:
ok single line: '931896041'
Test #7:
score: 10
Accepted
time: 2ms
memory: 6116kb
input:
10 70 5 10 1 8 7 8 6 2 5 7 9 2 4 7 3 7 1 6 3 10 7 9 8 4 7 1 5 2 1 7 4 2 8 3 8 1 3 9 8 2 2 10 4 3 9 10 5 3 3 8 3 4 6 10 4 8 4 5 5 8 9 5 9 6 10 2 10 5 6 1 2 1 9 4 7 10 5 6 10 7 10 8 5 9 9 7 9 8 4 10 8 9 7 2 2 7 10 1 7 3 6 8 7 6 9 1 6 5 2 4 6 3 2 9 8 10 10 9 8 5 4 1 6 9 2 3 1 3 1 9 5 4 1 5 5 1 10 4 10 6
output:
303656759
result:
ok single line: '303656759'
Test #8:
score: 10
Accepted
time: 254ms
memory: 6472kb
input:
15 130 7 10 9 12 4 6 1 10 14 9 4 8 8 9 4 3 15 9 3 9 1 8 2 15 8 4 13 7 3 5 14 13 6 2 14 6 8 3 4 2 8 13 9 2 6 13 12 11 6 4 11 8 15 5 3 8 10 8 15 7 15 6 12 15 8 12 13 9 12 9 8 15 11 6 6 7 10 4 2 8 11 12 7 9 7 12 14 1 5 8 10 9 3 7 7 13 11 9 11 10 1 5 1 3 2 1 2 7 10 1 10 15 7 14 5 6 6 1 15 10 5 15 15 8 5...
output:
717458968
result:
ok single line: '717458968'
Test #9:
score: 10
Accepted
time: 254ms
memory: 6356kb
input:
15 140 7 10 9 12 4 6 1 10 14 9 4 8 8 9 4 3 15 9 3 9 1 8 2 15 8 4 13 7 3 5 14 13 6 2 14 6 8 3 4 2 8 13 9 2 6 13 12 11 6 4 11 8 15 5 3 8 10 8 15 7 15 6 12 15 8 12 13 9 12 9 8 15 11 6 6 7 10 4 2 8 11 12 7 9 7 12 14 1 5 8 10 9 3 7 7 13 11 9 11 10 1 5 1 3 2 1 2 7 10 1 10 15 7 14 5 6 6 1 15 10 5 15 15 8 5...
output:
459157220
result:
ok single line: '459157220'
Test #10:
score: 10
Accepted
time: 256ms
memory: 6476kb
input:
15 150 7 10 9 12 4 6 1 10 14 9 4 8 8 9 4 3 15 9 3 9 1 8 2 15 8 4 13 7 3 5 14 13 6 2 14 6 8 3 4 2 8 13 9 2 6 13 12 11 6 4 11 8 15 5 3 8 10 8 15 7 15 6 12 15 8 12 13 9 12 9 8 15 11 6 6 7 10 4 2 8 11 12 7 9 7 12 14 1 5 8 10 9 3 7 7 13 11 9 11 10 1 5 1 3 2 1 2 7 10 1 10 15 7 14 5 6 6 1 15 10 5 15 15 8 5...
output:
663282473
result:
ok single line: '663282473'