Submission #1196410
Source Code Expand
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)
#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second
#define INF 1000000005
#define mod 1000000007
using namespace std;
int n, x, y, gmc = INF, smc = INF, gg = -1, sg = -1;
vector<int> v[200005];
int ans = 1;
int fact[200005], inv[200005];
int po(int a, int b){
int c = 1, d = a;
while(b){
if(b & 1) c = 1LL * c * d % mod;
d = 1LL * d * d % mod;
b >>= 1;
}
return c;
}
vector<int> u;
int main(){
fact[0] = inv[0] = 1;
FI(i, 1, 200000){
fact[i] = 1LL * fact[i - 1] * i % mod;
inv[i] = po(fact[i], mod - 2);
}
scanf("%d %d %d", &n, &x, &y);
FI(i, 1, n){
int a, b;
scanf("%d %d", &a, &b);
v[a].push_back(b);
}
FI(i, 1, n) sort(v[i].begin(), v[i].end());
FI(i, 1, n){
int sz = v[i].size();
if(sz){
if(v[i][0] < gmc){
smc = gmc, sg = gg;
gmc = v[i][0], gg = i;
}
else if(v[i][0] < smc){
smc = v[i][0], sg = i;
}
}
}
FI(i, 1, n){
int sz = v[i].size();
if(sz){
if(i == gg && v[i][0] + smc > y) continue;
if(i != gg && v[i][0] + gmc > y) continue;
//this color mobile
int c = 1;
FI(j, 1, sz - 1){
if(v[i][j] + v[i][0] <= x) c++;
else if(i == gg && v[i][j] + smc <= y) c++;
else if(i != gg && v[i][j] + gmc <= y) c++;
else break;
}
u.push_back(c);
}
}
int summ = 0, sz = u.size();
FI(i, 0, sz - 1) summ += u[i];
ans = fact[summ];
FI(i, 0, sz - 1) ans = 1LL * ans * inv[u[i]] % mod;
printf("%d\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Colorful Balls |
User |
alex20030190 |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
1778 Byte |
Status |
AC |
Exec Time |
98 ms |
Memory |
11520 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:46:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &n, &x, &y);
^
./Main.cpp:49:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1000 / 1000 |
Status |
|
|
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 |
35 ms |
6528 KB |
00_example_02.txt |
AC |
35 ms |
6528 KB |
00_example_03.txt |
AC |
35 ms |
6528 KB |
01.txt |
AC |
35 ms |
6528 KB |
02.txt |
AC |
35 ms |
6528 KB |
03.txt |
AC |
37 ms |
6784 KB |
04.txt |
AC |
35 ms |
6528 KB |
05.txt |
AC |
35 ms |
6528 KB |
06.txt |
AC |
35 ms |
6528 KB |
07.txt |
AC |
60 ms |
7936 KB |
08.txt |
AC |
35 ms |
6528 KB |
09.txt |
AC |
47 ms |
6912 KB |
10.txt |
AC |
43 ms |
6912 KB |
11.txt |
AC |
35 ms |
6528 KB |
12.txt |
AC |
35 ms |
6528 KB |
13.txt |
AC |
37 ms |
6656 KB |
14.txt |
AC |
35 ms |
6528 KB |
15.txt |
AC |
47 ms |
7552 KB |
16.txt |
AC |
61 ms |
7808 KB |
17.txt |
AC |
39 ms |
6656 KB |
18.txt |
AC |
44 ms |
6912 KB |
19.txt |
AC |
56 ms |
7296 KB |
20.txt |
AC |
94 ms |
11132 KB |
21.txt |
AC |
96 ms |
11132 KB |
22.txt |
AC |
95 ms |
10624 KB |
23.txt |
AC |
93 ms |
11136 KB |
24.txt |
AC |
92 ms |
10752 KB |
25.txt |
AC |
98 ms |
11136 KB |
26.txt |
AC |
95 ms |
11132 KB |
27.txt |
AC |
95 ms |
10496 KB |
28.txt |
AC |
95 ms |
11136 KB |
29.txt |
AC |
97 ms |
11132 KB |
30.txt |
AC |
93 ms |
10624 KB |
31.txt |
AC |
95 ms |
11136 KB |
32.txt |
AC |
93 ms |
10752 KB |
33.txt |
AC |
95 ms |
11136 KB |
34.txt |
AC |
94 ms |
10364 KB |
35.txt |
AC |
79 ms |
7680 KB |
36.txt |
AC |
86 ms |
8192 KB |
37.txt |
AC |
78 ms |
7808 KB |
38.txt |
AC |
78 ms |
7680 KB |
39.txt |
AC |
80 ms |
7680 KB |
40.txt |
AC |
94 ms |
11004 KB |
41.txt |
AC |
91 ms |
11516 KB |
42.txt |
AC |
91 ms |
11520 KB |
43.txt |
AC |
90 ms |
11136 KB |
44.txt |
AC |
92 ms |
11516 KB |
45.txt |
AC |
88 ms |
11136 KB |
46.txt |
AC |
89 ms |
11520 KB |
47.txt |
AC |
81 ms |
7672 KB |
48.txt |
AC |
82 ms |
7672 KB |
49.txt |
AC |
82 ms |
7672 KB |
50.txt |
AC |
77 ms |
10488 KB |
51.txt |
AC |
78 ms |
9976 KB |
52.txt |
AC |
76 ms |
7416 KB |
53.txt |
AC |
76 ms |
7416 KB |
54.txt |
AC |
76 ms |
7416 KB |