답안 #565481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565481 2022-05-21T00:37:03 Z lohacho 도서관 (JOI18_library) C++14
0 / 100
48 ms 288 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;

void Solve(int n)
{
	if(n == 1){
		return Answer({1});
	}
	vector<int> ans(n), inans(n);
	vector<int> chk(n, 1);
	for(int i = 0; i < n; ++i){
		chk[i] = 0;
		int rv = Query(chk);
		if(rv == 1){
			ans[0] = i;
			inans[i] = 1;
			break;
		}
	}
	vector<int> left;
	for(int i = 0; i < n; ++i){
		if(!inans[i]){
			left.push_back(i);
		}
	}
	int low = 0, high = (int)left.size() - 1, mid;
	while(low < high){
		mid = low + high >> 1;
		chk = vector<int>(n);
		chk[ans[0]] = 1;
		for(int i = 0; i <= mid; ++i){
			chk[left[i]] = 1;
		}
		int rv1 = Query(chk);
		chk[ans[0]] = 0;
		int rv2 = Query(chk);
		if(rv1 == rv2){
			high = mid;
		}
		else{
			low = mid + 1;
		}
	}
	ans[1] = left[low]; inans[left[low]] = 1;
	for(int i = 2; i < n; ++i){
		left.clear();
		for(int j = 0; j < n; ++j){
			if(!inans[j]){
				left.push_back(j);
			}
		}
		low = 0, high = (int)left.size() - 1, mid;
		while(low < high){
			mid = low + high >> 1;
			chk = vector<int>(n);
			for(int k = 0; k < i; ++k){
				chk[ans[k]] = 1;
			}
			for(int k = 0; k <= mid; ++k){
				chk[left[k]] = 1;
			}
			int rv1 = Query(chk);
			chk[ans[i - 1]] = 0;
			int rv2 = Query(chk);
			if(rv1 < rv2){
				high = mid;
			}
			else{
				low = mid + 1;
			}
		}
		ans[i] = left[low]; inans[left[low]] = 1;
	}
	for(int i = 0; i < n; ++i){
		++ans[i];
	}
	Answer(ans);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |   mid = low + high >> 1;
      |         ~~~~^~~~~~
library.cpp:53:44: warning: right operand of comma operator has no effect [-Wunused-value]
   53 |   low = 0, high = (int)left.size() - 1, mid;
      |                                            ^
library.cpp:55:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |    mid = low + high >> 1;
      |          ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 288 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 288 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -