답안 #778753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778753 2023-07-10T16:08:55 Z DobromirAngelov Coin Collecting (JOI19_ho_t4) C++14
0 / 100
0 ms 212 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAXN=1e5+5;

int n;
int cnt[2][MAXN];
long long ans=0;

void add(int t,int x)
{
    if(x<1)
    {
        ans+=1-x;
        cnt[t][1]++;
    }
    else if(x>n)
    {
        ans+=x-n;
        cnt[t][n]++;
    }
    else cnt[t][x]++;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    for(int i=1; i<=2*n; i++)
    {
        int x,y;
        cin>>x>>y;
        if(y<=1)
        {
            add(0,x);
            ans+=1-y;
        }
        else
        {
            add(1,x);
            ans+=y-2;
        }
    }

    int r0=0,r1=0;
    for(int i=1; i<=n; i++)
    {
        r0+=cnt[0][i];
        r1+=cnt[1][i];
        ans+=abs(r0+r1-2*i);
    }
    ans+=abs(r0-r1)/2;

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