Submission #130284

#TimeUsernameProblemLanguageResultExecution timeMemory
130284UserIsUndefinedRice Hub (IOI11_ricehub)C++11
68 / 100
1073 ms2172 KiB
#include <bits/stdc++.h>
#include <iostream>     
#include <algorithm>
#include <vector>
 
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
 
 
int X[100005];
int D[100005];
bool visited[100005];
 
int gethalf(int n){
    int hal = (n)/2;
    D[0] = hal;
    int ind = 1;
 
    for (int i = 1 ; i < n/2+2 ; i++){
    if (hal+i < n){
        D[ind] = hal+i;
        ind++;
    }
    if (hal-i >= 0){
        D[ind] = hal-i;
        ind++;
    }
    }
 
 
}
 
int besthub(int n, int L, int X[], long long B){
    int maxx = 0;
 
    gethalf(n);
 
 
 
    for (int h = 0 ; h < n ; h++){
        long long bud = B;
        int g = D[h];
        int i = g;
        int j = g+1;
        int cont = 0;
 
        while ((i >= 0)||(j < n)){
            long long absi = abs(X[g] - X[i]);
            long long absj = abs(X[g] - X[j]);
            if (i < 0)absi = LONG_MAX;
            if (j >= n)absj = LONG_MAX;
 
            if (bud-min(absi,absj) < 0)break;
 
            if (absi < absj){
                i--;
                bud-= absi;
                cont++;
            }
            else {
                j++;
                bud-= absj;
                cont++;
            }
 
        }
        maxx = max(maxx,cont);
        if (maxx == n)break;
 
 
    }
    return maxx;
 
}

Compilation message (stderr)

ricehub.cpp: In function 'int gethalf(int)':
ricehub.cpp:31:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...