Submission #1138892

#TimeUsernameProblemLanguageResultExecution timeMemory
1138892PlayVoltzCoin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms328 KiB
#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, ans=0;
	cin>>n;
	deque<pii> top, down;
	for (int i=0, a, b; i<2*n; ++i){
		cin>>a>>b;
		if (b>=2)down.pb(mp(a, b));
		else top.pb(mp(a, b));
	}
	sort(top.begin(), top.end());
	sort(down.begin(), down.end());
	for (int i=1; i<=n; ++i){
		if (down.size()>top.size()){
			ans+=abs(down[0].se-2)+abs(down[0].fi-i);
			down.pop_front();
			if (top.empty()||down[0].fi<top[0].fi){
				ans+=abs(down[0].se-1)+abs(down[0].fi-i);
				down.pop_front();
			}
			else{
				ans+=abs(top[0].se-1)+abs(top[0].fi-i);
				top.pop_front();
			}
		}
		else if (top.size()>down.size()){
			ans+=abs(top[0].se-1)+abs(top[0].fi-i);
			top.pop_front();
			if (down.empty()||top[0].fi<down[0].fi){
				ans+=abs(top[0].se-2)+abs(top[0].fi-i);
				top.pop_front();
			}
			else{
				ans+=abs(down[0].se-2)+abs(down[0].fi-i);
				down.pop_front();
			}
		}
		else{
			ans+=abs(top[0].se-1)+abs(top[0].fi-i);
			ans+=abs(down[0].se-2)+abs(down[0].fi-i);
			down.pop_front();
			top.pop_front();
		}
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...