-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_12869.cpp
More file actions
48 lines (45 loc) · 969 Bytes
/
BOJ_12869.cpp
File metadata and controls
48 lines (45 loc) · 969 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c;
int visited[62][62][62];
int arr[6][3] = { {9, 3, 1}, {9, 1, 3}, {3, 9, 1}, {3, 1, 9}, {1, 3, 9}, {1, 9, 3}};
struct str {
int x, y, z;
};
queue<str> q;
int solve(int x, int y, int z) {
visited[x][y][z] = 0;
q.push({ x, y, z });
while (!q.empty()) {
int px = q.front().x;
int py = q.front().y;
int pz = q.front().z;
q.pop();
if (visited[0][0][0]) break;
for (int i = 0; i < 6; i++) {
int nx = max(0, px - arr[i][0]);
int ny = max(0, py - arr[i][1]);
int nz = max(0, pz - arr[i][2]);
if (visited[nx][ny][nz] != 0) continue;
visited[nx][ny][nz] = visited[px][py][pz] + 1;
q.push({ nx, ny, nz });
}
}
return visited[0][0][0];
}
int main() {
cin >> n;
if (n == 3) {
cin >> a >> b >> c;
cout << solve(a, b, c) << '\n';
}
else if (n == 2) {
cin >> a >> b;
cout << solve(a, b, 0) << '\n';
}
else {
cin >> a;
cout << solve(a, 0, 0) << '\n';
}
return 0;
}