답안 #44866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44866 2018-04-08T19:48:47 Z iletavcioski Tracks in the Snow (BOI13_tracks) C++17
91.25 / 100
2000 ms 1048576 KB
#include <iostream>
#include <queue>
using namespace std;
int n,m;
char mat[4004][4004];
bool vis[4004][4004];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int brojac;
void bfs(queue<pair<int,int> > q1,queue<pair<int,int> > q2,int broj)
{
    if(q1.empty())
        return;
    brojac=broj;
    while(!q1.empty())
    {
        pair<int,int> g=q1.front();
        q1.pop();
        for(int i=0;i<4;i++)
        {
            if(g.first+dx[i]<n&&g.first+dx[i]>=0&&g.second+dy[i]<m&&g.second+dy[i]>=0)
            {
                if(!vis[g.first+dx[i]][g.second+dy[i]]&&mat[g.first+dx[i]][g.second+dy[i]]!='.')
                {
                    if(mat[g.first+dx[i]][g.second+dy[i]]!=mat[g.first][g.second])
                    {
                        q2.push(make_pair(g.first+dx[i],g.second+dy[i]));
                        vis[g.first+dx[i]][g.second+dy[i]]=true;
                    }
                    else
                    {
                        q1.push(make_pair(g.first+dx[i],g.second+dy[i]));
                        vis[g.first+dx[i]][g.second+dy[i]]=true;
                    }
                }
            }
        }
    }
    bfs(q2,q1,broj+1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>mat[i];
    }
    queue<pair<int,int> > q1,q2;
    q1.push(make_pair(0,0));
    vis[0][0]=true;
    bfs(q1,q2,1);
    cout<<brojac<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 5496 KB Output is correct
2 Correct 2 ms 5496 KB Output is correct
3 Correct 2 ms 5496 KB Output is correct
4 Correct 11 ms 5496 KB Output is correct
5 Correct 5 ms 5496 KB Output is correct
6 Correct 2 ms 5496 KB Output is correct
7 Correct 2 ms 5496 KB Output is correct
8 Correct 3 ms 5496 KB Output is correct
9 Correct 3 ms 5496 KB Output is correct
10 Correct 5 ms 5496 KB Output is correct
11 Correct 5 ms 5496 KB Output is correct
12 Correct 8 ms 5496 KB Output is correct
13 Correct 5 ms 5496 KB Output is correct
14 Correct 5 ms 5496 KB Output is correct
15 Correct 16 ms 6448 KB Output is correct
16 Correct 18 ms 6788 KB Output is correct
17 Correct 13 ms 6788 KB Output is correct
18 Correct 11 ms 6788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 39656 KB Output is correct
2 Correct 60 ms 39656 KB Output is correct
3 Correct 960 ms 900556 KB Output is correct
4 Correct 71 ms 900556 KB Output is correct
5 Execution timed out 2120 ms 1048576 KB Time limit exceeded
6 Correct 1026 ms 1048576 KB Output is correct
7 Correct 32 ms 1048576 KB Output is correct
8 Correct 32 ms 1048576 KB Output is correct
9 Correct 4 ms 1048576 KB Output is correct
10 Correct 5 ms 1048576 KB Output is correct
11 Correct 28 ms 1048576 KB Output is correct
12 Correct 17 ms 1048576 KB Output is correct
13 Correct 62 ms 1048576 KB Output is correct
14 Correct 36 ms 1048576 KB Output is correct
15 Correct 208 ms 1048576 KB Output is correct
16 Correct 29 ms 1048576 KB Output is correct
17 Correct 159 ms 1048576 KB Output is correct
18 Correct 833 ms 1048576 KB Output is correct
19 Correct 73 ms 1048576 KB Output is correct
20 Correct 207 ms 1048576 KB Output is correct
21 Correct 558 ms 1048576 KB Output is correct
22 Execution timed out 2096 ms 1048576 KB Time limit exceeded
23 Correct 309 ms 1048576 KB Output is correct
24 Execution timed out 2122 ms 1048576 KB Time limit exceeded
25 Execution timed out 2094 ms 1048576 KB Time limit exceeded
26 Correct 692 ms 1048576 KB Output is correct
27 Correct 770 ms 1048576 KB Output is correct
28 Correct 1049 ms 1048576 KB Output is correct
29 Correct 987 ms 1048576 KB Output is correct
30 Correct 854 ms 1048576 KB Output is correct
31 Correct 782 ms 1048576 KB Output is correct
32 Correct 630 ms 1048576 KB Output is correct