제출 #1156521

#제출 시각아이디문제언어결과실행 시간메모리
1156521brianhdzmdo선물상자 (IOI15_boxes)C++20
0 / 100
717 ms468 KiB
#include <algorithm>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <numeric>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define ll long long
#define ld long double
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, a, b) for (ll i = a - 1; i >= b; i--)
#define fi first
#define se second
#define mp(j, k) make_pair(j, k)
#define pb(x) push_back(x)
#define in(x) insert(x)
#define vec vector<ll>
#define vecv vector<vector<ll> >
#define veb vector<bool>
#define vecp vector<pair<ll,ll>>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define ac 1e-7
#define fauto(a)   \
  for (auto i : a) \
    cout << i << " ";
#define fautop(a)  \
  for (auto i : a) \
    cout << i.fi << " " << i.se << endl;

const ll INF = 1e9;

using namespace std;

int delivery(int N, int K, int L, int *positions)
{
    multiset<int> mst;

    int aux = 0;

    for(int i = 0; i < N; ++i)
    {
        if(positions[i] != 0)
            mst.insert(positions[i]);
        else
            aux++;
    }

    N -= aux;
    
    int cost = 0;
    int curK = K;
    bool ok = true;

    for(int i = 1; i < L; ++i)
    {
        if(ok)
        {
            cost++;
        }

        ll ax = mst.count(i);
        if(ax)
        {
            if(ax <= curK)
            {
                curK -= ax;
                N -= ax;
                if(!curK)
                {
                    ok = false;
                    ll dist = min(i, L - i);
                    cost += dist;
                }
            }
            else
            {
                ax -= curK;
                N -= curK;
                if(ax % K == 0 )
                {
                    ll dist = min(i, L - i);
                    if(ok)
                    {
                    cost += dist;
                    ok = false;
                    }   
                    ll c = ax / K;
                    //cout << i << " " << cost << "\n";
                    cost += dist * c * 2;
                    N -= ax;
                }
                else
                {
                    ll dist = min(i, L - i);
                    if(ok)
                        cost += dist;
                    ll c = ax / K;
                    cost += (dist * c * 2) + dist;
                    //cout << i << " " << cost << "\n";
                    N -= ax;
                    curK = ax % K;
                }
            }
        }

        if(N == 0)
        {
            cost += min(i, L - i);
            break;
        }

       // cout << cost << " ";
    }
    
    return cost;
}

/*int32_t main()
{
    int n, k, l;
    cin >> n >> k >> l;
    int positions[n];

    for(int i = 0; i < n; ++i)
        cin >> positions[i];
    
    delivery(n, k, l, positions);
}*/ 
#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...