답안 #933580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933580 2024-02-25T23:25:38 Z Ice_man Sightseeing in Kyoto (JOI22_kyoto) C++14
30 / 100
13 ms 1248 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
{
    int x, y;
    point() {};
    point(int _x, int _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(int x1, int x2, int y)
{
    return (x1 - x2) * y;
}


int n, m;

int a[maxn], b[maxn];

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

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

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

long long ans = 0;

vector <point> hulla, hullb;

void gen_hull_a()
{
    for(int 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(int 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(int x1, int x2, int y1, int 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 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 4 ms 772 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 12 ms 1116 KB Output is correct
8 Correct 13 ms 1112 KB Output is correct
9 Correct 13 ms 1116 KB Output is correct
10 Correct 12 ms 1116 KB Output is correct
11 Correct 11 ms 1116 KB Output is correct
12 Correct 12 ms 1248 KB Output is correct
13 Correct 12 ms 1116 KB Output is correct
14 Correct 11 ms 1116 KB Output is correct
15 Correct 12 ms 1112 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 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 412 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -