답안 #941683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941683 2024-03-09T09:44:22 Z alextodoran Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
354 ms 20560 KB
/**
 _  _   __  _ _ _  _  _ _
 |a  ||t  ||o    d | |o  |
| __    _| | _ | __|  _ |
| __ |/_  | __  /__\ / _\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N_MAX = 100000;
const int M_MAX = 100000;

int N, M;
int A[N_MAX + 2];
int B[M_MAX + 2];

int nxt_A[N_MAX + 2];
int prv_A[N_MAX + 2];
int nxt_B[M_MAX + 2];
int prv_B[M_MAX + 2];

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= M; i++) {
        cin >> B[i];
    }
    for (int i = 0; i + 1 <= N; i++) {
        nxt_A[i] = i + 1;
        prv_A[i + 1] = i;
    }
    for (int i = 0; i + 1 <= M; i++) {
        nxt_B[i] = i + 1;
        prv_B[i + 1] = i;
    }
    set <pair <ld, int>> S;
    for (int i = 1; i + 1 <= N; i++) {
        S.insert(make_pair(A[i + 1] - A[i], i));
    }
    for (int i = 1; i + 1 <= M; i++) {
        S.insert(make_pair(B[i + 1] - B[i], -i));
    }
    ll answer = 0;
    while (S.empty() == false) {
        int i = S.begin()->second;
        S.erase(S.begin());
        if (i > 0) {
            int l = prv_A[i], r = nxt_A[i];
            nxt_A[l] = r;
            prv_A[r] = l;
            if (l == 0) {
                answer += (ll) B[nxt_B[0]] * (r - i);
            }
            if (l != 0) {
                S.erase(make_pair((ld) (A[i] - A[l]) / (i - l), l));
                S.insert(make_pair((ld) (A[r] - A[l]) / (r - l), l));
            }
        } else {
            i = -i;
            int l = prv_B[i], r = nxt_B[i];
            nxt_B[l] = r;
            prv_B[r] = l;
            if (l == 0) {
                answer += (ll) A[nxt_A[0]] * (r - i);
            }
            if (l != 0) {
                S.erase(make_pair((ld) (B[i] - B[l]) / (i - l), -l));
                S.insert(make_pair((ld) (B[r] - B[l]) / (r - l), -l));
            }
        }
    }
    cout << answer << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2532 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2400 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 0 ms 2516 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2516 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 80 ms 9240 KB Output is correct
5 Correct 33 ms 9048 KB Output is correct
6 Correct 28 ms 5208 KB Output is correct
7 Correct 297 ms 19024 KB Output is correct
8 Correct 299 ms 19028 KB Output is correct
9 Correct 332 ms 19216 KB Output is correct
10 Correct 297 ms 19212 KB Output is correct
11 Correct 111 ms 19140 KB Output is correct
12 Correct 347 ms 19108 KB Output is correct
13 Correct 288 ms 19192 KB Output is correct
14 Correct 72 ms 19200 KB Output is correct
15 Correct 64 ms 19284 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2512 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2520 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2532 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2508 KB Output is correct
20 Correct 1 ms 2400 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 0 ms 2516 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2516 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 80 ms 9240 KB Output is correct
33 Correct 33 ms 9048 KB Output is correct
34 Correct 28 ms 5208 KB Output is correct
35 Correct 297 ms 19024 KB Output is correct
36 Correct 299 ms 19028 KB Output is correct
37 Correct 332 ms 19216 KB Output is correct
38 Correct 297 ms 19212 KB Output is correct
39 Correct 111 ms 19140 KB Output is correct
40 Correct 347 ms 19108 KB Output is correct
41 Correct 288 ms 19192 KB Output is correct
42 Correct 72 ms 19200 KB Output is correct
43 Correct 64 ms 19284 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2392 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2512 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2392 KB Output is correct
55 Correct 87 ms 10340 KB Output is correct
56 Correct 1 ms 2392 KB Output is correct
57 Correct 7 ms 3164 KB Output is correct
58 Correct 22 ms 4772 KB Output is correct
59 Correct 282 ms 20552 KB Output is correct
60 Correct 293 ms 20372 KB Output is correct
61 Correct 354 ms 20524 KB Output is correct
62 Correct 282 ms 20304 KB Output is correct
63 Correct 58 ms 20300 KB Output is correct
64 Correct 281 ms 20304 KB Output is correct
65 Correct 298 ms 20304 KB Output is correct
66 Correct 90 ms 20372 KB Output is correct
67 Correct 70 ms 20560 KB Output is correct