Skip to content

Commit

Permalink
[Unrated] Title: [모의 SW 역량테스트] 핀볼 게임, Time: 1,907 ms, Memory: 13,908 …
Browse files Browse the repository at this point in the history
…KB -BaekjoonHub
  • Loading branch information
belowyoon committed Apr 9, 2024
1 parent 8ba61df commit ce4d49c
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [Unrated] [모의 SW 역량테스트] 핀볼 게임 - 5650

[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRF8s6ezEDFAUo)

### 성능 요약

메모리: 13,908 KB, 시간: 1,907 ms, 코드길이: 2,119 Bytes

### 제출 일자

2024-04-09 16:54



> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n;
vector<vector<int> > map;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int changeD[6][5] = {
{1, 0, 3, 2},
{1, 3, 0, 2},
{1, 2, 3, 0},
{2, 0, 3, 1},
{3, 0, 1, 2},
{1, 0, 3, 2}
};

vector<vector<pair<int, int> > >warmhole;

int move(int sx, int sy, int d) {
int score = 0;
int x = sx, y = sy;
while (true) {
x += dx[d];
y += dy[d];
if (x < 0 || x >= n || y < 0 || y >= n) {
score++;
d = changeD[0][d];
continue;
}
int point = map[x][y];
if (point == -1 || (x == sx && y == sy)) {
break;
}
if (point >= 1 && point <= 5) {
score++;
d = changeD[point][d];
}
else if (point >= 6 && point <= 10) {
for (int i = 0; i < 2; i++) {
if (!(warmhole[point-6][i].first == x && warmhole[point-6][i].second == y)) {
x = warmhole[point-6][i].first;
y = warmhole[point-6][i].second;
break;
}
}
}
}
return score;

}

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);

int t, cnt = 1;
cin >> t;

while(t--) {
cin >> n;
warmhole.assign(5, vector<pair<int, int> >());

map.assign(n, vector<int>(n, 0));
vector<pair<int, int> > emptys;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
if (map[i][j] == 0) emptys.push_back(make_pair(i,j));
if (map[i][j] >= 6 && map[i][j] <= 10) warmhole[map[i][j]-6].push_back(make_pair(i,j));
}
}
int result = 0;
for (int i = 0; i < emptys.size(); i++) {
for (int j = 0; j < 4; j++) {
result = max(result, move(emptys[i].first, emptys[i].second, j));
}
}
cout << '#' << cnt << " " << result << '\n';
cnt++;
}
return 0;
}

0 comments on commit ce4d49c

Please sign in to comment.