Submission #1107902

#TimeUsernameProblemLanguageResultExecution timeMemory
11079020pt1mus23Tracks in the Snow (BOI13_tracks)C++14
0 / 100
1461 ms267608 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int #define ins insert #define pb push_back #define endl '\n' #define putr(x) cout<<x<<endl;return; #define all(x) x.begin(),x.end() const int mod = 1e9 +7, sze = 1e5 +5, inf = INT_MAX, LL = 30; int comp[4005][4005]; int used[4005][4005]; const int dx[4] = {-1,1,0,0}; const int dy[4] = {0,0,-1,1}; void rush(){ int n,m; cin>>n>>m; vector<vector<char>> arr(n,vector<char>(m)); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>arr[i][j]; comp[i][j]=-1; } } int ans=0; queue<pair<pair<int,int>,int>> q; q.push({{0,0},1}); comp[0][0]=1; int cnt=1; while(!q.empty()){ auto node = q.front(); q.pop(); if(used[node.first.first][node.first.second]){ continue; } ans=max(ans,node.second); used[node.first.first][node.first.second]=1; for(int i=0;i<4;i++){ int a = node.first.first + dx[i]; int b = node.first.second + dy[i]; if(a>=0 && a<n && b>=0 && b<m){ if(arr[a][b]!='.'){ if(!comp[a][b]){ if(arr[a][b]==arr[node.first.first][node.first.second]){ comp[a][b]= comp[node.first.first][node.first.second]; } else{ comp[a][b]=++cnt; } } if(comp[a][b]!=comp[node.first.first][node.first.second]){ q.push({{a,b}, node.second +1}); } else{ q.push({{a,b}, node.second}); } } else{ q.push({{a,b},node.second}); } } } } putr(ans); } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin>>tt; while(tt--){ rush(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...