답안 #933567

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

#define maxn 1005
#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? 0 : -1;
    }

};

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


int n, m;

int a[maxn], b[maxn];
long long dp[maxn][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[hulla.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 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -