답안 #778561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778561 2023-07-10T12:21:41 Z kamelfanger83 Vision Program (IOI19_vision) C++14
18 / 100
11 ms 1676 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) {
    if (H * W == 2) {
        add_and({0, 1});
        return;
    }
    int log2H = log2(H);
    int log2W = log2(W);
    int z = add_and({0,1,2});
    int o = add_not(z);
    vector<int> rows;
    for (int x = 0; x < H; ++x) {
        vector<int> tr;
        for (int y = 0; y < W; ++y) {
            tr.push_back(x * W + y);
        }
        rows.push_back(add_xor(tr));
    }
    vector<int> cols;
    for (int y = 0; y < W; ++y) {
        vector<int> tc;
        for (int x = 0; x < H; ++x) {
            tc.push_back(x * W + y);
        }
        cols.push_back(add_xor(tc));
    }
    vector<int> Hind;
    int a = z;
    for (int divs = 0; divs < log2H; divs++) {
        vector<int> tN;
        for (int x = 0; x < H; ++x) {
            if ((x >> divs) & 1) tN.push_back(rows[x]);
        }
        int raw = add_xor(tN);
        if (divs != 0 && 1 << divs < H){
            vector<int> hmm;
            vector<int> before;
            vector<int> afters;
            for (int x = 0; x < (1 << (divs - 1)) && x < H; ++x) {
                afters.push_back(rows[x]);
            }
            for (int cen = 1 << divs; cen < H; cen += 1 << divs) {
                for (int x = cen - (1 << (divs - 1)); x < cen; ++x) {
                    before.push_back(rows[x]);
                }
                int prebefore = add_xor(before);
                int preafter = add_xor(afters);
                int npreafter = add_not(preafter);
                hmm.push_back(add_and({prebefore, npreafter}));
                for (int x = cen; x < cen + (1 << (divs - 1)) && x < H; ++x) {
                    afters.push_back(rows[x]);
                }
            }
            hmm.push_back(a);
            int flip = add_or(hmm);
            flip = add_and({flip, Hind.back()});
            Hind.push_back(add_xor({raw, flip}));
            int nraw = add_not(raw);
            a = add_and({nraw, flip});
        }
        else {
            Hind.push_back(raw);
        }
    }
    for (int i = 0; i < log2W - log2H; ++i) {
        Hind.push_back(add_and({z}));
    }
    vector<int> Wind;
    a = z;
    for (int divs = 0; divs < log2W; divs++) {
        vector<int> tN;
        for (int y = 0; y < W; ++y) {
            if ((y >> divs) & 1) tN.push_back(cols[y]);
        }
        int raw = add_xor(tN);
        if (divs != 0 && 1 << divs < W){
            vector<int> hmm;
            vector<int> before;
            vector<int> afters;
            for (int x = 0; x < (1 << (divs - 1)) && x < W; ++x) {
                afters.push_back(cols[x]);
            }
            for (int cen = 1 << divs; cen < W; cen += 1 << divs) {
                for (int y = cen - (1 << (divs - 1)); y < cen; ++y) {
                    before.push_back(cols[y]);
                }
                int prebefore = add_xor(before);
                int preafter = add_xor(afters);
                int npreafter = add_not(preafter);
                hmm.push_back(add_and({prebefore, npreafter}));
                for (int y = cen; y < cen + (1 << (divs - 1)) && y < W; ++y) {
                    afters.push_back(cols[y]);
                }
            }
            hmm.push_back(a);
            int flip = add_or(hmm);
            flip = add_and({flip, Wind.back()});
            Wind.push_back(add_xor({raw, flip}));
            int nraw = add_not(raw);
            a = add_and({nraw, flip});
        }
        else{
            Wind.push_back(raw);
        }
    }
    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:138:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |     for (int i = 0; i < addeds.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~
vision.cpp:145:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  145 |     for (int i = 0; i < addeds.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~
vision.cpp:149:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |     for (int i = 0; i < XORS.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB on inputs (0, 5), (0, 8), expected 1, but computed 0
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB on inputs (0, 5), (0, 8), expected 1, but computed 0
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB on inputs (0, 5), (0, 8), expected 1, but computed 0
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 468 KB on inputs (0, 3), (0, 4), expected 1, but computed 0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 4 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 3 ms 468 KB Output is correct
20 Correct 8 ms 980 KB Output is correct
21 Correct 8 ms 1000 KB Output is correct
22 Correct 6 ms 980 KB Output is correct
23 Correct 6 ms 920 KB Output is correct
24 Correct 6 ms 980 KB Output is correct
25 Correct 9 ms 1024 KB Output is correct
26 Correct 6 ms 976 KB Output is correct
27 Correct 11 ms 1632 KB Output is correct
28 Correct 11 ms 1572 KB Output is correct
29 Correct 11 ms 1620 KB Output is correct
30 Correct 11 ms 1652 KB Output is correct
31 Correct 11 ms 1676 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1628 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 2 ms 420 KB on inputs (99, 26), (100, 26), expected 1, but computed 0
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 1 ms 212 KB on inputs (0, 5), (0, 8), expected 1, but computed 0
20 Halted 0 ms 0 KB -