제출 #951415

#제출 시각아이디문제언어결과실행 시간메모리
951415svitlanatsvitCave (IOI13_cave)C++11
컴파일 에러
0 ms0 KiB
#include <vector> using namespace std; int tryCombination(vector<int> S) { // This function will be provided by the grader // It allows us to try a combination of switches and returns the first closed door // If all doors are open, it returns -1 // The grader will ensure this function runs in O(N) time // It may be called at most 70,000 times } void answer(vector<int> S, vector<int> D) { // This procedure should be called when we have identified the correct positions of switches // and the doors each switch is connected to // It will cause the program to exit // The format of parameters matches that of the tryCombination function } void exploreCave(int N) { vector<int> switches(N, 0); // Initialize all switches to up position initially // Try different combinations of switches to determine the correct position for each switch // Use binary search strategy int left = 0, right = N; while (left < right) { int mid = (left + right) / 2; switches[mid] = 1; // Set the switch at mid position to down int first_closed_door = tryCombination(switches); if (first_closed_door == -1) { // All doors are open, adjust the search range right = mid; } else { // Adjust the search range based on the position of the first closed door left = first_closed_door; } switches[mid] = 0; // Reset the switch position for next iteration } // Once we have determined the correct positions of switches, assign the doors each switch is connected to vector<int> doors(N); for (int i = 0; i < N; ++i) { doors[i] = left + i; } // Provide the solution to the grader answer(switches, doors); } // Example usage int main() { int N = 4; // Number of switches and doors exploreCave(N); return 0; }

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

cave.cpp: In function 'int tryCombination(std::vector<int>)':
cave.cpp:11:1: warning: no return statement in function returning non-void [-Wreturn-type]
   11 | }
      | ^
/usr/bin/ld: /tmp/cclOQHOJ.o: in function `main':
cave.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPLucfL.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccPLucfL.o: in function `main':
grader.c:(.text.startup+0x10): undefined reference to `exploreCave'
collect2: error: ld returned 1 exit status