#include <bits/stdc++.h>
using namespace std;
int run_diagnostic(vector<int> T);
// begin my code
vector<int> U {0,0,0,1,0,0,1,0,1,0,1};
int run_diagnostic(vector<int> T) {
int s=0;
for(auto x:T)s+=U[x];
int cnt=0;for(auto x:U)cnt+=x;
int o = cnt-s;
return (s>o) - (o>s);
}
// end my code
vector<int> malfunctioning_cores(int N) {
vector<int> res(N);
int l=0, r=N-1;
// find the first i such that run[0...i] is >=
while(l<r) {
int m = l+(r-l)/2;
vector<int> t;
for(int i=0;i<=m;i++)t.push_back(i);
if((res[m]=run_diagnostic(t))>=0) r=m;
else l=m+1;
}
vector<int> on(N);
on[l] = 1;
if(l == N-1)
return on;
for(int i=0;i<l;i++) {
// try this one
vector<int> t;
for(int j=0;j<=l;j++)
if(i!=j)
t.push_back(j);
if(run_diagnostic(t)<0) on[i]=1;
}
for(int i=l+1;i<N-1;i++) {
vector<int> t;
for(int j=0;j<l;j++) t.push_back(j);
t.push_back(i);
if(run_diagnostic(t)>=0) on[i]=1;
}
if(res[l] == 0) {
int ls=0,rs=0;
for(int i=0;i<=l;i++)ls+=on[i];
for(int i=l+1;i<N;i++)rs+=on[i];
if(ls>rs) on[N-1]=1;
}
else {
int ls=0,rs=0;
for(int i=0;i<l;i++)ls+=on[i];
for(int i=l+1;i<N;i++)rs+=on[i];
if(ls>rs) on[N-1]=1;
}
return on;
}
int main() {
auto v=malfunctioning_cores(U.size());
for(auto x:v)cout<<x<<endl;
}
Compilation message
/usr/bin/ld: /tmp/ccBZFiCL.o: in function `run_diagnostic(std::vector<int, std::allocator<int> >)':
stub.cpp:(.text+0xc0): multiple definition of `run_diagnostic(std::vector<int, std::allocator<int> >)'; /tmp/ccL2jG0P.o:coreputer.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccBZFiCL.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccL2jG0P.o:coreputer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status