-
Notifications
You must be signed in to change notification settings - Fork 0
/
P11120.cpp
71 lines (66 loc) · 1.49 KB
/
P11120.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
#include <iostream>
int n, m;
bool occupied[1010][7] = {0};
bool check_valid() {
for (int i = 1; i <= n; i++) {
if (!(
occupied[1] == occupied[6] &&
occupied[2] == occupied[5] &&
occupied[3] == occupied[4]
))
return false;
}
return true;
}
void print() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 6; j++) {
if (occupied[i][j])
std::cout << "X";
else
std::cout << ".";
}
std::cout << std::endl;
}
}
int main() {
std::cin >> n >> m;
int occupied_count = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 6; j++) {
char ch; std::cin >> ch;
occupied[i][j] = ch == 'X';
if (ch == 'X') occupied_count++;
}
}
if (6*n - occupied_count < m || (6*n-occupied_count + m) % 2 != 0) {
std::cout << "Impossible" << std::endl;
return 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3; j++) {
if (occupied[i][j] ^ occupied[i][7-j]) {
occupied[i][j] = true;
occupied[i][7-j] = true;
m--;
}
}
}
if (m < 0 || m % 2 == 1) {
std::cout << "Impossible" << std::endl;
return 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3 && m > 0; j++) {
if (occupied[i][j]) continue;
if (m > 0) {
occupied[i][j] = true; occupied[i][7-j] = true;
m -= 2;
} else {
break;
}
}
}
print();
return 0;
}