Submission #904014

#TimeUsernameProblemLanguageResultExecution timeMemory
904014vjudge1Zoo (COCI19_zoo)C++17
45 / 110
2066 ms5748 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...