# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
72129 | 동진의 (#118) | 수중 미로 (FXCUP3_aqua) | C++17 | 3 ms | 488 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// main.cpp
// boj
//
// Created by 주진형 on 2018. 4. 17..
// Copyright © 2018년 주진형. All rights reserved.
//
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<list>
#include<cstring>
#include<algorithm>
#define fio ios_base::sync_with_stdio(0)
//배열크기 확인
#define MAXNUM 110
using namespace std;
struct point{
int x, y, cost;
bool operator <(const point & a) const{
return cost > a.cost;
}
point operator +(const point & a) const{
return {x + a.x, y + a.y, cost};
}
};
int main(){
int n;
int ans=-1;
char map[MAXNUM][MAXNUM]={0};
bool check[MAXNUM][MAXNUM]={0};
priority_queue<point> q;
point dir[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
point goal;
scanf("%d", &n);
for (int i=1; i<=n; i++)
scanf("%s", map[i]+1);
for (int i=0; i<=n+1; i++) {map[i][0] = map[i][n+1] = map[0][i] = map[n+1][i] = '#';}
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++) {
if (map[i][j] == 'M') {
q.push({j, i, 0});
check[i][j] = true;
}
else if(map[i][j] == 'H'){
goal = {j, i, 0};
}
}
}
while (!q.empty()) {
point cur = q.top(); q.pop();
for (int i=0; i<4; i++) {
int cnt=0;
point next = cur;
while (map[next.y][next.x] != 'W' && map[next.y][next.x] != '#') {
next = next + dir[i];
}
while (map[next.y][next.x] == 'W') {
cnt++;
next = next + dir[i];
}
if (map[next.y][next.x] == '.' || map[next.y][next.x] == 'H') {
if (check[next.y][next.x]) {continue;}
check[next.y][next.x] = true;
next.cost += cnt * cnt;
if (next.y == goal.y && next.x == goal.x) {
ans = next.cost;
goto stop;
}
q.push(next);
}
}
}
stop:
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |