답안 #98232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98232 2019-02-21T15:40:53 Z scanhex Coin Collecting (JOI19_ho_t4) C++17
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>

using namespace std;
using nagai = long long;
#define sz(x) int((x).size())

const int N=200200;

int cnt[N][2];

int dist(pair<int,int>a,pair<int,int>b){
	return abs(a.first-b.first)+abs(a.second-b.second);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	nagai ansich=0;
	for(int i=0;i<2*n;++i){
		int x,y;
		cin>>x>>y;
		int x1=x,y1=y;
		if(x<1)x1=1;
		if(x>n)x1=n;
		if(y<1)y1=1;
		if(y>2)y1=2;
		ansich+=abs(x-x1);
		ansich+=abs(y-y1);
		++cnt[x1-1][y1-1];
	}
	int sum1=-n;
	for(int i=0;i<n;++i)sum1+=cnt[i][0];
	if(sum1<0){
		sum1*=-1;
		for(int i=0;i<n;++i)swap(cnt[i][0],cnt[i][1]);
	}
	int ptr=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<cnt[i][1];++j)++ptr;
		while(cnt[i][0]&&ptr<=i&&sum1>0)--cnt[i][0],--sum1,++ptr,++ansich,++cnt[i][1];
	}
	for(int k=0;k<2;++k){
		int ptr=0;
		for(int i=0;i<n;++i){
			for(int j=0;j<cnt[i][k];++j)ansich+=abs(ptr-i),++ptr;
		}
	}
	cout<<ansich<<'\n';
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -