답안 #589079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589079 2022-07-04T09:12:02 Z 반딧불(#8402) Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
2000 ms 7196 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct vector2{
    ll x, y;
    vector2(){}
    vector2(ll x, ll y): x(x), y(y){}

    vector2 operator-(const vector2 &r)const{
        return vector2(x-r.x, y-r.y);
    }

    ll cross(vector2 r)const{
        return x*r.y - y*r.x;
    }

    bool operator<(const vector2 &r)const{
        return x<r.x;
    }
};

ll ccw(vector2 a, vector2 b){
    return a.cross(b);
}

ll ccw(vector2 a, vector2 b, vector2 c){
    return ccw(b-a, c-a);
}

vector<vector2> hull(vector<vector2> &v){
    int sz = (int)v.size();
    sort(v.begin(), v.end());
    sort(v.begin()+1, v.end(), [&](vector2 A, vector2 B){
        if(ccw(v[0], A, B) == 0) return A.x < B.x;
        return ccw(v[0], A, B) > 0;
    });
    vector<vector2> ret (1, v[0]);
    for(int i=1; i<(int)v.size(); i++){
        while(ret.size() >= 2 && ccw(ret[ret.size()-2], ret.back(), v[i]) <= 0) ret.pop_back();
        ret.push_back(v[i]);
        if(v[i].x == sz) break;
    }
    return ret;
}

void simplify(ll* arr, ll* narr, int &sz, ll* loc){
    vector<vector2> vec;
    for(int i=1; i<=sz; i++) vec.push_back(vector2(i, arr[i]));
    vec = hull(vec);
    assert((int)vec.back().x == sz);
    sz = (int)vec.size();
    for(int i=1; i<=sz; i++){
        narr[i] = vec[i-1].y;
        loc[i] = vec[i-1].x;
    }
}

int n, m;
ll ta[100002], tb[100002];
ll a[100002], b[100002];
ll al[100002], bl[100002];
ll dist[2][50002];

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++) scanf("%lld", &ta[i]);
    for(int i=1; i<=m; i++) scanf("%lld", &tb[i]);
    simplify(ta, a, n, al);
    simplify(tb, b, m, bl);
    for(int i=0; i<2; i++) for(int j=1; j<=m; j++) dist[i][j] = 1e18;
    dist[1][1] = 0;
    for(int i=1; i<=n; i++){
        int bit = i%2;
        for(int j=1; j<=m; j++) dist[!bit][j] = 1e18;
        for(int j=1; j<=m; j++){
            dist[bit][j+1] = min(dist[bit][j+1], dist[bit][j] + a[i] * (bl[j+1]-bl[j]));
            dist[!bit][j] = min(dist[!bit][j], dist[bit][j] + b[j] * (al[i+1]-al[i]));
        }
    }
    printf("%lld", dist[n%2][m]);
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:69:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     for(int i=1; i<=n; i++) scanf("%lld", &ta[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
kyoto.cpp:70:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     for(int i=1; i<=m; i++) scanf("%lld", &tb[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 18 ms 3040 KB Output is correct
5 Correct 14 ms 3016 KB Output is correct
6 Correct 8 ms 1676 KB Output is correct
7 Correct 50 ms 5520 KB Output is correct
8 Correct 51 ms 5504 KB Output is correct
9 Correct 49 ms 5408 KB Output is correct
10 Correct 62 ms 5480 KB Output is correct
11 Correct 39 ms 5448 KB Output is correct
12 Correct 46 ms 5504 KB Output is correct
13 Correct 49 ms 5460 KB Output is correct
14 Correct 34 ms 5408 KB Output is correct
15 Correct 36 ms 5400 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 18 ms 3040 KB Output is correct
33 Correct 14 ms 3016 KB Output is correct
34 Correct 8 ms 1676 KB Output is correct
35 Correct 50 ms 5520 KB Output is correct
36 Correct 51 ms 5504 KB Output is correct
37 Correct 49 ms 5408 KB Output is correct
38 Correct 62 ms 5480 KB Output is correct
39 Correct 39 ms 5448 KB Output is correct
40 Correct 46 ms 5504 KB Output is correct
41 Correct 49 ms 5460 KB Output is correct
42 Correct 34 ms 5408 KB Output is correct
43 Correct 36 ms 5400 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 23 ms 3144 KB Output is correct
56 Correct 1 ms 464 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 7 ms 1104 KB Output is correct
59 Correct 60 ms 5456 KB Output is correct
60 Correct 61 ms 5428 KB Output is correct
61 Correct 52 ms 5416 KB Output is correct
62 Correct 57 ms 5696 KB Output is correct
63 Execution timed out 2044 ms 7196 KB Time limit exceeded
64 Halted 0 ms 0 KB -