Submission #532308

#TimeUsernameProblemLanguageResultExecution timeMemory
532308ivan24Boxes with souvenirs (IOI15_boxes)C++14
0 / 100
1 ms292 KiB
#include<bits/stdc++.h> #include "boxes.h" using namespace std; using ll = long long int; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<vii> vvii; ll min (ll x, ll y){ return ((x < y) ? x : y); } ll max (ll x, ll y){ return ((x > y) ? x : y); } class RangeSum { private: vi og, pref; ll n; public: RangeSum (ll _n){ n = _n; og.assign(n,0); pref.assign(n,0); } void range_update (ll l, ll r, ll inc){ if (l <= r){ og[l]+=inc; if (r != n-1) og[r+1]-=inc; }else{ range_update(l,n-1,inc); range_update(0,r,inc); } } void setup (){ // O(n) for (ll i = 0; n > i; i++){ pref[i] = og[i]; if (i > 0) pref[i] += pref[i-1]; } } ll range_query (ll l, ll r){ ll res = pref[r]; if (l > 0) res -= pref[l-1]; } }; const ll INF = 1e18; long long delivery(int n, int k, int l, int p[]) { ll rem = k; vi fwd, bwd; fwd.assign(k,0); bwd.assign(k,0); ll fwd_ctr = 0, bwd_ctr = 0; for (ll i = 0; n > i; i++){ if (p[i] <= (l-1)/2){ fwd[i%k] += 2*p[i]; fwd_ctr++; } } for (ll i = 0; n > i; i++){ if (p[i] >= (l+2)/2){ bwd[i%k] += 2*(l+1-p[i]); bwd_ctr++; } } for (auto i: fwd) cout << i << " "; cout << endl; for (auto i: bwd) cout << i << " "; cout << endl; ll mid_ctr = n-fwd_ctr-bwd_ctr; rem -= mid_ctr; if (fwd_ctr == 0 && bwd_ctr == 0){ return n; }else if (fwd_ctr == 0){ if (mid_ctr == 1) return bwd[bwd_ctr%k]+l; else return bwd[(bwd_ctr+k-1)%k]; }else if (bwd_ctr == 0){ if (mid_ctr == 1) return fwd[fwd_ctr%k]+l; else return fwd[(fwd_ctr+k-1)%k]; }else{ ll res = bwd[(bwd_ctr+k-1)%k] + fwd[(fwd_ctr+k-1)%k]; if (mid_ctr == 1) res += l; for (ll i = 1; k > i; i++){ ll fwd_te = (fwd_ctr+k-1-i)%k; ll bwd_te = (bwd_ctr+k-1-(rem-i))%k; res = min(res,fwd[fwd_te]+bwd[bwd_te]+l); } return res; } } /* #include <stdio.h> #include <stdlib.h> static char _buffer[1024]; static int _currentChar = 0; static int _charsNumber = 0; static FILE *_inputFile, *_outputFile; static inline int _read() { if (_charsNumber < 0) { exit(1); } if (!_charsNumber || _currentChar == _charsNumber) { _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile); _currentChar = 0; } if (_charsNumber <= 0) { return -1; } return _buffer[_currentChar++]; } static inline int _readInt() { int c, x, s; c = _read(); while (c <= 32) c = _read(); x = 0; s = 1; if (c == '-') { s = -1; c = _read(); } while (c > 32) { x *= 10; x += c - '0'; c = _read(); } if (s < 0) x = -x; return x; } int main() { _inputFile = fopen("boxes.in", "rb"); _outputFile = fopen("boxes.out", "w"); int N, K, L, i; N = _readInt(); K = _readInt(); L = _readInt(); int *p = (int*)malloc(sizeof(int) * (unsigned int)N); for (i = 0; i < N; i++) { p[i] = _readInt(); } fprintf(_outputFile, "%lld\n", delivery(N, K, L, p)); cout << "result: " << delivery(N,K,L,p) << endl; return 0; } */

Compilation message (stderr)

boxes.cpp: In member function 'll RangeSum::range_query(ll, ll)':
boxes.cpp:49:5: warning: no return statement in function returning non-void [-Wreturn-type]
   49 |     }
      |     ^
#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...