Submission #294610

#TimeUsernameProblemLanguageResultExecution timeMemory
2946102qbingxuanVision Program (IOI19_vision)C++14
44 / 100
5 ms1792 KiB
#include "vision.h" #include <bits/stdc++.h> #ifdef local #define debug(args...) qqbx(#args, args) template <typename H, typename ...T> void qqbx(const char *s, const H&h, T &&...args) { for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s; std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n"); if constexpr(sizeof...(T)) qqbx(++s, args...); } #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #else #define debug(...) ((void)0) #define safe ((void)0) #endif // local #define pb emplace_back #define all(v) begin(v),end(v) using namespace std; void construct_network(int H, int W, int k) { int tot = H * W; int zero = -1; { add_not(0); add_and({0, tot++}); zero = tot++; } vector<vector<int>> id(H, vector<int>(W)); for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { id[i][j] = i * W + j; } } safe; vector<vector<int>> diagId(2, vector<int>(H+W, zero)); { vector<vector<vector<int>>> diag(2, vector<vector<int>>(H+W)); for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { diag[0][i+j].pb(id[i][j]); diag[1][i-j+W-1].pb(id[i][j]); } } for(int c = 0; c < 2; c++) for(int i = 0; i < H+W; i++) { if(diag[c][i].size()) { add_xor(diag[c][i]); diagId[c][i] = tot++; } } } vector<vector<int>> preId(2, vector<int>(H+W, zero)); for(int c = 0; c < 2; c++) for(int i = 0; i < H+W; i++) { add_xor({i ? preId[c][i-1] : zero, diagId[c][i]}); preId[c][i] = tot++; } vector<int> maybe; debug(zero); for(int i = 0; i < H; i++) { for(int j = 0; j < W; j++) { int x = i+j; int y = i-j+W-1; // x' = x+k, y' \in [y-k, y+k] if(x+k < H+W) { // ensure diag[0][x+k] is True, and sum(y, [y-k .. y+k]) is even int l = y-k <= 0 ? zero : preId[1][y-k-1]; int r = y+k < H+W ? preId[1][y+k] : preId[1][H+W-1]; add_xor({l, r}); add_not(tot++); vector<int> dep{ id[i][j], diagId[0][x+k], tot++ }; add_and(dep); maybe.pb(tot++); } if(y+k < H+W) { // ensure diag[1][y+k] is True, and sum(x, [x-k .. x+k]) is even int l = x-k <= 0 ? zero : preId[0][x-k-1]; int r = x+k < H+W ? preId[0][x+k] : preId[0][H+W-1]; add_xor({l, r}); add_not(tot++); vector<int> dep{ id[i][j], diagId[1][y+k], tot++ }; add_and(dep); maybe.pb(tot++); } } } add_or(maybe); assert(!maybe.empty()); safe; }
#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...