제출 #1308251

#제출 시각아이디문제언어결과실행 시간메모리
1308251afric동굴 (IOI13_cave)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include "cave.h"
using namespace std;

/*void answer(vector<int> i, vector<int> j)
{
    cout << "ANSWER with key Indexes = " << endl;
    for (int item : i)
    {
        cout << item << " ";
    } 
    cout << endl << "key States = " << endl;
    for (int item : j)
    {
        cout << item << " ";
    }
    cout << endl;
}

//TESTING
int tryCombination(vector<int> q)
{
    for (int item : q)
    {
        cout << item << " ";
    }
    cout << endl;
    int a;
    cin >> a;
    return a;
}*/

void binarySearch(int k, int n, vector<int> &keyIndex, vector<int> &keyState)
{
    // logN binary search to find key
    vector<int> ans = keyState;
    for (int i = 0; i < n; i++)
    {
        if (ans[i] == -1)
        {
            ans[i]=0;
        }
    }

    int pos = 1;
    if (tryCombination(ans)>k)
    {
        // correct position for switch is down
        pos = 0;
    }

    // binary search
    int start = 0;
    int end = n;
    while ((end-start)>1)
    {
        int mid = (start+end)/2;
        vector<int> q;
        for (int i = 0; i < n; i++)
        {
            if (keyState[i]!=-1)
            {
                q.push_back(keyState[i]);
            }
            // first we query range(start..mid)
            else if (i >= start && i < mid)
            {
                // we want to query this i
                q.push_back(pos);
            }
            else{
                // not in query --> use off position.
                q.push_back(abs(pos-1));
            }
        }

        int a = tryCombination(q);
        if (a > k)
        {
            // first closed door after k so k must be open.
            end = mid;
        }
        else{
            start = mid;
        }
    }
    // binary search is over so start==end (covers 1)
    keyIndex[start] = k;
    keyState[start] = pos;
}

void exploreCave(int N)
{
    vector<int> keyIndex(N,-1);
    vector<int> keyState(N, -1);
    for (int i = 0; i < N; i++)
    {
        binarySearch(i,N,keyIndex,keyState);
    }
    answer(keyState,keyIndex);
}

/*// TESTING
int main()
{
    int N;
    cin >> N;
    exploreCave(N);
}*/

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

cave.cpp: In function 'void binarySearch(int, int, std::vector<int>&, std::vector<int>&)':
cave.cpp:46:24: error: cannot convert 'std::vector<int>' to 'int*'
   46 |     if (tryCombination(ans)>k)
      |                        ^~~
      |                        |
      |                        std::vector<int>
In file included from cave.cpp:2:
cave.h:8:24: note:   initializing argument 1 of 'int tryCombination(int*)'
    8 | int tryCombination(int S[]);
      |                    ~~~~^~~
cave.cpp:77:32: error: cannot convert 'std::vector<int>' to 'int*'
   77 |         int a = tryCombination(q);
      |                                ^
      |                                |
      |                                std::vector<int>
cave.h:8:24: note:   initializing argument 1 of 'int tryCombination(int*)'
    8 | int tryCombination(int S[]);
      |                    ~~~~^~~
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:100:12: error: cannot convert 'std::vector<int>' to 'int*'
  100 |     answer(keyState,keyIndex);
      |            ^~~~~~~~
      |            |
      |            std::vector<int>
cave.h:9:17: note:   initializing argument 1 of 'void answer(int*, int*)'
    9 | void answer(int S[], int D[]);
      |             ~~~~^~~