# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
904015 |
2024-01-11T17:16:31 Z |
vjudge1 |
Zoo (COCI19_zoo) |
C++17 |
|
59 ms |
6496 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;
deque<pair<int, int>>q;
q.push_front({0, 0});
while(!q.empty()){
int x = q.front().first, y = q.front().second;
q.pop_front();
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] != '*'){
if(grid[x][y] != grid[cur_x][cur_y])q.push_back({cur_x, cur_y});
else q.push_front({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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
22 ms |
5980 KB |
Output is correct |
17 |
Correct |
15 ms |
5980 KB |
Output is correct |
18 |
Correct |
15 ms |
6072 KB |
Output is correct |
19 |
Correct |
18 ms |
5992 KB |
Output is correct |
20 |
Correct |
15 ms |
5972 KB |
Output is correct |
21 |
Correct |
43 ms |
5832 KB |
Output is correct |
22 |
Correct |
43 ms |
5748 KB |
Output is correct |
23 |
Correct |
44 ms |
6032 KB |
Output is correct |
24 |
Correct |
52 ms |
6496 KB |
Output is correct |
25 |
Correct |
47 ms |
5980 KB |
Output is correct |
26 |
Correct |
45 ms |
6008 KB |
Output is correct |
27 |
Correct |
55 ms |
5988 KB |
Output is correct |
28 |
Correct |
42 ms |
5728 KB |
Output is correct |
29 |
Correct |
52 ms |
6236 KB |
Output is correct |
30 |
Correct |
59 ms |
5972 KB |
Output is correct |