Submission #442183

# Submission time Handle Problem Language Result Execution time Memory
442183 2021-07-07T09:08:06 Z elazarkoren Game (eJOI20_game) C++17
20 / 100
1 ms 204 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define x first
#define y second
#define all(v) v.begin(), v.end()
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;

int n, m;

inline int Val(int i, int j) {
    return i + j * n;
}

int Dfs(vvi &graph, int node, vb &visited) {
    visited[node] = true;
    int ans = 1;
    for (int neighbor : graph[node]) {
        if (!visited[neighbor]) ans += Dfs(graph, neighbor, visited);
    }
    return ans;
}

int main() {
    cin >> n >> m;
    vvb hor_edge(n + 1, vb(m)), ver_edge(n, vb(m + 1));
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            char c;
            cin >> c;
            hor_edge[i][j] = c == '1';
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            char c;
            cin >> c;
            ver_edge[i][j] = c == '1';
        }
    }
    vvi graph(n * m);
    vb visited(n * m);
//    int ans = n * m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i < n - 1 && !hor_edge[i + 1][j]) {
                graph[Val(i, j)].push_back(Val(i + 1, j));
                graph[Val(i + 1, j)].push_back(Val(i, j));
            }
            if (j < m - 1 && !ver_edge[i][j + 1]) {
                graph[Val(i, j)].push_back(Val(i, j + 1));
                graph[Val(i, j + 1)].push_back(Val(i, j));
            }
            if (hor_edge[i][j] && hor_edge[i + 1][j] && ver_edge[i][j] && ver_edge[i][j + 1]) {
                visited[Val(i, j)] = true;
            }
        }
    }
    vi components;
    for (int i = 0; i < n * m; i++) {
        if (!visited[i]) components.push_back(Dfs(graph, i, visited));
    }
    sort(all(components));
    int sa = 0, st = 0;
    for (int i = 0; i < components.size(); i++) {
        if (i & 1) {
            sa += components[i];
        } else {
            st += components[i];
        }
    }
    cout << sa - st;
//    cout << -ans;
    return 0;
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i = 0; i < components.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -