답안 #344801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344801 2021-01-06T14:56:49 Z JovanK26 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1084 ms 978416 KB
#include <bits/stdc++.h>

using namespace std;
int n,m;
string mat[4000];
int addc[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
vector< array<int,2> > pt[2];
int rez=0;
bool check(int i,int j)
{
    if(i<0 || i>=n || j<0 || j>=m || mat[i][j]=='.')return 0;
    return 1;
}
void dfs(int x,int y)
{
    char cur=mat[x][y];
    mat[x][y]='.';
    for(int i=0;i<4;i++)
    {
        int c1=x+addc[i][0];
        int c2=y+addc[i][1];
        if(!check(c1,c2))
        {
            continue;
        }
        if(mat[c1][c2]==cur)
        {
            dfs(c1,c2);
        }
        else
        {
            pt[(rez&1)^1].push_back({c1,c2});
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i=0;i<n;i++)
    {
        cin >> mat[i];
    }
    pt[rez&1].push_back({0,0});
    while(pt[rez&1].size())
    {
        for(array<int,2> p : pt[rez&1])
        {
            if(check(p[0],p[1]))
            {
                dfs(p[0],p[1]);
            }
        }
        pt[rez&1].clear();
        rez++;
    }
    cout << rez;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1388 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 8 ms 2288 KB Output is correct
5 Correct 3 ms 748 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 3 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 10 ms 1260 KB Output is correct
16 Correct 13 ms 1388 KB Output is correct
17 Correct 8 ms 1132 KB Output is correct
18 Correct 7 ms 2436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 34 ms 4076 KB Output is correct
3 Correct 168 ms 23148 KB Output is correct
4 Correct 35 ms 6380 KB Output is correct
5 Correct 145 ms 13932 KB Output is correct
6 Correct 626 ms 101504 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 1 ms 876 KB Output is correct
11 Correct 2 ms 876 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 33 ms 3948 KB Output is correct
14 Correct 19 ms 2540 KB Output is correct
15 Correct 12 ms 2668 KB Output is correct
16 Correct 18 ms 2028 KB Output is correct
17 Correct 90 ms 7020 KB Output is correct
18 Correct 53 ms 6636 KB Output is correct
19 Correct 37 ms 6508 KB Output is correct
20 Correct 40 ms 5996 KB Output is correct
21 Correct 102 ms 14076 KB Output is correct
22 Correct 144 ms 13804 KB Output is correct
23 Correct 175 ms 13036 KB Output is correct
24 Correct 103 ms 13676 KB Output is correct
25 Correct 259 ms 23276 KB Output is correct
26 Correct 1084 ms 978416 KB Output is correct
27 Correct 794 ms 552344 KB Output is correct
28 Correct 631 ms 97996 KB Output is correct
29 Correct 612 ms 134964 KB Output is correct
30 Correct 684 ms 247704 KB Output is correct
31 Correct 545 ms 14600 KB Output is correct
32 Correct 801 ms 504672 KB Output is correct