답안 #933579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933579 2024-02-25T23:23:14 Z Ice_man Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
20 ms 6772 KB
#include <iostream>
#include <chrono>
#include <vector>

#define maxn 200005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;

#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")

using namespace std;

std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;

double timePassed()
{
    using namespace std::chrono;
    currT = high_resolution_clock::now();
    double time = duration_cast<duration<double>>(currT - startT).count();
    return time * TIME_MULT;
}

struct point
{
    long long x, y;
    point() {};
    point(long long _x, long long _y)
    {
        x = _x;
        y = _y;
    }

    int direction(const point &a, const point &b)
    {
        long long face = 0;

        face += (a.x - x) * (a.y + y);
        face += (b.x - a.x) * (b.y + a.y);
        face += (x - b.x) * (y + b.y);

        return face > 0? 1 : face < 0? -1 : 0;
    }

};

long long dist(long long x1, long long x2, long long y)
{
    return (x1 - x2) * y;
}


long long n, m;

long long a[maxn], b[maxn];

void read()
{
    cin >> n >> m;

    for(long long i = 1; i <= n; i++)
        cin >> a[i];

    for(long long i = 1; i <= m; i++)
        cin >> b[i];
}

long long ans = 0;

vector <point> hulla, hullb;

void gen_hull_a()
{
    for(long long i = 1; i <= n; i++)
    {
        point e = {i, a[i]};

        while(hulla.size() >= 2 && hulla[hulla.size() - 2].direction(hulla[hulla.size() - 1], e) >= 0)
            hulla.pop_back();

        hulla.pb(e);
    }
}


void gen_hull_b()
{
    for(long long i = 1; i <= m; i++)
    {
        point e = {i, b[i]};

        while(hullb.size() >= 2 && hullb[hullb.size() - 2].direction(hullb[hullb.size() - 1], e) >= 0)
            hullb.pop_back();

        hullb.pb(e);
    }
}


long long try_dist(long long x1, long long x2, long long y1, long long y2)
{
    return (x1 - x2) * (y1 - y2);
}


void solve()
{
    point e, e2;

    while(hulla.size() > 1 || hullb.size() > 1)
    {
        //cout << hulla.size() << " - " << hullb.size() << endl;

        //cout << ans << endl;

        if(hulla.size() == 1)
        {
            ///control

            e = hullb[hullb.size() - 1];
            hullb.pop_back();

            e2 = hullb[hullb.size() - 1];

            ans += dist(e.x, e2.x, hulla[hulla.size() - 1].y);
            continue;
        }


        if(hullb.size() == 1)
        {
            ///cout << "inb" << endl;

            e = hulla[hulla.size() - 1];
            hulla.pop_back();

            e2 = hulla[hulla.size() - 1];

            ans += dist(e.x, e2.x, hullb[hullb.size() - 1].y);
            continue;
        }

        long long dist1 = try_dist(hulla[hulla.size() - 1].x, hulla[hulla.size() - 2].x, hullb[hullb.size() - 1].y, hullb[hullb.size() - 2].y);
        long long dist2 = try_dist(hullb[hullb.size() - 1].x, hullb[hullb.size() - 2].x, hulla[hulla.size() - 1].y, hulla[hulla.size() - 2].y);

        ///cout << ":: " << dist1 << " " << dist2 << endl;

        if(dist2 > dist1)
        {
            e = hulla[hulla.size() - 1];
            hulla.pop_back();

            e2 = hulla[hulla.size() - 1];

            ans += dist(e.x, e2.x, hullb[hullb.size() - 1].y);
            continue;
        }

        e = hullb[hullb.size() - 1];
        hullb.pop_back();

        e2 = hullb[hullb.size() - 1];

        ans += dist(e.x, e2.x, hulla[hulla.size() - 1].y);
        continue;

    }

    cout << ans << endl;
}





int main()
{

    /**#ifdef ONLINE_JUDGE
        freopen("taxi.in", "r", stdin);
        freopen("taxi.out", "w", stdout);
    #endif*/

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    startT = std::chrono::high_resolution_clock::now();

    read();
    gen_hull_a();

    /**cout << "-----------------------" << endl;
    for(point e : hulla)
        cout << e.x << " " << e.y << endl;*/

    gen_hull_b();

    /**cout << "----------------------" << endl;
    for(point e : hullb)
        cout << e.x << " " << e.y << endl;
    cout << "----------------------" << endl;*/

    solve();


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 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 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 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 0 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 6 ms 2652 KB Output is correct
5 Correct 5 ms 2908 KB Output is correct
6 Correct 3 ms 2392 KB Output is correct
7 Correct 13 ms 3528 KB Output is correct
8 Correct 12 ms 3420 KB Output is correct
9 Correct 13 ms 3584 KB Output is correct
10 Correct 12 ms 3420 KB Output is correct
11 Correct 12 ms 3512 KB Output is correct
12 Correct 13 ms 3420 KB Output is correct
13 Correct 13 ms 3392 KB Output is correct
14 Correct 11 ms 3420 KB Output is correct
15 Correct 12 ms 3792 KB Output is correct
16 Correct 0 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 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 0 ms 2648 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 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 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 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 0 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 6 ms 2652 KB Output is correct
33 Correct 5 ms 2908 KB Output is correct
34 Correct 3 ms 2392 KB Output is correct
35 Correct 13 ms 3528 KB Output is correct
36 Correct 12 ms 3420 KB Output is correct
37 Correct 13 ms 3584 KB Output is correct
38 Correct 12 ms 3420 KB Output is correct
39 Correct 12 ms 3512 KB Output is correct
40 Correct 13 ms 3420 KB Output is correct
41 Correct 13 ms 3392 KB Output is correct
42 Correct 11 ms 3420 KB Output is correct
43 Correct 12 ms 3792 KB Output is correct
44 Correct 0 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 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 0 ms 2648 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 9 ms 3164 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 3 ms 2648 KB Output is correct
59 Correct 19 ms 4716 KB Output is correct
60 Correct 18 ms 4692 KB Output is correct
61 Correct 20 ms 4692 KB Output is correct
62 Correct 19 ms 4676 KB Output is correct
63 Correct 19 ms 6772 KB Output is correct
64 Correct 19 ms 4700 KB Output is correct
65 Correct 18 ms 4700 KB Output is correct
66 Correct 17 ms 4892 KB Output is correct
67 Correct 18 ms 4952 KB Output is correct