Submission #1350895

#TimeUsernameProblemLanguageResultExecution timeMemory
1350895Desh03Vision Program (IOI19_vision)C++20
22 / 100
3 ms1728 KiB
#include "vision.h"
#include <bits/stdc++.h>

using namespace std;

void construct_network(int h, int w, int k) {
    if (min(h, w) == 1) {
        vector<int> v;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                for (int i2 = 0; i2 < h; i2++) {
                    for (int j2 = 0; j2 < w; j2++) {
                        if (abs(i - i2) + abs(j - j2) == k && make_pair(i, j) < make_pair(i2, j2)) {
                            add_and({w * i + j, w * i2 + j2});
                            v.push_back(h * w + v.size());
                        }
                    }
                }
            }
        }
        if (v.empty()) {
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    v.push_back({h * w + v.size()});
                }
            }
            add_and(v);
        } else {
            add_or(v);
        }
        return;
    }
    vector<int> col(w), row(h), v;
    for (int i = 0; i < h; i++) {
        v.clear();
        for (int j = 0; j < w; j++) {
            v.push_back(w * i + j);
        }
        row[i] = add_or(v);
    }
    for (int j = 0; j < w; j++) {
        vector<int> v;
        for (int i = 0; i < h; i++) {
            v.push_back(w * i + j);
        }
        col[j] = add_or(v);
    }
    vector<int> x(w), y(h);
    vector<int> vv;
    for (int i = 0; i < h; i++) {
        v.clear();
        for (int j = 0; j < w; j++) {
            v.push_back(w * i + j);
        }
        vv.push_back(add_xor(v));
    }
    y[0] = add_not(add_or(vv));
    vv.clear();
    for (int j = 0; j < w; j++) {
        v.clear();
        for (int i = 0; i < h; i++) {
            v.push_back(w * i + j);
        }
        vv.push_back(add_xor(v));
    }
    x[0] = add_not(add_or(vv));
    vv.clear();
    for (int dx = w - 1; dx >= max(1, w / 2); dx--) {
        if (dx == w - 1) {
            x[dx] = add_and({col[0], col[w - 1]});
            vv.push_back(x[dx]);
            continue;
        }
        vector<int> v;
        for (int j = dx; j < w; j++) {
            v.push_back(add_and({col[j], col[j - dx]}));
        }
        x[dx] = add_or(v);
        vv.push_back(x[dx]);
    }
    int suf = -1;
    if (vv.size()) {
        suf = add_or(vv);
    }
    for (int dx = w / 2 - 1; dx > 0; dx--) {
        vector<int> v1, v2;
        vector<vector<int>> res1(dx), res2(dx);
        for (int j = 0; j < w; j++) {
            if ((j / dx) & 1) res1[j % dx].push_back(col[j]);
            else if (j + dx < w || j >= dx) res2[j % dx].push_back(col[j]);
        }
        v.clear();
        for (int j = 0; j < dx; j++) {
            if (res1[j].size()) {
                if (res1[j].size() == 1) {
                    v.push_back(add_and({res1[j][0], res2[j][0]}));
                } else {
                    v.push_back(add_and({add_or(res1[j]), add_or(res2[j])}));
                }
            }
        }
        if (suf != -1) {
            x[dx] = add_and({add_or(v), add_not(suf)});
            if (dx > 1) suf = add_or({suf, x[dx]});
        } else {
            x[dx] = add_or(v);
            suf = x[dx];
        }
    }
    vv.clear();
    for (int dy = h - 1; dy >= max(1, h / 2); dy--) {
        if (dy == h - 1) {
            y[dy] = add_and({row[0], row[h - 1]});
            vv.push_back(y[dy]);
            continue;
        }
        vector<int> v;
        for (int j = dy; j < h; j++) {
            v.push_back(add_and({row[j], row[j - dy]}));
        }
        y[dy] = add_or(v);
        vv.push_back(y[dy]);
    }
    suf = -1;
    if (vv.size()) {
        suf = add_or(vv);
    }
    for (int dy = h / 2 - 1; dy > 0; dy--) {
        vector<int> v1, v2;
        vector<vector<int>> res1(dy), res2(dy);
        for (int j = 0; j < h; j++) {
            if ((j / dy) & 1) res1[j % dy].push_back(row[j]);
            else if (j + dy < h || j >= dy) res2[j % dy].push_back(row[j]);
        }
        v.clear();
        for (int j = 0; j < dy; j++) {
            if (res1[j].size()) {
                if (res1[j].size() == 1) {
                    v.push_back(add_and({res1[j][0], res2[j][0]}));
                } else {
                    v.push_back(add_and({add_or(res1[j]), add_or(res2[j])}));
                }
            }
        }
        if (suf != -1) {
            y[dy] = add_and({add_or(v), add_not(suf)});
            if (dy > 1) suf = add_or({suf, y[dy]});
        } else {
            y[dy] = add_or(v);
            suf = y[dy];
        }
    }
    v.clear();
    for (int i = max(0, k - h + 1); i <= min(w - 1, k); i++) {
        v.push_back(add_and({x[i], y[k - i]}));
    }
    add_or(v);
}

Compilation message (stderr)

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:24:40: warning: narrowing conversion of '(((std::vector<int>::size_type)(h * w)) + v.std::vector<int>::size())' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'std::vector<int>::value_type' {aka 'int'} [-Wnarrowing]
   24 |                     v.push_back({h * w + v.size()});
      |                                  ~~~~~~^~~~~~~~~~
#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...