QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#809601#9735. Japanese BandszzuqyTL 2623ms433804kbC++204.4kb2024-12-11 16:15:072024-12-11 16:15:14

Judging History

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

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

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;
}
set<int> s[22];
int now[1<<20];
int F[1<<20][21];
int Q[1<<20][41];
int S1[1<<20][41];
int getfather1(int v,int x)
{
	return x==Q[v][x]?x:Q[v][x]=getfather1(v,Q[v][x]);
}
void merge1(int v,int x,int y)
{
	int xx=getfather1(v,x);
	int yy=getfather1(v,y);
	if(xx==yy)return;
	if(yy<=m)
	{
		int s1=S1[v][yy];
		int s2=S1[v][yy+m];
		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];
	}
	Q[v][yy]=Q[v][xx];
	S1[v][xx]+=S1[v][yy];
}
void gx(int v,int x)
{
	Q[v][x]=x;Q[v][x+m]=x+m;
	S1[v][x]=1;
	go(x)
	{
		if(Q[v][tn]==0)continue;
		merge1(v,x,tn+m);
		merge1(v,x+m,tn);
	}
	if(getfather1(v,x)==getfather1(v,x+m))
	{
		now[v]=-2;return;
	}
	else
	{
		int s1=S1[v][x];
		int s2=S1[v][x+m];
		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,s[i].clear();
		len=ww=gd=0;
		rep(1,k,i)
		{
			int x,y;
			sc(x);sc(y);
			s[x].insert(y);
			s[y].insert(x);
			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;
			for(auto x:s[i])
			{
				if(x==i)continue;
				if(vis[x]!=1)continue;
				add(i,x);
			}
		}
		int maxx=1<<cnt;--maxx;
		int ans=0;
		
		rep(0,m,j)F[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)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];
				if(now[i]!=-2)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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11964kb

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: 18ms
memory: 69840kb

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: 11ms
memory: 18152kb

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: 13ms
memory: 24052kb

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: 2412ms
memory: 433144kb

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: 0
Accepted
time: 2623ms
memory: 433804kb

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:

ok 500 lines

Test #7:

score: 0
Accepted
time: 1264ms
memory: 433668kb

input:

500
643910770 5887448 4 3
2 3
4 3
2 3
483024012 714786389 2 1
2 1
735205996 288464482 7 46
4 2
3 7
5 7
4 2
3 1
5 2
4 2
5 2
3 6
3 6
3 2
3 2
3 2
5 7
5 7
4 7
5 2
5 1
4 6
4 1
5 7
5 6
3 2
4 2
3 1
5 7
3 2
4 7
4 2
3 7
3 2
5 7
4 1
3 1
3 1
5 2
5 2
5 6
4 1
4 1
4 2
4 7
4 2
5 1
3 2
4 7
143954125 56574503 3 2
1 ...

output:

772480244
118770152
108641022
615067819
872673860
900276958
951405638
705098808
308078046
912436115
266068466
270465299
858128867
591071828
345756242
253238303
226837537
15366
16188333
896137863
637986485
386483060
601850323
980044594
35
951860846
97816824
379760475
813023811
973778941
948954783
749...

result:

ok 500 lines

Test #8:

score: 0
Accepted
time: 2306ms
memory: 432376kb

input:

500
72235422 449924898 2 4
2 1
2 1
2 1
2 1
826908873 897131377 8 44
7 6
7 5
4 2
7 1
7 2
4 5
7 6
4 2
4 8
7 2
4 3
4 3
4 1
4 5
7 1
7 1
4 3
4 2
7 1
4 3
4 2
4 8
7 8
4 8
7 8
7 1
7 5
7 2
4 2
7 2
4 5
7 6
4 5
7 6
7 8
4 3
7 3
7 3
4 2
4 6
4 8
4 1
4 3
4 5
398346835 179283845 3 4
2 1
2 1
2 1
3 1
146844881 503366...

output:

169993670
63971922
447978336
415747130
17523830
520716693
376879328
858277870
165
142685959
3399
88
339812162
591663632
856960754
861425853
527624471
210
960737551
318751600
197044810
0
0
578594559
980927816
1765
215406311
230128376
3178
155563197
347921715
794781090
928438409
129
890907226
21574705...

result:

ok 500 lines

Test #9:

score: -100
Time Limit Exceeded

input:

500
940751563 43705451 3 2
2 1
1 3
4 2 2 1
2 1
756411639 690869710 9 8
3 5
3 6
3 4
5 1
1 7
2 8
3 8
7 9
892465776 834697020 7 6
6 2
4 7
2 3
1 4
5 7
4 3
3649468 246352594 5 4
5 1
5 2
3 2
2 4
927157783 349300522 2 1
2 1
283790347 262369656 8 7
8 6
2 1
7 4
4 3
4 5
2 4
2 6
290590966 415217454 6 5
6 3
4 3...

output:

366369420
13
764641683
869116386
335233317
587724158
945604675
811601159
131513017
113193821
577434289
177358129
220715079
411623223
706865979
34307455
0
1500
273659818
320221078
332322756
811169602
833121521
0
197721600
910924732
638897790
9520
784101624
445798182
313260639
877480788
935885491
9882...

result: