Submission #197572

#TimeUsernameProblemLanguageResultExecution timeMemory
197572AaronNaiduBoxes with souvenirs (IOI15_boxes)C++14
Compilation error
0 ms0 KiB
long long delivery(int n, int k, int l, int positions[]) {
    long long sum = 0;
    long long minSum;
    if(k == 1) {
        //cout << "In branch\n";
        for(int i = 0; i < n; i++) {
            //cout << "Value " << positions[i] << "\n";
            sum += 2 * min(positions[i], l - positions[i]);
            //cout << "Sum now " << sum << "\n"; 
        }
        return sum;
    }
    sort(positions, positions + n);
    /*long long zeroes;
    for (int i = 0; i < n; i++)
    {
        if(positions[i] == 0) {
            zeroes++;
        }
        else {
            break;
        }
    }
    n -= zeroes;*/
    for (int i = 0; i < n; i++)
    {
        positions[i] = positions[i+zeroes];
    }
    if(k >= n) {
        if(positions[0] > (double) l/2) {
            return 2 * (l - positions[0]);
        }
        if(positions[n-1] < (double) l/2) {
            return 2 * positions[n-1];
        }
        for(int i = 0; i < n-1; i++) {
            if(positions[i+1] - positions[i] > double(l/2)) {
                return 2 * (positions[i] + (l - positions[i+1]));
            }
        }
        return l;
    }
    long long bestSum = n * l;
    if(positions[0] > (double) l/2) {
        int delivered = 0;
        int counter = 0;
        while(delivered < n) {
            delivered += k;
            sum += 2 * (l - positions[counter]);
            counter += k;
        }
        return sum;
    }
    if(positions[n-1] < (double) l/2) {
        int delivered = 0;
        int counter = 0;
        reverse(positions, positions + n);
        while(delivered < n) {
            delivered += k;
            sum += 2 * positions[counter];
            counter += k;
        }
        return sum;
    }
    
    
    
    long long remainde = n%k;
    long long trial = 0;
    long long trial2 = 0;
    long long point = -1;
    sum = 0;
    long long trialNew = 0;
    if (remainde)
    {
        //cout << "Was remainder\n";
        //cout << "It's " << positions[remainde - 1] << "vs" << n- positions[n-remainde] << "\n";
        //if (positions[remainde - 1] < l - positions[n-remainde]) {
        if(true) {
             bool firstHalf = false;
            //cout << "Cut out first \n";
            sum += min(2 * positions[remainde - 1], l);
            //cout << "Initial sum " << sum << "\n";
            for (int i = remainde; i < n; i++) {
                point++;
                if(point % k == 0) {
                    trial =  2 * min(positions[i], l - positions[i]);
                    if(positions[i] < double (l/2)) {
                        firstHalf = true;
                    }
                    else {
                        firstHalf = false;
                    }
                    //cout << "Start with distance " << trial << "\n";
                }
                trial2 = 2 * min(positions[i], l - positions[i]);
                trial = max(trial, trial2);
                if(point % k == k-1 or i == n-1 or positions[i+1] - positions[i] > double(l/2)) {
                    trial2 = 2 * min(positions[i], l - positions[i]);
                    //cout << "End with distance " << trial << "\n";
                    trial = max(trial, trial2);
                    if(firstHalf and positions[i] > double (l/2)) {
                        sum += l;
                    }
                    else {
                        sum += trial;
                    }
                    
                    point = -1;
                }
            }
        
        }
        if(true) {
            bool firstHalf = false;
            minSum = sum;
            sum = 0;
            sum += min(l, 2 * (n - positions[n-remainde]));
            for (int i = 0; i < n-remainde; i++) {
                point++;
                if(point % k == 0) {
                    trial =  2 * min(positions[i], l - positions[i]);
                    if(positions[i] < double (l/2)) {
                        firstHalf = true;
                    }
                    else {
                        firstHalf = false;
                    }
                }
                trial2 = 2 * min(positions[i], l - positions[i]);
                trial = max(trial, trial2);
                if(point % k == k-1 or i == n-1-remainde or positions[i+1] - positions[i] > double(l/2)) {
                    trial2 = 2 * min(positions[i], l - positions[i]);
                    trial = max(trial, trial2);
                    if(firstHalf and positions[i] > double (l/2)) {
                        sum += l;
                    }
                    else {
                        sum += trial;
                    }
                    
                    point = -1;
                }
            }
        }
        minSum = min(minSum, sum);
        return minSum;
    }
    else {
         bool firstHalf = false;
        for (int i = 0; i < n; i++)
        {
            point++;
            if(point % k == 0) {
                trial =  2 * min(positions[i], l - positions[i]);
                if(positions[i] < double (l/2)) {
                        firstHalf = true;
                    }
                    else {
                        firstHalf = false;
                    }
            }
            trial2 = 2 * min(positions[i], l - positions[i]);
            trial = max(trial, trial2);
            if(point % k == k-1 or i == n-1 or positions[i+1] - positions[i] > double(l/2)) {
                trial2 = 2 * min(positions[i], l - positions[i]);
                    trial = max(trial, trial2);
                    if(firstHalf and positions[i] > double (l/2)) {
                        sum += l;
                    }
                    else {
                        sum += trial;
                    }
                    
                    point = -1;
            }
        }
        return sum;
    }
    
    for(;;) {

    }
    return n;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:8:24: error: 'min' was not declared in this scope
             sum += 2 * min(positions[i], l - positions[i]);
                        ^~~
boxes.cpp:13:5: error: 'sort' was not declared in this scope
     sort(positions, positions + n);
     ^~~~
boxes.cpp:13:5: note: suggested alternative: 'short'
     sort(positions, positions + n);
     ^~~~
     short
boxes.cpp:27:36: error: 'zeroes' was not declared in this scope
         positions[i] = positions[i+zeroes];
                                    ^~~~~~
boxes.cpp:57:9: error: 'reverse' was not declared in this scope
         reverse(positions, positions + n);
         ^~~~~~~
boxes.cpp:82:20: error: 'min' was not declared in this scope
             sum += min(2 * positions[remainde - 1], l);
                    ^~~
boxes.cpp:84:26: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
             for (int i = remainde; i < n; i++) {
                          ^~~~~~~~
boxes.cpp:97:25: error: 'max' was not declared in this scope
                 trial = max(trial, trial2);
                         ^~~
boxes.cpp:118:20: error: 'min' was not declared in this scope
             sum += min(l, 2 * (n - positions[n-remainde]));
                    ^~~
boxes.cpp:131:25: error: 'max' was not declared in this scope
                 trial = max(trial, trial2);
                         ^~~
boxes.cpp:146:18: error: 'min' was not declared in this scope
         minSum = min(minSum, sum);
                  ^~~
boxes.cpp:155:30: error: 'min' was not declared in this scope
                 trial =  2 * min(positions[i], l - positions[i]);
                              ^~~
boxes.cpp:163:26: error: 'min' was not declared in this scope
             trial2 = 2 * min(positions[i], l - positions[i]);
                          ^~~
boxes.cpp:164:21: error: 'max' was not declared in this scope
             trial = max(trial, trial2);
                     ^~~
boxes.cpp:43:15: warning: unused variable 'bestSum' [-Wunused-variable]
     long long bestSum = n * l;
               ^~~~~~~
boxes.cpp:73:15: warning: unused variable 'trialNew' [-Wunused-variable]
     long long trialNew = 0;
               ^~~~~~~~