Submission #163008

# Submission time Handle Problem Language Result Execution time Memory
163008 2019-11-10T19:52:26 Z kostia244 Boxes with souvenirs (IOI15_boxes) C++14
10 / 100
2 ms 376 KB
#include "boxes.h"
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
ll n, k, l;
vi pos, dpl, dpr;
ll getl(ll x) {
	return min(2ll*x, l);
}
ll getr(ll x) {
	return min(2ll*(l-x), l);
}
long long delivery(int N, int K, int L, int P[]) {
	n=N, k = K, l = L;
	ll ans = LLONG_MAX;
	pos.resize(n+2);
	dpl.resize(n+2);
	dpr.resize(n+2);
	for(int i = 0; i < n; i++)
		pos[i+1] = P[i];
	for(int i = 1; i <= n; i++) {
		if(i%k==1) {
			dpl[i] = dpl[i-1]+getl(pos[i]);
		} else {
			dpl[i] = dpl[i-1]-getl(pos[i-1])+getl(pos[i]);
		}
	}
	for(int i = n; i; i--) {
		if((n-i)%k==0) {
			dpr[i] = dpr[i+1]+getr(pos[i]);
		} else {
			dpr[i] = dpr[i+1]-getr(pos[i+1])+getr(pos[i]);
		}
	}
	for(int i = 0; i <= n; i++) {
		ans = min(ans, dpl[i]+dpr[i+1]);
//		cout << i << " " << dpl[i] << " " << dpr[i+1] << "\n";
	}
    return ans;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:31:14: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  for(int i = n; i; i--) {
              ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -