Submission #205662

#TimeUsernameProblemLanguageResultExecution timeMemory
205662mraronZoo (COCI19_zoo)C++14
110 / 110
75 ms7288 KiB
//0-1 bfs-sel szebb lett volna... #include<bits/stdc++.h> using namespace std; int n,m; string t[1001]; int ans; int d[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; int volt[1001][1001]; vector<pair<int,int>> lst; void dfs(int x, int y, int cnt) { assert(volt[x][y]==0); volt[x][y]=cnt; ans=max(ans, cnt); for(int i=0;i<4;++i) { int nx=x+d[i][0], ny=y+d[i][1]; if(nx>=0 && ny>=0 && nx<n && ny<m && !volt[nx][ny]) { if(t[nx][ny]==t[x][y]) dfs(nx,ny,cnt); } } for(int i=0;i<4;++i) { int nx=x+d[i][0], ny=y+d[i][1]; if(nx>=0 && ny>=0 && nx<n && ny<m && !volt[nx][ny]) { if(t[nx][ny]!=t[x][y] && t[nx][ny]!='*') lst.push_back({nx,ny}); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0;i<n;++i) cin>>t[i]; lst={{n-1,m-1}}; do { vector<pair<int,int>> kell=lst; lst.clear(); ans++; for(auto i:kell) { if(!volt[i.first][i.second]) dfs(i.first,i.second,ans); } }while(!lst.empty()); cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...