Submission #3245152
Source Code Expand
#include <algorithm> #include <cassert> #include <cstring> #include <iostream> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define TRACE(x) cout << #x << " = " << x << endl #define _ << " _ " << typedef long long llint; const int inf = 1e9; const int mod = 1e9 + 7; inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } inline int sub(int a, int b) { return a >= b ? a - b : a - b + mod; } inline int mul(int a, int b) { return llint(a) * b % mod; } int powmod(int a, int b) { if (b == 0) return 1; if (b % 2) return mul(a, powmod(a, b - 1)); return powmod(mul(a, a), b / 2); } int main(void) { ios_base::sync_with_stdio(false); int N, X, Y; cin >> N >> X >> Y; vector<int> fact(N + 1); fact[0] = 1; for (int i = 1; i <= N; ++i) { fact[i] = mul(fact[i - 1], i); } vector<vector<int>> W(N); REP(i, N) { int c, w; cin >> c >> w; W[c - 1].push_back(w); } int minW1 = inf; int minW2 = inf; for (auto& w : W) { if (w.size() > 0) { sort(w.begin(), w.end()); if (w[0] <= minW1) minW2 = minW1, minW1 = w[0]; else if (w[0] <= minW2) minW2 = w[0]; } } vector<pair<int, int>> a; for (auto& w : W) { if (w.size() > 0) { int L = X - w[0]; if (w[0] == minW1) { L = max(L, Y - minW2); } else { L = max(L, Y - minW1); } while (w.size() > 0 && w.back() > L) w.pop_back(); if (w.size() > 0) a.push_back({w[0], w.size()}); } } if (a.size() == 0) { cout << "1\n"; return 0; } sort(a.begin(), a.end()); int r = 1; while (r < (int)a.size() && a[r].first + a[0].first <= Y) r++; int s = 0, denom = 1; REP(i, r) { s += a[i].second; denom = mul(denom, fact[a[i].second]); } int ret = mul(fact[s], powmod(denom, mod - 2)); cout << ret << "\n"; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | ikatanic |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 2041 Byte |
Status | AC |
Exec Time | 75 ms |
Memory | 11256 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 | 1 ms | 256 KB |
00_example_02.txt | AC | 1 ms | 256 KB |
00_example_03.txt | AC | 1 ms | 256 KB |
01.txt | AC | 1 ms | 256 KB |
02.txt | AC | 1 ms | 256 KB |
03.txt | AC | 3 ms | 640 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 2 ms | 384 KB |
06.txt | AC | 1 ms | 256 KB |
07.txt | AC | 30 ms | 4480 KB |
08.txt | AC | 1 ms | 256 KB |
09.txt | AC | 15 ms | 2304 KB |
10.txt | AC | 10 ms | 1664 KB |
11.txt | AC | 1 ms | 256 KB |
12.txt | AC | 1 ms | 256 KB |
13.txt | AC | 4 ms | 768 KB |
14.txt | AC | 1 ms | 256 KB |
15.txt | AC | 15 ms | 2560 KB |
16.txt | AC | 30 ms | 4608 KB |
17.txt | AC | 5 ms | 896 KB |
18.txt | AC | 12 ms | 1920 KB |
19.txt | AC | 24 ms | 3584 KB |
20.txt | AC | 71 ms | 10872 KB |
21.txt | AC | 69 ms | 10872 KB |
22.txt | AC | 68 ms | 10872 KB |
23.txt | AC | 74 ms | 10872 KB |
24.txt | AC | 63 ms | 10112 KB |
25.txt | AC | 70 ms | 10872 KB |
26.txt | AC | 73 ms | 10872 KB |
27.txt | AC | 72 ms | 10872 KB |
28.txt | AC | 73 ms | 10872 KB |
29.txt | AC | 73 ms | 10872 KB |
30.txt | AC | 63 ms | 9984 KB |
31.txt | AC | 72 ms | 10872 KB |
32.txt | AC | 70 ms | 10872 KB |
33.txt | AC | 75 ms | 10872 KB |
34.txt | AC | 66 ms | 10104 KB |
35.txt | AC | 48 ms | 7040 KB |
36.txt | AC | 55 ms | 7552 KB |
37.txt | AC | 48 ms | 7040 KB |
38.txt | AC | 48 ms | 6784 KB |
39.txt | AC | 49 ms | 6912 KB |
40.txt | AC | 67 ms | 10748 KB |
41.txt | AC | 68 ms | 11256 KB |
42.txt | AC | 65 ms | 11256 KB |
43.txt | AC | 66 ms | 11256 KB |
44.txt | AC | 70 ms | 11256 KB |
45.txt | AC | 60 ms | 10496 KB |
46.txt | AC | 69 ms | 11256 KB |
47.txt | AC | 52 ms | 6904 KB |
48.txt | AC | 53 ms | 6904 KB |
49.txt | AC | 53 ms | 6904 KB |
50.txt | AC | 47 ms | 9976 KB |
51.txt | AC | 45 ms | 9208 KB |
52.txt | AC | 45 ms | 6776 KB |
53.txt | AC | 45 ms | 6648 KB |
54.txt | AC | 45 ms | 6648 KB |