Skip to content

Commit 55e7a83

Browse files
authored
Merge pull request #1388 from AlgorithmWithGod/khj20006
[20251112] BOJ / P4 / 이게 게임이냐? / 권혁준
2 parents 360f283 + 3932f4c commit 55e7a83

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N;
6+
int a[51]{}, b[51]{};
7+
int vis[111][111][122][122]{};
8+
9+
int main() {
10+
cin.tie(0)->sync_with_stdio(0);
11+
12+
cin >> N;
13+
N >>= 1;
14+
for (int i = 1; i <= N; i++) {
15+
cin >> a[i] >> b[i];
16+
a[i] += 10;
17+
b[i] += 10;
18+
}
19+
queue<tuple<int, int, int, int, int>> q;
20+
q.emplace(0, 0, 121, 121, 1);
21+
vis[0][0][121][121] = 1;
22+
while (!q.empty()) {
23+
auto [c, d, e, f, t] = q.front(); q.pop();
24+
if (t == N + 1) return cout << "WIN", 0;
25+
int x = a[t], y = b[t];
26+
27+
if ((x > c || abs(x - c) == 10) && (y > x || abs(y - x) == 10) && vis[y][d][e][f] != t + 1) {
28+
q.emplace(y, d, e, f, t + 1);
29+
vis[y][d][e][f] = t + 1;
30+
}
31+
if ((y > c || abs(y - c) == 10) && (x > y || abs(x - y) == 10) && vis[x][d][e][f] != t + 1) {
32+
q.emplace(x, d, e, f, t + 1);
33+
vis[x][d][e][f] = t + 1;
34+
}
35+
if ((x > c || abs(x - c) == 10) && (y > d || abs(y - d) == 10) && vis[x][y][e][f] != t + 1) {
36+
q.emplace(x, y, e, f, t + 1);
37+
vis[x][y][e][f] = t + 1;
38+
}
39+
if ((x > c || abs(x - c) == 10) && (y < e || abs(y - e) == 10) && vis[x][d][y][f] != t + 1) {
40+
q.emplace(x, d, y, f, t + 1);
41+
vis[x][d][y][f] = t + 1;
42+
}
43+
if ((x > c || abs(x - c) == 10) && (y < f || abs(y - f) == 10) && vis[x][d][e][y] != t + 1) {
44+
q.emplace(x, d, e, y, t + 1);
45+
vis[x][d][e][y] = t + 1;
46+
}
47+
48+
if ((x > d || abs(x - d) == 10) && (y > x || abs(y - x) == 10) && vis[c][y][e][f] != t + 1) {
49+
q.emplace(c, y, e, f, t + 1);
50+
vis[c][y][e][f] = t + 1;
51+
}
52+
if ((y > d || abs(y - d) == 10) && (x > y || abs(x - y) == 10) && vis[c][x][e][f] != t + 1) {
53+
q.emplace(c, x, e, f, t + 1);
54+
vis[c][x][e][f] = t + 1;
55+
}
56+
if ((x > d || abs(x - d) == 10) && (y > c || abs(y - c) == 10) && vis[y][x][e][f] != t + 1) {
57+
q.emplace(y, x, e, f, t + 1);
58+
vis[y][x][e][f] = t + 1;
59+
}
60+
if ((x > d || abs(x - d) == 10) && (y < e || abs(y - e) == 10) && vis[c][x][y][f] != t + 1) {
61+
q.emplace(c, x, y, f, t + 1);
62+
vis[c][x][y][f] = t + 1;
63+
}
64+
if ((x > d || abs(x - d) == 10) && (y < f || abs(y - f) == 10) && vis[c][x][e][y] != t + 1) {
65+
q.emplace(c, x, e, y, t + 1);
66+
vis[c][x][e][y] = t + 1;
67+
}
68+
69+
if ((x < e || abs(x - e) == 10) && (y < x || abs(y - x) == 10) && vis[c][d][y][f] != t + 1) {
70+
q.emplace(c, d, y, f, t + 1);
71+
vis[c][d][y][f] = t + 1;
72+
}
73+
if ((y < e || abs(y - e) == 10) && (x < y || abs(x - y) == 10) && vis[c][d][x][f] != t + 1) {
74+
q.emplace(c, d, x, f, t + 1);
75+
vis[c][d][x][f] = t + 1;
76+
}
77+
if ((x < e || abs(x - e) == 10) && (y > c || abs(y - c) == 10) && vis[y][d][x][f] != t + 1) {
78+
q.emplace(y, d, x, f, t + 1);
79+
vis[y][d][x][f] = t + 1;
80+
}
81+
if ((x < e || abs(x - e) == 10) && (y > d || abs(y - d) == 10) && vis[c][y][x][f] != t + 1) {
82+
q.emplace(c, y, x, f, t + 1);
83+
vis[c][y][x][f] = t + 1;
84+
}
85+
if ((x < e || abs(x - e) == 10) && (y < f || abs(y - f) == 10) && vis[c][d][x][y] != t + 1) {
86+
q.emplace(c, d, x, y, t + 1);
87+
vis[c][d][x][y] = t + 1;
88+
}
89+
90+
if ((x < f || abs(x - f) == 10) && (y < x || abs(y - x) == 10) && vis[c][d][e][y] != t + 1) {
91+
q.emplace(c, d, e, y, t + 1);
92+
vis[c][d][e][y] = t + 1;
93+
}
94+
if ((y < f || abs(y - f) == 10) && (x < y || abs(x - y) == 10) && vis[c][d][e][x] != t + 1) {
95+
q.emplace(c, d, e, x, t + 1);
96+
vis[c][d][e][x] = t + 1;
97+
}
98+
if ((x < f || abs(x - f) == 10) && (y > c || abs(y - c) == 10) && vis[y][d][e][x] != t + 1) {
99+
q.emplace(y, d, e, x, t + 1);
100+
vis[y][d][e][x] = t + 1;
101+
}
102+
if ((x < f || abs(x - f) == 10) && (y > d || abs(y - d) == 10) && vis[c][y][e][x] != t + 1) {
103+
q.emplace(c, y, e, x, t + 1);
104+
vis[c][y][e][x] = t + 1;
105+
}
106+
if ((x < f || abs(x - f) == 10) && (y < e || abs(y - e) == 10) && vis[c][d][y][x] != t + 1) {
107+
q.emplace(c, d, y, x, t + 1);
108+
vis[c][d][y][x] = t + 1;
109+
}
110+
111+
}
112+
cout << "LOSE";
113+
114+
}
115+
```

0 commit comments

Comments
 (0)