Submission #209643

# Submission time Handle Problem Language Result Execution time Memory
209643 2020-03-15T01:39:13 Z Kenzo_1114 Boxes with souvenirs (IOI15_boxes) C++17
10 / 100
14 ms 376 KB
#include<bits/stdc++.h>
#include "boxes.h"
using namespace std;
const int MAXN = 10000010;
const int INF = 2e9 + 7;
 
int N, K, L, POSITIONS[MAXN];
long long int clk[MAXN], cnt[MAXN];
 
long long int delivery(int n, int k, int l, int pos[])
{	
	for(int i = n; i > 0; i--) pos[i] = pos[i - 1];
	pos[0] = 0;

	sort(pos, pos + n + 1);
		
	for(int i = 1; i <= n; i++)
	{
		cnt[i] = 2 * pos[i];
		if(i - k > 0) cnt[i] += cnt[i - 1];
	}
	
	for(int i = n; i > 0; i--)
	{
		clk[i] = 2 * (l - pos[i]);
		if(i + k <= n) clk[i] += clk[i + k];
	}
	
	long long int ans = INF;

	for(int i = 0; i <= n; i++)
		ans = min(ans, cnt[i] + clk[i + 1]);

	for(int i = 0; i + k + 1 <= n + 1; i++)
		ans = min(ans, cnt[i] + l + clk[i + k + 1]);
	
//	long long int ANS2 = ans[id1] + l + ans[id1 + k + 1];
//	long long int ANS3 = ans[id2] + l + ans[id2 - k - 1];
//	printf("ans[%d](%lld) + %d + ans[%d](%lld)\n", id2, ans[id2], l, id2 - k - 1, ans[id2 - k - 1]);
 
//	printf("ans = %lld  ans2 = %lld ans3 = %lld\n", ANS, ANS2, ANS3);
 
	return	ans;
}
/*
int main ()
{
	scanf("%d %d %d", &N ,&K, &L);
	
	for(int i = 0; i < N; i++)	scanf("%d", &POSITIONS[i]);
	
	printf("%lld\n",delivery(N, K, L, POSITIONS));
}
*/
 
/*
	4 2 8 
	1 2 3 5
*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -