Submission #747281

# Submission time Handle Problem Language Result Execution time Memory
747281 2023-05-24T03:42:54 Z Trunkty Zoo (COCI19_zoo) C++14
0 / 110
1 ms 224 KB
#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=='R'){
			st = 'F';
		}
		else{
			st = 'R';
		}
		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

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
1 Incorrect 1 ms 224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 224 KB Output isn't correct
2 Halted 0 ms 0 KB -