답안 #82057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82057 2018-10-28T20:47:58 Z wzy 선물상자 (IOI15_boxes) C++11
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define F first
#define S second
long long dpL[10000001] , dpR[10000001]; 

long long delivery(int N, int K, int L, int p[]) {
	#define int long long 
	int ans = (int) 1e18;
	int k = K;
	int n = N;
	int l = L;
	for(int i = 0 ; i < N ;i ++){
		dpL[i] = 2*p[i];
		if(i >= K) dpL[i] = dpL[i-k] + 2*p[i]; // pick the last block and then solve for [0 , i-k]
	}
	for(int j = N - 1 ; j >= 0 ; j--){
		int u = j + K ;
		dpR[j] = 2*(L - p[j]);
		if(u <= n - 1) dpR[j] = dpR[u] + 2*(L - p[j]); 
	}
	#define pii pair<long long, long long> 
	deque<pii> dq;
	int left = 1;
	for(int i = 0 ; i < N  - 1; i ++){
		while(dq.size() && dq.front().second <= i) dq.pop_front();
		left = max(left, i + 1);
		while(left < N && k >= (left - i - 1)){
			while(dq.size() && dq.back().first >= dpR[left]) dq.pop_back();
			dq.push_back(pii(dpR[left] , left));
			left++;
		}
		ans = min(ans , dpL[i] + dpR[i+1]);
		ans = min(ans , dpL[i] + dq.front().F + L);
	}
	for(int i = 0 ; i < N ; i ++){
		int X = (i+1);
		X = n  - X;
		if(X <= k){
			ans = min(ans , dpL[i] + L);
		}
		int Y = N - i ;
		Y = N - Y;
		if(Y <= k) ans = min(ans , dpR[i] + L);
	}
    return ans;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:13:6: warning: unused variable 'l' [-Wunused-variable]
  int l = L;
      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 296 KB Output is correct
2 Incorrect 2 ms 252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -