답안 #532104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532104 2022-03-02T05:57:18 Z rk42745417 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(4e15) + ll(2e15);
const double EPS = 1e-9;
static int LamyIsCute = []() {
	EmiliaMyWife
	return 48763;
}();

signed main() {
	int n;
	cin >> n;
	vector<pair<ll, ll>> arr(n * 2);
	for(int i = 0; i < n * 2; i++)
		cin >> arr[i].first >> arr[i].second;
	sort(arr.begin(), arr.end());
	int a = 0;
	for(const auto &[_, y] : arr) {
		if(y <= 1)
			a++;
		else
			a--;
	}
	ll ans = abs(a) / 2;
	//cerr << ans << '\n';
	a = 0;
	int b = 0;
	for(const auto &[x, y] : arr) {
		ll costa = a < n ? abs(x - (a + 1)) : LINF, costb = b < n ? abs(x - (b + 1)) : LINF;
		if(costa < costb || (costa == costb && a <= b))
			ans += costa, a++;
		else
			ans += costb, b++;
		//cout << a << ' ' << b << ' ' << costa << ' ' << costb << '\n';
		ans += min(abs(y - 1), abs(y - 2));
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -