This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
const int MAXL = 1005;
int h,w;
char track[MAXL][MAXL];
bool check[MAXL][MAXL];
vector<pair<int,int>> p={{1,1}},p2;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> h >> w;
for(int i=1;i<=h;i++){
string a;
cin >> a;
for(int j=0;j<w;j++){
track[i][j+1] = a[j];
}
}
char st=track[1][1];
check[1][1] = true;
for(int i=0;i<p.size();i++){
int x=p[i].first,y=p[i].second;
if(track[x-1][y]==st and not check[x-1][y]){
p.push_back({x-1,y});
check[x-1][y] = true;
}
if(track[x+1][y]==st and not check[x+1][y]){
p.push_back({x+1,y});
check[x+1][y] = true;
}
if(track[x][y-1]==st and not check[x][y-1]){
p.push_back({x,y-1});
check[x][y-1] = true;
}
if(track[x][y+1]==st and not check[x][y+1]){
p.push_back({x,y+1});
check[x][y+1] = true;
}
}
int cnt=0;
while(p.size()>0){
if(st=='T'){
st = 'B';
}
else{
st = 'T';
}
p2 = {};
for(int i=0;i<p.size();i++){
int x=p[i].first,y=p[i].second;
if(track[x-1][y]==st and not check[x-1][y]){
p2.push_back({x-1,y});
check[x-1][y] = true;
}
if(track[x+1][y]==st and not check[x+1][y]){
p2.push_back({x+1,y});
check[x+1][y] = true;
}
if(track[x][y-1]==st and not check[x][y-1]){
p2.push_back({x,y-1});
check[x][y-1] = true;
}
if(track[x][y+1]==st and not check[x][y+1]){
p2.push_back({x,y+1});
check[x][y+1] = true;
}
}
p = p2;
for(int i=0;i<p.size();i++){
int x=p[i].first,y=p[i].second;
if(track[x-1][y]==st and not check[x-1][y]){
p.push_back({x-1,y});
check[x-1][y] = true;
}
if(track[x+1][y]==st and not check[x+1][y]){
p.push_back({x+1,y});
check[x+1][y] = true;
}
if(track[x][y-1]==st and not check[x][y-1]){
p.push_back({x,y-1});
check[x][y-1] = true;
}
if(track[x][y+1]==st and not check[x][y+1]){
p.push_back({x,y+1});
check[x][y+1] = true;
}
}
cnt++;
}
cout << cnt;
return 0;
}
Compilation message (stderr)
zoo.cpp: In function 'int main()':
zoo.cpp:25:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
zoo.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
zoo.cpp:73:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |