Submission #831880

#TimeUsernameProblemLanguageResultExecution timeMemory
831880GordonRemzi007Game (eJOI20_game)C++17
0 / 100
1 ms300 KiB
#include <bits/stdc++.h> using namespace std; int n, m, cnt, loop; vector<string> h, v; vector<vector<bool>> visited; struct Pos { Pos(int xi, int yi):x(xi),y(yi){} int x, y; }; Pos temp(0, 0); queue<Pos> q; vector<Pos> c; bool srt(Pos a, Pos b) { return a.x < b.x; } int main() { cin >> n >> m; h = vector<string>(n+1), v = vector<string>(n), visited = vector<vector<bool>>(n, vector<bool>(m, false)); for(int i = 0; i <= n; i++) cin >> h[i]; for(int i = 0; i < n; i++) cin >> v[i]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(!visited[i][j] && (h[i][j] == '0' || h[i+1][j] == '0' || v[i][j] == '0' || v[i][j+1] == '0')) { cnt = 0, loop = 1; q.push({i, j}); while(q.size()) { temp = q.front(); q.pop(); if(visited[temp.x][temp.y]) continue; cnt++; visited[temp.x][temp.y] = true; if((temp.x == 0 && h[temp.x][temp.y] == '0') || (temp.x == n-1 && h[temp.x+1][temp.y] == '0') || (temp.y == 0 && v[temp.x][temp.y] == '0') || (temp.y == m-1 && v[temp.x][temp.y+1] == '0')) loop = 0; if(temp.x > 0 && h[temp.x][temp.y] == '0' && !visited[temp.x-1][temp.y]) q.push(Pos(temp.x-1, temp.y)); if(temp.x < n-1 && h[temp.x+1][temp.y] == '0' && !visited[temp.x+1][temp.y]) q.push(Pos(temp.x+1, temp.y)); if(temp.y > 0 && v[temp.x][temp.y] == '0' && !visited[temp.x][temp.y-1]) q.push(Pos(temp.x, temp.y-1)); if(temp.y < m-1 && v[temp.x][temp.y+1] == '0' && !visited[temp.x][temp.y+1]) q.push(Pos(temp.x, temp.y+1)); } c.push_back(Pos(cnt, loop)); } } } sort(c.begin(), c.end(), srt); //for(auto i : c) cout << i.x << " " << i.y << "\n"; cout << max(min((c[0].y ? 8 : 4)-c[0].x-c[1].x, c[1].x-c[0].x), min((c[1].y ? 8 : 4)-c[0].x-c[1].x, c[0].x-c[1].x)) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...