Submission #521996

#TimeUsernameProblemLanguageResultExecution timeMemory
521996tabrVision Program (IOI19_vision)C++17
100 / 100
14 ms1608 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

#ifdef tabr
function<int(int)> add_not;
function<int(vector<int>)> add_and;
function<int(vector<int>)> add_or;
function<int(vector<int>)> add_xor;
#else
#include "vision.h"
#endif

void construct_network(int h, int w, int k) {
    vector<int> z(h + w);
    for (int i = 0; i < h; i++) {
        vector<int> ask;
        for (int j = 0; j < w; j++) {
            ask.emplace_back(i * w + j);
        }
        if (i != 0) {
            ask.emplace_back(z[i - 1]);
        }
        z[i] = add_xor(ask);
    }
    for (int j = 0; j < w; j++) {
        vector<int> ask;
        for (int i = 0; i < h; i++) {
            ask.emplace_back(i * w + j);
        }
        if (j != 0) {
            ask.emplace_back(z[h + j - 1]);
        }
        z[h + j] = add_xor(ask);
    }
    vector<int> a(9);
    for (int i = 0; i < 9; i++) {
        a[i] = add_and({z.back()});
    }
    for (int x : z) {
        vector<int> b(9);
        b[0] = x;
        for (int i = 0; i < 9; i++) {
            int new_a = add_xor({a[i], b[i]});
            if (i != 8) {
                b[i + 1] = add_and({a[i], b[i]});
            }
            a[i] = new_a;
        }
    }
    for (int i = 0; i < 9; i++) {
        if (!(k & (1 << i))) {
            a[i] = add_not(a[i]);
        }
    }
    add_and(a);
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    vector<int> data(h * w);
    data[x1 * w + y1] = 1;
    data[x2 * w + y2] = 1;
    int cnt1 = 0;
    int cnt2 = 0;
    auto get = [&](int id) {
        assert(0 <= id && id < (int) data.size());
        // assert(cnt2 < 1000000);
        cnt2++;
        return data[id];
    };
    auto add = [&](int v) {
        // assert(cnt1 < 10000);
        cnt1++;
        data.emplace_back(v);
    };
    add_not = [&](int n) {
        add(!get(n));
        return (int) data.size() - 1;
    };
    add_and = [&](vector<int> ns) {
        int res = 1;
        for (int n : ns) {
            res &= get(n);
        }
        add(res);
        return (int) data.size() - 1;
    };
    add_or = [&](vector<int> ns) {
        int res = 0;
        for (int n : ns) {
            res |= get(n);
        }
        add(res);
        return (int) data.size() - 1;
    };
    add_xor = [&](vector<int> ns) {
        int res = 0;
        for (int n : ns) {
            res ^= get(n);
        }
        add(res);
        return (int) data.size() - 1;
    };
    construct_network(h, w, k);
    cout << cnt1 << " " << cnt2 << '\n';
    // cout << x1 << " " << x2 << " " << y1 << " " << y2 << '\n';
    cout << data.back() << '\n';
    cout << (k == abs(x1 - x2) + abs(y1 - y2)) << '\n';
    return 0;
}
#endif
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...