Submission #2381760
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i,n) rep2(i,0,n) #define rep2(i,m,n) for(int i=m;i<(n);i++) #define ALL(c) (c).begin(),(c).end() const ll MOD = 1000000007; const int MN = 200010; ll mod_pow(ll x, ll k) { ll res = 1; for (; k; k /= 2, x = x * x % MOD) { if (k & 1) { res = res * x % MOD; } } return res; } int N, X, Y; vi vec[MN]; ll fac[MN], ifac[MN]; ll comb(int n, int k) { if (k < 0 || k > n) return 1; return fac[n] * ifac[k] % MOD * ifac[n-k] % MOD; } int main() { fac[0] = ifac[0] = 1; for (int i = 1; i < MN; ++i) { fac[i] = fac[i-1] * i % MOD; ifac[i] = ifac[i-1] * mod_pow(i, MOD - 2) % MOD; } cin >> N >> X >> Y; rep(i, N) { int c, w; cin >> c >> w; --c; vec[c].pb(w); } rep(i, N) sort(ALL(vec[i])); vector<pii> mns; rep(i, N) if (vec[i].size()) { mns.eb(vec[i][0], i); int p = 1; while (p < vec[i].size() && vec[i][p] + vec[i][0] <= X) { vec[i][p] = vec[i][0]; ++p; } } sort(ALL(mns)); if (mns.size() == 1) { puts("1"); return 0; } vi nums; for (int i = 1; i < mns.size(); ++i) { int id = mns[i].se; if (mns[i].fi + mns[0].fi <= Y) { int p = upper_bound(ALL(vec[id]), Y - mns[0].fi) - vec[id].begin(); nums.pb(p); } } int id = mns[0].se; if (mns[0].fi + mns[1].fi <= Y) { int p = upper_bound(ALL(vec[id]), Y - mns[1].fi) - vec[id].begin(); nums.pb(p); } int sum = 0; for (int x:nums) { sum += x; } ll t = fac[sum]; for (int x:nums) { t = t * ifac[x] % MOD; } cout << t << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | satashun |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 1810 Byte |
Status | AC |
Exec Time | 201 ms |
Memory | 14584 KB |
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 | 34 ms | 8064 KB |
00_example_02.txt | AC | 34 ms | 8064 KB |
00_example_03.txt | AC | 34 ms | 8064 KB |
01.txt | AC | 34 ms | 8064 KB |
02.txt | AC | 34 ms | 8064 KB |
03.txt | AC | 40 ms | 8192 KB |
04.txt | AC | 34 ms | 8064 KB |
05.txt | AC | 36 ms | 8192 KB |
06.txt | AC | 35 ms | 8064 KB |
07.txt | AC | 101 ms | 9852 KB |
08.txt | AC | 35 ms | 8064 KB |
09.txt | AC | 67 ms | 8448 KB |
10.txt | AC | 56 ms | 8448 KB |
11.txt | AC | 34 ms | 8064 KB |
12.txt | AC | 34 ms | 8064 KB |
13.txt | AC | 40 ms | 8320 KB |
14.txt | AC | 34 ms | 8064 KB |
15.txt | AC | 64 ms | 9344 KB |
16.txt | AC | 102 ms | 9852 KB |
17.txt | AC | 44 ms | 8320 KB |
18.txt | AC | 61 ms | 8448 KB |
19.txt | AC | 90 ms | 8832 KB |
20.txt | AC | 186 ms | 13812 KB |
21.txt | AC | 185 ms | 13812 KB |
22.txt | AC | 184 ms | 13300 KB |
23.txt | AC | 186 ms | 13944 KB |
24.txt | AC | 184 ms | 13300 KB |
25.txt | AC | 185 ms | 13816 KB |
26.txt | AC | 196 ms | 13940 KB |
27.txt | AC | 188 ms | 13180 KB |
28.txt | AC | 201 ms | 13944 KB |
29.txt | AC | 191 ms | 13940 KB |
30.txt | AC | 188 ms | 13180 KB |
31.txt | AC | 192 ms | 13944 KB |
32.txt | AC | 191 ms | 13304 KB |
33.txt | AC | 199 ms | 13944 KB |
34.txt | AC | 190 ms | 13044 KB |
35.txt | AC | 169 ms | 9344 KB |
36.txt | AC | 175 ms | 9856 KB |
37.txt | AC | 170 ms | 9472 KB |
38.txt | AC | 169 ms | 9216 KB |
39.txt | AC | 173 ms | 9344 KB |
40.txt | AC | 193 ms | 13940 KB |
41.txt | AC | 185 ms | 14580 KB |
42.txt | AC | 182 ms | 14584 KB |
43.txt | AC | 188 ms | 14580 KB |
44.txt | AC | 188 ms | 14580 KB |
45.txt | AC | 190 ms | 14580 KB |
46.txt | AC | 190 ms | 14584 KB |
47.txt | AC | 158 ms | 9208 KB |
48.txt | AC | 165 ms | 9208 KB |
49.txt | AC | 164 ms | 9208 KB |
50.txt | AC | 156 ms | 12792 KB |
51.txt | AC | 165 ms | 12792 KB |
52.txt | AC | 143 ms | 9080 KB |
53.txt | AC | 143 ms | 9080 KB |
54.txt | AC | 145 ms | 9080 KB |