Submission #6773341


Source Code Expand

Copy
#include <cstdio>
#include <iostream>
#include <cstring>
#define MN 201000
#define mod 1000000007

int Min[MN]; 
int cnt[MN];
int id1 = -1, id2 = -1; 
int c[MN], w[MN];
int fac[MN], inv[MN];

int C(int a, int b) {return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;}

int main()
{
	memset(Min, 0x3f, sizeof(Min));
	int n, x, y; scanf("%d%d%d", &n, &x, &y);
	
	fac[0] = inv[0] = inv[1] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	for(int i = 2; i <= n; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 1; i <= n; i++) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
	 
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d", &c[i], &w[i]);
		Min[c[i]] = std::min(Min[c[i]], w[i]);
	}
	
	for(int i = 1; i <= n; i++)
	{
		if(id1 == -1) id1 = i;
		else if(Min[i] <= Min[id1]) {id2 = id1; id1 = i;}
		else if(id2 == -1 || Min[i] <= Min[id2]) id2 = i;
	}
	
	for(int i = 1; i <= n; i++)
	{
		if(w[i] + Min[c[i]] <= x || (id1 == c[i] ? w[i] + Min[id2] : w[i] + Min[id1]) <= y)
			cnt[c[i]]++;
	}
	
	int tot = 0, ans = 1;
	for(int i = 1; i <= n; i++) if(Min[i] + Min[id1] <= y) tot += cnt[i];
	for(int i = 1; i <= n; i++) if(Min[i] + Min[id1] <= y) ans = 1ll * ans * C(tot, cnt[i]) % mod, tot -= cnt[i];
	printf("%d\n", ans);
}

Submission Info

Submission Time
Task D - Colorful Balls
User luhong
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1303 Byte
Status
Exec Time 48 ms
Memory 4992 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:18:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n, x, y; scanf("%d%d%d", &n, &x, &y);
                                          ^
./Main.cpp:27:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &c[i], &w[i]);
                              ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 1000 / 1000 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 2 ms 2944 KB
00_example_02.txt 2 ms 2944 KB
00_example_03.txt 2 ms 2944 KB
01.txt 2 ms 2944 KB
02.txt 2 ms 2944 KB
03.txt 3 ms 3072 KB
04.txt 2 ms 2944 KB
05.txt 2 ms 2944 KB
06.txt 2 ms 2944 KB
07.txt 22 ms 4096 KB
08.txt 2 ms 2944 KB
09.txt 13 ms 3584 KB
10.txt 9 ms 3328 KB
11.txt 2 ms 2944 KB
12.txt 2 ms 2944 KB
13.txt 3 ms 3072 KB
14.txt 2 ms 2944 KB
15.txt 10 ms 3456 KB
16.txt 22 ms 4096 KB
17.txt 5 ms 3072 KB
18.txt 10 ms 3456 KB
19.txt 20 ms 3968 KB
20.txt 46 ms 4992 KB
21.txt 46 ms 4992 KB
22.txt 45 ms 4992 KB
23.txt 46 ms 4992 KB
24.txt 45 ms 4992 KB
25.txt 45 ms 4992 KB
26.txt 47 ms 4992 KB
27.txt 45 ms 4992 KB
28.txt 47 ms 4992 KB
29.txt 47 ms 4992 KB
30.txt 46 ms 4992 KB
31.txt 48 ms 4992 KB
32.txt 46 ms 4992 KB
33.txt 48 ms 4992 KB
34.txt 45 ms 4992 KB
35.txt 44 ms 4992 KB
36.txt 46 ms 4992 KB
37.txt 45 ms 4992 KB
38.txt 44 ms 4992 KB
39.txt 46 ms 4992 KB
40.txt 44 ms 4992 KB
41.txt 44 ms 4992 KB
42.txt 44 ms 4992 KB
43.txt 44 ms 4992 KB
44.txt 44 ms 4992 KB
45.txt 44 ms 4992 KB
46.txt 44 ms 4992 KB
47.txt 41 ms 4992 KB
48.txt 42 ms 4992 KB
49.txt 42 ms 4992 KB
50.txt 41 ms 4992 KB
51.txt 40 ms 4992 KB
52.txt 38 ms 4992 KB
53.txt 38 ms 4992 KB
54.txt 37 ms 4992 KB