# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
72244 | 2018-08-26T06:19:00 Z | Semteo For Ajou(#2257, tph00300, txepahs, bmw) | 수중 미로 (FXCUP3_aqua) | C++14 | 815 ms | 22888 KB |
#include <stdio.h> #include <algorithm> using namespace std; int map[901][901]; int x[5] = { 0,-1,0,1,0 }, y[5] = { 0,0,1,0,-1 }; int tx, ty, f, s, px[10000001], py[10000001]; char arr[10001]; int main() { int n,i,j,k,ex,ey; scanf("%d", &n); f = 1; s = 1; for (i = 1; i <= n; i++) { scanf("%s", arr); for (j = 0; j < n; j++) { if (arr[j] == 'M') { map[i][j + 1] = 0; px[f] = i; py[f] = j + 1; } else if (arr[j] == 'W') map[i][j + 1] = -1; else if (arr[j] == '.') map[i][j + 1] = 0; else if (arr[j] == 'H') { map[i][j + 1] = 0; ex = i; ey = j+1; } } } map[px[f]][py[f]] = 1; int flag,a=0; while (f <= s) { for (i = 1; i <= 4; i++) { flag = 0; a = 0; tx = px[f]; ty = py[f]; while (1) { tx += x[i]; ty += y[i]; if (tx<0 || ty<0 || tx>n || ty>n) break; if (map[tx][ty] == -1 && flag!=2) { flag = 1; a++; } if (map[tx][ty] != -1 && flag == 1) { flag = 2; } if (flag == 2) { if (map[tx][ty] == 0 || map[tx][ty] > a*a + map[px[f]][py[f]]) { map[tx][ty] = a * a + map[px[f]][py[f]]; s++; px[s] = tx; py[s] = ty; } } if (flag == 2 && map[tx][ty] == -1) break; } } f++; } /*for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { printf("%d ", map[i][j]); } printf("\n"); }*/ if (map[ex][ey] == 0) printf("%d", -1); else printf("%d", map[ex][ey]-1); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 720 KB | Output is correct |
5 | Correct | 3 ms | 744 KB | Output is correct |
6 | Correct | 4 ms | 744 KB | Output is correct |
7 | Correct | 7 ms | 964 KB | Output is correct |
8 | Correct | 7 ms | 964 KB | Output is correct |
9 | Correct | 3 ms | 964 KB | Output is correct |
10 | Correct | 3 ms | 964 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 2 ms | 720 KB | Output is correct |
5 | Correct | 3 ms | 744 KB | Output is correct |
6 | Correct | 4 ms | 744 KB | Output is correct |
7 | Correct | 7 ms | 964 KB | Output is correct |
8 | Correct | 7 ms | 964 KB | Output is correct |
9 | Correct | 3 ms | 964 KB | Output is correct |
10 | Correct | 3 ms | 964 KB | Output is correct |
11 | Correct | 69 ms | 3384 KB | Output is correct |
12 | Correct | 18 ms | 3384 KB | Output is correct |
13 | Correct | 402 ms | 13880 KB | Output is correct |
14 | Correct | 50 ms | 13880 KB | Output is correct |
15 | Correct | 10 ms | 13880 KB | Output is correct |
16 | Correct | 815 ms | 22888 KB | Output is correct |
17 | Correct | 705 ms | 22888 KB | Output is correct |
18 | Correct | 34 ms | 22888 KB | Output is correct |
19 | Correct | 65 ms | 22888 KB | Output is correct |
20 | Correct | 34 ms | 22888 KB | Output is correct |