답안 #150942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150942 2019-09-01T12:25:58 Z baikdohyup King of Chairs (FXCUP4_chairs) C++17
0 / 100
53 ms 3996 KB
#include "king.h"

long long SendInfo(std::vector<int> W, std::vector<int> C) {
	return 0;
}

#include "vassal.h"
#include <algorithm>

std::vector<std::pair<int, int>> chair;

void Init(long long B, std::vector<int> C){
	int N = C.size();

	for (int i = 0; i < N; i++) {
		chair.push_back(std::pair<int,int>(C[i], i));
	}

	sort(chair.begin(), chair.end());
}

int findidx(int first, int last, int weight) {
	int mid;

	while (first <= last) {
		mid = (first + last) / 2;
		if (chair[mid].first > weight) {
			if (mid != 0 && chair[mid - 1].first < weight) {
				return mid;
			}
			last = mid - 1;
		}
		else if (chair[mid].first == weight) {
			if (mid != 0 && chair[mid - 1].first == weight) {
				last = mid - 1;
			}
			else {
				return mid;
			}
		}
		else {
			first = mid + 1;
		}
	}

	return -1;
}

int Maid(int W){
	int first = 0, last = (int)chair.size() - 1;
	int idx;

	while (1) {
		idx = findidx(first, last, W);

		if (idx == -1) {
			return -1;
		}

		if (chair[idx].second != -1) {
			int temp = chair[idx].second;
			chair[idx].second = -1;
			return temp;
		}
		else {
			first = idx + 1;
		}
	}

	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 644 KB Wrong
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 3968 KB Wrong
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 3996 KB Wrong
2 Halted 0 ms 0 KB -