Submission #205662

# Submission time Handle Problem Language Result Execution time Memory
205662 2020-02-29T11:47:09 Z mraron Zoo (COCI19_zoo) C++14
110 / 110
75 ms 7288 KB
//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 time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 760 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 6 ms 764 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 6 ms 888 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 6 ms 888 KB Output is correct
8 Correct 6 ms 760 KB Output is correct
9 Correct 6 ms 760 KB Output is correct
10 Correct 6 ms 760 KB Output is correct
11 Correct 6 ms 760 KB Output is correct
12 Correct 6 ms 764 KB Output is correct
13 Correct 6 ms 760 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 5 ms 760 KB Output is correct
16 Correct 16 ms 7032 KB Output is correct
17 Correct 17 ms 6904 KB Output is correct
18 Correct 16 ms 6904 KB Output is correct
19 Correct 18 ms 7288 KB Output is correct
20 Correct 17 ms 6904 KB Output is correct
21 Correct 70 ms 6264 KB Output is correct
22 Correct 67 ms 6392 KB Output is correct
23 Correct 67 ms 6392 KB Output is correct
24 Correct 71 ms 6648 KB Output is correct
25 Correct 69 ms 6692 KB Output is correct
26 Correct 71 ms 6332 KB Output is correct
27 Correct 66 ms 6520 KB Output is correct
28 Correct 69 ms 6264 KB Output is correct
29 Correct 75 ms 6572 KB Output is correct
30 Correct 67 ms 6444 KB Output is correct