Submission #1886947
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 200200;
VI A[MAX];
LL F[MAX];
LL bpow(LL a, LL b)
{
LL res = 1;
while(b)
{
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
b /= 2;
}
return res;
}
LL inv(LL a)
{
return bpow(a, MOD - 2);
}
int main()
{
//freopen("in.txt", "r", stdin);
//ios::sync_with_stdio(false); cin.tie(0);
F[0] = 1;
FOR (i, 1, MAX)
{
F[i] = (F[i-1] * i) % MOD;
}
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
FOR (i, 0, n)
{
int c, w;
scanf("%d%d", &c, &w);
A[c].PB(w);
}
FOR (i, 0, MAX)
{
sort(ALL(A[i]));
}
PII mn = MP(INF, INF);
PII mn2 = MP(INF, INF);
FOR (i, 0, MAX)
{
if (A[i].empty()) continue;
mn2 = min(mn2, MP(A[i][0], i));
if (mn2 < mn) swap(mn, mn2);
}
VI cnt;
int sum = 0;
FOR (i, 0, MAX)
{
if (A[i].empty()) continue;
int val = mn.first;
if (mn.second == i) val = mn2.first;
if (val + A[i][0] > y) continue;
int cur = 0;
FOR (j, 0, SZ(A[i]))
{
if (A[i][j] + val <= y || A[i][j] + A[i][0] <= x) cur++;
}
cnt.PB(cur);
sum += cur;
}
LL res = F[sum];
FOR (i, 0, SZ(cnt))
{
res = (res * inv(F[cnt[i]])) % MOD;
}
cout<<res<<endl;
}
Submission Info
Submission Time |
|
Task |
D - Colorful Balls |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
1739 Byte |
Status |
AC |
Exec Time |
83 ms |
Memory |
11520 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:59:29: 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:64:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &c, &w);
^
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 |
5 ms |
6528 KB |
00_example_02.txt |
AC |
5 ms |
6528 KB |
00_example_03.txt |
AC |
5 ms |
6528 KB |
01.txt |
AC |
5 ms |
6528 KB |
02.txt |
AC |
5 ms |
6528 KB |
03.txt |
AC |
7 ms |
6656 KB |
04.txt |
AC |
5 ms |
6528 KB |
05.txt |
AC |
6 ms |
6528 KB |
06.txt |
AC |
5 ms |
6528 KB |
07.txt |
AC |
35 ms |
7936 KB |
08.txt |
AC |
5 ms |
6528 KB |
09.txt |
AC |
17 ms |
6912 KB |
10.txt |
AC |
14 ms |
6912 KB |
11.txt |
AC |
5 ms |
6528 KB |
12.txt |
AC |
5 ms |
6528 KB |
13.txt |
AC |
7 ms |
6656 KB |
14.txt |
AC |
5 ms |
6528 KB |
15.txt |
AC |
20 ms |
7552 KB |
16.txt |
AC |
34 ms |
7808 KB |
17.txt |
AC |
9 ms |
6656 KB |
18.txt |
AC |
15 ms |
6912 KB |
19.txt |
AC |
27 ms |
7296 KB |
20.txt |
AC |
76 ms |
11132 KB |
21.txt |
AC |
75 ms |
11132 KB |
22.txt |
AC |
66 ms |
10752 KB |
23.txt |
AC |
80 ms |
11136 KB |
24.txt |
AC |
67 ms |
10752 KB |
25.txt |
AC |
73 ms |
11136 KB |
26.txt |
AC |
83 ms |
11132 KB |
27.txt |
AC |
62 ms |
10496 KB |
28.txt |
AC |
82 ms |
11136 KB |
29.txt |
AC |
80 ms |
11132 KB |
30.txt |
AC |
65 ms |
10624 KB |
31.txt |
AC |
81 ms |
11520 KB |
32.txt |
AC |
68 ms |
10752 KB |
33.txt |
AC |
82 ms |
11136 KB |
34.txt |
AC |
77 ms |
10364 KB |
35.txt |
AC |
47 ms |
7808 KB |
36.txt |
AC |
58 ms |
8192 KB |
37.txt |
AC |
48 ms |
7808 KB |
38.txt |
AC |
47 ms |
7680 KB |
39.txt |
AC |
49 ms |
7680 KB |
40.txt |
AC |
78 ms |
11004 KB |
41.txt |
AC |
73 ms |
11516 KB |
42.txt |
AC |
71 ms |
11520 KB |
43.txt |
AC |
62 ms |
11136 KB |
44.txt |
AC |
77 ms |
11516 KB |
45.txt |
AC |
63 ms |
11136 KB |
46.txt |
AC |
70 ms |
11520 KB |
47.txt |
AC |
50 ms |
7672 KB |
48.txt |
AC |
52 ms |
7672 KB |
49.txt |
AC |
53 ms |
7672 KB |
50.txt |
AC |
52 ms |
10488 KB |
51.txt |
AC |
47 ms |
9976 KB |
52.txt |
AC |
45 ms |
7416 KB |
53.txt |
AC |
46 ms |
7416 KB |
54.txt |
AC |
46 ms |
7416 KB |