답안 #104340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104340 2019-04-05T11:32:44 Z ihdignite Coin Collecting (JOI19_ho_t4) C++14
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=1e5;
int n, c[mxN][2];
ll a1;

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

	cin >> n;
	for(int i=0, x, y; i<2*n; ++i) {
		cin >> x >> y;
		if(x<1) {
			a1+=1-x;
			x=1;
		}
		if(x>n) {
			a1+=x-n;
			x=n;
		}
		if(y<1) {
			a1+=1-y;
			y=1;
		}
		if(y>2) {
			a1+=y-2;
			y=2;
		}
		++c[x-1][y-1];
	}
	for(int i1=0, i2=0, j=0; i1<n||i2<n; ) {
		while(!c[j][0]&&!c[j][1])
			++j;
		if(c[j][0]&&i1<=j) {
			--c[j][0];
			a1+=j-i1++;
		} else if(c[j][1]&&i2<=j) {
			--c[j][1];
			a1+=j-i2++;
		} else if(c[j][0]&&i2<=j) {
			--c[j][0];
			a1+=j-i2+++1;
		} else if(c[j][1]&&i1<=j) {
			--c[j][1];
			a1+=j-i1+++1;
		} else if(i1<i2||i1==i2&&c[j][0]) {
			if(c[j][0]) {
				--c[j][0];
				a1+=i1++-j;
			} else {
				--c[j][1];
				a1+=i1++-j+1;
			}
		} else {
			if(c[j][1]) {
				--c[j][1];
				a1+=i2++-j;
			} else {
				--c[j][0];
				a1+=i2++-j+1;
			}
		}
	}
	cout << a1;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:50:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   } else if(i1<i2||i1==i2&&c[j][0]) {
                    ~~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 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 3 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 3 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 3 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 3 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 3 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -