제출 #672742

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

using namespace std;
 
typedef long long ll;
const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;

int S[MAX], D[MAX];
bool mark[MAX];

bool f(int x, int j, int c){
	for(int i = 0; i < x; i++) if(!mark[i]) S[i] = c;
	for(int i = x; i < n; i++) if(!mark[i]) S[i] = !c;

	int query = tryCombination(S);
	return (query != j);
}

void exploreCave(int n){
	for(int door = 0; door < n; door++){	
		for(int i = 0; i < n; i++)
			if(!mark[i]) S[i] = 0;

		int color = (tryCombination(S) == door), pos = -1;

		int l = 0, r = n, pos = -1;

		while(l <= r){
			int m = (l + r) >> 1;
			if(f(m, door, color)) r = m - 1, pos = m;
			else l = m + 1;
		}

		assert(pos != -1);

		mark[pos] = true;

		D[pos] = door;
		S[pos] = color;
	}

	answer(S, D);
}

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

cave.cpp: In function 'bool f(int, int, int)':
cave.cpp:15:21: error: 'n' was not declared in this scope
   15 |  for(int i = x; i < n; i++) if(!mark[i]) S[i] = !c;
      |                     ^
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:28:21: error: redeclaration of 'int pos'
   28 |   int l = 0, r = n, pos = -1;
      |                     ^~~
cave.cpp:26:44: note: 'int pos' previously declared here
   26 |   int color = (tryCombination(S) == door), pos = -1;
      |                                            ^~~