Submission #127984

# Submission time Handle Problem Language Result Execution time Memory
127984 2019-07-10T09:51:10 Z Sorting Boxes with souvenirs (IOI15_boxes) C++14
0 / 100
5 ms 760 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;
			v2[i] = v2[i - k] + v2[i] * 2ll;
		}
		else{
			v1[i] = v1[i] * 2ll;
			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
*/
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 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 2 ms 376 KB Output is correct
2 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 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 Runtime error 2 ms 504 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 Runtime error 2 ms 504 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 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -