Submission #889874

# Submission time Handle Problem Language Result Execution time Memory
889874 2023-12-20T08:49:00 Z vjudge1 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pllll pair<pll,pll>
#define vl vector<ll>
#define vll vector<pll>
#define vlll vector<plll>
#define vllll vector<pllll>
#define vb vector<bool>
#define sz size()
#define fr front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bk back();
using namespace std;
const ld pi=3.14159265359;
const ll e5=1e5;
const ll e6=1e6;
const ll e9=1e9;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;
const ll N=1e5+5;
ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;if(y==1)return x%m;ll p=bpm(x,y/2,m);
if(y%2==0)return p*p%m;else return p*p%m*x%m;}
ll bp(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll p=bp(x,y/2);
if(y%2==0)return p*p;else return p*p*x;}
void solve(/**/){
    ll n,n2,ans=0;
    cin>>n;
    n2=n*2;
    pll p[n2+1];
    for(ll i=1;i<=n2;i++) cin>>p[i].F>>p[i].S;
    sort(p+1,p+n2+1);
    for(ll i=1;i<=n2;i++){
        ans+=abs(p[i].F-(i+1)/2);
    }
    ll x=0,y=0,s1=0,s2=0,l=1;
    ll q=0;
    for(ll i=1;i<=n2;i++){
        if(p[i].S>=2) x++, s1+=p[i].S-2;
        else y++, s2+=1-p[i].S;
        if(i==n2||p[i].F!=p[i+1].F){
            if(l%2==0){
                if(q==1) x--;
                else if(q==2) y--;
            }
            if(i%2==1){
                if(q==3){
                    if(x>y) ans+=(x-y-2)/2, q=2;
                    else if(y>x) ans+=(y-x-2)/2, q=1;
                    else q=3;
                }
                else if(x>y) ans+=(x-y-1)/2, q=2;
                else ans+=(y-x-1)/2, q=1;
            }else{
                if(q==3){
                    if(x>y) x--;
                    else y--;
                }
                if(x>=y) ans+=(x-y)/2;
                else ans+=(y-x)/2;
                q=0;
            }
            x=y=0;
            l=i+1;
        }
    }
    ans+=s1+s2;
    cout<<ans;
    return;
}
int main(/*Aldk*/){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);    
    //cout<<setprecision(6)<<fixed;
    ll T=1;
    //cin>>T;
    for(ll i=1;i<=T;i++){
        //cout<<"Case #"<<i<<": ";
        solve();
        //cout<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -