제출 #589879

#제출 시각아이디문제언어결과실행 시간메모리
589879FatihSolak선물상자 (IOI15_boxes)C++17
100 / 100
594 ms254556 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int n, int k, int l, int p[]) { vector<int> a,b; for(int i = 0;i<n;i++){ if(2*p[i] <= l){ a.push_back(p[i]); } } for(int i = n-1;i>=0;i--){ if(2*(l-p[i]) < l){ b.push_back(p[i]); } } int sza = a.size(); int szb = b.size(); assert(sza + szb == n); vector<long long> dpa(sza,0),dpb(szb,0); for(int i = 0;i<sza;i++){ dpa[i] = 2 * a[i]; if(i - k >= 0){ dpa[i] += dpa[i-k]; } } for(int i = 0;i<szb;i++){ dpb[i] = 2 * (l-b[i]); if(i - k >= 0){ dpb[i] += dpb[i-k]; } } if(b.empty())return dpa[sza-1]; if(a.empty())return dpb[szb-1]; long long ans = dpa[sza-1] + dpb[szb-1]; for(int i = sza-k;i<sza;i++){ long long val = l; if(i >= 0){ val += dpa[i]; } if(szb-1 - (k-(sza - i - 1)) >= 0){ val += dpb[szb-1 - (k-(sza - i - 1))]; } ans = min(ans,val); } return ans; }

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:16:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   16 |     int sza = a.size();
      |               ~~~~~~^~
boxes.cpp:17:21: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   17 |     int szb = b.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...