Submission #1350956

#TimeUsernameProblemLanguageResultExecution timeMemory
1350956Desh03Vision Program (IOI19_vision)C++20
100 / 100
9 ms2860 KiB
#include "vision.h"
#include <bits/stdc++.h>

using namespace std;

void construct_network(int h, int w, int k) {
    vector<int> p(max(h, w), 1), pp(max(h, w));
    pp[1] = 1;
    p[0] = p[1] = 0;
    for (int i = 2; i < max(h, w); i++) {
        if (p[i]) {
            for (int j = i + i; j < max(h, w); j += i) {
                p[j] = 0;
            }
            for (int k = i; k < max(h, w); k *= i) {
                pp[k] = 1;
            }
        }
    }
    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));
    for (int dx = w - 1; dx > 0; dx--) {
        if (pp[dx]) {
            if (dx == w - 1) {
                x[dx] = add_and({col[0], col[w - 1]});
                continue;
            }
            vector<vector<int>> res(dx);
            vv.clear();
            for (int j = 0; j < w; j++) {
                if (j >= dx || j + dx < w) {
                    res[j % dx].push_back(col[j]);
                    vv.push_back(col[j]);
                }
            }
            v.clear();
            for (int j = 0; j < dx; j++) {
                if (res[j].size()) {
                    v.push_back(add_xor(res[j]));
                }
            }
            if (dx > (w - 1) / 2) x[dx] = add_and({add_not(add_or(v)), add_or(vv)});
            else x[dx] = add_not(add_or(v));
        }
    }
    for (int dx = w - 1; dx > 0; dx--) {
        if (!pp[dx]) {
            v.clear();
            for (int j = dx - 1; j > 0; j--) {
                if (dx % j == 0 && pp[j]) {
                    v.push_back(x[j]);
                }
            }
            x[dx] = add_and(v);
        }
        for (int j = dx - 1; j > 0; j--) {
            if (dx % j == 0 && pp[j]) {
                x[j] = add_and({x[j], add_not(x[dx])});
            }
        }
    }
    for (int dy = h - 1; dy > 0; dy--) {
        if (pp[dy]) {
            if (dy == h - 1) {
                y[dy] = add_and({row[0], row[h - 1]});
                continue;
            }
            vector<vector<int>> res(dy);
            vv.clear();
            for (int j = 0; j < h; j++) {
                if (j >= dy || j + dy < h) {
                    res[j % dy].push_back(row[j]);
                    vv.push_back(row[j]);
                }
            }
            v.clear();
            for (int j = 0; j < dy; j++) {
                if (res[j].size()) {
                    v.push_back(add_xor(res[j]));
                }
            }
            if (dy > (h - 1) / 2) y[dy] = add_and({add_not(add_or(v)), add_or(vv)});
            else y[dy] = add_not(add_or(v));
        }
    }
    for (int dy = h - 1; dy > 0; dy--) {
        if (!pp[dy]) {
            v.clear();
            for (int j = dy - 1; j > 0; j--) {
                if (dy % j == 0 && pp[j]) {
                    v.push_back(y[j]);
                }
            }
            y[dy] = add_and(v);
        }
        for (int j = dy - 1; j > 0; j--) {
            if (dy % j == 0 && pp[j]) {
                y[j] = add_and({y[j], add_not(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);
}
#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...