답안 #938751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938751 2024-03-05T13:43:31 Z Pannda Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
23 ms 10452 KB
#include <bits/stdc++.h>
using namespace std;

typedef complex<long long> point;
long long cross(point a, point b) {
    return (conj(a) * b).imag();
}

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

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

    vector<point> a(n), b(m);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[i] = point(i, x);
    }
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        b[i] = point(i, x);
    }

    auto f = [](vector<point> a, bool is_a) -> vector<array<int, 4>> {
        vector<point> hull;
        for (point p : a) {
            while (hull.size() >= 2 && cross(p - hull.end()[-2], p - hull.end()[-1]) <= 0) hull.pop_back();
            hull.push_back(p);
        }
        vector<array<int, 4>> res;
        point last(-1, -1);
        for (point p : hull) {
            if (last != point(-1, -1)) {
                int length = p.real() - last.real();
                int delta = p.imag() - last.imag();
                int di = length, dj = 0;
                if (!is_a) swap(di, dj);
                res.push_back({length, delta, di, dj});
            }
            last = p;
        }
        return res;
    };

    vector<array<int, 4>> fa = f(a, true);
    vector<array<int, 4>> fb = f(b, false);
    vector<array<int, 4>> fab(fa.size() + fb.size());
    merge(fa.begin(), fa.end(), fb.begin(), fb.end(), fab.begin(), [&](array<int, 4> x, array<int, 4> y) {
        return 1LL * x[1] * y[0] < 1LL * y[1] * x[0];
    });
    int i = 0, j = 0;
    long long answer = 0;
    for (auto [length, delta, di, dj] : fab) {
        answer += 1LL * di * b[j].imag() + 1LL * dj * a[i].imag();
        i += di;
        j += dj;
    }
    cout << answer << '\n';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 420 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 3164 KB Output is correct
5 Correct 5 ms 2904 KB Output is correct
6 Correct 3 ms 1628 KB Output is correct
7 Correct 15 ms 5760 KB Output is correct
8 Correct 14 ms 5724 KB Output is correct
9 Correct 14 ms 5848 KB Output is correct
10 Correct 15 ms 5944 KB Output is correct
11 Correct 13 ms 5724 KB Output is correct
12 Correct 14 ms 5888 KB Output is correct
13 Correct 16 ms 5892 KB Output is correct
14 Correct 13 ms 5900 KB Output is correct
15 Correct 17 ms 5980 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 356 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 460 KB Output is correct
22 Correct 0 ms 460 KB Output is correct
23 Correct 0 ms 452 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 420 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 6 ms 3164 KB Output is correct
33 Correct 5 ms 2904 KB Output is correct
34 Correct 3 ms 1628 KB Output is correct
35 Correct 15 ms 5760 KB Output is correct
36 Correct 14 ms 5724 KB Output is correct
37 Correct 14 ms 5848 KB Output is correct
38 Correct 15 ms 5944 KB Output is correct
39 Correct 13 ms 5724 KB Output is correct
40 Correct 14 ms 5888 KB Output is correct
41 Correct 16 ms 5892 KB Output is correct
42 Correct 13 ms 5900 KB Output is correct
43 Correct 17 ms 5980 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 356 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 460 KB Output is correct
50 Correct 0 ms 460 KB Output is correct
51 Correct 0 ms 452 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 11 ms 3932 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 3 ms 1372 KB Output is correct
59 Correct 22 ms 6916 KB Output is correct
60 Correct 21 ms 6900 KB Output is correct
61 Correct 22 ms 7000 KB Output is correct
62 Correct 20 ms 7012 KB Output is correct
63 Correct 21 ms 10452 KB Output is correct
64 Correct 21 ms 7016 KB Output is correct
65 Correct 23 ms 6960 KB Output is correct
66 Correct 20 ms 7044 KB Output is correct
67 Correct 19 ms 7260 KB Output is correct