Submission #202574

# Submission time Handle Problem Language Result Execution time Memory
202574 2020-02-17T03:22:03 Z dndhk Coin Collecting (JOI19_ho_t4) C++14
0 / 100
6 ms 400 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

const int MAX_N = 100000;

int cnt[MAX_N+1][3];

int N;
ll ans = 0;


int main(){
	scanf("%d", &N);
	for(int i=1; i<=2*N; i++){
		int x, y; scanf("%d%d", &x, &y);
		if(x<=1 && y<=1){
			cnt[1][1]++;
			ans+=(ll)(1-x+1-y);
		}else if(x<=1 && y>=2){
			cnt[1][2]++;
			ans+=(ll)(1-x+y-2);
		}else if(x>=N && y<=1){
			cnt[N][1]++;
			ans+=(ll)(x-N+1-y);
		}else if(x>=N && y>=2){
			cnt[N][2]++;
			ans+=(ll)(x-N+y-2);
		}else if(y<=1){
			cnt[x][1]++;
			ans+=(ll)(1-y);
		}else{
			cnt[x][2]++;
			ans+=(ll)(y-2);
		}
	}
	for(int i=1; i<=N; i++){
		for(int j=1; j<=2; j++)	{
			cnt[i][j]--;
		}
	}
	int cnt1 = 0, cnt2 = 0;
	for(int i=1; i<=N; i++){
		while(cnt[i][1]>0){
			cnt[i][1]--;
			if(cnt1<0){
				cnt1++;
			}else if(cnt2<0){
				cnt2++;
				ans+=1LL;
			}else{
				cnt1++;
			}
		}
		while(cnt[i][2]>0){
			cnt[i][2]--;
			if(cnt2<0){
				cnt2++;
			}else if(cnt1<0){
				ans+=1LL;
				cnt1++;
			}else{
				cnt2++;
			}
		}
		if(cnt[i][1]<0){
			cnt[i][1]++;
			if(cnt1>0){
				cnt1--;
			}else if(cnt2>0){
				cnt2--;
				ans+=1LL;
			}else{
				cnt1--;
			}
		}
		if(cnt[i][2]<0){
			cnt[i][2]++;
			if(cnt2>0){
				cnt2--;
			}else if(cnt1>0){
				cnt1--;
				ans+=1LL;
			}else{
				cnt2--;
			}
		}
		ans+=(ll)(cnt1>0?cnt1:-cnt1);
		ans+=(ll)(cnt2>0?cnt2:-cnt2);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:22:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 400 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Incorrect 5 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 400 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Incorrect 5 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 400 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Incorrect 5 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -