답안 #117160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117160 2019-06-15T05:40:21 Z Diuven Coin Collecting (JOI19_ho_t4) C++14
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n, A[2][MAX];
lint ans;

void go(int &x, int z){
	while(x<=n && A[z][x]==0) x++;
	if(x>n) x = INF;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);

	cin>>n;
	for(int i=1; i<=2*n; i++){
		int x,y; cin>>x>>y;
		ans += min(abs(y-1), abs(y-2));
		ans += (1<=x && x<=n ? 0 : min(abs(x-1), abs(x-n)));
		y = (y<=1 ? 1 : 2) - 1;
		x = (1<=x && x<=n ? x : (x<=1 ? 1 : n));
		A[y][x]++;
	}

	// cout<<ans<<'\n';

	// for(int i=1; i<=n; i++) cout<<A[0][i]<<' ';
	// cout<<'\n';
	// for(int i=1; i<=n; i++) cout<<A[1][i]<<' ';
	// cout<<'\n';

	for(int i=1; i<=n; i++){
		static int p[2]={1,1};

		go(p[0],0); go(p[1],1);
		if(p[0]==p[1]){
			ans += abs(p[0]-i)*2;
			A[0][p[0]]--, A[1][p[1]]--;
		}
		else{
			int z = (p[0]<p[1] ? 0 : 1);
			A[z][p[z]]--; ans += abs(p[z]-i);
			go(p[z], z);

			int w = (p[0]==p[1] ? 1-z : (p[0]<p[1] ? 0 : 1));
			A[w][p[w]]--; ans += abs(p[w]-i);
			if(w==z) ans++;
		}
	}

	cout<<ans<<'\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 Correct 2 ms 384 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 Correct 2 ms 384 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 Correct 2 ms 384 KB Output is correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -