This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <fstream>
#include <vector>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
const int nmax=200005;
const int prdf=2;//modifici dupa asta
int lg[nmax];
int spec[nmax],norm[nmax],us[nmax];
int mx,nr,i,gasit;
vector<int> v[nmax];
int cate_st(int poz)
{
if(v[poz].empty()) v[poz]=ask(poz);
return v[poz][0];
}
int cate(int poz)
{
if(v[poz].empty()) v[poz]=ask(poz);
if(!(v[poz][0]+v[poz][1])) gasit=1;
return (v[poz][0]+v[poz][1]);
}
int cate_dr(int poz)
{
return (cate(poz)-cate_st(poz));
}
int n;
void solve(int st,int dr)
{
if(st>dr) return;
if(gasit) return;
if(cate(st)!=cate(dr))
{
if(cate(st)<cate(dr))
{
if(!us[st])spec[++nr]=st,us[st]=1;
solve(st+1,dr);
return;
}
if(!us[dr])spec[++nr]=dr,us[dr]=1;
solve(st,dr-1);
return;
}
if(st==dr&&cate(st)==0)
{
if(!us[st]) spec[++nr]=st,us[st]=1;
}
if(st+1>=dr) return;
if(cate_st(st)+cate_dr(dr)==cate(st)) return;
int m=(st+dr)/2;
if(rand()%2)
{
solve(st,m);
solve(m,dr);
}
else
{
solve(m,dr);
solve(st,m);
}
}
int find_best(int N) {
n=N;srand(time(NULL));
spec[0]=-1;
solve(0,n-1);
for(i=1;i<=nr;i++)
if(cate(spec[i])==0)
return spec[i];
return 0;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:69:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(i=1;i<=nr;i++)
^~~
prize.cpp:72:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
return 0;
^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |