Submission #292143

# Submission time Handle Problem Language Result Execution time Memory
292143 2020-09-06T12:42:32 Z YJU Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 384 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
typedef pair<ll,pair<ll,pair<ll,pll> > > TY;
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

ll n,x,y,cnt[3],d[N],lst=1,ans;

pll to(pll A){
	if(A.X<1)ans+=abs(A.X-1),A.X=1;
	if(A.X>n)ans+=abs(A.X-n),A.X=n;
	if(A.Y>2)ans+=abs(A.Y-2),A.Y=2;
	if(A.Y<1)ans+=abs(A.Y-1),A.Y=1;
	return A;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	REP1(i,2*n){
		cin>>x>>y;
		pll nd=to(mp(x,y));
		++cnt[nd.Y];
		++d[nd.X];
	}
	ans+=abs(cnt[1]-cnt[2])/2;
	REP1(i,n){
		while(d[i]>2){
			while(d[lst]>=2&&lst<=n)++lst;
			if(lst==n+1)break;
			--d[i];++d[lst];
			ans+=abs(lst-i);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

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