답안 #1116163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116163 2024-11-21T09:45:44 Z Dan4Life Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
#define int long long
const int N = (int)2e5+10;
int n, a[N][3];

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n; int ans = 0, xd = 0;
	for(int i = 0; i < 2*n; i++){
		int x, y; cin >> x >> y;
		int X = x, Y = y;
		x=clamp(x,1ll,n), y=clamp(y,1ll,2ll);
		ans+=abs(X-x)+abs(Y-y); a[x][y]++;
	}
	for(int i = 1; i <= n; i++) 
		xd+=a[i][1], a[i][1]+=a[i][2];
	ans+=abs(xd-n);
	int j = 1;
	for(int i = 1; i < n; i++){
		int tot = a[i][1];
		if(tot==2) continue;
		if(tot<2){
			int need = 2-tot;
			j = max(j,i);
			while(1){
				while(j<n and !a[j][1]) j++;
				int use = min(need,a[j][1]);
				a[j][1]-=use; a[i][1]+=use;
				ans+=(j-i)*use; need-=use;
				if(!need) break;
			}
		}
		else{
			tot-=2; ans+=tot;
			a[i+1][1]+=tot,a[i][1]-=tot;
		}
	}
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB Output isn't correct
7 Halted 0 ms 0 KB -