Submission #849508

# Submission time Handle Problem Language Result Execution time Memory
849508 2023-09-14T19:26:29 Z danikoynov Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
65 ms 10052 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int maxn = 1e5 + 10;

struct point
{
    ll x, y;

    point(ll _x = 0, ll _y = 0)
    {
        x = _x;
        y = _y;
    }
};

ll signed_area(point A, point B, point C)
{
    ll area = (B.x - A.x) * (B.y + A.y) +
              (C.x - B.x) * (C.y + B.y) +
              (A.x - C.x) * (A.y + C.y);
    return area; /// area is multiplied by 2
}


int orientation(point A, point B, point C)
{
    ll area = signed_area(A, B, C);
    if (area > 0)
        return 1; /// clockwise
    if (area < 0)
        return -1; /// anticlockwise
    return 0; /// collinear
}

int h, w;
ll a[maxn], b[maxn];

vector < point > lower_hull(vector < point > v)
{
    vector < point > res;
    for (int i = 0; i < v.size(); i ++)
    {
        while(res.size() > 1 && orientation(res[res.size() - 2], res.back(), v[i]) >= 0)
            res.pop_back();
        res.push_back(v[i]);
    }
    return res;
}

void print_vector(vector < point > vec) /// debug
{
    for (point p : vec)
        cout << p.x << " ";
    cout << endl;
}

void solve()
{
    cin >> h >> w;
    for (int i = 1; i <= h; i ++)
        cin >> a[i];
    for (int i = 1; i <= w; i ++)
        cin >> b[i];

    vector < point > row, col;

    for (int i = 1; i <= h; i ++)
    {
        row.push_back(point(i, a[i]));
    }

    for (int i = 1; i <= w; i ++)
    {
        col.push_back(point(i, b[i]));
    }

    row = lower_hull(row);
    col = lower_hull(col);

    /// print hull
    /**cout << "row hull: ";
    print_vector(row);
        cout << "col hull: ";
    print_vector(col);*/
    ///exit(0);
    ll ans = 0;
    while(true)
    {
        if (row.size() == 1 && col.size() == 1)
            break;

        if (row.size() == 1)
        {
            point cur = col.back();
            col.pop_back();
            ans = ans + (cur.x - col.back().x) * row.back().y;
        }
        else if (col.size() == 1)
        {
            point cur = row.back();
            row.pop_back();
            ans = ans + (cur.x - row.back().x) * col.back().y;
        }
        else
        {
            /// row slope = (row[n].y - row[n - 1].y) / (row[n].x - row[n - 1].x)
            /// col slope = (col[m].y - col[m - 1].y) / (col[m].x - col[m - 1].x)
            ///if (row_slope > col_slope)
            int rs = row.size(), cs = col.size();
            ///cout << "row slope "<< row[rs - 1].y - row[rs - 2].y << " " << row[rs - 1].x - row[rs - 2].x << endl;
            if ((row[rs - 1].y - row[rs - 2].y) * (col[cs - 1].x - col[cs - 2].x) <
                    (col[cs - 1].y - col[cs - 2].y) * (row[rs - 1].x - row[rs - 2].x))
            {

                point cur = col.back();
                col.pop_back();
                ans = ans + (cur.x - col.back().x) * row.back().y;
            }
            else
            {
                point cur = row.back();
                row.pop_back();
                ans = ans + (cur.x - row.back().x) * col.back().y;
            }
        }
    }

    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Compilation message

kyoto.cpp: In function 'std::vector<point> lower_hull(std::vector<point>)':
kyoto.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0; i < v.size(); i ++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 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 344 KB Output is correct
9 Correct 1 ms 344 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 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 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 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 16 ms 3788 KB Output is correct
5 Correct 13 ms 3784 KB Output is correct
6 Correct 6 ms 2000 KB Output is correct
7 Correct 37 ms 7684 KB Output is correct
8 Correct 37 ms 7492 KB Output is correct
9 Correct 37 ms 7500 KB Output is correct
10 Correct 37 ms 7492 KB Output is correct
11 Correct 34 ms 7492 KB Output is correct
12 Correct 38 ms 7496 KB Output is correct
13 Correct 37 ms 7492 KB Output is correct
14 Correct 37 ms 7388 KB Output is correct
15 Correct 42 ms 7748 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 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 344 KB Output is correct
9 Correct 1 ms 344 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 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 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 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 16 ms 3788 KB Output is correct
33 Correct 13 ms 3784 KB Output is correct
34 Correct 6 ms 2000 KB Output is correct
35 Correct 37 ms 7684 KB Output is correct
36 Correct 37 ms 7492 KB Output is correct
37 Correct 37 ms 7500 KB Output is correct
38 Correct 37 ms 7492 KB Output is correct
39 Correct 34 ms 7492 KB Output is correct
40 Correct 38 ms 7496 KB Output is correct
41 Correct 37 ms 7492 KB Output is correct
42 Correct 37 ms 7388 KB Output is correct
43 Correct 42 ms 7748 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 28 ms 4800 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 3 ms 980 KB Output is correct
58 Correct 9 ms 1744 KB Output is correct
59 Correct 62 ms 8732 KB Output is correct
60 Correct 63 ms 8768 KB Output is correct
61 Correct 63 ms 8772 KB Output is correct
62 Correct 63 ms 8772 KB Output is correct
63 Correct 64 ms 10052 KB Output is correct
64 Correct 64 ms 8656 KB Output is correct
65 Correct 64 ms 8560 KB Output is correct
66 Correct 61 ms 8516 KB Output is correct
67 Correct 65 ms 8852 KB Output is correct