답안 #101427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101427 2019-03-19T01:47:01 Z dwsc Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1213 ms 134948 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> i3;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    char grid[h][w];
    int visit[h][w];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
            visit[i][j] = 0;
        }
    }
    deque<i3> dq;
    int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
    int ans = 1;
    visit[0][0] = 1;
    dq.push_front(i3(1,ii(0,0)));
    while (!dq.empty()){
        i3 f = dq.front();
        dq.pop_front();
        int num = f.first,x = f.second.first,y = f.second.second;
        for (int i = 0; i < 4; i++){
            int nx = x+dx[i],ny = y+dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (grid[nx][ny] == '.') continue;
            if (visit[nx][ny]) continue;
            visit[nx][ny] = 1;
            int nnum = num;
            if (grid[x][y] != grid[nx][ny]) {
                nnum++;
                dq.push_back(i3(nnum,ii(nx,ny)));
            }
            else dq.push_front(i3(nnum,ii(nx,ny)));
            ans = max(ans,nnum);
        }
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1792 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 15 ms 1536 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 7 ms 896 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 5 ms 896 KB Output is correct
15 Correct 18 ms 1880 KB Output is correct
16 Correct 21 ms 1864 KB Output is correct
17 Correct 14 ms 1664 KB Output is correct
18 Correct 10 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 62 ms 8616 KB Output is correct
3 Correct 430 ms 79144 KB Output is correct
4 Correct 115 ms 19324 KB Output is correct
5 Correct 270 ms 44796 KB Output is correct
6 Correct 1073 ms 99960 KB Output is correct
7 Correct 4 ms 640 KB Output is correct
8 Correct 3 ms 688 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 4 ms 640 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 65 ms 8748 KB Output is correct
14 Correct 34 ms 5376 KB Output is correct
15 Correct 31 ms 5900 KB Output is correct
16 Correct 31 ms 3976 KB Output is correct
17 Correct 169 ms 20796 KB Output is correct
18 Correct 150 ms 20456 KB Output is correct
19 Correct 139 ms 19320 KB Output is correct
20 Correct 94 ms 17752 KB Output is correct
21 Correct 219 ms 46380 KB Output is correct
22 Correct 255 ms 44904 KB Output is correct
23 Correct 277 ms 38776 KB Output is correct
24 Correct 284 ms 45432 KB Output is correct
25 Correct 575 ms 79140 KB Output is correct
26 Correct 576 ms 134948 KB Output is correct
27 Correct 922 ms 130280 KB Output is correct
28 Correct 1213 ms 99908 KB Output is correct
29 Correct 1171 ms 96332 KB Output is correct
30 Correct 1022 ms 106068 KB Output is correct
31 Correct 795 ms 51716 KB Output is correct
32 Correct 774 ms 115076 KB Output is correct