답안 #589059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589059 2022-07-04T09:05:15 Z 반딧불(#8402) Sightseeing in Kyoto (JOI22_kyoto) C++17
10 / 100
36 ms 12316 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){
        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[5002][5002];

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);
    assert(max(n, m) <= 5000);
    for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) dist[i][j] = 1e18;
    dist[1][1] = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            dist[i][j+1] = min(dist[i][j+1], dist[i][j] + a[i] * (bl[j+1]-bl[j]));
            dist[i+1][j] = min(dist[i+1][j], dist[i][j] + b[j] * (al[i+1]-al[i]));
        }
    }
    printf("%lld", dist[n][m]);
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:68:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     for(int i=1; i<=n; i++) scanf("%lld", &ta[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
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<=m; i++) scanf("%lld", &tb[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 980 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 2 ms 1692 KB Output is correct
7 Correct 1 ms 1204 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 10 ms 12316 KB Output is correct
10 Correct 11 ms 12244 KB Output is correct
11 Correct 10 ms 12292 KB Output is correct
12 Correct 12 ms 12296 KB Output is correct
13 Correct 10 ms 12244 KB Output is correct
14 Correct 10 ms 12244 KB Output is correct
15 Correct 10 ms 12304 KB Output is correct
16 Correct 11 ms 12244 KB Output is correct
17 Correct 10 ms 12224 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 304 KB Output is correct
26 Correct 2 ms 308 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 5 ms 4668 KB Output is correct
4 Runtime error 36 ms 5004 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 980 KB Output is correct
5 Correct 2 ms 2260 KB Output is correct
6 Correct 2 ms 1692 KB Output is correct
7 Correct 1 ms 1204 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 10 ms 12316 KB Output is correct
10 Correct 11 ms 12244 KB Output is correct
11 Correct 10 ms 12292 KB Output is correct
12 Correct 12 ms 12296 KB Output is correct
13 Correct 10 ms 12244 KB Output is correct
14 Correct 10 ms 12244 KB Output is correct
15 Correct 10 ms 12304 KB Output is correct
16 Correct 11 ms 12244 KB Output is correct
17 Correct 10 ms 12224 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 304 KB Output is correct
26 Correct 2 ms 308 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 5 ms 4668 KB Output is correct
32 Runtime error 36 ms 5004 KB Execution killed with signal 6
33 Halted 0 ms 0 KB -