Submission #140301

#TimeUsernameProblemLanguageResultExecution timeMemory
140301SirCenessBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
867 ms275144 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; ll n, k, s; vector<int> arr; vector<int> ters; ll tekcoz(vector<ll>& ar){ if (ar.size() == 0) return 0; if (ar[0] > ar.back()) reverse(ar.begin(), ar.end()); int i = (int)ar.size()-1; ll ans = 0; while (i >= 0){ ans += ar[i] + ar[i]; i -= k; } return ans; } ll solve(){ vector<ll> 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 coz(int duz, int a){ ll ans = 0; if (duz){ int i = a; while(i >= 0){ ans += arr[i]*2; i -= k; } } else { int i = a; while (i < n){ ans += ters[i]*2; i += k; } } return ans; } ll solve2(){ int l = 0; int r = k-1; ll ans = 1000000000000000; int sinir; for (sinir = 0; sinir < n-1; sinir++){ if (arr[sinir] >= s-arr[sinir]) break; } while (r < n && l <= sinir){ if (r >= sinir){ ans = min(ans, coz(1, l-1) + coz(0, r+1) + s); } l++; r++; } return ans; } 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()); for (int i = 0; i < n; i++) ters.pb(s-p[i]); 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, min(solve(), solve2())); }

Compilation message (stderr)

boxes.cpp: In function 'll tekcoz(std::vector<long long int>&)':
boxes.cpp:29:5: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   i -= k;
   ~~^~~~
boxes.cpp: In function 'll coz(int, int)':
boxes.cpp:46:6: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    i -= k;
    ~~^~~~
boxes.cpp:52:6: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    i += k;
    ~~^~~~
boxes.cpp: In function 'll solve2()':
boxes.cpp:60:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  int r = k-1;
          ~^~
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:81:39: warning: conversion to 'std::vector<int>::value_type {aka int}' from 'll {aka long long int}' may alter its value [-Wconversion]
  for (int i = 0; i < n; i++) ters.pb(s-p[i]);
                                      ~^~~~~
boxes.cpp:85:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  int artik = n%k;
              ~^~
boxes.cpp:87:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  int r = n-1;
          ~^~
boxes.cpp:107:6: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    l += k;
    ~~^~~~
boxes.cpp:110:34: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   if (bas < son) ans += bas*2, l += k;
                                ~~^~~~
boxes.cpp:111:24: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   else ans += son*2, r -= k;
                      ~~^~~~
#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...