Submission #1201964
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;
struct UnionFind{
vector<int> par,rank;
UnionFind(int n) :par(n + 1),rank(n + 1,1){
for(int i = 1;i <= n;i++) par [i] = i;
}
int find(int x){
return par [x] == x ? x : par [x] = find(par [x]);
}
bool connect(int x,int y){
x = find(x);
y = find(y);
if(x == y) return false;
if(rank [x] < rank [y]) swap(x,y);
rank [x] += rank [x] == rank [y];
par [y] = x;
return true;
}
bool same(int x,int y){
return find(x) == find(y);
}
};
int N,X,Y;
pair<int,int> colorMin [200001];
ll fact [200001],rfact [200001];
const int INF = 2e9;
const ll MOD = 1e9 + 7;
ll mod_pow(ll x,ll y = MOD - 2)
{
ll res = 1;
while(y){
if(y & 1) (res *= x) %= MOD;
(x *= x) %= MOD;
y >>= 1;
}
return res;
}
int main()
{
scanf("%d%d%d",&N,&X,&Y);
vector<int> C(N),W(N);
fill(colorMin + 1,colorMin + N + 1,make_pair(INF,0));
FOR(i,0,N){
scanf("%d%d",&C [i],&W [i]);
chmin(colorMin [C [i]],make_pair(W [i],i));
}
if(count(colorMin + 1,colorMin + N + 1,make_pair(INF,0)) >= N - 1){
printf("1\n");
return 0;
}
sort(colorMin + 1,colorMin + N + 1);
UnionFind uf(N);
FOR(i,0,N){
if(C [i] == C [colorMin [1].second]){
if(W [i] + W [colorMin [1].second] <= X){
uf.connect(i,colorMin [1].second);
}
}
else{
if(W [i] + W [colorMin [1].second] <= Y){
uf.connect(i,colorMin [1].second);
}
}
if(C [i] == C [colorMin [2].second]){
if(W [i] + W [colorMin [2].second] <= X){
uf.connect(i,colorMin [2].second);
}
}
else{
if(W [i] + W [colorMin [2].second] <= Y){
uf.connect(i,colorMin [2].second);
}
}
}
map<int,int> mp;
FOR(i,0,N) if(uf.same(i,colorMin [1].second)){
mp [C [i]]++;
}
fact [0] = rfact [0] = 1;
for(int i = 1;i <= 200000;i++){
fact [i] = fact [i - 1] * i % MOD;
rfact [i] = mod_pow(fact [i]);
}
ll ans = 1,sum = 0;
for(const auto& it : mp){
(ans *= rfact [it.second]) %= MOD;
sum += it.second;
}
(ans *= fact [sum]) %= MOD;
printf("%lld\n",ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Colorful Balls |
User |
gigime |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2418 Byte |
Status |
WA |
Exec Time |
145 ms |
Memory |
13824 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:51:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&N,&X,&Y);
^
./Main.cpp:55:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&C [i],&W [i]);
^
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 |
33 ms |
4352 KB |
00_example_02.txt |
AC |
2 ms |
2304 KB |
00_example_03.txt |
AC |
33 ms |
4352 KB |
01.txt |
AC |
33 ms |
4352 KB |
02.txt |
AC |
33 ms |
4352 KB |
03.txt |
AC |
35 ms |
4608 KB |
04.txt |
AC |
33 ms |
4352 KB |
05.txt |
AC |
34 ms |
4480 KB |
06.txt |
AC |
33 ms |
4352 KB |
07.txt |
AC |
71 ms |
7296 KB |
08.txt |
WA |
33 ms |
4352 KB |
09.txt |
AC |
48 ms |
5248 KB |
10.txt |
AC |
44 ms |
5120 KB |
11.txt |
AC |
33 ms |
4352 KB |
12.txt |
AC |
33 ms |
4352 KB |
13.txt |
AC |
36 ms |
4608 KB |
14.txt |
AC |
33 ms |
4352 KB |
15.txt |
AC |
52 ms |
6144 KB |
16.txt |
AC |
63 ms |
6912 KB |
17.txt |
AC |
38 ms |
4736 KB |
18.txt |
AC |
45 ms |
5120 KB |
19.txt |
AC |
59 ms |
6016 KB |
20.txt |
WA |
114 ms |
11392 KB |
21.txt |
AC |
114 ms |
11392 KB |
22.txt |
WA |
93 ms |
9216 KB |
23.txt |
AC |
139 ms |
13312 KB |
24.txt |
WA |
94 ms |
9344 KB |
25.txt |
WA |
111 ms |
11136 KB |
26.txt |
AC |
143 ms |
13568 KB |
27.txt |
AC |
86 ms |
8064 KB |
28.txt |
AC |
144 ms |
13568 KB |
29.txt |
WA |
129 ms |
12544 KB |
30.txt |
WA |
90 ms |
8704 KB |
31.txt |
AC |
144 ms |
13568 KB |
32.txt |
WA |
97 ms |
9600 KB |
33.txt |
AC |
145 ms |
13440 KB |
34.txt |
WA |
118 ms |
12800 KB |
35.txt |
AC |
86 ms |
8064 KB |
36.txt |
WA |
91 ms |
8832 KB |
37.txt |
AC |
88 ms |
8064 KB |
38.txt |
AC |
85 ms |
8064 KB |
39.txt |
WA |
82 ms |
8064 KB |
40.txt |
WA |
123 ms |
13824 KB |
41.txt |
WA |
110 ms |
11520 KB |
42.txt |
AC |
110 ms |
11648 KB |
43.txt |
WA |
91 ms |
9344 KB |
44.txt |
AC |
137 ms |
13824 KB |
45.txt |
WA |
91 ms |
9472 KB |
46.txt |
WA |
107 ms |
11264 KB |
47.txt |
AC |
36 ms |
4480 KB |
48.txt |
AC |
37 ms |
4480 KB |
49.txt |
AC |
37 ms |
4480 KB |
50.txt |
AC |
85 ms |
9984 KB |
51.txt |
AC |
79 ms |
8064 KB |
52.txt |
AC |
74 ms |
8064 KB |
53.txt |
AC |
74 ms |
8064 KB |
54.txt |
AC |
74 ms |
8064 KB |