답안 #209646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209646 2020-03-15T01:58:11 Z Kenzo_1114 선물상자 (IOI15_boxes) C++17
0 / 100
5 ms 380 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], pos[MAXN];
long long int clk[MAXN], cnt[MAXN];
 
long long int delivery(int n, int k, int l, int positions[])
{	
	int N = n;
	for(int i = 0; i < n; i++)	pos[i + 1] = positions[i];

	for(int i = 1; i <= n; i++)	
		if(!pos[i])
			pos[i] = INF, N--;

	sort(pos, pos + n + 1);
	n = N;
		
	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]);
 
	for(int i = n + 1; i - k - 1 >= 0; i--)
		ans = min(ans, clk[i] + l + cnt[i - k - 1]);
 
	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
*/

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:12:6: warning: declaration of 'N' shadows a global declaration [-Wshadow]
  int N = n;
      ^
boxes.cpp:7:5: note: shadowed declaration is here
 int N, K, L, POSITIONS[MAXN], pos[MAXN];
     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -