Submission #963665

#TimeUsernameProblemLanguageResultExecution timeMemory
963665hirayuu_ojBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
577 ms334948 KiB
#include "boxes.h" #include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define all(x) x.begin(),x.end() using ll=long long; const ll INF=1LL<<60; long long delivery(int N, int K, int L, int p[]) { vector<int> ps; rep(i,N){ if(p[i]!=0)ps.emplace_back(p[i]); } N=ps.size(); vector<ll> dp(N+1,0); rep(i,N){ dp[i+1]=ps[i]+dp[max(0,i+1-K)]+min(ps[i],L-ps[i]); } rep(i,N){ ps[i]=(L-ps[i])%L; } reverse(all(ps)); vector<ll> dp2(N+1,0); rep(i,N){ dp2[i+1]=ps[i]+dp2[max(0,i+1-K)]+min(ps[i],L-ps[i]); } ll ans=INF; rep(i,N+1){ ans=min(ans,dp[i]+dp2[N-i]); } return ans; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:14:14: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   14 |     N=ps.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...