답안 #127985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127985 2019-07-10T09:52:04 Z Sorting 선물상자 (IOI15_boxes) C++14
20 / 100
3 ms 376 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 7;
const long long inf = 1e18 + 7;

vector<long long> v1, v2, v3, v4;

void output(vector<long long> v){
	for(long long &x: v){
		cout << x << " ";
	}
	cout << endl;
}

long long delivery(int n, int k, int l, int *positions){
	sort(positions, positions + n);
	
	int idx = 0;

	for(; idx < n && positions[idx] <= l / 2; idx++){
		v1.push_back(positions[idx]);
	}
	for(; idx < n; idx++){
		v2.push_back(l - positions[idx]);
	}
	if(!v2.empty()){
		reverse(v2.begin(), v2.end());
	}

	//output(v1);
	//output(v2);

	long long ans = 0, sum1 = 0, sum2 = 0;

	for(int i = -1; true;){
		if(i + k >= (int)v1.size()){
			for(++i; i < (int)v1.size(); ++i){
				v3.push_back(v1[i]);
			}
			break;
		}
		i += k;
		sum1 += (long long)v1[i] * 2ll;
	}
	for(int i = -1; true;){
		if(i + k >= (int)v2.size()){
			for(++i; i < (int)v2.size(); ++i){
				v4.push_back(v2[i]);
			}
			break;
		}
		i += k;
		sum2 += (long long)v2[i] * 2ll;
	}

	for(int i = 0 ; i < (int)v1.size(); i++){
		if(i >= k){
			v1[i] = v1[i - k] + v1[i] * 2ll;
		}
		else{
			v1[i] = v1[i] * 2ll;
		}
	}

	for(int i = 0 ; i < (int)v2.size(); i++){
		if(i >= k){
			v2[i] = v2[i - k] + v2[i] * 2ll;
		}
		else{
			v2[i] = v2[i] * 2ll;
		}
	}

	//output(v3);
	//output(v4);

	ans = sum1 + sum2;

	if(v3.empty() || v4.empty()){
		if(!v3.empty()){
			ans += v3.back() * 2ll;
		}
		if(!v4.empty()){
			ans += v4.back() * 2ll;
		}

		return ans;
	}

	if((int)v3.size() + (int)v4.size() <= k){
		ans += min((long long)l, v3.back() * 2ll + v4.back() * 2ll);

		return ans;
	}

	ans = v1.back() + v2.back();

	return ans;
}

/*int positions[N], n, k, l;

int main(){
	cin >> n >> k >> l;
	for(int i = 0; i < n; i++){
		cin >> positions[i];
	}

	cout << delivery(n, k, l, positions) << "\n";

	return 0;
}*/
/*
3 2 8
1 2 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 252 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 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
7 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 Correct 2 ms 252 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 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 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 Correct 2 ms 252 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 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 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 Correct 2 ms 252 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 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 252 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 Halted 0 ms 0 KB -