답안 #101727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101727 2019-03-19T15:53:49 Z KCSC Coin Collecting (JOI19_ho_t4) C++14
0 / 100
861 ms 275456 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 100005;

int cnt[DIM][2];
vector<int> qry[3], bal[3];

int main(void) {
#ifdef HOME
	freopen("coins.in", "r", stdin);
	freopen("coins.out", "w", stdout);
#endif
	int n; cin >> n;
	long long ans = 0;
	for (int i = 1; i <= n * 2; ++i) {
		int x, y; cin >> x >> y;
		if (x < 1) { ans += 1 - x; x = 1; }
		if (x > n) { ans += x - n; x = n; }
		if (y < 1) { ans += 1 - y; y = 1; }
		if (y > 2) { ans += y - 2; y = 2; } 
		++cnt[x][y]; }
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= 2; ++j) {		
			qry[j].push_back(i);
			for (; cnt[i][j]; --cnt[i][j]) {
				bal[j].push_back(i); } }
		// solve as many columns with balls placed on the same line
		for (int j = 1; j <= 2; ++j) {
			while (qry[j].size() and bal[j].size()) {
				int p1 = qry[j].back(), p2 = bal[j].back();
				qry[j].pop_back(); bal[j].pop_back(); ans += abs(p1 - p2); } }
		// solve as many columns with balls placed on the opposite line
		for (int j = 1; j <= 2; ++j) {
			while (qry[j].size() and bal[3 - j].size()) {
				int p1 = qry[j].back(), p2 = bal[3 - j].back();
				qry[j].pop_back(); bal[3 - j].pop_back(); ans += abs(p1 - p2) + 1; } } }
	cout << ans << endl;
	return 0; }
# 결과 실행 시간 메모리 Grader output
1 Runtime error 861 ms 275456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 861 ms 275456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 861 ms 275456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -