Submission #831880

# Submission time Handle Problem Language Result Execution time Memory
831880 2023-08-20T16:40:40 Z GordonRemzi007 Game (eJOI20_game) C++17
0 / 100
1 ms 300 KB
#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 time Memory Grader output
1 Incorrect 1 ms 300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 300 KB Output isn't correct
2 Halted 0 ms 0 KB -