이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <fstream>
#include <vector>
#include <iostream>
#include <cmath>
using namespace std;
const int nmax=200005;
const int prdf=500;//modifici dupa asta
int lg[nmax];
int spec[nmax],norm[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;
pair<int,int> vezi_al_catelea(int x)
{
int pp=0;
while(x<n&&cate(x)<mx)
x++;
if(x==n) pp=mx;
else pp=cate_st(x);
x--;
pair<int,int> ret;
ret.second=pp;
while(x>=0&&cate(x)<mx)
{
spec[pp]=x;norm[x]=pp;
pp--;x--;
}
ret.first=pp;
return ret;
}
void solve(int st,int dr,int avem_st,int avem_dr)
{
if(st>dr) return;
if(avem_st+1>=avem_dr) return;
if(gasit) return;
pair<int,int> pe;
if(cate(st)<mx)
{
spec[++nr]=st;
pe=vezi_al_catelea(st);
solve(pe.second+1,dr,norm[pe.second],avem_dr);
return;
}
if(cate(dr)<mx)
{
spec[++nr]=dr;
pe=vezi_al_catelea(dr);
solve(st,pe.first-1,avem_st,norm[pe.first]);
return;
}
if(cate_st(st)+cate_dr(dr)==mx) return;
int m=(st+dr)/2;
if(cate(m)<mx)
{
pe=vezi_al_catelea(m);
solve(st,pe.first-1,avem_st,norm[pe.first]);
solve(pe.second+1,dr,norm[pe.second],avem_dr);
}
else
{
if(cate_st(st)+cate_dr(m)!=mx) solve(st,m-1,avem_st,mx-cate_dr(m)+1);
if(cate_st(m)+cate_dr(dr)!=mx) solve(m+1,dr,cate_st(m),avem_dr);
}
}
int find_best(int N) {
n=N;
for(i=0;i<min(prdf,n);i++)
{
v[i]=ask(i);
if(v[i][0]+v[i][1]>mx)
mx=v[i][0]+v[i][1];
}
spec[0]=-1;
for(i=0;i<min(prdf,n);i++)
{
if(v[i][0]+v[i][1]!=mx)
{
++nr;norm[i]=nr;spec[nr]=i;
if(!cate(i)) return i;
}
}
spec[mx+1]=n;
solve(prdf,n-1,nr,mx+1);
for(i=1;i<=mx;i++)
if(cate(spec[i])==0)
return spec[i];
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:101:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(i=1;i<=mx;i++)
^~~
prize.cpp:104: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... |