답안 #705807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705807 2023-03-05T10:32:46 Z piOOE Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
462 ms 26744 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using db = double;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<int> a(n), b(m);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (int j = 0; j < m; ++j) {
        cin >> b[j];
    }

    set<tuple<db, int, int>> st;

    set<int> rows, columns;

    vector<int> last(n + m);

    int iter = 0;

    for (int i = 0; i < n; ++i) {
        rows.insert(rows.end(), i);
    }

    for (int i = 0; i < m; ++i) {
        columns.insert(columns.end(), i);
    }

    for (int i = 0; i < n - 1; ++i) {
        st.emplace(a[i + 1] - a[i], i, 0);
    }

    for (int i = n; i < n + m - 1; ++i) {
        st.emplace(b[i + 1 - n] - b[i - n], i, 0);
    }

    vector<int> when(n + m, -1);

    while (!st.empty()) {
        auto [delta, i, iteration] = *st.begin();
        st.erase(st.begin());

        if (last[i] != iteration) {
            continue;
        }

        when[i] = ++iter;

//        cout << i << endl;


        if (i >= n) {
            auto it = columns.erase(columns.find(i - n));

            if (it != columns.begin()) {
                assert(it != columns.end());
                int j = *it, p = *prev(it);
                assert(j > i - n);

                st.emplace(db(b[j] - b[p]) / (j - p), p + n, last[p + n] = iter);
            }
        } else {
            auto it = rows.erase(rows.find(i));

            if (it != rows.begin()) {
                assert(it != rows.end());
                int j = *it, p = *prev(it);
                assert(j > i);

                st.emplace(db(a[j] - a[p]) / (j - p), p, last[p] = iter);
            }
        }
    }

    int x = 0, y = 0;
    ll ans = 0;

    while (x < n - 1 || y < m - 1) {
        if (x < n - 1 && (y == m - 1 || when[x] < when[y + n])) {
            ans += b[y];
            x += 1;
        } else {
            ans += a[x];
            y += 1;
        }
    }

    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 244 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 129 ms 10236 KB Output is correct
5 Correct 42 ms 9820 KB Output is correct
6 Correct 35 ms 4460 KB Output is correct
7 Correct 459 ms 25364 KB Output is correct
8 Correct 400 ms 25352 KB Output is correct
9 Correct 438 ms 25372 KB Output is correct
10 Correct 402 ms 25416 KB Output is correct
11 Correct 130 ms 25252 KB Output is correct
12 Correct 415 ms 25368 KB Output is correct
13 Correct 395 ms 25364 KB Output is correct
14 Correct 130 ms 25348 KB Output is correct
15 Correct 87 ms 25568 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 244 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 129 ms 10236 KB Output is correct
33 Correct 42 ms 9820 KB Output is correct
34 Correct 35 ms 4460 KB Output is correct
35 Correct 459 ms 25364 KB Output is correct
36 Correct 400 ms 25352 KB Output is correct
37 Correct 438 ms 25372 KB Output is correct
38 Correct 402 ms 25416 KB Output is correct
39 Correct 130 ms 25252 KB Output is correct
40 Correct 415 ms 25368 KB Output is correct
41 Correct 395 ms 25364 KB Output is correct
42 Correct 130 ms 25348 KB Output is correct
43 Correct 87 ms 25568 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 316 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 133 ms 11788 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 8 ms 1484 KB Output is correct
58 Correct 28 ms 3824 KB Output is correct
59 Correct 452 ms 26524 KB Output is correct
60 Correct 443 ms 26528 KB Output is correct
61 Correct 435 ms 26536 KB Output is correct
62 Correct 462 ms 26516 KB Output is correct
63 Correct 84 ms 26440 KB Output is correct
64 Correct 421 ms 26456 KB Output is correct
65 Correct 423 ms 26548 KB Output is correct
66 Correct 121 ms 26548 KB Output is correct
67 Correct 99 ms 26744 KB Output is correct