# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
521741 | 2022-02-02T23:02:58 Z | tabr | Vision Program (IOI19_vision) | C++17 | 0 ms | 0 KB |
#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; #endif void constract_network(int h, int w, int k) { vector<int> xs(h); for (int i = 0; i < h; i++) { vector<int> ask; for (int j = 0; j < w; j++) { ask.emplace_back(i * w + j); } xs[i] = add_or(ask); } vector<int> ys(w); for (int j = 0; j < w; j++) { vector<int> ask; for (int i = 0; i < h; i++) { ask.emplace_back(i * w + j); } ys[j] = add_or(ask); } vector<vector<int>> xt(h); xt[0].emplace_back(add_xor(xs)); for (int i = 0; i < h; i++) { for (int j = i + 1; j < h; j++) { xt[j - i].emplace_back(add_and({xs[i], xs[j]})); } } vector<vector<int>> yt(w); yt[0].emplace_back(add_xor(ys)); for (int i = 0; i < w; i++) { for (int j = i + 1; j < w; j++) { yt[j - i].emplace_back(add_and({ys[i], ys[j]})); } } vector<int> xu(h); for (int i = 0; i < h; i++) { xu[i] = add_or(xt[i]); } vector<int> yu(w); for (int i = 0; i < w; i++) { yu[i] = add_or(yt[i]); } vector<int> z; for (int i = 0; i <= k; i++) { int j = k - i; if (j < 0 || w <= j) { continue; } z.emplace_back(add_and({xu[i], yu[j]})); } add_or(z); } #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); return data[id]; }; auto add = [&](int v) { assert(cnt1++ < 1000000); 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; }; constract_network(h, w, k); cout << data.back() << '\n'; cout << (k == abs(x1 - x2) + abs(y1 - y2)) << '\n'; return 0; } #endif