Skip to content

Commit ce4d49c

Browse files
committed
[Unrated] Title: [모의 SW 역량테스트] 핀볼 게임, Time: 1,907 ms, Memory: 13,908 KB -BaekjoonHub
1 parent 8ba61df commit ce4d49c

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [Unrated] [모의 SW 역량테스트] 핀볼 게임 - 5650
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRF8s6ezEDFAUo)
4+
5+
### 성능 요약
6+
7+
메모리: 13,908 KB, 시간: 1,907 ms, 코드길이: 2,119 Bytes
8+
9+
### 제출 일자
10+
11+
2024-04-09 16:54
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
using namespace std;
5+
6+
int n;
7+
vector<vector<int> > map;
8+
int dx[4] = {0, 0, 1, -1};
9+
int dy[4] = {1, -1, 0, 0};
10+
11+
int changeD[6][5] = {
12+
{1, 0, 3, 2},
13+
{1, 3, 0, 2},
14+
{1, 2, 3, 0},
15+
{2, 0, 3, 1},
16+
{3, 0, 1, 2},
17+
{1, 0, 3, 2}
18+
};
19+
20+
vector<vector<pair<int, int> > >warmhole;
21+
22+
int move(int sx, int sy, int d) {
23+
int score = 0;
24+
int x = sx, y = sy;
25+
while (true) {
26+
x += dx[d];
27+
y += dy[d];
28+
if (x < 0 || x >= n || y < 0 || y >= n) {
29+
score++;
30+
d = changeD[0][d];
31+
continue;
32+
}
33+
int point = map[x][y];
34+
if (point == -1 || (x == sx && y == sy)) {
35+
break;
36+
}
37+
if (point >= 1 && point <= 5) {
38+
score++;
39+
d = changeD[point][d];
40+
}
41+
else if (point >= 6 && point <= 10) {
42+
for (int i = 0; i < 2; i++) {
43+
if (!(warmhole[point-6][i].first == x && warmhole[point-6][i].second == y)) {
44+
x = warmhole[point-6][i].first;
45+
y = warmhole[point-6][i].second;
46+
break;
47+
}
48+
}
49+
}
50+
}
51+
return score;
52+
53+
}
54+
55+
int main()
56+
{
57+
ios_base::sync_with_stdio(0);
58+
cin.tie(0);
59+
60+
int t, cnt = 1;
61+
cin >> t;
62+
63+
while(t--) {
64+
cin >> n;
65+
warmhole.assign(5, vector<pair<int, int> >());
66+
67+
map.assign(n, vector<int>(n, 0));
68+
vector<pair<int, int> > emptys;
69+
for (int i = 0; i < n; i++) {
70+
for (int j = 0; j < n; j++) {
71+
cin >> map[i][j];
72+
if (map[i][j] == 0) emptys.push_back(make_pair(i,j));
73+
if (map[i][j] >= 6 && map[i][j] <= 10) warmhole[map[i][j]-6].push_back(make_pair(i,j));
74+
}
75+
}
76+
int result = 0;
77+
for (int i = 0; i < emptys.size(); i++) {
78+
for (int j = 0; j < 4; j++) {
79+
result = max(result, move(emptys[i].first, emptys[i].second, j));
80+
}
81+
}
82+
cout << '#' << cnt << " " << result << '\n';
83+
cnt++;
84+
}
85+
return 0;
86+
}

0 commit comments

Comments
 (0)