제출 #380168

#제출 시각아이디문제언어결과실행 시간메모리
380168Theo830선물상자 (IOI15_boxes)C++17
100 / 100
654 ms333388 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll delivery(int n, int k, int l, int ar[]) {
    ll ans = 1e18;
    vector<int>arr;
    f(i,0,n){
        if(ar[i] != 0){
            arr.pb(ar[i]);
        }
    }
    n = arr.size();
    ll pre[n];
    f(i,0,n){
        if(i < k){
            pre[i] = min(l,2 * arr[i]);
        }
        else{
            pre[i] = min(l,2 * arr[i]) + pre[i-k];
        }
    }
    ll suf[n];
    f(i,0,n){
        if(i < k){
            suf[i] = min(l,2 * (l - arr[n-i-1]));
        }
        else{
            suf[i] = min(l,2 * (l - arr[n-i-1])) + suf[i-k];
        }
    }
    n = arr.size();
    f(p,0,n+1){
        ll res = 0;
        if(p != 0){
            res += pre[p-1];
        }
        int p2 = n - p;
        if(p2 != 0){
            res += suf[p2-1];
        }
        ans = min(ans,res);
    }
    return ans;
}

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

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:31:17: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   31 |     n = arr.size();
      |         ~~~~~~~~^~
boxes.cpp:50:17: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   50 |     n = arr.size();
      |         ~~~~~~~~^~
#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...