Submission #831575

# Submission time Handle Problem Language Result Execution time Memory
831575 2023-08-20T10:38:48 Z GordonRemzi007 Game (eJOI20_game) C++17
20 / 100
1 ms 320 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n, m, cnt;
    pair<int,int> temp;
    queue<pair<int,int>> q;
    cin >> n >> m;
    vector<int> c;
    vector<string> h(n+1), v(n);
    vector<vector<bool>> visited(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;
                q.push({i, j});
                visited[i][j] = true;
                while(q.size()) {
                    cnt++;
                    temp = q.front();
                    q.pop();
                    if(temp.first != 0 && h[temp.first][temp.second] == '0' && !visited[temp.first-1][temp.second]) {
                        visited[temp.first-1][temp.second] = true;
                        q.push({temp.first-1, temp.second});
                    }
                    if(temp.first != n-1 && h[temp.first+1][temp.second] == '0' && !visited[temp.first+1][temp.second]) {
                        visited[temp.first+1][temp.second] = true;
                        q.push({temp.first+1, temp.second});
                    }
                    if(temp.second != 0 && v[temp.first][temp.second] == '0' && !visited[temp.first][temp.second-1]) {
                        visited[temp.first][temp.second-1] = true;
                        q.push({temp.first, temp.second-1});
                    }
                    if(temp.second != m-1 && v[temp.first][temp.second+1] == '0'  && !visited[temp.first][temp.second+1]) {
                        visited[temp.first][temp.second+1] = true;
                        q.push({temp.first, temp.second+1});
                    }
                }
                c.push_back(cnt);
            }
        }
    }
    sort(c.begin(), c.end());
    //for(auto i : c) cout << i << "\n";
    cout << c[1]-c[0] << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 244 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 244 KB Output is correct
12 Correct 0 ms 320 KB Output is correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Halted 0 ms 0 KB -