Submission #60723

# Submission time Handle Problem Language Result Execution time Memory
60723 2018-07-24T15:19:49 Z Flugan42 Boxes with souvenirs (IOI15_boxes) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double lld;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define per(i,a,b) for(ll i = a; i >= b; i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto a : x)
#define inf 1000000000000000000

long long delivery(int N, int K, int L, int p[]) {
  ll best = inf,n = N,cur,res;
  vi a;
  rep(i,0,N) {
    if (p[i] == 0) n--;
    else a.push_back(p[i]);
  }

  rep(h,0,n+1) rep(v,0,n+1){
    if (h+v > n) break;
    ll l = n-h-v;
    res = ((l+K-1)/K)*L;
    cur = h-1;
    while(cur >= 0){
      res += a[cur]*2;
      cur -= K;
    }
    cur = n-v;
    while (cur < n){
      res += (L-a[cur])*2;
      cur += K;
    }
    best = min(best,res);
  }

  return best;
}




////grader////
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));
    return 0;
}

Compilation message

/tmp/ccH3tOhH.o: In function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'
/tmp/ccR2mpp2.o:boxes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status