제출 #72186

#제출 시각아이디문제언어결과실행 시간메모리
72186동진의 (#118)수중 미로 (FXCUP3_aqua)C++17
0 / 100
8 ms5240 KiB
// // 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 910 using namespace std; struct point{ int x, y; point operator +(const point & a) const{ return {x + a.x, y + a.y}; } }; int main(){ int n; int ans=1000000000; int cost[MAXNUM][MAXNUM]={0}; bool inQueue[MAXNUM][MAXNUM]={0}; char map[MAXNUM][MAXNUM]={0}; queue<point> q; memset(cost, 40, sizeof(cost)); point dir[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; 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}); cost[i][j] = 0; inQueue[i][j] = true; } } } while (!q.empty()) { point cur = q.front(); 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 (cost[next.y][next.x] > cost[cur.y][cur.x] + cnt * cnt) { cost[next.y][next.x] = cost[cur.y][cur.x] + cnt * cnt; if (map[next.y][next.x] == 'H') { ans = min(ans, cost[next.y][next.x]); continue; } if (!inQueue[next.y][next.x]) { inQueue[next.y][next.x] = true; q.push(next); } } } } } printf("%d\n", ans > 999999999 ? -1 : ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

aqua.cpp: In function 'int main()':
aqua.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
aqua.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", map[i]+1);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...