Submission #759708

# Submission time Handle Problem Language Result Execution time Memory
759708 2023-06-16T15:40:23 Z piOOE Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
424 ms 26688 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;

        if (i >= n) {
            auto it = columns.erase(columns.find(i - n));
            if (it != columns.begin()) {
                int j = *it, p = *prev(it);
                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()) {
                int j = *it, p = *prev(it);
                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 (y < m - 1 && (x == n - 1 || when[x] > when[y + n])) {
            ans += a[x];
            y += 1;
        } else {
            ans += b[y];
            x += 1;
        }
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 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 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 2 ms 460 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 456 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 452 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 1 ms 584 KB Output is correct
18 Correct 1 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 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 90 ms 10564 KB Output is correct
5 Correct 35 ms 9728 KB Output is correct
6 Correct 34 ms 4380 KB Output is correct
7 Correct 418 ms 25352 KB Output is correct
8 Correct 334 ms 25268 KB Output is correct
9 Correct 373 ms 25412 KB Output is correct
10 Correct 351 ms 25364 KB Output is correct
11 Correct 111 ms 25264 KB Output is correct
12 Correct 391 ms 25292 KB Output is correct
13 Correct 325 ms 25376 KB Output is correct
14 Correct 95 ms 25292 KB Output is correct
15 Correct 79 ms 25500 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 320 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 320 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 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 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 324 KB Output is correct
9 Correct 2 ms 460 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 456 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 452 KB Output is correct
16 Correct 2 ms 456 KB Output is correct
17 Correct 1 ms 584 KB Output is correct
18 Correct 1 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 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 316 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 90 ms 10564 KB Output is correct
33 Correct 35 ms 9728 KB Output is correct
34 Correct 34 ms 4380 KB Output is correct
35 Correct 418 ms 25352 KB Output is correct
36 Correct 334 ms 25268 KB Output is correct
37 Correct 373 ms 25412 KB Output is correct
38 Correct 351 ms 25364 KB Output is correct
39 Correct 111 ms 25264 KB Output is correct
40 Correct 391 ms 25292 KB Output is correct
41 Correct 325 ms 25376 KB Output is correct
42 Correct 95 ms 25292 KB Output is correct
43 Correct 79 ms 25500 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 320 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 320 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 324 KB Output is correct
55 Correct 103 ms 11800 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 9 ms 1492 KB Output is correct
58 Correct 25 ms 3736 KB Output is correct
59 Correct 340 ms 26432 KB Output is correct
60 Correct 350 ms 26568 KB Output is correct
61 Correct 370 ms 26540 KB Output is correct
62 Correct 346 ms 26544 KB Output is correct
63 Correct 72 ms 26444 KB Output is correct
64 Correct 390 ms 26436 KB Output is correct
65 Correct 424 ms 26548 KB Output is correct
66 Correct 108 ms 26524 KB Output is correct
67 Correct 77 ms 26688 KB Output is correct