Submission #2367701


Source Code Expand

#include<cstdio>
#define ll long long
const int N=2e5+5,mo=1e9+7;
int n,nx,ny,mx1,mx2,a[N],b[N],mx[N],inv[N],i;
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int Min(int x,int y){return b[x]<b[y]?x:y;}
int et,he[N];
struct edge{int l,to;}e[4*N];
void line(int x,int y){
	e[++et].l=he[x];he[x]=et;e[et].to=y;
	e[++et].l=he[y];he[y]=et;e[et].to=x;
}
int cnt,qn,q[N],g[N],ans;
void dfs(int x){
	cnt++;ans=(ll)ans*cnt%mo;
	if (!(g[a[x]]++)) q[++qn]=a[x];
	a[x]=0;
	for (int i=he[x];i;i=e[i].l)
		if (a[e[i].to]) dfs(e[i].to);
}
int main(){
	n=read();nx=read();ny=read();b[0]=1e9+1;
	for (i=1;i<=n;i++){
		a[i]=read();b[i]=read();
		mx[a[i]]=Min(mx[a[i]],i);
	}
	for (i=1;i<=n;i++)
		if (b[mx[i]]<b[mx1]) mx2=mx1,mx1=mx[i];
		else if (b[mx[i]]<b[mx2]) mx2=mx[i];
	for (i=1;i<=n;i++){
		if (i!=mx[i]&&b[i]+b[mx[a[i]]]<=nx) line(i,mx[a[i]]);
		if (a[i]==a[mx1]){
			if (b[i]+b[mx2]<=ny) line(i,mx2);
		}
		else if (b[i]+b[mx1]<=ny) line(i,mx1);
	}
	for (inv[1]=1,i=2;i<=n;i++)
		inv[i]=(ll)inv[mo%i]*(mo-mo/i)%mo;
	for (i=2;i<=n;i++) inv[i]=(ll)inv[i]*inv[i-1]%mo;
	for (ans=1,i=1;i<=n;i++) if (a[i]){
		qn=0;cnt=0;dfs(i);
		for (i=1;i<=qn;i++)
			ans=(ll)ans*inv[g[q[i]]]%mo,g[q[i]]=0;
	}
	printf("%d",ans);
}

Submission Info

Submission Time
Task D - Colorful Balls
User zhanglexing
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1338 Byte
Status TLE
Exec Time 2107 ms
Memory 11520 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 3
AC × 19
TLE × 38
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 4224 KB
00_example_02.txt AC 1 ms 2176 KB
00_example_03.txt AC 1 ms 4224 KB
01.txt AC 1 ms 4224 KB
02.txt AC 1 ms 4224 KB
03.txt AC 8 ms 4480 KB
04.txt AC 1 ms 4224 KB
05.txt AC 5 ms 4352 KB
06.txt AC 2 ms 4224 KB
07.txt TLE 2103 ms 7680 KB
08.txt AC 2 ms 4352 KB
09.txt AC 194 ms 7168 KB
10.txt AC 114 ms 7040 KB
11.txt AC 1 ms 4224 KB
12.txt AC 1 ms 4224 KB
13.txt AC 9 ms 4480 KB
14.txt AC 1 ms 4224 KB
15.txt AC 130 ms 7296 KB
16.txt TLE 2103 ms 7680 KB
17.txt AC 30 ms 4736 KB
18.txt AC 646 ms 7040 KB
19.txt TLE 2103 ms 7424 KB
20.txt TLE 2103 ms 11392 KB
21.txt TLE 2103 ms 9344 KB
22.txt TLE 2103 ms 9088 KB
23.txt TLE 2103 ms 11520 KB
24.txt TLE 2103 ms 9216 KB
25.txt TLE 2103 ms 11392 KB
26.txt TLE 2103 ms 11520 KB
27.txt TLE 2103 ms 11136 KB
28.txt TLE 2103 ms 11520 KB
29.txt TLE 2107 ms 11520 KB
30.txt TLE 2103 ms 7040 KB
31.txt TLE 2103 ms 11520 KB
32.txt TLE 2103 ms 9216 KB
33.txt TLE 2103 ms 11520 KB
34.txt TLE 2103 ms 11520 KB
35.txt TLE 2103 ms 10624 KB
36.txt TLE 2103 ms 11136 KB
37.txt TLE 2103 ms 10880 KB
38.txt TLE 2103 ms 10496 KB
39.txt TLE 2103 ms 11136 KB
40.txt TLE 2103 ms 11520 KB
41.txt TLE 2103 ms 11392 KB
42.txt TLE 2103 ms 9344 KB
43.txt TLE 2103 ms 9088 KB
44.txt TLE 2103 ms 11520 KB
45.txt TLE 2103 ms 9216 KB
46.txt TLE 2103 ms 11392 KB
47.txt TLE 2103 ms 8320 KB
48.txt TLE 2103 ms 8320 KB
49.txt TLE 2103 ms 8320 KB
50.txt TLE 2103 ms 8832 KB
51.txt TLE 2103 ms 8320 KB
52.txt TLE 2103 ms 10368 KB
53.txt TLE 2103 ms 10368 KB
54.txt TLE 2103 ms 10368 KB