Submission #704792

#TimeUsernameProblemLanguageResultExecution timeMemory
704792pccZoo (COCI19_zoo)C++14
0 / 110
2081 ms340 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...