제출 #1168430

#제출 시각아이디문제언어결과실행 시간메모리
1168430yellowtoadCoin Collecting (JOI19_ho_t4)C++20
100 / 100
121 ms2776 KiB
#include <iostream>
using namespace std;

long long n, x, y, xx, yy, a[100010][3], ans, c[100010], b[3];

int main() {
	cin >> n;
	for (int i = 1; i <= 2*n; i++) {
		cin >> x >> y;
		if (y <= 1) yy = 1;
		else yy = 2;
		if (x < 1) xx = 1;
		else if (x > n) xx = n;
		else xx = x;
		a[xx][yy]++;
		ans += abs(x-xx)+abs(y-yy);
	}
	x = y = 0;
	for (int i = 1; i <= n; i++) {
		x += a[i][1]-1;
		y += a[i][2]-1;
		while (x < 0 && y > 0) x++, y--, ans++;
		while (x > 0 && y < 0) x--, y++, ans++;
		ans += abs(x)+abs(y); 
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...