답안 #413756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413756 2021-05-29T10:46:47 Z ollel Vision Program (IOI19_vision) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int w, h, k, n_instructions;
//
// bool add_or(vi& q) {
//   cout << "or:\n";
//   for(auto &i : q) cout << i << " ";cout<<endl;
//   bool ans; cin >> ans;
//   return ans;
// }
//
// bool add_and(vi& q) {
//   cout << "and:\n";
//   for(auto &i : q) cout << i << " ";cout<<endl;
//   bool ans; cin >> ans;
//   return ans;
// }
//
// bool add_not(int x ) {
//   cout << "not:\n";
//   cout << x << endl;
//   bool ans; cin >> ans; return ans;
// }

int binary_search() {
  vi p(w*h); rep(i,0,w*h) p[i] = i;

  while (p.size() > 1) {
    vi half(p.size() / 2);
    rep(i,0,p.size() / 2) half[i] = p[i];
    n_instructions++;
    vi np;
    if (add_or(half)) np = half;
    else {
      rep(i, p.size() / 2, p.size()) np.pb(p[i]);
    }
    p = np;
  }
  return p[0];
}

void get_k(int x) {
  int wx = x % w, hx = x / w;
  int first_inst = n_instructions;

  rep(add_w, -k, k + 1) {
    int nw = wx + add_w, nh1 = hx + k - abs(add_w), nh2 = hx - (k + abs(add_w));

    if (!(0 <= nw && nw < w)) continue;
    if (0 <= nh1 && nh1 < h) {
      int ask = nh1 * w + nw;
      vi k = {ask};
      add_and(k);
      n_instructions++;
    }
    if (0 <= nh2 && nh2 < h) {

      int ask = nh1 * w + nw;
      vi k = {ask};
      add_and(k);
      n_instructions++;
    }
  }

  if (first_inst != n_instructions) {
    vi f;
    rep(i, first_inst, n_instructions) f.pb(i);
    add_or(f);
  }
  else {
    add_not(x);
  }
}

void construct_network(int H, int W, int K) {
  h = H; w = W; k = K;
  n_instructions = w*h;
  int x = binary_search();
  get_k(x);
  return;
}
//
// int main() {
//   construct_network(3, 3, 3);
// }

Compilation message

vision.cpp: In function 'int binary_search()':
vision.cpp:5:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,b) for(int i = a; i < b; i++)
......
   40 |     rep(i,0,p.size() / 2) half[i] = p[i];
      |         ~~~~~~~~~~~~~~~~             
vision.cpp:40:5: note: in expansion of macro 'rep'
   40 |     rep(i,0,p.size() / 2) half[i] = p[i];
      |     ^~~
vision.cpp:43:9: error: 'add_or' was not declared in this scope
   43 |     if (add_or(half)) np = half;
      |         ^~~~~~
vision.cpp:5:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,b) for(int i = a; i < b; i++)
......
   45 |       rep(i, p.size() / 2, p.size()) np.pb(p[i]);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~  
vision.cpp:45:7: note: in expansion of macro 'rep'
   45 |       rep(i, p.size() / 2, p.size()) np.pb(p[i]);
      |       ^~~
vision.cpp: In function 'void get_k(int)':
vision.cpp:63:7: error: 'add_and' was not declared in this scope; did you mean 'add_w'?
   63 |       add_and(k);
      |       ^~~~~~~
      |       add_w
vision.cpp:70:7: error: 'add_and' was not declared in this scope; did you mean 'add_w'?
   70 |       add_and(k);
      |       ^~~~~~~
      |       add_w
vision.cpp:78:5: error: 'add_or' was not declared in this scope
   78 |     add_or(f);
      |     ^~~~~~
vision.cpp:81:5: error: 'add_not' was not declared in this scope
   81 |     add_not(x);
      |     ^~~~~~~