Submission #778390

# Submission time Handle Problem Language Result Execution time Memory
778390 2023-07-10T09:05:49 Z kamelfanger83 Vision Program (IOI19_vision) C++17
0 / 100
5 ms 5160 KB
#include "vision.h"
#include <cassert>

using namespace std;

int log2(int n){
    int res = 0, tres = 1;
    while(tres < n){
        tres <<= 1;
        res++;
    }
    return res;
}

void construct_network(int H, int W, int K) {
    int log2H = log2(H) - 1;
    int log2W = log2(W) - 1;
    int z = add_and({0,1,2});
    int o = add_not(z);
    vector<int> Hind;
    for (int divs = 0; divs < log2H; divs++) {
        vector<int> tN;
        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                if (x >> divs && 1) tN.push_back(x * W + y);
            }
        }
        Hind.push_back(add_xor(tN));
    }
    for (int i = 0; i < log2W - log2H; ++i) {
        Hind.push_back(add_and({z}));
    }
    vector<int> Wind;
    for (int divs = 0; divs < log2W; divs++) {
        vector<int> tN;
        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                if (y >> divs && 1) tN.push_back(x * W + y);
            }
        }
        add_xor(tN);
    }
    for (int i = 0; i < log2H - log2W; ++i) {
        Wind.push_back(add_and({z}));
    }

    assert(Hind.size() == Wind.size());

    int addbits = max(log2H, log2W);
    vector<int> addeds, carries;
    addeds.push_back(add_xor({Wind[0], Hind[0]}));
    carries.push_back(add_and({Wind[0], Hind[0]}));
    for (int i = 1; i < addbits; ++i) {
        addeds.push_back(add_xor({Wind[i], Hind[i], carries[i - 1]}));
        int o1 = add_and({Wind[i], Hind[i]});
        int o2 = add_and({carries[i - 1], Hind[i]});
        int o3 = add_and({Wind[i], carries[i - 1]});
        carries.push_back(add_or({o1, o2, o3}));
    }
    addeds.push_back(add_and({carries.back()}));
    vector<int> Kbits;
    for (int i = 0; i < addeds.size(); ++i) {
        if (K && 1) Kbits.push_back(add_and({o}));
        else Kbits.push_back(add_and({z}));
        K >>=1;
    }
    assert(K == 0);
    vector<int> XORS;
    for (int i = 0; i < addeds.size(); ++i) {
        XORS.push_back(add_xor({addeds[i], Kbits[i]}));
    }
    vector<int> NOTS;
    for (int i = 0; i < XORS.size(); ++i) {
        NOTS.push_back(add_not(XORS[i]));
    }
    add_and(NOTS);
}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < addeds.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~
vision.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for (int i = 0; i < addeds.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~
vision.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int i = 0; i < XORS.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 284 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 284 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 284 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 284 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5160 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 284 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -