-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi_karlsson.cpp
75 lines (58 loc) · 1.22 KB
/
i_karlsson.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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstdio>
#include <memory.h>
using namespace std;
int const maxSize = 5001;
int grundy[maxSize];
void calcGrundy() {
int mex[10000];
for (int i = 1; i < maxSize; i++) {
memset(mex, 0, sizeof(mex));
for (int j = i - 1; j >= (i + 1) / 2; j--) {
mex[grundy[j]] = 1;
}
int gr = 0;
for (int k = 0; k < 10000 && mex[k] != 0; k++) {
gr++;
}
grundy[i] = gr;
}
}
int main() {
calcGrundy();
FILE* in = fopen("karlsson.in", "r");
int a;
int b;
int c;
fscanf(in, "%d %d %d", &a, &b, &c);
fclose(in);
FILE* out = fopen("karlsson.out", "w");
if ((grundy[a] ^ grundy[b] ^ grundy[c]) == 0) {
fprintf(out, "NO");
fclose(out);
return 0;
}
fprintf(out, "YES\n");
for (int i = a - 1; i >= (a + 1) / 2; i--) {
if ((grundy[i] ^ grundy[b] ^ grundy[c]) == 0) {
fprintf(out, "%d %d %d", i, b, c);
fclose(out);
return 0;
}
}
for (int i = b - 1; i >= (b + 1) / 2; i--) {
if ((grundy[a] ^ grundy[i] ^ grundy[c]) == 0) {
fprintf(out, "%d %d %d", a, i, c);
fclose(out);
return 0;
}
}
for (int i = c - 1; i >= (c + 1) / 2; i--) {
if ((grundy[a] ^ grundy[b] ^ grundy[i]) == 0) {
fprintf(out, "%d %d %d", a, b, i);
fclose(out);
return 0;
}
}
fclose(out);
return 0;
}