#include "coreputer.h"
#include <bits/stdc++.h>
using namespace std;
bool par = false;
bool check(vector<int>& tagged){
int answer = run_diagnostic(tagged);
if(answer == 0) par = true;
return answer >= 0;
}
std::vector<int> malfunctioning_cores(int N) {
vector<int> tagged;
vector<int> cores(N);
vector<int> ans(N, 0);
for(int i = 0; i < N; ++i) cores[i] = i;
int fh = 0, sh = 0;
int lo = 0, hi = N;
while(hi > lo + 1){
int mid = lo + (hi - lo)/2;
vector<int> temp;
for(int i = 0; i <= mid; ++i) temp.push_back(cores[i]);
if(check(temp)){
hi = mid;
} else {
lo = mid;
}
}
ans[hi] = 1;
fh++;
for(int i = 0; i <= hi; ++i) tagged.push_back(i);
for(int i = 0; i < hi; ++i) {
vector<int> temp(tagged.begin(), tagged.end());
temp.erase(find(temp.begin(), temp.end(), i));
if(!check(temp)) {
ans[i] = 1;
fh++;
}
temp.push_back(i);
}
tagged.clear();
int sel = 0;
if(par) sel = hi+1;
else sel = hi;
for(int i = sel; i < N; ++i) tagged.push_back(i);
for(int i = hi+1; i < N-1; ++i) {
vector<int> temp(tagged.begin(), tagged.end());
temp.erase(find(temp.begin(), temp.end(), i));
if(!check(temp)) {
ans[i] = 1;
sh++;
}
temp.push_back(i);
}
if(par){
if(fh != sh) ans[N-1] = 1;
} else {
if(fh-1 != sh) ans[N-1] = 1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |