Submission #1034517

#TimeUsernameProblemLanguageResultExecution timeMemory
1034517fv3Boxes with souvenirs (IOI15_boxes)C++14
100 / 100
694 ms372060 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1ll << 60; ll delivery(int N_, int K_, int L_, int p[]) { ll L = L_; ll N = N_; ll K = K_; vector<ll> v(N); for (int i = 0; i < N; i++) v[i] = p[i]; sort(v.begin(), v.end()); // Subtask 5: K <= 3000 // Solve with Dynamic Programming // Let DP_r[i] be the minimum time to deliver the first i // packages and go back to start while only going right // Let DP_l[i] be the minimum time to deliver the last i // packages and go back to start while only going left // Find the optimal place to stop going right vector<ll> DP_r(N + 1, INF), DP_l(N + 1, INF); DP_r[0] = 0; DP_l[N] = 0; for (int i = 1; i <= N; i++) { DP_r[i] = min(DP_r[max(0ll, i - K)] + v[i - 1] * 2, DP_r[max(0ll, i - K)] + L); } for (int i = N-1; i >= 0; i--) { DP_l[i] = min(DP_l[min(i+K, N)] + (L - v[i]) * 2, DP_l[min(i+K, N)] + L); } ll res = INF; for (int i = 0; i <= N; i++) res = min(res, DP_r[i] + DP_l[i]); return res; }

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:36:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   36 |     for (int i = N-1; i >= 0; i--)
      |                  ~^~
#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...