-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path469D. Two Sets.cpp
63 lines (48 loc) · 1.15 KB
/
469D. Two Sets.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <vector>
#include <map>
#include <memory.h>
using namespace std;
int const N = 1e5 + 1;
int n, a, b, match[N];
bool vis[N];
vector<int> arr;
map<int, int> mp;
bool findMatch(int i) {
vis[i] = true;
if(arr[i] <= a && mp.count(a - arr[i]) &&
(match[mp[a - arr[i]]] == -1 || !vis[match[mp[a - arr[i]]]] && findMatch(match[mp[a - arr[i]]]))) {
match[mp[a - arr[i]]] = i;
return true;
}
if(arr[i] <= b && mp.count(b - arr[i]) &&
(match[mp[b - arr[i]]] == -1 || !vis[match[mp[b - arr[i]]]] && findMatch(match[mp[b - arr[i]]]))) {
match[mp[b - arr[i]]] = i;
return true;
}
return false;
}
int main() {
scanf("%d%d%d", &n, &a, &b);
arr.resize(n);
for(int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
mp[arr[i]] = i;
}
memset(match, -1, sizeof match);
for(int i = 0; i < n; ++i) {
memset(vis, false, sizeof vis);
if(!findMatch(i)) {
puts("NO");
return 0;
}
}
puts("YES");
for(int i = 0; i < n; ++i) {
if(i) putchar(' ');
if(arr[i] + arr[match[i]] == a) putchar('0');
else putchar('1');
}
putchar('\n');
return 0;
}