답안 #151021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151021 2019-09-01T15:07:06 Z baikdohyup King of Chairs (FXCUP4_chairs) C++17
17 / 100
1000 ms 9372 KB
#include "king.h"

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

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

std::vector<std::pair<int, int>> chair; // chair weight, order of chair
std::vector<std::pair<int, int>> num; // chair total, chair remain

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

	for (int i = 0; i < N; i++) {
		if (!chair.empty() && chair.back().first == C[i]) {
			num.back().first++, num.back().second++;
		}
		else {
			chair.push_back(std::pair<int, int>(C[i], i));
			num.push_back(std::pair<int, int>(1, 1));
		}
	}
}

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

	while (first <= last) {
		mid = (first + last) / 2;
		
		if (mid != cut && chair[mid - 1].first < weight && chair[mid].first >= weight) {
			return mid;
		}
		else if (chair[mid].first < weight) {
			first = mid + 1;
		}
		else if (chair[mid].first >= weight && mid == cut) {
			return mid;
		}
		else {
			last = 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, first);

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

		if (num[idx].second > 0) {
			int index = chair[idx].second + (num[idx].first - num[idx].second);
			num[idx].second--;

			return index;
		}
		else {
			first = idx + 1;
		}
	}

	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 764 KB Correct
2 Correct 4 ms 764 KB Correct
3 Correct 4 ms 880 KB Correct
4 Correct 4 ms 764 KB Correct
5 Correct 4 ms 784 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 5572 KB Correct
2 Execution timed out 1085 ms 9372 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 5732 KB Correct
2 Execution timed out 1113 ms 9312 KB Time limit exceeded
3 Halted 0 ms 0 KB -