Submission #100714

# Submission time Handle Problem Language Result Execution time Memory
100714 2019-03-13T15:25:25 Z Bodo171 The Big Prize (IOI17_prize) C++14
0 / 100
1000 ms 5812 KB
#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];
int mx,nr,i,n;
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);
    return (v[poz][0]+v[poz][1]);
}
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;
       pp--;x--;
    }
    ret.first=pp;
}
void solve(int st,int dr)
{
    if(st+1>=dr) return;
    int len=spec[dr]-spec[st];
    int poz=spec[st];
    for(int p=lg[len];p>=0;p--)
    {
        if(poz+(1<<p)<spec[dr])
     {
        if(cate(poz+(1<<p))<mx)
        {
            poz+=(1<<p);
            pair<int,int> pe=vezi_al_catelea(poz);
            solve(st,pe.first);solve(pe.second,dr);
            return;
        }
        if(cate_st(poz+(1<<p))==st&&cate(poz+(1<<p))==mx)
            poz+=(1<<p);
     }
    }
    poz++;spec[st+1]=poz;
}
int find_best(int N) {
    n=N;
    for(i=2;i<=n+1;i++)
        lg[i]=lg[i/2]+1;
    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)
            {
                spec[++nr]=i;
                if(!cate(i)) return i;
            }

    }
    spec[mx+1]=n;
    solve(nr,mx+1);
    for(i=1;i<=mx;i++)
        if(cate(spec[i])==0)
           return spec[i];
	return 0;
}

Compilation message

prize.cpp: In function 'std::pair<int, int> vezi_al_catelea(int)':
prize.cpp:39:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
prize.cpp: In function 'int find_best(int)':
prize.cpp:84:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for(i=1;i<=mx;i++)
     ^~~
prize.cpp:87: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
1 Execution timed out 3023 ms 5752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3089 ms 5812 KB Time limit exceeded
2 Halted 0 ms 0 KB -