Submission #1887148
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> 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 int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 4 * 1000 * 100 + 47; const int MOD = 1000 * 1000 * 1000 + 7; int n, x, y; PII A[MAX]; LL F[MAX]; LL FR[MAX]; int C[MAX]; int N[MAX]; map<int, int> mapp; LL bp(LL a, int n) { LL res = 1; while (n) { if (n & 1) res = (res * a) % MOD; a = (a * a) % MOD; n >>= 1; } return res; } LL inv(LL a) { return bp(a, MOD - 2); } struct DSU { int P[MAX]; multiset<int> S[MAX]; void init() { FOR(i, 0, n) { P[i] = i; S[i].insert(A[i].second); } } int getParent(int v) { if (P[v] == v) return v; return P[v] = getParent(P[v]); } void unionSet(int a, int b) { a = getParent(a); b = getParent(b); if (a == b) return; if (SZ(S[a]) < SZ(S[b])) swap(a, b); for (auto i = S[b].begin(); i != S[b].end(); i++) { S[a].insert(*i); } P[b] = a; } LL calc() { LL ans = 1; FOR(i, 0, n) { if (P[i] != i) continue; LL all = SZ(S[i]); LL res = F[all]; mapp.clear(); for (auto it = S[i].begin(); it != S[i].end(); it++) { mapp[*it]++; } for (auto it = mapp.begin(); it != mapp.end(); it++) { res = (res * FR[it->second]) % MOD; } ans = (ans * res) % MOD; } return ans; } } D; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); F[0] = FR[0] = 1; FOR(i, 1, MAX) { F[i] = (F[i - 1] * i) % MOD; FR[i] = inv(F[i]); } cin >> n >> x >> y; FOR(i, 0, n) { cin >> A[i].second >> A[i].first; } sort(A, A + n); int px = 1, py = 1; D.init(); FOR(i, 0, n) C[i] = INF; RFOR(i, n, 0) { N[i] = C[A[i].second]; C[A[i].second] = i; } FOR(i, 0, n) { if (N[i] != INF && A[N[i]].first - A[i].first <= x) { D.unionSet(i, N[i]); } while (py < n && A[py].first + A[i].first <= y) { if (A[i].second != A[py].second) { //cout << i << " " << py << endl; D.unionSet(i, py); } py++; } } LL ans = D.calc(); cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | vjudge5 |
Language | C++14 (Clang 3.8.0) |
Score | 0 |
Code Size | 2890 Byte |
Status | WA |
Exec Time | 552 ms |
Memory | 47616 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 | WA | 58 ms | 21760 KB |
00_example_02.txt | AC | 57 ms | 21632 KB |
00_example_03.txt | WA | 57 ms | 21632 KB |
01.txt | WA | 58 ms | 21760 KB |
02.txt | AC | 57 ms | 21632 KB |
03.txt | WA | 71 ms | 22528 KB |
04.txt | AC | 57 ms | 21632 KB |
05.txt | AC | 62 ms | 22016 KB |
06.txt | WA | 58 ms | 21760 KB |
07.txt | WA | 256 ms | 31872 KB |
08.txt | WA | 59 ms | 21760 KB |
09.txt | WA | 167 ms | 27904 KB |
10.txt | WA | 123 ms | 25344 KB |
11.txt | WA | 58 ms | 21760 KB |
12.txt | WA | 57 ms | 21632 KB |
13.txt | WA | 71 ms | 22656 KB |
14.txt | WA | 57 ms | 21632 KB |
15.txt | WA | 142 ms | 26880 KB |
16.txt | WA | 241 ms | 29568 KB |
17.txt | WA | 87 ms | 23424 KB |
18.txt | WA | 138 ms | 25856 KB |
19.txt | WA | 225 ms | 29568 KB |
20.txt | WA | 477 ms | 41472 KB |
21.txt | WA | 463 ms | 40192 KB |
22.txt | WA | 435 ms | 36224 KB |
23.txt | AC | 513 ms | 45568 KB |
24.txt | WA | 429 ms | 35712 KB |
25.txt | WA | 480 ms | 41600 KB |
26.txt | AC | 536 ms | 46208 KB |
27.txt | WA | 441 ms | 35968 KB |
28.txt | WA | 541 ms | 46336 KB |
29.txt | WA | 520 ms | 43904 KB |
30.txt | WA | 435 ms | 34048 KB |
31.txt | AC | 552 ms | 46464 KB |
32.txt | WA | 460 ms | 37376 KB |
33.txt | WA | 532 ms | 45952 KB |
34.txt | WA | 541 ms | 46720 KB |
35.txt | WA | 464 ms | 41984 KB |
36.txt | WA | 503 ms | 42752 KB |
37.txt | WA | 471 ms | 41984 KB |
38.txt | WA | 476 ms | 41984 KB |
39.txt | WA | 478 ms | 41984 KB |
40.txt | WA | 540 ms | 47616 KB |
41.txt | WA | 467 ms | 41344 KB |
42.txt | WA | 453 ms | 40320 KB |
43.txt | WA | 427 ms | 36096 KB |
44.txt | AC | 506 ms | 46080 KB |
45.txt | WA | 425 ms | 35584 KB |
46.txt | WA | 471 ms | 41344 KB |
47.txt | AC | 455 ms | 41984 KB |
48.txt | AC | 444 ms | 40448 KB |
49.txt | AC | 462 ms | 41984 KB |
50.txt | AC | 416 ms | 41088 KB |
51.txt | AC | 417 ms | 37248 KB |
52.txt | WA | 434 ms | 41984 KB |
53.txt | WA | 437 ms | 41984 KB |
54.txt | WA | 438 ms | 41984 KB |