Submission #904014

# Submission time Handle Problem Language Result Execution time Memory
904014 2024-01-11T17:14:16 Z vjudge1 Zoo (COCI19_zoo) C++17
45 / 110
2000 ms 5748 KB
#include<bits/stdc++.h>
using namespace std;
int n, m;
bool check(int i, int j){
  return (i >= 0 && i < n && j >= 0 && j < m);
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	vector<vector<char>>grid(n, vector<char>(m));
	for(int i = 0;i < n;++i){
		for(int j = 0;j < m;++j){
			cin >> grid[i][j];
		}
	}
	vector<vector<int>>dist(n, vector<int>(m, 1e9));
	dist[0][0] = 0;
	queue<pair<int, int>>q;
	q.push({0, 0});
	while(!q.empty()){
		int x = q.front().first, y = q.front().second;
		q.pop();
        for(int i = 0;i < 4;++i){
        	int cur_x = x + dx[i], cur_y = y + dy[i];
        	if(check(cur_x, cur_y) && dist[cur_x][cur_y] > dist[x][y] + (grid[x][y] != grid[cur_x][cur_y]) && grid[cur_x][cur_y] != '*'){
        		q.push({cur_x, cur_y});
        		dist[cur_x][cur_y] = dist[x][y] + (grid[x][y] != grid[cur_x][cur_y]);
        	}
        }
	}
	int mx = 0;
	for(int i = 0;i < n;++i){
		for(int j = 0;j < m;++j){
			if(dist[i][j] != 1e9)mx = max(mx, dist[i][j]);
		}
	}
	cout << mx + 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 360 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 2 ms 360 KB Output is correct
13 Correct 1 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 2 ms 508 KB Output is correct
10 Correct 2 ms 360 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 2 ms 360 KB Output is correct
13 Correct 1 ms 360 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 25 ms 5212 KB Output is correct
17 Correct 31 ms 5000 KB Output is correct
18 Correct 22 ms 5208 KB Output is correct
19 Correct 35 ms 5300 KB Output is correct
20 Correct 30 ms 4956 KB Output is correct
21 Execution timed out 2066 ms 5748 KB Time limit exceeded
22 Halted 0 ms 0 KB -