답안 #468388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468388 2021-08-27T23:27:44 Z Dan4Life Tracks in the Snow (BOI13_tracks) C++17
100 / 100
642 ms 235956 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, depth[4001][4001];
int X[] = {1, -1, 0, 0};
int Y[] = {0, 0, 1, -1};
string a[4001];

bool inside(int i, int j)
{
    if(i<0 or j<0 or i>=n or j>=m or a[i][j]=='.') return false;
    return true;
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> a[i];
    depth[0][0]=1;
    deque<pair<int,int>> Q;
    Q.push_back({0,0}); int ans = 0;
    while(!Q.empty())
    {
        auto s = Q.front(); Q.pop_front();
        int x = s.first, y = s.second;
        ans = max(ans, depth[x][y]);
        for(int i = 0; i < 4; i++)
        {
            int nx = x+X[i], ny = y+Y[i];
            if(inside(nx,ny) and depth[nx][ny]==0){
                if(a[x][y]==a[nx][ny]){
                    depth[nx][ny]=depth[x][y];
                    Q.push_front({nx,ny});
                }
                else{
                    depth[nx][ny]=1+depth[x][y];
                    Q.push_back({nx,ny});
                }
            }
        }
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 4812 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 8 ms 4328 KB Output is correct
5 Correct 3 ms 2252 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 844 KB Output is correct
10 Correct 3 ms 1868 KB Output is correct
11 Correct 3 ms 1740 KB Output is correct
12 Correct 5 ms 2508 KB Output is correct
13 Correct 3 ms 2252 KB Output is correct
14 Correct 3 ms 2252 KB Output is correct
15 Correct 11 ms 4456 KB Output is correct
16 Correct 13 ms 4808 KB Output is correct
17 Correct 9 ms 4556 KB Output is correct
18 Correct 10 ms 4300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16204 KB Output is correct
2 Correct 40 ms 15072 KB Output is correct
3 Correct 195 ms 93432 KB Output is correct
4 Correct 77 ms 43052 KB Output is correct
5 Correct 167 ms 69348 KB Output is correct
6 Correct 642 ms 186168 KB Output is correct
7 Correct 12 ms 16844 KB Output is correct
8 Correct 11 ms 16152 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 12 ms 16460 KB Output is correct
12 Correct 2 ms 1228 KB Output is correct
13 Correct 40 ms 15132 KB Output is correct
14 Correct 24 ms 9924 KB Output is correct
15 Correct 23 ms 14204 KB Output is correct
16 Correct 20 ms 6464 KB Output is correct
17 Correct 102 ms 32748 KB Output is correct
18 Correct 92 ms 47792 KB Output is correct
19 Correct 76 ms 43052 KB Output is correct
20 Correct 53 ms 27208 KB Output is correct
21 Correct 123 ms 61116 KB Output is correct
22 Correct 164 ms 69252 KB Output is correct
23 Correct 198 ms 56516 KB Output is correct
24 Correct 128 ms 59260 KB Output is correct
25 Correct 523 ms 158916 KB Output is correct
26 Correct 390 ms 235956 KB Output is correct
27 Correct 504 ms 212176 KB Output is correct
28 Correct 633 ms 186164 KB Output is correct
29 Correct 639 ms 182984 KB Output is correct
30 Correct 577 ms 191508 KB Output is correct
31 Correct 572 ms 115328 KB Output is correct
32 Correct 442 ms 183436 KB Output is correct