답안 #559952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559952 2022-05-11T01:39:20 Z karrigan Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 328 KB
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
using namespace std;
const int maxn=1e6;
using ll=long long int;
int a[100009][3];
struct lena{
int x,y;
};
bool cmp(const lena &p, const lena &q){
return ((p.x<q.x)||(p.x==q.x&&p.y<q.y));
}
int main()
{
    fastio
    //freopen(".INP","r",stdin);
    //freopen(".OUT","w",stdout);
    //solve();
    int n;
    cin>>n;
    long long ans=0;
    for (int i=1;i<=n*2;i++){
        long long x,y;
        cin>>x>>y;
        long long x2,y2;
        if (x>=n)x2=n;
        else if (x<=1)x2=1;
        else x2=x;
        if (y>=2)y2=2;
        else y2=1;
        ans=ans+abs(x-x2)+abs(y-y2);
        a[x2][y2]++;
        //cout<<x2<<" "<<y2<<'\n';
    }
    vector<lena>lp;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=2;j++){
            if (a[i][j]>1)lp.push_back({i,j});
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=2;j++){
            if (a[i][j]==0){
                int x=1e9,y=1e9;
                for (int k=0;k<(int)lp.size();k++){
                    int u=lp[k].x,v=lp[k].y;
                    if (a[u][v]>1&&abs(i-x)+abs(j-y)>abs(i-u)+abs(j-v)){
                        x=u;
                        y=v;
                    }
                }
                ans=ans+abs(i-x)+abs(j-y);
                a[x][y]--;
            }
        }
    }
    cout<<ans;

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