제출 #1161860

#제출 시각아이디문제언어결과실행 시간메모리
1161860zyq181도서관 (JOI18_library)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
#define int long long

vector<int> ask;
vector<int> ask2;
vector<int> ans;

bool determined[1005];
int determinedcnt;
int lastright = -1;
int lastleft = -1;

void side(int lo, int hi){
    while(lo < hi){
        int m = (lo + hi)/2;
        int sz = (m - lo + 1);
        fill(ask.begin(), ask.end(), 0);
        fill(ask2.begin(), ask2.end(), 0);
        int cnt = 0;
        for(int a=0; a<N; a++){
            if(!determined[a]){
                if(cnt < sz){
                    ask[a] = 1;
                    cnt++;
                }
                else{
                    ask2[a] = 1;
                }
            }
        }
        int ret1 = Query(ask);
        int ret2 = Query(ask2);
        if(ret1 > ret2){
            hi = m;
        }
        else{
            lo = m + 1;
        }
    }
    int cntr = 0;
    for(int a=0; a<N; a++){
        if(!determined[a]){
            cntr++;
        }
        if(cntr == lo) {
            cntr = a + 1;
            break;
        }
    }
    if(lastright == N && lastleft == -1){
        lastleft++;
        determined[cntr-1] = true;
        ans[lastleft] = cntr;
    }
    else if(lastright == N){
        fill(ask.begin(), ask.end(), 0);
        ask[ans[lastleft] - 1] = 1;
        ask[cntr-1] = 1;
        ret = Query(ask);
        if(ret == 1){
            lastleft++;
            ans[lasleft] = cntr;
            determined[cntr-1] = true;
        }else{
            lastright--;
            ans[lastright] = cntr;
            determined[cntr-1] = true;
        }
    }
    else{
        fill(ask.begin(), ask.end(), 0);
        ask[ans[lastright] - 1] = 1;
        ask[cntr-1] = 1;
        ret = Query(ask);
        if(ret == 1){
            lastright--;
            ans[lastright] = cntr;
            determined[cntr-1] = true;
        }else{
            lastleft++;
            ans[lastleft] = cntr;
            determined[cntr-1] = true;
        }
  
    }
}

void Solve(int N){
    lastright = N;
    for(int a=0; a<N; a++){
        ask.push_back(0);
        ask2.push_back(0);
        ans.push_back(0);
    }
    for(int a=0; a<N; a++){
        side(1, N-a);
    }
    Answer(ans);
}

컴파일 시 표준 에러 (stderr) 메시지

library.cpp: In function 'void side(long long int, long long int)':
library.cpp:22:24: error: 'N' was not declared in this scope
   22 |         for(int a=0; a<N; a++){
      |                        ^
library.cpp:33:26: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   33 |         int ret1 = Query(ask);
      |                          ^~~
In file included from library.cpp:2:
library.h:2:35: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
    2 | int Query(const std::vector<int>& M);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^
library.cpp:34:26: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   34 |         int ret2 = Query(ask2);
      |                          ^~~~
In file included from library.cpp:2:
library.h:2:35: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
    2 | int Query(const std::vector<int>& M);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^
library.cpp:43:20: error: 'N' was not declared in this scope
   43 |     for(int a=0; a<N; a++){
      |                    ^
library.cpp:52:21: error: 'N' was not declared in this scope
   52 |     if(lastright == N && lastleft == -1){
      |                     ^
library.cpp:61:9: error: 'ret' was not declared in this scope
   61 |         ret = Query(ask);
      |         ^~~
library.cpp:61:21: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   61 |         ret = Query(ask);
      |                     ^~~
In file included from library.cpp:2:
library.h:2:35: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
    2 | int Query(const std::vector<int>& M);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^
library.cpp:64:17: error: 'lasleft' was not declared in this scope; did you mean 'lastleft'?
   64 |             ans[lasleft] = cntr;
      |                 ^~~~~~~
      |                 lastleft
library.cpp:76:9: error: 'ret' was not declared in this scope
   76 |         ret = Query(ask);
      |         ^~~
library.cpp:76:21: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   76 |         ret = Query(ask);
      |                     ^~~
In file included from library.cpp:2:
library.h:2:35: note: in passing argument 1 of 'int Query(const std::vector<int>&)'
    2 | int Query(const std::vector<int>& M);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^
library.cpp: In function 'void Solve(long long int)':
library.cpp:100:12: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
  100 |     Answer(ans);
      |            ^~~
In file included from library.cpp:2:
library.h:3:37: note: in passing argument 1 of 'void Answer(const std::vector<int>&)'
    3 | void Answer(const std::vector<int>& res);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~