Submission #1195890
Source Code Expand
// In the name of God #include <iostream> #include <algorithm> #include <fstream> #include <vector> #include <deque> #include <assert.h> #include <queue> #include <stack> #include <set> #include <map> #include <stdio.h> #include <string.h> #include <utility> #include <math.h> #include <bitset> #include <iomanip> #include <complex> using namespace std; #define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i) #define debug(...) fprintf(stderr, __VA_ARGS__) #define mp make_pair #define x first #define y second #define pb push_back #define SZ(x) (int((x).size())) #define ALL(x) (x).begin(), (x).end() template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template<typename T> inline bool smin(T &a, const T &b) { return a > b ? a = b : a; } template<typename T> inline bool smax(T &a, const T &b) { return a < b ? a = b : a; } typedef long long LL; const int N = (int) 1e6 + 6, mod = (int) 1e9 + 7; vector<int> col[N]; int f[N], par[N], sz[N], inv[N]; map<int, int> c[N]; int fpm(int a, int b) { return b != 0 ? (LL) fpm((LL) a * a % mod, b >> 1) * (b & 1 ? a : 1) % mod: 1; } pair<int, int> a[N]; int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); } void unite(int u, int v) { u = find(u); v = find(v); if (u == v) return; sz[u] += sz[v]; par[v] = u; } int main() { f[0] = inv[0] = 1; for (int j = 1; j < N; ++j) { f[j] = f[j - 1] * (LL) j % mod; inv[j] = fpm(f[j], mod - 2); } ios_base::sync_with_stdio(0); int n, x, y; cin >> n >> x >> y; for (int j = 0; j < n; ++j) { par[j] = j; sz[j] = 1; cin >> a[j].second >> a[j].first; } sort(a, a + n); int cnt = 0; for (int j = 0; j < n; ++j) { col[a[j].second].push_back(j); if ((j == 0 || a[j].second != a[j - 1].second) && cnt <= 10) { ++cnt; for (int k = 0; k < n; ++k) if (k != j) { if (a[k].second == a[j].second) { if (a[k].first + a[j].first <= x) { unite(k, j); } } else { if (a[k].first + a[j].first <= y) { unite(k, j); } } } } } for (int j = 0; j < n; ++j) if ((int) col[j].size()) { int fst = col[j][0]; for (int xx : col[j]) { if (a[fst].first + a[xx].first <= x) { unite(fst, xx); } } } for (int j = 0; j < n; ++j) c[find(j)][a[j].second]++; int res = 1; for (int j = 0; j < n; ++j) if (par[j] == j) { res = (LL) res * f[sz[j]] % mod; for (auto x : c[j]) { res = (LL) res * inv[x.second] % mod; } } cout << res << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | Reyna |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2700 Byte |
Status | WA |
Exec Time | 438 ms |
Memory | 99840 KB |
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 | 281 ms | 83840 KB |
00_example_02.txt | AC | 281 ms | 83840 KB |
00_example_03.txt | AC | 281 ms | 83840 KB |
01.txt | AC | 281 ms | 83840 KB |
02.txt | AC | 283 ms | 83840 KB |
03.txt | AC | 285 ms | 84224 KB |
04.txt | AC | 281 ms | 83840 KB |
05.txt | AC | 283 ms | 83968 KB |
06.txt | AC | 284 ms | 83840 KB |
07.txt | AC | 339 ms | 89472 KB |
08.txt | AC | 282 ms | 83840 KB |
09.txt | AC | 306 ms | 85632 KB |
10.txt | AC | 299 ms | 85248 KB |
11.txt | AC | 282 ms | 83840 KB |
12.txt | AC | 281 ms | 83840 KB |
13.txt | AC | 286 ms | 84352 KB |
14.txt | AC | 281 ms | 83840 KB |
15.txt | AC | 309 ms | 86784 KB |
16.txt | AC | 330 ms | 90368 KB |
17.txt | AC | 290 ms | 84480 KB |
18.txt | AC | 302 ms | 85760 KB |
19.txt | AC | 326 ms | 88064 KB |
20.txt | AC | 411 ms | 98048 KB |
21.txt | AC | 402 ms | 99328 KB |
22.txt | AC | 385 ms | 98048 KB |
23.txt | AC | 431 ms | 98816 KB |
24.txt | AC | 382 ms | 99072 KB |
25.txt | AC | 409 ms | 97408 KB |
26.txt | AC | 437 ms | 98688 KB |
27.txt | AC | 375 ms | 95360 KB |
28.txt | AC | 438 ms | 98688 KB |
29.txt | AC | 424 ms | 98432 KB |
30.txt | AC | 380 ms | 98816 KB |
31.txt | AC | 438 ms | 98688 KB |
32.txt | AC | 392 ms | 97664 KB |
33.txt | AC | 435 ms | 98816 KB |
34.txt | AC | 422 ms | 96384 KB |
35.txt | AC | 352 ms | 91008 KB |
36.txt | AC | 370 ms | 89856 KB |
37.txt | AC | 357 ms | 91008 KB |
38.txt | AC | 352 ms | 90752 KB |
39.txt | AC | 348 ms | 89344 KB |
40.txt | WA | 432 ms | 98048 KB |
41.txt | AC | 410 ms | 98816 KB |
42.txt | AC | 403 ms | 99840 KB |
43.txt | AC | 384 ms | 98688 KB |
44.txt | AC | 432 ms | 99584 KB |
45.txt | AC | 385 ms | 99456 KB |
46.txt | AC | 408 ms | 98304 KB |
47.txt | AC | 340 ms | 91380 KB |
48.txt | AC | 344 ms | 93300 KB |
49.txt | AC | 343 ms | 92020 KB |
50.txt | AC | 367 ms | 94200 KB |
51.txt | AC | 348 ms | 95096 KB |
52.txt | AC | 350 ms | 91768 KB |
53.txt | AC | 351 ms | 91768 KB |
54.txt | AC | 351 ms | 91768 KB |