제출 #1359101

#제출 시각아이디문제언어결과실행 시간메모리
1359101whallyCoreputer (IOI23_coreputer)C++20
20 / 100
0 ms344 KiB
#include <bits/stdc++.h>
#include "coreputer.h"
using namespace std;

std::vector<int> malfunctioning_cores(int N)
{
	if (N == 2){
		int res = run_diagnostic({0});
		if (res == 0) return {1,1};
		else if (res == 1) return {1,0};
		else return {0,1};
	}
	int l = 0, r = N-1;
	int ch0 = 0;
	while (l < r){
		int mid = (l+r)/2;
		vector<int> now;
		for (int i = 0; i <= mid; i++) now.push_back(i);
		int res = run_diagnostic(now);
		if (res == -1) l = mid+1;
		else{
			if (res == 0) ch0 = 1;
			r = mid;
		}
	}

	int mid = l;

	vector<int> ans, col;
	for (int i = 0; i < N; i++){
		col.push_back(0);
		ans.push_back(0);
	}

	set<int> st;
	l = mid-1;
	r = mid+1;
	if (ch0){
		for (int i = 0; i <= mid; i++) st.insert(i);
		while (l >= 0){
			st.erase(l);
			vector<int> ask;
			for (int x : st) ask.push_back(x);
			int res = run_diagnostic(ask);
			if (res != 0) st.insert(l);
			l--;
		}
		for (int x : st) ans[x] = 1;
		st.clear();
		for (int i = mid; i < N-1; i++) st.insert(i);
		int mnres = 2e9;
		while (r < N-1){
			st.erase(r);
			vector<int> ask;
			for (int x : st) ask.push_back(x);
			int res = run_diagnostic(ask);
			mnres = min(mnres, res);
			col[r] = res;
			st.insert(r);
			r++;
		}
		for (int i = mid+1; i < N-1; i++){
			if (col[i] == mnres){
				ans[i] = 1;
			}
		}
		if (mnres == -1) ans[N-1] = 1;

		return ans;
	}
	else {
		for (int i = 0; i <= mid; i++) st.insert(i);
		while (l >= 0){
			st.erase(l);
			vector<int> ask;
			for (int x : st) ask.push_back(x);
			int res = run_diagnostic(ask);
			if (res == -1) st.insert(l);
			l--;
		}
		for (int x : st) ans[x] = 1;
		st.clear();
		for (int i = mid; i < N; i++) st.insert(i);
		while (r < N){
			st.erase(r);
			vector<int> ask;
			for (int x : st) ask.push_back(x);
			int res = run_diagnostic(ask);
			if (res == -1) st.insert(r);
			r++;
		}
		for (int x : st) ans[x] = 1;
		return ans;
	}

	return ans;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…