# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
704792 |
2023-03-03T03:16:24 Z |
pcc |
Zoo (COCI19_zoo) |
C++14 |
|
2000 ms |
340 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 101;
int arr[mxn][mxn];
int n,m;
int now;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
bool check(){
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(arr[i][j] != -1&&arr[i][j] != 2)return false;
}
}
return true;
}
bool vis[mxn][mxn];
void BFS(){
memset(vis,false,sizeof(vis));
queue<pair<int,int>> q;
q.push({1,1});
while(!q.empty()){
auto tmp = q.front();
q.pop();
for(int i= 0;i<4;i++){
auto nxt = make_pair(tmp.fs+dx[i],tmp.sc+dy[i]);
if(arr[nxt.fs][nxt.sc] != -1&&arr[nxt.fs][nxt.sc] != (now^1)&&!vis[nxt.fs][nxt.sc]){
arr[nxt.fs][nxt.sc] = 2;
vis[nxt.fs][nxt.sc] = true;
q.push(nxt);
}
}
}
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(auto &i:arr)for(auto &j:i)j = -1;
for(int i = 1;i<=n;i++){
for(int j= 1;j<=m;j++){
char c;
cin>>c;
arr[i][j] = (c == 'T'?0:(c == 'B'?1:-1));
}
}
now = arr[1][1];
int ans = 0;
while(!check()){
ans++;
BFS();
now^=1;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
2081 ms |
332 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Execution timed out |
2081 ms |
332 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |