답안 #110303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110303 2019-05-10T15:30:53 Z polyfish Coin Collecting (JOI19_ho_t4) C++14
100 / 100
123 ms 8440 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 (int64_t _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int64_t _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "coincollecting"

const int64_t MAX_N = 200002;
const int64_t INF = 1e18;

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

void read_input() {
    cin >> n;

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

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

        int64_t d = INF;

        for (int64_t 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 (int64_t 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() {
    int64_t u = 0, d = 0;

    for (int64_t 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 + abs(u) + abs(d);
    }
}

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 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 432 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 428 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 412 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 432 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 428 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 412 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 428 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 7 ms 512 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 4 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 5 ms 512 KB Output is correct
50 Correct 10 ms 384 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 5 ms 512 KB Output is correct
53 Correct 5 ms 512 KB Output is correct
54 Correct 4 ms 384 KB Output is correct
55 Correct 6 ms 384 KB Output is correct
56 Correct 4 ms 384 KB Output is correct
57 Correct 3 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 4 ms 384 KB Output is correct
61 Correct 3 ms 512 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 4 ms 512 KB Output is correct
64 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 432 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 428 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 412 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 428 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 4 ms 512 KB Output is correct
36 Correct 7 ms 512 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 3 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 512 KB Output is correct
43 Correct 4 ms 512 KB Output is correct
44 Correct 4 ms 512 KB Output is correct
45 Correct 4 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 5 ms 512 KB Output is correct
50 Correct 10 ms 384 KB Output is correct
51 Correct 4 ms 384 KB Output is correct
52 Correct 5 ms 512 KB Output is correct
53 Correct 5 ms 512 KB Output is correct
54 Correct 4 ms 384 KB Output is correct
55 Correct 6 ms 384 KB Output is correct
56 Correct 4 ms 384 KB Output is correct
57 Correct 3 ms 384 KB Output is correct
58 Correct 3 ms 384 KB Output is correct
59 Correct 3 ms 384 KB Output is correct
60 Correct 4 ms 384 KB Output is correct
61 Correct 3 ms 512 KB Output is correct
62 Correct 3 ms 384 KB Output is correct
63 Correct 4 ms 512 KB Output is correct
64 Correct 4 ms 384 KB Output is correct
65 Correct 102 ms 6652 KB Output is correct
66 Correct 76 ms 8180 KB Output is correct
67 Correct 82 ms 8284 KB Output is correct
68 Correct 106 ms 8424 KB Output is correct
69 Correct 116 ms 8284 KB Output is correct
70 Correct 101 ms 8324 KB Output is correct
71 Correct 113 ms 8440 KB Output is correct
72 Correct 111 ms 6788 KB Output is correct
73 Correct 84 ms 6776 KB Output is correct
74 Correct 96 ms 6904 KB Output is correct
75 Correct 82 ms 6660 KB Output is correct
76 Correct 83 ms 6776 KB Output is correct
77 Correct 114 ms 6776 KB Output is correct
78 Correct 91 ms 6824 KB Output is correct
79 Correct 66 ms 6696 KB Output is correct
80 Correct 114 ms 6828 KB Output is correct
81 Correct 104 ms 6804 KB Output is correct
82 Correct 89 ms 6776 KB Output is correct
83 Correct 67 ms 6904 KB Output is correct
84 Correct 69 ms 7288 KB Output is correct
85 Correct 96 ms 7288 KB Output is correct
86 Correct 108 ms 8320 KB Output is correct
87 Correct 123 ms 8312 KB Output is correct
88 Correct 88 ms 8324 KB Output is correct
89 Correct 86 ms 8436 KB Output is correct
90 Correct 94 ms 8184 KB Output is correct
91 Correct 97 ms 8364 KB Output is correct
92 Correct 89 ms 7588 KB Output is correct
93 Correct 88 ms 8316 KB Output is correct
94 Correct 92 ms 8184 KB Output is correct
95 Correct 93 ms 7416 KB Output is correct
96 Correct 88 ms 7328 KB Output is correct
97 Correct 93 ms 7296 KB Output is correct
98 Correct 84 ms 7720 KB Output is correct
99 Correct 65 ms 7544 KB Output is correct
100 Correct 74 ms 7160 KB Output is correct
101 Correct 97 ms 7160 KB Output is correct
102 Correct 74 ms 7672 KB Output is correct
103 Correct 114 ms 7416 KB Output is correct