제출 #427706

#제출 시각아이디문제언어결과실행 시간메모리
427706Dan4LifeBoxes with souvenirs (IOI15_boxes)C++17
35 / 100
223 ms348 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll delivery(int n, int k, int l, int a[])
{
    if(n<=10)
    {
        ll ans = 100000000000;
        vector<int> v; v.clear();
        for(int i = 0; i < n; i++) v.push_back(a[i]);
        do
        {
            ll sum = 0; int cur = 0;
            for(int i = 0; i < n; i++)
            {
                sum+=min(abs(cur-v[i]), l-abs(cur-v[i])), cur = v[i];
                if(i%k==k-1) sum+=min(cur, l-cur), cur = 0;
            }
            sum+=min(cur, l-cur), ans = min(ans, sum);
        }while(next_permutation(v.begin(), v.end()));
        return ans;
    }
    else if(k==1){
        ll ans = 0;
        for(int i = 0; i < n; i++) ans+=min((ll)a[i], (ll)l-a[i]);
        return ans*2;
    }
    else if(k==n){
        ll ans = min({l, a[n-1]*2, (l-a[0])*2});
        for(int i = 0; i < n-1; i++)
            ans = min(ans, (ll)(a[i]+(l-a[i+1]))*2ll),
            ans = min(ans, (ll)(a[i-1]+(l-a[i]))*2ll);
        return ans;
    }
    else{
        ll ans = 0ll; int cur = 0, cnt = k, i = 0;
        for(i = 0; i < n; i++)
        {
            if(a[i]>l/2)break;
            if(cnt==0) ans+=cur, cur = 0, cnt = k;
            ans+=abs(cur-a[i]), cur = a[i];
            if(cur==0) cnt = k+1; cnt--;
        }
        ans+=min(cur, l-cur); cnt = k;
        for(int j = n-1; j>=i; j--)
        {
            if(cnt==0) ans+=l-cur, cur = 0, cnt = k;
            ans+=abs(cur-a[j]), cur = a[j];
            if(cur==0) cnt = k+1; cnt--;
        }
        ans+=min(cur, l-cur);
        return ans;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:43:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   43 |             if(cur==0) cnt = k+1; cnt--;
      |             ^~
boxes.cpp:43:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   43 |             if(cur==0) cnt = k+1; cnt--;
      |                                   ^~~
boxes.cpp:50:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   50 |             if(cur==0) cnt = k+1; cnt--;
      |             ^~
boxes.cpp:50:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   50 |             if(cur==0) cnt = k+1; cnt--;
      |                                   ^~~
#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...