Submission #909914

#TimeUsernameProblemLanguageResultExecution timeMemory
909914PlayVoltzCoreputer (IOI23_coreputer)C++17
90 / 100
1 ms600 KiB
#include "coreputer.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

vector<int> malfunctioning_cores(int n){
	int c1=0, c2=0;
	vector<int> c(n, 0), vect;
	int low=-1, high=n, end;
	while (low+1<high){
		int mid=(low+high)/2;
		vect.clear();
		for (int i=0; i<=mid; ++i)vect.pb(i);
		int res=run_diagnostic(vect);
		if (res>=0)high=mid, end=res;
		else low=mid;
	}
	c[high]=1;
	++c1;
	for (int i=0; i<high; ++i){
		vect.clear();
		for (int j=0; j<=high; ++j)if (i!=j)vect.pb(j);
		if (run_diagnostic(vect)<0)c[i]=1, ++c1;
	}
	if (end){
		for (int i=high+1; i<n-1; ++i){
			vect.clear();
			for (int j=high; j<n; ++j)if (i!=j)vect.pb(j);
			if (run_diagnostic(vect)<0)c[i]=1, ++c2;
		}
		if (c1>c2+1)c[n-1]=1;
	}
	else{
		for (int i=high+1; i<n-1; ++i){
			vect.clear();
			for (int j=high+1; j<n; ++j)if (i!=j)vect.pb(j);
			if (run_diagnostic(vect)<0)c[i]=1, ++c2;
		}
		if (c1>c2)c[n-1]=1;
	}
	return c;
}

Compilation message (stderr)

coreputer.cpp: In function 'std::vector<int> malfunctioning_cores(int)':
coreputer.cpp:26:2: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |  if (end){
      |  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...