#include "coreputer.h"
#include<vector>
#include<numeric>
#include<random>
#include<chrono>
using namespace std;
using ll=int;
using vll=vector<ll>;
using pll=pair<ll,ll>;
vll to_vector(ll x, ll n){
vll vec;
while(n--){
vec.push_back(x%2);
x/=2;
}
return vec;
}
vll vect(ll x){
vll res;
for(ll i=0;i<32;i++){
if(x&(1<<i)){
res.push_back(i);
}
}
return res;
}
std::vector<int> malfunctioning_cores(int N) {
vll vec((1<<N)-1);
iota(vec.begin(),vec.end(),1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<pll> past;
while(vec.size()!=1){
l:
ll x=0;
for(ll i=0;i<N;i++){
if(uniform_int_distribution<ll>(0,1)(rng)){
x^=(1<<i);
}
}
if(x==0||x==(1<<N)-1){
goto l;
}
for(pll p:past){
if(x&p.first==x&&p.second==-1){
goto l;
}
if(x&p.first==p.first&&p.second==-1){
goto l;
}
}
ll x1=0,x2=0,x3=0;
for(ll y:vec){
if(__builtin_popcount(y&x)>__builtin_popcount(y&(~x))){
x1++;
}
if(__builtin_popcount(y&x)==__builtin_popcount(y&(~x))){
x2++;
}
if(__builtin_popcount(y&x)<__builtin_popcount(y&(~x))){
x3++;
}
}
if(min(x1,x3)<vec.size()/4){
goto l;
}
vll t;
ll res=run_diagnostic(vect(x));
for(ll y:vec){
if(res==1){
if(__builtin_popcount(y&x)>__builtin_popcount(y&(~x))){
t.push_back(y);
}
}
if(res==0){
if(__builtin_popcount(y&x)==__builtin_popcount(y&(~x))){
t.push_back(y);
}
}
if(res==-1){
if(__builtin_popcount(y&x)<__builtin_popcount(y&(~x))){
t.push_back(y);
}
}
}
vec=t;
past.push_back({x,res});
}
return to_vector(vec[0],N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |