QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#808731#9735. Japanese BandszzuqyTL 2826ms605468kbC++204.8kb2024-12-11 00:47:052024-12-11 00:47:11

Judging History

你现在查看的是最新测评结果

  • [2025-01-18 23:34:05]
  • hack成功,自动添加数据
  • (/hack/1459)
  • [2024-12-11 00:47:11]
  • 评测
  • 测评结果:TL
  • 用时:2826ms
  • 内存:605468kb
  • [2024-12-11 00:47:05]
  • 提交

answer

 //#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<queue>
#include<deque>
#include<stack>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1100000000
#define inf 100000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x)
#define putl_(x) printf("%lld ",x)
#define get(x) x=read()
#define putl(x) printf("%lld\n",x)
#define rep(p,n,i) for(int i=p;i<=n;i+=1)
#define fep(n,p,i) for(int i=n;i>=p;--i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define pii pair<int,int>
#define mk make_pair
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define ui unsigned
#define sq sqrt
#define l(w) t[w].l
#define r(w) t[w].r
#define x(w) t[w].x
#define tag(w) t[w].tag
#define sum(w) t[w].sum
#define sc(A) scanf("%d",&A)
#define scl(A) scanf("%lld",&A)
#define scs(A) scanf("%s",A);
#define put(A) printf("%d\n",A)
#define min(x,y) (x>=y?y:x)
#define max(x,y) (x>=y?x:y)
#define sub(x,y) (x-y<0?x-y+mod:x-y)
#define uint unsigned int
#define mod 1000000007
#define zz p<<1
using namespace std;
const int MAXN=410;

int T,n1,n2,m,k,id;
int vis[MAXN];

int cnt,gd,ww,len,flag,res;


int w[1<<21],col[MAXN],sum[MAXN];
int lin[MAXN],ver[MAXN<<1],nex[MAXN<<1];
int q[MAXN][2],l;
int fac[MAXN],inv[MAXN],dfn[MAXN];
int f[MAXN],g[MAXN];
int ksm(int b,int p)
{
	int cnt=1;
	while(p)
	{
		if(p&1)cnt=(ll)cnt*b%mod;
		b=(ll)b*b%mod;p=p>>1;
	}
	return cnt;
}
void prepare()
{
	int ww=100;
	fac[0]=1;
	rep(1,ww,i)fac[i]=(ll)fac[i-1]*i%mod;
	inv[ww]=ksm(fac[ww],mod-2);
	fep(ww-1,0,i)inv[i]=(ll)inv[i+1]*(i+1)%mod;
}
int C(int a,int b)
{
	int cc=1;
	fep(a,a-b+1,i)cc=(ll)cc*i%mod;
	return (ll)cc*inv[b]%mod;
}
void add(int x,int y)
{
	ver[++len]=y;nex[len]=lin[x];lin[x]=len;
	ver[++len]=x;nex[len]=lin[y];lin[y]=len;
}
int now[1<<20];
int F[1<<20][21];
int Q[1<<20][41];
int S[1<<20][21];
int S1[1<<20][41];
int fa[1<<20][21];
int getfather(int v,int x)
{
	return x==fa[v][x]?x:fa[v][x]=getfather(v,fa[v][x]);
}
int getfather1(int v,int x)
{
	return x==Q[v][x]?x:Q[v][x]=getfather1(v,Q[v][x]);
}
void merge(int x,int y,int v)
{
	int xx=getfather(v,x);
	int yy=getfather(v,y);
	if(xx==yy)return;
	int s1=S[v][yy];
	int s2=S1[v][getfather1(v,y)];
	s1=s1-s2;
	if(s1<s2)swap(s1,s2);
	rep(0,m,j)
	{
		if(s1==s2)
		{
			g[j]=(ll)f[j+s1]*inv[2]%mod;
		}
		else
		{
			g[j]=f[j+s2];
			f[j+s1]=(f[j+s1]-g[j]+mod)%mod;
		}
	}
	rep(0,m,j)f[j]=g[j];
	S[v][xx]+=S[v][yy];
	fa[v][yy]=fa[v][xx];
}

void merge1(int v,int x,int y)
{
	int xx=getfather1(v,x);
	int yy=getfather1(v,y);
	if(xx==yy)return;
	Q[v][yy]=Q[v][xx];
	S1[v][xx]+=S1[v][yy];
}
void gx(int v,int x)
{
	int ww=0;
	Q[v][x]=x;Q[v][x+m]=x+m;
	S1[v][x]=1;
	fa[v][x]=x;
	S[v][x]=1;
	S1[v][x]=1;
	go(x)
	{
		if(Q[v][tn]==0)continue;
		int cc=getfather(v,tn);
		if(S[v][cc]==-1)
		{
			ww=1;break;
			continue;
		}
		merge(x,tn,v);
		merge1(v,x,tn+m);
		merge1(v,x+m,tn);
	}
	if(ww||getfather1(v,x)==getfather1(v,x+m))
	{
		S[v][x]=-1;now[v]=-2;return;
	}
	else
	{
		int s1=S[v][x];
		int s2=s1-S1[v][x];
		s1=s1-s2;
		rep(0,m,j)g[j]=f[j],f[j]=0;
		fep(m,0,j)
		{
			if(j>=s1)f[j]=(f[j]+g[j-s1])%mod;
			if(j>=s2)f[j]=(f[j]+g[j-s2])%mod;
		}
	}
}
int main()
{
	//freopen("1.in","r",stdin);
	sc(T);
	prepare();
	rep(1,T,TT)
	{
		sc(n1);sc(n2);sc(m);sc(k);
		rep(1,m,i)lin[i]=vis[i]=0;
		len=ww=gd=0;
		rep(1,k,i)
		{
			int x,y;
			sc(x);sc(y);
			if(x!=y)add(x,y);
			if(x==y&&vis[x]!=2)++gd,vis[x]=2;
			if(!vis[x])vis[x]=1;
			if(!vis[y])vis[y]=1;
		}
		rep(1,m,i)if(vis[i])++ww;
		cnt=ww-gd;res=m-ww;
		int cc=0;
		rep(1,m,i)if(vis[i]==1)++cc,w[1<<(cc-1)]=i;
	
		int maxx=1<<cnt;--maxx;
		int ans=0;
		
		rep(0,m,j)F[maxx][j]=0,fa[maxx][j]=0,S[maxx][j]=0,f[j]=0;
		rep(1,m*2,j)Q[maxx][j]=0,S1[maxx][j]=0;
		F[maxx][0]=1;
		now[maxx]=-1;
		f[0]=1;
		fep(maxx,0,i)
		{
			
			if(i!=maxx)
			{
				int ww=i^maxx;
				int x=ww&(-ww);
				int id=w[x];
				rep(0,m,j)S[i][j]=S[i^x][j],fa[i][j]=fa[i^x][j],f[j]=F[i^x][j];
				rep(1,m*2,j)Q[i][j]=Q[i^x][j],S1[i][j]=S1[i^x][j];
				now[i]=now[i^x];
				gx(i,id);
			}
			if(now[i]!=-2)
			{
				++now[i];
				int gg=now[i];
				int g1=gd+cnt-now[i];
				rep(0,m,k)
				{
					F[i][k]=f[k];
					if(!f[k])continue;
					ans=((ll)C(n1+res-1,g1+k+res-1)*C(n2+res-1,g1+gg-k+res-1)%mod*f[k]+ans)%mod;
				}
			}
			
		}
		put(ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 16172kb

input:

3
2 3 3 3
2 3
1 1
2 3
2 2 2 1
1 1
1 1 10 2
1 2
1 3

output:

6
4
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 29ms
memory: 85420kb

input:

500
481199252 336470888 8 58
4 7
7 6
4 7
2 6
2 6
2 7
8 3
8 7
8 1
2 6
2 6
1 2
1 5
3 1
6 4
2 4
4 7
2 6
2 3
7 1
4 4
5 1
2 7
6 7
8 1
8 7
5 6
4 2
4 2
8 5
5 4
6 8
5 6
3 8
1 7
1 6
7 1
5 6
6 3
1 1
2 7
3 3
1 5
5 5
8 7
3 4
6 3
8 8
7 4
1 6
2 1
8 7
4 5
2 7
3 5
2 6
4 5
4 3
2 6 2 2
2 1
1 1
500330171 987581927 10 ...

output:

724920553
11
966099120
846759476
528107862
1
245313614
144990327
1
269113412
946380890
1
0
996348464
376698469
453289929
53346774
238565800
260837053
956196844
0
487514263
842710229
8376584
16
300260118
933415828
808801372
1
612901047
137099259
14974173
0
531418108
1
522718622
264859767
1
1
59318545...

result:

ok 500 lines

Test #3:

score: 0
Accepted
time: 7ms
memory: 30844kb

input:

500
54748096 75475634 8 64
3 8
3 2
3 5
5 6
5 7
5 4
2 2
5 8
5 3
3 5
7 6
1 7
3 3
6 8
3 5
3 4
1 2
7 5
7 6
4 7
8 7
7 5
4 2
3 2
8 5
7 1
4 3
4 6
3 3
8 3
6 1
5 4
1 4
2 3
5 6
1 4
5 8
8 2
1 3
8 1
5 7
1 2
3 8
4 2
5 4
7 2
4 6
5 8
4 6
3 5
5 7
4 6
4 8
6 4
7 4
3 3
5 2
1 6
4 5
3 1
1 4
5 6
4 3
3 1
44007561 94403501...

output:

48662676
1
138912221
349671067
150052712
86775188
956490545
756234965
1
567881550
726030753
1
914856825
867349578
0
784807018
388018114
433007753
524010032
507842496
282218203
442034917
668340856
1
1
1
489645337
153477090
564466420
1673
0
390234222
604892803
264163973
601602052
135055881
27720
15744...

result:

ok 500 lines

Test #4:

score: 0
Accepted
time: 16ms
memory: 44960kb

input:

500
923264237 374288891 9 36
8 8
5 8
3 6
2 4
2 6
4 7
3 8
3 4
5 5
5 1
9 3
1 9
5 4
5 8
4 3
2 8
7 6
7 3
8 9
3 4
4 1
8 1
7 3
6 3
6 2
9 6
2 3
2 5
6 1
8 5
4 5
3 1
8 7
6 5
3 2
1 1
885955146 964950238 8 59
1 3
7 7
8 1
2 7
6 5
1 3
1 2
2 3
1 2
8 2
4 1
5 6
5 8
3 1
8 3
2 3
8 3
6 5
2 5
6 7
7 2
6 3
6 5
6 7
7 8
8 ...

output:

975815187
715739872
849684680
940532257
1
181582862
672614348
487379998
1
872849956
969457677
827780523
98088
1
496360790
568133531
231661973
1
981238143
13510
8
663802864
252
107191472
18522
415132978
697199493
116414735
1
10
912343690
81
583097677
223080594
33251656
117275734
1
419400938
630591794...

result:

ok 500 lines

Test #5:

score: 0
Accepted
time: 2826ms
memory: 605468kb

input:

500
1 9 7 21
4 3
4 5
4 3
4 5
4 5
4 7
4 7
4 2
4 3
4 6
4 1
4 7
4 5
4 1
4 2
4 2
4 2
4 1
4 2
4 6
4 6
192019400 315755530 10 56
8 10
9 7
9 6
8 4
3 4
1 6
8 7
9 10
8 7
5 7
2 4
5 7
1 6
9 7
2 4
1 4
2 7
5 7
5 7
2 10
3 7
8 4
8 4
3 4
5 7
9 6
2 10
3 4
8 10
9 4
5 10
2 4
8 7
5 4
5 7
9 4
8 6
1 7
5 4
8 10
3 4
9 7
8 ...

output:

84
668356110
663215632
0
0
578736401
597267922
0
33363799
1161
80106560
13486
379410136
346687579
215079152
954964869
0
749122504
842423167
0
739926379
822901144
642136628
770357778
886
370384128
817027991
684214806
463554366
759552089
16
384293072
744192004
475
443091214
298039661
815658191
7064088...

result:

ok 500 lines

Test #6:

score: -100
Time Limit Exceeded

input:

500
365329221 412106895 9 25
3 8
3 9
3 6
3 4
3 4
3 5
3 2
3 9
3 4
3 8
3 7
3 7
3 4
3 7
3 5
3 4
3 1
3 6
3 2
3 2
3 1
3 2
3 7
3 2
3 9
777109873 324284579 2 4
2 1
2 1
2 1
2 1
203265013 578140767 9 46
4 7
4 3
4 9
4 8
4 6
4 9
4 8
4 3
4 6
4 9
4 1
4 6
4 2
4 1
4 3
4 2
4 2
4 9
4 2
4 8
4 1
4 1
4 3
4 2
4 6
4 2
4 ...

output:

437314267
339909689
523663972
939772260
15
294996
873351127
420170527
361605716
10
6317
1015
698532307
716316221
827134829
526287544
433650509
256800385
596882660
574424501
589351733
505841163
517919676
378556809
150786280
1
4103867
986751324
345294966
926479261
557962762
987
133774068
568046845
778...

result: