답안 #110295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110295 2019-05-10T14:59:09 Z polyfish Coin Collecting (JOI19_ho_t4) C++14
0 / 100
2 ms 384 KB
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;

#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int MAX_N = 200002;
const int INF = 1e9;

int n, cnt[3][MAX_N];
int64_t res;
pair<int, int> a[MAX_N];

void read_input() {
    cin >> n;

    for (int i=1; i<=2*n; ++i)
        cin >> a[i].second >> a[i].first;
}

void init() {
    for (int i=1; i<=2*n; ++i) {
        vector<int> p = {1, n};
        if (0<a[i].second && a[i].second<=n)
            p.push_back(a[i].second);

        int d = INF;

        for (int x=1; x<=2; ++x) {
            for (auto y : p)
                d = min(d, abs(a[i].first-x)+abs(a[i].second-y));
        }

        res += d;

        for (int x=1; x<=2; ++x) {
            for (auto y : p) {
                if (d==abs(a[i].first-x)+abs(a[i].second-y)) {
                    ++cnt[x][y];
                    break;
                }
            }
        }
    }
}

void solve() {
    int u = 0, d = 0;

    for (int i=1; i<=n; ++i) {
        u += (cnt[1][i]-1);
        d += (cnt[2][i]-1);

        while (d>0 && u<0) {
            --d;
            ++u;
            ++res;
        }

        while (d<0 && u>0) {
            ++d;
            --u;
            ++res;
        }

        res = res + (u!=0) + (d!=0);
    }
}

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".in", "r", stdin);
//		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);

	read_input();
	init();
	solve();
	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -