Submission #832387

#TimeUsernameProblemLanguageResultExecution timeMemory
832387maomao90Vision Program (IOI19_vision)C++17
66 / 100
13 ms2088 KiB
// I can do all things through Christ who strenghthens me
// Philippians 4:13

#include "bits/stdc++.h"
#include "vision.h"
using namespace std;

#define REP(i, j, k) for (int i = j; i < (k); i++)
#define RREP(i, j, k) for (int i = j; i >= (k); i--)

template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 200005;

int h, w, k;

void construct_network(int H, int W, int K) {
    h = H, w = W; k = K;
    if (k == 1 && h != 1 && w != 1) {
        int hs = h * w;
        REP (i, 0, h) {
            vi v(w);
            iota(ALL(v), i * w);
            add_or(v);
        }
        int ws = hs + h;
        REP (j, 0, w) {
            vi v;
            REP (i, 0, h) {
                v.pb(i * w + j);
            }
            add_or(v);
        }
        vi hall;
        REP (i, 0, h - 1) {
            hall.pb(add_and({hs + i, hs + i + 1}));
        }
        int hb = add_or(hall);
        vi wall;
        REP (i, 0, w - 1) {
            wall.pb(add_and({ws + i, ws + i + 1}));
        }
        int wb = add_or(wall);
        {
            vi v;
            vi all;
            vi pfx(w);
            REP (i, 0, w) {
                v.pb(ws + i);
                pfx[i] = add_not(add_or(v));
            }
            v.clear();
            vi sfx(w);
            RREP (i, w - 1, 0) {
                v.pb(ws + i);
                sfx[i] = add_not(add_or(v));
            }
            all.pb(sfx[1]);
            REP (i, 1, w - 1) {
                all.pb(add_and({pfx[i - 1], sfx[i + 1]}));
            }
            all.pb(pfx[w - 2]);
            hb = add_and({add_or(all), hb});
        }
        {
            vi v;
            vi all;
            vi pfx(h);
            REP (i, 0, h) {
                v.pb(hs + i);
                pfx[i] = add_not(add_or(v));
            }
            v.clear();
            vi sfx(h);
            RREP (i, h - 1, 0) {
                v.pb(hs + i);
                sfx[i] = add_not(add_or(v));
            }
            all.pb(sfx[1]);
            REP (i, 1, h - 1) {
                all.pb(add_and({pfx[i - 1], sfx[i + 1]}));
            }
            all.pb(pfx[h - 2]);
            wb = add_and({add_or(all), wb});
        }
        add_or({hb, wb});
        /*
        vi v1, v2;
        REP (i, 0, h) {
            REP (j, 0, w) {
                if (i + j & 1) {
                    v1.pb(i * w + j);
                } else {
                    v2.pb(i * w + j);
                }
            }
        }
        int t1 = add_or(v1), t2 = add_or(v2);
        add_and({wb, hb, t1, t2});
        */
        return;
    }
    vi all;
    REP (i, 0, h) {
        REP (j, 0, w) {
            if (max(h, w) > 30 && min(h, w) != 1 && j != 0) {
                break;
            }
            vi v;
            REP (ni, 0, h) {
                if (abs(ni - i) > k) {
                    continue;
                }
                {
                    // abs(ni - i) + nj - j = k
                    // nj = k - abs(ni - i) + j
                    int nj = k - abs(ni - i) + j;
                    if (nj >= 0 && nj < w) {
                        v.pb(ni * w + nj);
                    }
                }
            }
            if (v.empty()) {
                continue;
            }
            int tmp = add_or(v);
            all.pb(add_and({i * w + j, tmp}));
        }
    }
    add_or(all);
}
#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...