답안 #430413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430413 2021-06-16T13:32:39 Z Drew_ Coin Collecting (JOI19_ho_t4) C++17
0 / 100
24 ms 328 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define ll long long
#define ii pair<int, int>
#define pl pair<ll, ll>
#define f1 first
#define s2 second

const int MAX = 2e5 + 69;

ll X[MAX], Y[MAX];

int main()
{
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	for (int i = 0; i < 2*n; ++i)
		cin >> X[i] >> Y[i];
	sort(X, X + 2*n);
	sort(Y, Y + 2*n);

	ll ans = 0;

	//calculate X coordinate contribution
	for (int i = 0; i < 2*n; ++i)
		ans += abs(X[i] - (i/2 + 1));
	
	ll mn = 1e18;
	for (int mask = 0; mask < (1 << 2*n); ++mask)
	{
		if (__builtin_popcount(mask) == n)
		{
			ll ctr = 0;
			for (int i = 0; i < 2*n; ++i)
			{
				if (mask & (1 << i)) ctr += abs(Y[i] - 2);
				else ctr += abs(Y[i] - 1);
			}
			mn = min(mn, ctr);
		}
	}
	cout << ans + mn << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 17 ms 328 KB Output is correct
5 Correct 18 ms 328 KB Output is correct
6 Incorrect 24 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 17 ms 328 KB Output is correct
5 Correct 18 ms 328 KB Output is correct
6 Incorrect 24 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 17 ms 328 KB Output is correct
5 Correct 18 ms 328 KB Output is correct
6 Incorrect 24 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -