Submission #1026875

# Submission time Handle Problem Language Result Execution time Memory
1026875 2024-07-18T12:42:47 Z ach00 Vision Program (IOI19_vision) C++14
33 / 100
2 ms 1116 KB
#include "vision.h"
#include <bits/stdc++.h>
using namespace std;

int h,w,k;
#define rrnn row_results_nn
#define crnn column_results_nn
bool bounds(int y, int x) {
	if(y >= 0 && x >= 0 && y < h && x < w) return true;
	return false;
}



void construct_network(int H, int W, int K) {
    h = H; w = W; k = K;
    if(H <= 20 || W <= 20) {
        int index = H*W;
        vector<int> and_indices;

        for(int y = 0; y < H; y++) {
            for(int x = 0; x < W; x++) {
                vector<int> P;
                for(int i = 0; i <= K; i++) {
                    int fdir = i;
                    int sdir = K-i;
                    if(bounds(y+fdir, x+sdir)) P.push_back((y+fdir)*W + x+sdir);
                    if(bounds(y+fdir, x-sdir)) P.push_back((y+fdir)*W + x-sdir);
                    if(bounds(y-fdir, x+sdir)) P.push_back((y-fdir)*W + x+sdir);
                    if(bounds(y-fdir, x-sdir)) P.push_back((y-fdir)*W + x-sdir);
                }
                if(P.size()) {
                    add_or(P);
                    index++;
                    and_indices.push_back(index);
                    add_and({y*W + x, index-1});
                    index++;
                }
            }
        }
        add_or(and_indices); 
        return;
    } 
    int index = H*W;
    vector<int> column_results;
    vector<int> row_results;
    vector<int> column_results_nn;
    int csz = column_results_nn.size()-1;
    vector<int> row_results_nn;
    int rsz = row_results_nn.size()-1;
    for(int i = 0; i < W-1; i++) {
        vector<int> to_xor;
        for(int j = 0; j < H; j++) {
            to_xor.push_back(W*j + i);
            to_xor.push_back(W*j + i + 1);
        }
        add_xor(to_xor);
        column_results_nn.push_back(index);
        index++;
        add_not(index-1);
        column_results.push_back(index);
        index++;
    }
    for(int i = 0; i < H-1; i++) {
        vector<int> to_xor;
        for(int j = 0; j < W; j++) {
            to_xor.push_back(i*W + j);
            to_xor.push_back((i+1)*W + j);
        }
        add_xor(to_xor);
        row_results_nn.push_back(index);
        index++;
        add_not(index-1);
        row_results.push_back(index);
        index++;
    }
    add_and(column_results);
    int lie_on_column = index++;
    add_and(row_results);
    int lie_on_row = index++;

    add_not(column_results_nn[0]);
    index++;
    add_not(column_results_nn[2]);
    index++;
    add_and({column_results_nn[1], index-1, index-2});
    int tgat_column_left = index++;
    add_not(column_results_nn[csz]);
    index++;
    add_not(column_results_nn[csz-2]);
    index++;
    add_and({column_results_nn[csz-1], index-1, index-2});
    int tgat_column_right = index++;
    add_or({tgat_column_right, tgat_column_left});
    int tgat_column = index++;


    add_not(row_results_nn[0]);
    index++;
    add_not(row_results_nn[2]);
    index++;
    add_and({row_results_nn[1], index-1, index-2});
    int tgat_row_left = index++;
    add_not(row_results_nn[rsz]);
    index++;
    add_not(row_results_nn[rsz-2]);
    index++;
    add_and({row_results_nn[rsz-1], index-1, index-2});
    int tgat_row_right = index++;
    add_or({tgat_row_right, tgat_row_left});
    int tgat_row = index++;


    vector<int> column_ors;
    vector<int> column_ands;
    for(int i = 0; i < crnn.size()-5; i++) {
        add_or({crnn[i], crnn[i+2], crnn[i+4]});
        index++;
        column_ors.push_back(index);
        add_not(index-1);
        index++;
        add_and({crnn[i+1],crnn[i+3]});
        column_ands.push_back(index);
        index++;
    }
    int column101check = index;
    for(int i = 0; i < column_ors.size(); i++) {
        add_and({column_ors[i], column_ands[i]});
        index++;
    }
    vector<int> column101fin;
    for(int i = column101check; i < index; i++) {
        column101fin.push_back(i);
    }
    add_or(column101fin);
    int columnworking101 = index++;

    vector<int> row_ors;
    vector<int> row_ands;
    for(int i = 0; i < rrnn.size()-5; i++) {
        add_or({rrnn[i], rrnn[i+2], rrnn[i+4]});
        index++;
        row_ors.push_back(index);
        add_not(index-1);
        index++;
        add_and({rrnn[i+1],rrnn[i+3]});
        row_ands.push_back(index);
        index++;
    }
    int row101check = index;
    for(int i = 0; i < row_ors.size(); i++) {
        add_and({row_ors[i], row_ands[i]});
        index++;
    }
    vector<int> row101fin;
    for(int i = row101check; i < index; i++) {
        row101fin.push_back(i);
    }
    add_or(row101fin);
    int rowworking101 = index++;



    int start_sol = index;
    vector<int> sol;
    add_and({tgat_column, lie_on_row}); index++;
    add_and({tgat_row, lie_on_column}); index++;
    add_and({columnworking101, lie_on_row}); index++;
    add_and({rowworking101, lie_on_column}); index++;
    for(int i = start_sol; i < index; i++) {
        sol.push_back(i);
    }
    add_or(sol);
}

Compilation message

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:116:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |     for(int i = 0; i < crnn.size()-5; i++) {
      |                    ~~^~~~~~~~~~~~~~~
vision.cpp:127:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |     for(int i = 0; i < column_ors.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~
vision.cpp:140:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |     for(int i = 0; i < rrnn.size()-5; i++) {
      |                    ~~^~~~~~~~~~~~~~~
vision.cpp:151:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |     for(int i = 0; i < row_ors.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Incorrect 0 ms 348 KB WA in grader: Invalid index
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Incorrect 0 ms 348 KB WA in grader: Invalid index
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 408 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB WA in grader: Invalid index
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB WA in grader: Invalid index
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Incorrect 0 ms 348 KB WA in grader: Invalid index
29 Halted 0 ms 0 KB -