Submission #140088

#TimeUsernameProblemLanguageResultExecution timeMemory
140088SirCenessBoxes with souvenirs (IOI15_boxes)C++14
50 / 100
91 ms16580 KiB
#include "boxes.h" #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define inside sl<=l&&r<=sr #define outside r<sl||sr<l #define orta ((l+r)>>1) #define INF 1000000009 #define mod 1000000007 #define ppair(x); cerr << "(" << x.first << ", " << x.second << ")\n"; #define bas(x) #x << ": " << x << " " #define prarr(x, n); cerr << #x << ": "; for(int qsd = 0; qsd < n; qsd++) cerr << x[qsd] << " "; cerr << "\n"; #define prarrv(x); cerr << #x << ": "; for(int qsd = 0; qsd < (int)x.size(); qsd++) cerr << x[qsd] << " "; cerr << "\n"; using namespace std; typedef long long ll; int n, k, s; vector<int> arr; ll tekcoz(vector<int>& ar){ sort(ar.begin(), ar.end()); int i = ar.size()-1; ll ans = 0; while (i >= 0){ ans += ar[i] + ar[i]; i -= k; } return ans; } ll solve(){ vector<int> sol, sag; for (int i = 0; i < n; i++) if (arr[i] < s - arr[i]) sol.pb(arr[i]); else sag.pb(s - arr[i]); return tekcoz(sol) + tekcoz(sag); } ll delivery(int N, int K, int L, int p[]) { n = N; k = K; s = L; for (int i = 0; i < n; i++) arr.pb(p[i]); sort(arr.begin(), arr.end()); ll ans = 0; int artik = n%k; int l = 0; int r = n-1; ll bas, son; if (artik){ bas = arr[l+artik-1]; son = s - arr[r-artik+1]; if (bas < son){ ans = bas*2; l += artik; } else { ans = son*2; r -= artik; } } while (l <= r){ bas = arr[l+k-1]; son = s-arr[r-k+1]; //cout << bas(bas) << bas(son) << endl; if (2*bas > s && 2*son > s){ ans += s; l += k; continue; } if (bas < son) ans += bas*2, l += k; else ans += son*2, r -= k; } //cout << solve() << endl; return min(ans, solve()); }

Compilation message (stderr)

boxes.cpp: In function 'll tekcoz(std::vector<int>&)':
boxes.cpp:23:19: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int i = ar.size()-1;
          ~~~~~~~~~^~
#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...