Submission #1008975

#TimeUsernameProblemLanguageResultExecution timeMemory
1008975jer033Boxes with souvenirs (IOI15_boxes)C++17
50 / 100
2098 ms37560 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 (int j=i+1; j<=N; j++) { ll cost = 0; if (i!=-1) cost+=forwards[i]; if (j!=N) cost+=backwards[j]; ll runaround = j-i-1; ll KK = K; ll circles = 0; if (runaround!=0) circles = ((runaround-1)/KK)+1; cost+=(slices*circles); bestcost = min(bestcost, cost); } return bestcost; }

Compilation message (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
      |         ~~~~~~~~~^~
#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...