Submission #1200023
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;
int N,X,Y;
pair<int,int> colorMin [200001];
vector<int> colors [200001];
ll fact [200001],rfact [200001];
const int INF = 2e9;
const ll MOD = 1e9 + 7;
ll mod_pow(ll x,ll y = MOD - 2)
{
ll res = 1;
while(y){
if(y & 1) (res *= x) %= MOD;
(x *= x) %= MOD;
y >>= 1;
}
return res;
}
int main()
{
scanf("%d%d%d",&N,&X,&Y);
vector<int> C(N),W(N);
fill(colorMin + 1,colorMin + N + 1,make_pair(INF,INF));
FOR(i,0,N){
scanf("%d%d",&C [i],&W [i]);
colors [C [i]].push_back(W [i]);
chmin(colorMin [C [i]],make_pair(W [i],C [i]));
}
FOR(i,1,N + 1){
sort(ALL(colors [i]));
}
sort(colorMin + 1,colorMin + N + 1);
int allMin = colorMin [1].first;
int r = lower_bound(colorMin + 1,colorMin + N + 1,make_pair(Y - allMin + 1,0)) - colorMin;
chmax(r,2);
map<int,int> mp;
for(int i = 1;i < r;i++){
int idx = colorMin [i].second;
int res = upper_bound(ALL(colors [idx]),X - colorMin [i].first) - colors [idx].begin();
chmax(res,(int) (upper_bound(ALL(colors [idx]),Y - allMin) - colors [idx].begin()));
chmax(res,1);
mp [idx] += res;
}
fact [0] = rfact [0] = 1;
for(int i = 1;i <= 200000;i++){
fact [i] = fact [i - 1] * i % MOD;
rfact [i] = mod_pow(fact [i]);
}
ll ans = 1,sum = 0;
for(const auto& it : mp){
(ans *= rfact [it.second]) %= MOD;
sum += it.second;
}
(ans *= fact [sum]) %= MOD;
printf("%lld\n",ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Colorful Balls |
User |
gigime |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1783 Byte |
Status |
WA |
Exec Time |
172 ms |
Memory |
21248 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:30:26: 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:34: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]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 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 |
34 ms |
8448 KB |
00_example_02.txt |
AC |
34 ms |
8448 KB |
00_example_03.txt |
AC |
34 ms |
8448 KB |
01.txt |
AC |
34 ms |
8448 KB |
02.txt |
AC |
34 ms |
8448 KB |
03.txt |
AC |
37 ms |
8704 KB |
04.txt |
AC |
34 ms |
8448 KB |
05.txt |
AC |
35 ms |
8576 KB |
06.txt |
AC |
34 ms |
8448 KB |
07.txt |
AC |
73 ms |
12160 KB |
08.txt |
AC |
34 ms |
8448 KB |
09.txt |
AC |
48 ms |
9344 KB |
10.txt |
AC |
45 ms |
9216 KB |
11.txt |
AC |
34 ms |
8448 KB |
12.txt |
AC |
34 ms |
8448 KB |
13.txt |
AC |
37 ms |
8832 KB |
14.txt |
AC |
34 ms |
8448 KB |
15.txt |
AC |
54 ms |
10752 KB |
16.txt |
AC |
70 ms |
11776 KB |
17.txt |
AC |
39 ms |
8832 KB |
18.txt |
AC |
46 ms |
9216 KB |
19.txt |
AC |
60 ms |
10368 KB |
20.txt |
AC |
143 ms |
18432 KB |
21.txt |
AC |
134 ms |
18560 KB |
22.txt |
AC |
117 ms |
16384 KB |
23.txt |
AC |
158 ms |
20352 KB |
24.txt |
AC |
115 ms |
16512 KB |
25.txt |
AC |
132 ms |
18176 KB |
26.txt |
AC |
172 ms |
20608 KB |
27.txt |
AC |
111 ms |
15104 KB |
28.txt |
AC |
160 ms |
20608 KB |
29.txt |
AC |
146 ms |
19584 KB |
30.txt |
AC |
115 ms |
15744 KB |
31.txt |
AC |
163 ms |
20608 KB |
32.txt |
AC |
124 ms |
16640 KB |
33.txt |
AC |
161 ms |
20480 KB |
34.txt |
AC |
147 ms |
19200 KB |
35.txt |
WA |
83 ms |
12416 KB |
36.txt |
AC |
97 ms |
13312 KB |
37.txt |
WA |
83 ms |
12544 KB |
38.txt |
WA |
83 ms |
12416 KB |
39.txt |
AC |
86 ms |
12416 KB |
40.txt |
AC |
149 ms |
20864 KB |
41.txt |
AC |
131 ms |
19072 KB |
42.txt |
AC |
135 ms |
19072 KB |
43.txt |
AC |
119 ms |
16768 KB |
44.txt |
AC |
156 ms |
21248 KB |
45.txt |
AC |
115 ms |
16896 KB |
46.txt |
AC |
130 ms |
18816 KB |
47.txt |
AC |
86 ms |
12148 KB |
48.txt |
AC |
87 ms |
12148 KB |
49.txt |
AC |
87 ms |
12148 KB |
50.txt |
AC |
98 ms |
16632 KB |
51.txt |
AC |
88 ms |
14712 KB |
52.txt |
AC |
82 ms |
12152 KB |
53.txt |
AC |
81 ms |
12152 KB |
54.txt |
AC |
82 ms |
12152 KB |