답안 #867982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867982 2023-10-30T05:04:40 Z Nuraly_Serikbay Coin Collecting (JOI19_ho_t4) C++17
8 / 100
20 ms 4700 KB
//çalışan kazanır//
 
#include "bits/stdc++.h"
 
using namespace std;
 
#define int long long
#define pb push_back
#define S second
#define F first
#define all(x) x.begin(),x.end()
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
int gcd (int a, int b) {if (b == 0){return a;}else {return gcd (b, a % b);}}
 
const int N = 4e5 + 15;
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MODD = 1070234587ll;
const double eps = 0.0001;
const int p = 87;

int n, x[N], y[N];
int cnt[N][3], dp[2001];


void solution () {
	cin >> n;
	for (int i = 1; i <= n * 2; ++ i) cin >> x[i] >> y[i];
	int res = 0;
	for (int i = 1; i <= n * 2; ++ i) {
		if (1 <= x[i] && x[i] <= n) {
			if (1 <= y[i] && y[i] <= 2) cnt[x[i]][y[i]] ++;
			if (y[i] < 1) cnt[x[i]][1] ++, res += (1 - y[i]), y[i] = 1;
			if (2 < y[i]) cnt[x[i]][2] ++, res += (y[i] - 2), y[i] = 2;
		}
		if (x[i] < 1) {
			res += 1 - x[i];
			if (1 <= y[i] && y[i] <= 2) cnt[1][y[i]] ++;
			if (y[i] < 1) cnt[1][1] ++, res += (1 - y[i]), y[i] = 1;
			if (2 < y[i]) cnt[1][2] ++, res += (y[i] - 2), y[i] = 2;
			x[i] = 1;
		}
		if (n < x[i]) {
			res += x[i] - n;
			if (1 <= y[i] && y[i] <= 2) cnt[n][y[i]] ++;
			if (y[i] < 1) cnt[n][1] ++, res += (1 - y[i]), y[i] = 1;
			if (2 < y[i]) cnt[n][2] ++, res += (y[i] - 2), y[i] = 2;
			x[i] = n;
		}
	//	cout << "cors -> " << x[i] << ' ' << y[i] << '\n';
	}
//	cout << res << '\n';
	n *= 2;
	vector <pair <int, int>> ord;
	for (int i = 1; i <= n; ++ i) ord.pb ({x[i], y[i]});
	sort (all (ord));
	int mn = INF;
	for (int mask = 0; mask < (1 << n); ++ mask) {
		if (__builtin_popcount (mask) != n / 2) continue;
		int t = 0, tt = 0, cur = 0;
		
		for (int i = 0; i < n; ++ i) {
			if (((mask >> i) & 1)) {
				cur += abs(ord[i].F - (++t));
				if (ord[i].S != 1) cur ++;
			} else {
				cur += abs(ord[i].F - (++tt));
				if (ord[i].S == 1) cur ++;
			}
		}
		mn = min (mn, cur);	
	}
	cout << res + mn;
	return;	
}
 
signed main() {
//	YOSIK();
//	srand (time(0));
//	freopen ("E.in", "r", stdin);
//	freopen ("E.out", "w", stdout);
	int TT = 1;// cin >> TT;
	for (int i = 1; i <= TT; ++ i) {
//		cout << "Case " << i << ": ";
		solution ();
		
  	}
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 18 ms 4556 KB Output is correct
5 Correct 16 ms 4560 KB Output is correct
6 Correct 16 ms 4444 KB Output is correct
7 Correct 16 ms 4556 KB Output is correct
8 Correct 16 ms 4440 KB Output is correct
9 Correct 16 ms 4444 KB Output is correct
10 Correct 16 ms 4444 KB Output is correct
11 Correct 16 ms 4552 KB Output is correct
12 Correct 16 ms 4444 KB Output is correct
13 Correct 16 ms 4440 KB Output is correct
14 Correct 18 ms 4444 KB Output is correct
15 Correct 17 ms 4444 KB Output is correct
16 Correct 16 ms 4556 KB Output is correct
17 Correct 16 ms 4560 KB Output is correct
18 Correct 16 ms 4440 KB Output is correct
19 Correct 17 ms 4440 KB Output is correct
20 Correct 20 ms 4444 KB Output is correct
21 Correct 18 ms 4440 KB Output is correct
22 Correct 15 ms 4444 KB Output is correct
23 Correct 16 ms 4552 KB Output is correct
24 Correct 16 ms 4444 KB Output is correct
25 Correct 19 ms 4444 KB Output is correct
26 Correct 16 ms 4440 KB Output is correct
27 Correct 16 ms 4444 KB Output is correct
28 Correct 19 ms 4556 KB Output is correct
29 Correct 18 ms 4700 KB Output is correct
30 Correct 16 ms 4444 KB Output is correct
31 Correct 18 ms 4444 KB Output is correct
32 Correct 16 ms 4640 KB Output is correct
33 Correct 16 ms 4556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 18 ms 4556 KB Output is correct
5 Correct 16 ms 4560 KB Output is correct
6 Correct 16 ms 4444 KB Output is correct
7 Correct 16 ms 4556 KB Output is correct
8 Correct 16 ms 4440 KB Output is correct
9 Correct 16 ms 4444 KB Output is correct
10 Correct 16 ms 4444 KB Output is correct
11 Correct 16 ms 4552 KB Output is correct
12 Correct 16 ms 4444 KB Output is correct
13 Correct 16 ms 4440 KB Output is correct
14 Correct 18 ms 4444 KB Output is correct
15 Correct 17 ms 4444 KB Output is correct
16 Correct 16 ms 4556 KB Output is correct
17 Correct 16 ms 4560 KB Output is correct
18 Correct 16 ms 4440 KB Output is correct
19 Correct 17 ms 4440 KB Output is correct
20 Correct 20 ms 4444 KB Output is correct
21 Correct 18 ms 4440 KB Output is correct
22 Correct 15 ms 4444 KB Output is correct
23 Correct 16 ms 4552 KB Output is correct
24 Correct 16 ms 4444 KB Output is correct
25 Correct 19 ms 4444 KB Output is correct
26 Correct 16 ms 4440 KB Output is correct
27 Correct 16 ms 4444 KB Output is correct
28 Correct 19 ms 4556 KB Output is correct
29 Correct 18 ms 4700 KB Output is correct
30 Correct 16 ms 4444 KB Output is correct
31 Correct 18 ms 4444 KB Output is correct
32 Correct 16 ms 4640 KB Output is correct
33 Correct 16 ms 4556 KB Output is correct
34 Incorrect 2 ms 4444 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 18 ms 4556 KB Output is correct
5 Correct 16 ms 4560 KB Output is correct
6 Correct 16 ms 4444 KB Output is correct
7 Correct 16 ms 4556 KB Output is correct
8 Correct 16 ms 4440 KB Output is correct
9 Correct 16 ms 4444 KB Output is correct
10 Correct 16 ms 4444 KB Output is correct
11 Correct 16 ms 4552 KB Output is correct
12 Correct 16 ms 4444 KB Output is correct
13 Correct 16 ms 4440 KB Output is correct
14 Correct 18 ms 4444 KB Output is correct
15 Correct 17 ms 4444 KB Output is correct
16 Correct 16 ms 4556 KB Output is correct
17 Correct 16 ms 4560 KB Output is correct
18 Correct 16 ms 4440 KB Output is correct
19 Correct 17 ms 4440 KB Output is correct
20 Correct 20 ms 4444 KB Output is correct
21 Correct 18 ms 4440 KB Output is correct
22 Correct 15 ms 4444 KB Output is correct
23 Correct 16 ms 4552 KB Output is correct
24 Correct 16 ms 4444 KB Output is correct
25 Correct 19 ms 4444 KB Output is correct
26 Correct 16 ms 4440 KB Output is correct
27 Correct 16 ms 4444 KB Output is correct
28 Correct 19 ms 4556 KB Output is correct
29 Correct 18 ms 4700 KB Output is correct
30 Correct 16 ms 4444 KB Output is correct
31 Correct 18 ms 4444 KB Output is correct
32 Correct 16 ms 4640 KB Output is correct
33 Correct 16 ms 4556 KB Output is correct
34 Incorrect 2 ms 4444 KB Output isn't correct
35 Halted 0 ms 0 KB -