답안 #205741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205741 2020-02-29T16:19:26 Z mayhoubsaleh Zoo (COCI19_zoo) C++14
45 / 110
2000 ms 7992 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mid (l+r)/2
#define left 2*i+1
#define righ 2*i+2

using namespace std;
int n,m,cnt;
char c[1010][1010];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dfs(int x,int y){
    int ret=1;
    char cur=c[x][y];
    if(c[x][y]=='B')c[x][y]='T';
    else c[x][y]='B';
    for(int i=0;i<4;i++){
        int tox=x+dx[i],toy=y+dy[i];
        if(tox<1||tox>n||toy<1||toy>m)continue;
        if(cur!=c[tox][toy])continue;
        ret+=dfs(tox,toy);
    }
    return ret;
}
int ans;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>c[i][j];
            if(c[i][j]!='*')cnt++;
        }
    }

    while(dfs(1,1)!=cnt)ans++;
    cout<<ans+1<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 10 ms 504 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 9 ms 504 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 10 ms 504 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 11 ms 504 KB Output is correct
13 Correct 9 ms 504 KB Output is correct
14 Correct 9 ms 504 KB Output is correct
15 Correct 9 ms 504 KB Output is correct
16 Correct 92 ms 3320 KB Output is correct
17 Correct 92 ms 3448 KB Output is correct
18 Correct 93 ms 3192 KB Output is correct
19 Correct 98 ms 3960 KB Output is correct
20 Correct 92 ms 3064 KB Output is correct
21 Execution timed out 2062 ms 7992 KB Time limit exceeded
22 Halted 0 ms 0 KB -