제출 #543077

#제출 시각아이디문제언어결과실행 시간메모리
543077FystyCoin Collecting (JOI19_ho_t4)C++17
100 / 100
53 ms5068 KiB
#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=3e18;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m)
{
    if(!b) return 1;
    ll ans=fpow(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}

#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define F first
#define S second
#define pb push_back
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
ll cnt[100001][2];
signed main()
{
    MottoHayaku
    ll n;
    cin>>n;
    ll ans=0;
    rep1(i,n*2)
    {
        ll x,y;
        cin>>x>>y;
        if(x<1) ans+=1-x,x=1;
        else if(x>n) ans+=x-n,x=n;
        if(y<1) ans+=1-y,y=0;
        else if(y>2) ans+=y-2,y=1;
        else y--;
        cnt[x][y]++;
    }
    ll cur0=0,cur1=0;
    rep1(i,n)
    {
        cur0+=cnt[i][0]-1;
        cur1+=cnt[i][1]-1;
        while(cur0<0&&cur1>0) ans++,cur0++,cur1--;
        while(cur0>0&&cur1<0) ans++,cur0--,cur1++;
        ans+=abs(cur0)+abs(cur1);
    }
    cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...