Submission #867991

# Submission time Handle Problem Language Result Execution time Memory
867991 2023-10-30T06:10:54 Z Nuraly_Serikbay Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 6492 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], u[3];
int dp[2001][2001], cnt[N], cnt1[N];
void solution () {
	cin >> n;
//	n = 2;
//	cout << 2 << '\n';
	for (int i = 1; i <= n * 2; ++ i) {
		cin >> x[i] >> y[i];
	//	x[i] = rand() % 5, y[i] = rand() % 5;
	//	cout << x[i] << ' ' << y[i] << '\n';
	}
	int res = 0;
	for (int i = 1; i <= n * 2; ++ i) {
		if (x[i] < 1) res += 1 - x[i], x[i] = 1;
		if (n < x[i]) res += x[i] - n, x[i] = n;
		if (y[i] < 1) res += (1 - y[i]), y[i] = 1;
		if (2 < y[i]) res += (y[i] - 2), y[i] = 2;
		if (y[i] == 1) cnt[x[i]] ++;
		else cnt1[x[i]] ++;
//		cout << x[i] << ' ' << y[i] << " cords\n";
	}
	n *= 2;
	vector <pair <int, int>> ord;
	int t = 0;
	for (int i = 1; i <= n; ++ i) ord.pb ({x[i], y[i]});
	sort (all (ord));
	for (int i = 0; i < n; ++ i) {
		if (i % 2 == 0) {
			++t;
			cnt[ord[i].F] --, cnt1[ord[i].F] --;
		}		 
		res += abs(ord[i].F - t);	
	}
	int sum = 0, sum1 = 0;
	for (int i = 1; i <= n; ++ i) {
		sum += abs(cnt[i]);
		sum1 += abs(cnt1[i]);
	}
	res += min (sum, sum1);
	cout << res;
	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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Incorrect 1 ms 6492 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Incorrect 1 ms 6492 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Incorrect 1 ms 6492 KB Output isn't correct
7 Halted 0 ms 0 KB -