답안 #58747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58747 2018-07-19T07:25:05 Z Batrr Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1671 ms 44264 KB
#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long                   
#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 
#define IOS ios_base::sync_with_stdio(0);

using namespace std;                    

const ll maxn=2e5+123,inf=1e18,mod=1e9+7,N=1e7+12,LOG=20;

int n,m,ans;
pair<int,int> dir[]={{0,-1},{-1,0},{1,0},{0,1}};
bool was[4001][4001];
string s[4001];
bool check(int x,int y){
    if(x<0 || x>=n || y<0 || y>=m || s[x][y]=='.')
        return 0;
     return 1;
}
int main(){
    #ifdef LOCAL
        freopen ("test.in", "r", stdin);
    #endif
    IOS
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>s[i];
    queue< pair<int,int> > q1,q2;
    q1.push({0,0});
    was[0][0]=1;
    while(true){
        while(!q1.empty()){
            int x=q1.front().f,y=q1.front().s;
            q1.pop();
            for(int i=0;i<4;i++){
                int nx=x+dir[i].f,ny=y+dir[i].s;
                if( check(nx,ny) && !was[nx][ny] ){     
                    if(s[x][y]==s[nx][ny])
                        q1.push({nx,ny});
                     else
                        q2.push({nx,ny});             
                    was[nx][ny]=1;
                }
            }
        }
        ans++;
        if(q2.empty())
            break;
        swap(q1,q2);
    }            
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2680 KB Output is correct
2 Correct 2 ms 2680 KB Output is correct
3 Correct 3 ms 2680 KB Output is correct
4 Correct 14 ms 2900 KB Output is correct
5 Correct 6 ms 2900 KB Output is correct
6 Correct 3 ms 2900 KB Output is correct
7 Correct 3 ms 2900 KB Output is correct
8 Correct 3 ms 2900 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 6 ms 2900 KB Output is correct
11 Correct 5 ms 2900 KB Output is correct
12 Correct 10 ms 2900 KB Output is correct
13 Correct 6 ms 2900 KB Output is correct
14 Correct 6 ms 2900 KB Output is correct
15 Correct 24 ms 2924 KB Output is correct
16 Correct 19 ms 2924 KB Output is correct
17 Correct 20 ms 2924 KB Output is correct
18 Correct 13 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 15596 KB Output is correct
2 Correct 83 ms 15596 KB Output is correct
3 Correct 293 ms 34076 KB Output is correct
4 Correct 92 ms 34076 KB Output is correct
5 Correct 227 ms 34076 KB Output is correct
6 Correct 1543 ms 44264 KB Output is correct
7 Correct 27 ms 44264 KB Output is correct
8 Correct 22 ms 44264 KB Output is correct
9 Correct 4 ms 44264 KB Output is correct
10 Correct 3 ms 44264 KB Output is correct
11 Correct 21 ms 44264 KB Output is correct
12 Correct 4 ms 44264 KB Output is correct
13 Correct 69 ms 44264 KB Output is correct
14 Correct 37 ms 44264 KB Output is correct
15 Correct 30 ms 44264 KB Output is correct
16 Correct 31 ms 44264 KB Output is correct
17 Correct 166 ms 44264 KB Output is correct
18 Correct 111 ms 44264 KB Output is correct
19 Correct 118 ms 44264 KB Output is correct
20 Correct 69 ms 44264 KB Output is correct
21 Correct 168 ms 44264 KB Output is correct
22 Correct 236 ms 44264 KB Output is correct
23 Correct 336 ms 44264 KB Output is correct
24 Correct 168 ms 44264 KB Output is correct
25 Correct 436 ms 44264 KB Output is correct
26 Correct 912 ms 44264 KB Output is correct
27 Correct 1273 ms 44264 KB Output is correct
28 Correct 1671 ms 44264 KB Output is correct
29 Correct 1590 ms 44264 KB Output is correct
30 Correct 1460 ms 44264 KB Output is correct
31 Correct 1088 ms 44264 KB Output is correct
32 Correct 1151 ms 44264 KB Output is correct