Submission #73732

# Submission time Handle Problem Language Result Execution time Memory
73732 2018-08-28T19:57:46 Z aleksam Boxes with souvenirs (IOI15_boxes) C++14
20 / 100
3 ms 428 KB
#include "boxes.h"
#include <bits/stdc++.h>
#define MAX_N 10000000
using namespace std;
long long r[MAX_N], l[MAX_N];
long long p[MAX_N];
long long N, K, L;
void compute_l(){//l[i]=cena koju moram da platim ako hocu da snabdem sve do i-tog direktno
	for(int i=0; i<N; ++i){
		if(i%K!=0)l[i]=l[i-1]-p[i-1]+p[i];
		else l[i]=l[i-1]+p[i];
	}
	for(int i=0; i<N; ++i){
		l[i]*=2;
	}
}
void compute_r(){
	for(int i=N-1; i>=0; --i){//r[i]=cena za koju mogu da garantujem da pokrivam sve od i do N-1
		if((N-1-i)%K!=0)r[i]=r[i+1]+(L-p[i])-(L-p[i+1]);
		else r[i]=r[i+1]+L-p[i];
	}
	for(int i=0; i<N; ++i){
		r[i]*=2;
	}
}
long long delivery(int n, int k, int li, int P[]) {
	N=n;K=k;L=li;
	int nula=0;
	while(nula<N && P[nula]==0)nula++;
	N-=nula;
	for(int i=0; i<N; ++i)p[i]=P[i+nula];
	compute_l();
	compute_r();
	//for(int i=0; i<N; ++i)printf("l[%d]=%d\n", i, l[i]);
	//for(int i=0; i<N; ++i)printf("r[%d]=%d\n", i, r[i]);
	long long min=(long long)r[0];
	if(r[0]<min)min=r[0];//Ako idemo skroz s iste strane
	if(l[N-1]<min)min=l[N-1];
	for(int i=0; i<N-1; ++i){
		//Od 0...i radi l, a i+1...N-1 uzima r
		if(l[i]+r[i+1]<min)min=l[i]+r[i+1];
	}
	for(int i=0; i+k+1<N; ++i){
		//0...i radi l, i+k+1...N-1 radi r
		if(l[i]+r[i+k+1]+L<min)min=l[i]+r[i+k+1]+L;
	}
	if(r[k]+L<min)min=r[k]+L;
	if(l[N-k-1]+L<min)min=l[N-k-1]+L;
	return min;
}

Compilation message

boxes.cpp: In function 'void compute_r()':
boxes.cpp:18:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  for(int i=N-1; i>=0; --i){//r[i]=cena za koju mogu da garantujem da pokrivam sve od i do N-1
            ~^~
# 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 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 384 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
# 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 296 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 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
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 428 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 296 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 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
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 428 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 296 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 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
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 428 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 296 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 Halted 0 ms 0 KB -