제출 #1009071

#제출 시각아이디문제언어결과실행 시간메모리
1009071jer033선물상자 (IOI15_boxes)C++17
100 / 100
476 ms325404 KiB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1'000'111'000'111'000'111;

long long delivery(int N, int K, int L, int p[]) {
    ll slices = L;
    vector<ll> locs;
    for (int i=0; i<N; i++)
    {
        if (p[i]!=0)
            locs.push_back(p[i]);
    }
    N = locs.size();//update N, I don't care how many teams are sitting in section 0
    vector<ll> forwards(N, 0);
    for (int i=0; i<N; i++)
    {
        if (i<K)
            forwards[i] = 2*locs[i];
        else
            forwards[i] = forwards[i-K]+(2*locs[i]);
    }
    vector<ll> backwards(N, 0);
    for (int i=N-1; i>=0; i--)
    {
        if (i>=(N-K))
            backwards[i] = 2*(L-locs[i]);
        else
            backwards[i] = backwards[i+K]+(2*(L-locs[i]));
    }
    ll bestcost = INF;
    for (int i=-1; i<N; i++)
        for (ll circles=0; circles<=1; circles++)
        {
            int j = i+1+(K*circles);
            ll cost = 0;
            if (i!=-1)
                cost+=forwards[i];
            if (j<N)
                cost+=backwards[j];
            cost+=(slices*circles);
            bestcost = min(bestcost, cost);
        }
    return bestcost;
}

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:15:18: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   15 |     N = locs.size();//update N, I don't care how many teams are sitting in section 0
      |         ~~~~~~~~~^~
boxes.cpp:36:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   36 |             int j = i+1+(K*circles);
      |                     ~~~^~~~~~~~~~~~
#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...