Submission #1195667


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 <= 2) {
			++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 x : col[j]) {
			if (a[fst].first + a[x].first <= x) {
				unite(fst, x);
			}
		}
	}
	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 2691 Byte
Status WA
Exec Time 429 ms
Memory 99840 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 3
AC × 39
WA × 18
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 282 ms 83840 KB
00_example_02.txt AC 282 ms 83840 KB
00_example_03.txt AC 282 ms 83840 KB
01.txt AC 282 ms 83840 KB
02.txt AC 282 ms 83840 KB
03.txt AC 286 ms 84224 KB
04.txt AC 282 ms 83840 KB
05.txt AC 284 ms 83968 KB
06.txt AC 283 ms 83840 KB
07.txt AC 335 ms 89472 KB
08.txt WA 283 ms 83968 KB
09.txt AC 303 ms 85632 KB
10.txt AC 298 ms 85248 KB
11.txt AC 283 ms 83840 KB
12.txt AC 282 ms 83840 KB
13.txt AC 286 ms 84352 KB
14.txt AC 282 ms 83840 KB
15.txt AC 308 ms 86784 KB
16.txt AC 329 ms 90368 KB
17.txt AC 289 ms 84480 KB
18.txt AC 300 ms 85760 KB
19.txt AC 321 ms 88064 KB
20.txt WA 402 ms 99200 KB
21.txt WA 402 ms 99200 KB
22.txt WA 386 ms 98304 KB
23.txt AC 421 ms 98816 KB
24.txt WA 386 ms 98432 KB
25.txt WA 398 ms 99072 KB
26.txt AC 425 ms 98688 KB
27.txt AC 375 ms 98432 KB
28.txt AC 425 ms 98688 KB
29.txt WA 412 ms 99072 KB
30.txt WA 378 ms 98688 KB
31.txt AC 428 ms 98688 KB
32.txt WA 386 ms 99072 KB
33.txt AC 429 ms 98816 KB
34.txt WA 417 ms 98688 KB
35.txt AC 345 ms 91008 KB
36.txt WA 367 ms 94848 KB
37.txt AC 347 ms 91008 KB
38.txt AC 345 ms 90752 KB
39.txt WA 353 ms 94080 KB
40.txt WA 418 ms 99840 KB
41.txt WA 400 ms 99840 KB
42.txt WA 401 ms 99840 KB
43.txt WA 384 ms 98944 KB
44.txt AC 423 ms 99584 KB
45.txt WA 384 ms 98944 KB
46.txt WA 400 ms 99712 KB
47.txt AC 341 ms 91380 KB
48.txt AC 343 ms 91380 KB
49.txt AC 343 ms 92020 KB
50.txt AC 361 ms 94200 KB
51.txt AC 349 ms 95096 KB
52.txt AC 343 ms 91768 KB
53.txt AC 343 ms 91768 KB
54.txt AC 343 ms 91768 KB