Submission #933576

# Submission time Handle Problem Language Result Execution time Memory
933576 2024-02-25T23:21:29 Z Ice_man Sightseeing in Kyoto (JOI22_kyoto) C++14
10 / 100
1 ms 348 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
{
    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];
long long dp[maxn][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;
}
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 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 344 KB Output is correct
20 Correct 0 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 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 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 344 KB Output is correct
20 Correct 0 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 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 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 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Incorrect 0 ms 348 KB Output isn't correct
32 Halted 0 ms 0 KB -