답안 #705105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705105 2023-03-03T11:41:18 Z jiahng Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 300010
#define INF (ll)1e18
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
#define DEBUG 0
#define MOD 1000003233

int TC;
int N;
int X[maxn],Y[maxn],num[maxn];
int C[maxn];
void solve(){
    fast;
    cin >> N;
    int ans = 0;
    vi v;
    FOR(i,1,2*N){
        cin >> X[i] >> Y[i];
        if (Y[i] < 1){
            ans += abs(1-Y[i]); Y[i] = 1;
        }
        if (Y[i] > 2){
            ans += abs(2-Y[i]); Y[i] = 2;
        }
        if (X[i] < 1){
            ans += abs(1-X[i]); X[i] = 1;
        }
        if (X[i] > N){
            ans += abs(N-X[i]); X[i] = N;
        }
        C[Y[i]-1]++;
        num[X[i]]++;
    }
    //cout << ans << ' ';

    int sm = 0;
    FOR(i,1,N){
        sm += num[i];
        //ans += abs(sm - 2*i);
    }
    sort(X+1,X+2*N+1);
    FOR(i,1,N){
        ans += abs(X[2*i-1]-i) + abs(X[2*i]-i);
    }

    /*
    sort(all(v));
    int ptr = 0;
    int sm = 0;
    while (ptr < v.size()){
        int cur = v[ptr];
        while (ptr < v.size() && v[ptr] == cur){
            ptr++; sm++;
        }
        if (ptr < v.size()) ans += abs(2*ptr - sm) * (v[ptr] - cur);
    }
    */
    ans += abs(C[0] - N);
    cout << ans;

}
int32_t main(){
    fast;
    solve();

    

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -