Submission #1026865

#TimeUsernameProblemLanguageResultExecution timeMemory
1026865ach00Vision Program (IOI19_vision)C++14
33 / 100
1 ms860 KiB
#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 brute_force(int H, int W, int K) { 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); } void construct_network(int H, int W, int K) { h = H; w = W; k = K; if(H <= 20 || W <= 20) { brute_force(H,W,K); 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++; } cerr << "Row ors size : " << row_ors.size() << '\n'; 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 (stderr)

vision.cpp: In function 'void construct_network(int, int, int)':
vision.cpp:119:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |     for(int i = 0; i < crnn.size()-5; i++) {
      |                    ~~^~~~~~~~~~~~~~~
vision.cpp:130:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     for(int i = 0; i < column_ors.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~~
vision.cpp:143:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |     for(int i = 0; i < rrnn.size()-5; i++) {
      |                    ~~^~~~~~~~~~~~~~~
vision.cpp:154:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |     for(int i = 0; i < row_ors.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
#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...