Submission #680844

#TimeUsernameProblemLanguageResultExecution timeMemory
680844speedyArdaBoxes with souvenirs (IOI15_boxes)C++14
35 / 100
1 ms256 KiB
#include "boxes.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
long long delivery(int N, int K, int L, int p[]) {
    ll pos = 0;
    while(p[pos] == 0 && pos < N)
        pos++;
    if(pos == N)
        return 0;
    ll ans = 1e18;
    //ll temp = 0;
    ll t_pos = 0;
    ll take = 0;
    while(t_pos < N && p[t_pos] <= L / 2)
    {
        take++;
        t_pos++;
    }

    ll oldtake = take;
    ll r_pos = N - 1;
    ll toadd = 0;
    ll temp = 0;
    ll last_l = t_pos - 1;
    while(last_l >= 0)
    {
        //cout << last_l << "\n";
        toadd += p[last_l] * 2LL;
        last_l -= K;
    }
    ll last_r = t_pos;
    while(last_r < N)
    {
        toadd += (L - p[last_r]) * 2LL;
        //cout << L << " " << p[last_r] << "\n";
        last_r += K;
    }
    //cout << temp << " " << toadd << " " << p[last_r] << " " << last_r << " " << p[last_r]<< "\n";
    ans = min(ans, toadd);

    // Go to other half
    toadd = 0;
    take = oldtake;
    
    while(take < K && t_pos < N)
    {
        t_pos++;
        take++;
    }
    //cout << t_pos << " " << take << "\n";
    last_l = t_pos - 1;
    if(take > 0) {
        toadd += (ll)L;
        last_l -= K;
    }
    while(last_l >= 0)
    {
        toadd += p[last_l] * 2LL;
        last_l -= K;
    }
    last_r = t_pos;
    while(last_r < N)
    {
        toadd += (L - p[last_r]) * 2LL;
        last_r += K;
    }

    //cout << temp << " " << toadd << " " << t_pos << " " << p[t_pos] << "\n";
    //cout << temp << " " << toadd << "\n";
    ans = min(ans, toadd);
    

    //Begin with right side
    r_pos = N - 1;
    take = 0;
    //toadd = 0;
    while(r_pos >= 0 && p[r_pos] >= L / 2)
    {
        take++;
        r_pos--;
    }
    oldtake = take;
    //Begin with right side
            // Don't go to other half
            //l_pos = ;
            temp = 0;
            toadd = 0;
            last_l = r_pos;
            last_r = r_pos + 1;
            while(last_l >= 0)
            {
                toadd += p[last_l] * 2LL;
                last_l -= K;
            }
            while(last_r < N)
            {
                toadd += (L - p[last_r]) * 2LL;
                last_r += K;
            }
           //cout << temp << " " << toadd << " " << p[r_pos] << " " << r_pos << "\n";
            ans = min(ans, toadd);

            //int l_pos = pos;
            toadd = 0;
            take = oldtake;
            while(r_pos >= 0 && take < K)
            {
                //l_pos += K;
                take++;
                r_pos--;
            }
            last_l = r_pos;
            last_r = r_pos + 1;
            if(take > 0) {
                toadd += (ll)L;
                last_r += K;
            }
            while(last_r < N)
            {
                toadd += (L - p[last_r]) * 2LL;
                last_r += K;
            }
            while(last_l >= 0)
            {
                toadd += p[last_l] * 2LL;
                last_l -= K;
            }
           //cout << temp << " " << toadd << " " << p[r_pos] << " " << r_pos << "\n";
            ans = min(ans, toadd);

           
   // ans = min(ans, temp);

    return ans;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:24:8: warning: variable 'temp' set but not used [-Wunused-but-set-variable]
   24 |     ll temp = 0;
      |        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...