Submission #533710

# Submission time Handle Problem Language Result Execution time Memory
533710 2022-03-07T03:06:41 Z alvingogo Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 308 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define cd complex<double>
#define p_q priority_queue
using namespace std;

int main(){
	AquA;
	int n;
	cin >> n;
	vector<int> a(n,-1),b(n,-1);
	long long ans=0;
	for(int i=0;i<2*n;i++){
		int x,y;
		cin >> x >> y;
		int c=max(1,min(x,n)),d=max(1,min(y,2));
		ans+=abs(c-x)+abs(d-y);
		if(y==1){
			a[c-1]++;
		}
		else{
			b[c-1]++;
		}
	}
	int e=0,f=0;
	for(int i=0;i<n;i++){
		e+=a[i];
		f+=b[i];
		if(e>0 && f<0){
			int y=min(abs(e),abs(f));
			e-=y;
			f+=y;
			ans+=y;
		}
		else if(f>0 && e<0){
			int y=min(abs(e),abs(f));
			e+=y;
			f-=y;
			ans+=y;
		}
		ans+=abs(e);
		ans+=abs(f);
	}
	cout << ans << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 304 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 304 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 1 ms 304 KB Output isn't correct
7 Halted 0 ms 0 KB -