# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
549060 | 2022-04-15T04:02:56 Z | Amylopectin | 포탈들 (BOI14_portals) | C++14 | 257 ms | 53740 KB |
#include <iostream> #include <stdio.h> #include <queue> #include <limits.h> using namespace std; const int mxn = 1010,dn[4] = {0,0,1,-1},dm[4] = {1,-1,0,0},mav = INT_MAX; struct we { int nn,mm,dis; bool operator () (const struct we &l,const struct we &r) { return l.dis > r.dis; } }; struct pp { int nn,mm; }; queue <struct we> fq; priority_queue<struct we, vector<struct we>,struct we> qu; struct pp jn[4][mxn][mxn] = {}; int fw[mxn][mxn] = {},u[mxn][mxn] = {},di[mxn][mxn] = {}; char s[mxn][mxn] = {}; int main() { int i,j,n,m,stn,stm,cn,cm,fn,fm,tn,tm,cdi,fdi,k,o,sta,of; scanf("%d %d",&n,&m); for(i=0; i<n; i++) { scanf("%s",&s[i]); // for(j=0; j<m; j++) // { // if(s[i][j] == 'S') // { // stn = i; // stm = j; // } // } } for(i=0; i<n; i++) { for(j=0; j<m; j++) { di[i][j] = mav; if(s[i][j] == 'S') { stn = i; stm = j; } if(s[i][j] != '#') { if(i == 0 || i == n-1 || j == 0 || j == m-1 || s[i-1][j] == '#' || s[i+1][j] == '#' || s[i][j-1] == '#' || s[i][j+1] == '#') { fq.push({i,j,0}); fw[i][j] = 0; u[i][j] = 1; } } } } while(!fq.empty()) { cn = fq.front().nn; cm = fq.front().mm; cdi = fq.front().dis; fq.pop(); for(i=0; i<4; i++) { fn = cn + dn[i]; fm = cm + dm[i]; if(fn < 0 || fn > n-1 || fm < 0 || fm > m-1 || s[fn][fm] == '#' || u[fn][fm] == 1) continue; u[fn][fm] = 1; fw[fn][fm] = cdi + 1; fq.push({fn,fm,cdi + 1}); } } for(i=0; i<n; i++) { sta = 0; for(j=0; j<m; j++) { if(sta == 0) { if(s[i][j] != '#') { cn = i; cm = j; sta = 1; jn[0][i][j] = {cn,cm}; } } else { if(s[i][j] != '#') { jn[0][i][j] = {cn,cm}; } else { sta = 0; } } } } for(i=0; i<n; i++) { sta = 0; for(j=m-1; j>=0; j--) { if(sta == 0) { if(s[i][j] != '#') { cn = i; cm = j; sta = 1; jn[1][i][j] = {cn,cm}; } } else { if(s[i][j] != '#') { jn[1][i][j] = {cn,cm}; } else { sta = 0; } } } } for(j=0; j<m; j++) { sta = 0; for(i=0; i<n; i++) { if(sta == 0) { if(s[i][j] != '#') { cn = i; cm = j; sta = 1; jn[2][i][j] = {cn,cm}; } } else { if(s[i][j] != '#') { jn[2][i][j] = {cn,cm}; } else { sta = 0; } } } } for(j=0; j<m; j++) { sta = 0; for(i=n-1; i>=0; i--) { if(sta == 0) { if(s[i][j] != '#') { cn = i; cm = j; sta = 1; jn[3][i][j] = {cn,cm}; } } else { if(s[i][j] != '#') { jn[3][i][j] = {cn,cm}; } else { sta = 0; } } } } qu.push({stn,stm,0}); di[stn][stm] = 0; while(!qu.empty()) { cn = qu.top().nn; cm = qu.top().mm; cdi = qu.top().dis; qu.pop(); if(di[cn][cm] != cdi) continue; if(s[cn][cm] == 'C') break; for(i=0; i<4; i++) { fn = cn + dn[i]; fm = cm + dm[i]; if(fn < 0 || fn >= n || fm < 0 || fm >= m || s[fn][fm] == '#' || cdi + 1 >= di[fn][fm]) { continue; } di[fn][fm] = cdi + 1; qu.push({fn,fm,cdi + 1}); } for(i=0; i<4; i++) { fn = jn[i][cn][cm].nn; fm = jn[i][cn][cm].mm; if(cdi + 1 + fw[cn][cm] < di[fn][fm]) { di[fn][fm] = cdi + 1 + fw[cn][cm]; qu.push({fn,fm,di[fn][fm]}); } } } printf("%d\n",cdi); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 568 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 1 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 596 KB | Output is correct |
8 | Correct | 1 ms | 568 KB | Output is correct |
9 | Correct | 1 ms | 432 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 596 KB | Output is correct |
3 | Correct | 1 ms | 560 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 736 KB | Output is correct |
6 | Correct | 1 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 596 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
9 | Correct | 2 ms | 1876 KB | Output is correct |
10 | Correct | 1 ms | 1748 KB | Output is correct |
11 | Correct | 2 ms | 1876 KB | Output is correct |
12 | Correct | 1 ms | 1876 KB | Output is correct |
13 | Correct | 2 ms | 1880 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 1 ms | 1752 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 304 KB | Output is correct |
2 | Correct | 1 ms | 596 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 596 KB | Output is correct |
5 | Correct | 8 ms | 7616 KB | Output is correct |
6 | Correct | 9 ms | 7708 KB | Output is correct |
7 | Correct | 7 ms | 7636 KB | Output is correct |
8 | Correct | 5 ms | 7636 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 568 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 1 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 564 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
9 | Correct | 2 ms | 1748 KB | Output is correct |
10 | Correct | 2 ms | 1748 KB | Output is correct |
11 | Correct | 1 ms | 1876 KB | Output is correct |
12 | Correct | 1 ms | 1876 KB | Output is correct |
13 | Correct | 1 ms | 1876 KB | Output is correct |
14 | Correct | 8 ms | 7620 KB | Output is correct |
15 | Correct | 8 ms | 7708 KB | Output is correct |
16 | Correct | 7 ms | 7636 KB | Output is correct |
17 | Correct | 6 ms | 7636 KB | Output is correct |
18 | Correct | 10 ms | 7548 KB | Output is correct |
19 | Correct | 5 ms | 7380 KB | Output is correct |
20 | Correct | 7 ms | 7360 KB | Output is correct |
21 | Correct | 7 ms | 7636 KB | Output is correct |
22 | Correct | 8 ms | 7636 KB | Output is correct |
23 | Correct | 8 ms | 7616 KB | Output is correct |
24 | Correct | 8 ms | 7444 KB | Output is correct |
25 | Correct | 1 ms | 468 KB | Output is correct |
26 | Correct | 1 ms | 1748 KB | Output is correct |
27 | Correct | 0 ms | 340 KB | Output is correct |
28 | Correct | 5 ms | 7704 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 304 KB | Output is correct |
2 | Correct | 1 ms | 564 KB | Output is correct |
3 | Correct | 1 ms | 596 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 596 KB | Output is correct |
6 | Correct | 1 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 596 KB | Output is correct |
8 | Correct | 1 ms | 596 KB | Output is correct |
9 | Correct | 1 ms | 1748 KB | Output is correct |
10 | Correct | 1 ms | 1748 KB | Output is correct |
11 | Correct | 1 ms | 1876 KB | Output is correct |
12 | Correct | 1 ms | 1876 KB | Output is correct |
13 | Correct | 1 ms | 1848 KB | Output is correct |
14 | Correct | 7 ms | 7656 KB | Output is correct |
15 | Correct | 7 ms | 7704 KB | Output is correct |
16 | Correct | 7 ms | 7636 KB | Output is correct |
17 | Correct | 6 ms | 7636 KB | Output is correct |
18 | Correct | 7 ms | 7636 KB | Output is correct |
19 | Correct | 4 ms | 7380 KB | Output is correct |
20 | Correct | 7 ms | 7380 KB | Output is correct |
21 | Correct | 7 ms | 7636 KB | Output is correct |
22 | Correct | 7 ms | 7616 KB | Output is correct |
23 | Correct | 8 ms | 7704 KB | Output is correct |
24 | Correct | 134 ms | 51668 KB | Output is correct |
25 | Correct | 257 ms | 46204 KB | Output is correct |
26 | Correct | 71 ms | 45772 KB | Output is correct |
27 | Correct | 139 ms | 45992 KB | Output is correct |
28 | Correct | 118 ms | 52664 KB | Output is correct |
29 | Correct | 133 ms | 52816 KB | Output is correct |
30 | Correct | 133 ms | 52828 KB | Output is correct |
31 | Correct | 8 ms | 7380 KB | Output is correct |
32 | Correct | 212 ms | 45876 KB | Output is correct |
33 | Correct | 1 ms | 468 KB | Output is correct |
34 | Correct | 1 ms | 1748 KB | Output is correct |
35 | Correct | 118 ms | 47776 KB | Output is correct |
36 | Correct | 1 ms | 340 KB | Output is correct |
37 | Correct | 5 ms | 7624 KB | Output is correct |
38 | Correct | 84 ms | 53740 KB | Output is correct |
39 | Correct | 85 ms | 43892 KB | Output is correct |