이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define FOD(i,a,b) for (int i=(a);i>=(b);i--)
#define bit(x,y) ((x)>>(y))&1
#define pb push_back
#define ll long long
#define ii pair < int,int >
#define f first
#define s second
#define M 1000000007
#define N 100005
using namespace std;
int cnt[N][2];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);
    int n,res=0;
    cin>>n;
    FOR(i,1,2*n) {
        int x,y;
        cin>>x>>y;
        if (x<1) {
            res+=1-x;
            x=1;
        } else
        if (x>n) {
            res+=x-n;
            x=n;
        }
        if (y>2) {
            res+=y-2;
            y=2;
        } else
        if (y<1) {
            res+=1-y;
            y=1;
        }
        ++cnt[x][y];
    }
    int x=0,y=0;
    FOR(i,1,n) {
        --cnt[i][1];
        --cnt[i][2];
        x+=cnt[i][1];
        y+=cnt[i][2];
        if (x<0 && y>0) {
            int z=min(abs(x),abs(y));
            x+=z;
            y-=z;
            res+=z;
        } else
        if (x>0 && y<0) {
            int z=min(abs(x),abs(y));
            x-=z;
            y+=z;
            res+=z;
        }
        res+=abs(x)+abs(y);
    }
    cout<<res;
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:47:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   47 |         --cnt[i][2];
      |           ~~~~~~~~^
joi2019_ho_t4.cpp:47:19: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |