Submission #442374

# Submission time Handle Problem Language Result Execution time Memory
442374 2021-07-07T15:39:39 Z elazarkoren Game (eJOI20_game) C++17
0 / 100
193 ms 8524 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define x first
#define y second
//#define int short
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

const int MAX_N = 13;
const int infinity = 1e3;

bitset<MAX_N> edges1[MAX_N], edges2[MAX_N];
int id1[MAX_N][MAX_N], id2[MAX_N][MAX_N];

int n, m;

inline bool IsEdge1(int i, int j, int bit) {
    if (edges1[i][j]) return true;
    if (id1[i][j] != -1) return !((bit >> id1[i][j]) & 1);
    return false;
}

inline bool IsEdge2(int i, int j, int bit) {
    if (edges2[i][j]) return true;
    if (id2[i][j] != -1) return !((bit >> id2[i][j]) & 1);
    return false;
}

inline bool Inside(int i, int j, int bit) {
    if (i < 0 || i >= n || j < 0 || j >= m) return false;
    return IsEdge1(i, j, bit) && IsEdge1(i + 1, j, bit) && IsEdge2(i, j, bit) && IsEdge2(i, j + 1, bit);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
//    edges1.resize(n + 1, vb(m)), edges2.resize(n, vb(m + 1));
    vector<pair<pii, bool>> edges;
//    id1.resize(n + 1, vi(m, -1)), id2.resize(n, vi(m + 1, -1));
    char c;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> c;
            edges1[i][j] = c == '1';
            if (c == '0') {
                id1[i][j] = edges.size();
                edges.push_back({{i, j}, false});
            } else id1[i][j] = -1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            cin >> c;
            edges2[i][j] = c == '1';
            if (c == '0') {
                id2[i][j] = edges.size();
                edges.push_back({{i, j}, true});
            } else id2[i][j] = -1;
        }
    }
    int sz = edges.size();
    int32_t pow = 1 << sz;
    vi dp1(pow, -infinity), dp2(pow, infinity);
    dp1[0] = dp2[0] = 0;
    for (int32_t i = 1; i < pow; i++) {
        for (int j = 0; j < sz; j++) {
            if (!((i >> j) & 1)) continue;
            int squares = 0;
            int32_t sub = i - (1 << j);
            if (edges[j].y) {
                squares = Inside(edges[j].x.x, edges[j].x.y, sub) + Inside(edges[j].x.x, edges[j].x.y - 1, sub);
            } else {
                squares = Inside(edges[j].x.x, edges[j].x.y, sub) + Inside(edges[j].x.x - 1, edges[j].x.y, sub);
            }
            chkmax(dp1[i], int((squares ? dp1[sub] : dp2[sub]) + squares));
            chkmin(dp2[i], int((squares ? dp2[sub] : dp1[sub]) - squares));
        }
    }
    cout << dp1[pow - 1];
}
//2 2
//11
//01
//11
//100
//100

//3 2
//00
//10
//11
//11
//011
//001
//000
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 193 ms 8524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -