Submission #98238

# Submission time Handle Problem Language Result Execution time Memory
98238 2019-02-21T16:07:46 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]);
	}
	for(int i=0;i<n;++i){
		while(cnt[i][1]>1&&cnt[i][0]<1)++cnt[i][0],--cnt[i][1],++ansich;
		if(cnt[i][0]<1)ansich+=(1-cnt[i][0]),cnt[i+1][0]-=(1-cnt[i][0]);
		if(cnt[i][0]>1)ansich+=cnt[i][0]-1,cnt[i+1][0]+=cnt[i][0]-1;
		if(cnt[i][1]>1)ansich+=cnt[i][1]-1,cnt[i+1][1]+=cnt[i][1]-1;
	}
	cout<<ansich<<'\n';
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -