Submission #588844

# Submission time Handle Problem Language Result Execution time Memory
588844 2022-07-04T06:28:07 Z 반딧불(#8402) Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
139 ms 75496 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void simplify(ll* arr, ll* narr, int &sz, ll* loc){
    int pnt = min_element(arr+1, arr+sz+1) - arr;
    int rn = 1;
    narr[1] = arr[1], loc[1] = 1;
    for(int i=2; i<=pnt; i++){
        if(narr[rn] > arr[i]){
            narr[++rn] = arr[i];
            loc[rn] = i;
        }
    }
    vector<pair<int, int> > vec (1, make_pair(arr[sz], sz));
    for(int i=sz-1; i>=pnt; i--){
        if(vec.back().first > arr[i]){
            vec.push_back(make_pair(arr[i], i));
        }
    }
    reverse(vec.begin(), vec.end());
    for(int i=0; i<(int)vec.size(); i++){
        if(loc[rn] == vec[i].second) continue;
        narr[++rn] = vec[i].first;
        loc[rn] = vec[i].second;
    }

    if(rn == 1){
        narr[++rn] = arr[sz];
        loc[rn] = sz;
    }
    sz = rn;
}

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

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=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:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:45:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     for(int i=1; i<=n; i++) scanf("%lld", &ta[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
kyoto.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     for(int i=1; i<=m; i++) scanf("%lld", &tb[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 468 KB Output is correct
6 Correct 1 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 320 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 10 ms 12260 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 9 ms 12244 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 3924 KB Output is correct
4 Correct 7 ms 2748 KB Output is correct
5 Correct 9 ms 3168 KB Output is correct
6 Correct 5 ms 696 KB Output is correct
7 Correct 15 ms 2624 KB Output is correct
8 Correct 16 ms 2616 KB Output is correct
9 Correct 21 ms 4980 KB Output is correct
10 Correct 20 ms 5076 KB Output is correct
11 Correct 42 ms 33916 KB Output is correct
12 Correct 18 ms 5436 KB Output is correct
13 Correct 16 ms 5436 KB Output is correct
14 Correct 44 ms 33492 KB Output is correct
15 Correct 16 ms 2884 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 308 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 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
# Verdict Execution time Memory 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 468 KB Output is correct
6 Correct 1 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 320 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 10 ms 12260 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 9 ms 12244 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 308 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 3924 KB Output is correct
32 Correct 7 ms 2748 KB Output is correct
33 Correct 9 ms 3168 KB Output is correct
34 Correct 5 ms 696 KB Output is correct
35 Correct 15 ms 2624 KB Output is correct
36 Correct 16 ms 2616 KB Output is correct
37 Correct 21 ms 4980 KB Output is correct
38 Correct 20 ms 5076 KB Output is correct
39 Correct 42 ms 33916 KB Output is correct
40 Correct 18 ms 5436 KB Output is correct
41 Correct 16 ms 5436 KB Output is correct
42 Correct 44 ms 33492 KB Output is correct
43 Correct 16 ms 2884 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 308 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 308 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 308 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 11 ms 1876 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 2 ms 1044 KB Output is correct
58 Correct 4 ms 1748 KB Output is correct
59 Correct 21 ms 3824 KB Output is correct
60 Correct 27 ms 3880 KB Output is correct
61 Correct 23 ms 6768 KB Output is correct
62 Correct 22 ms 7020 KB Output is correct
63 Runtime error 139 ms 75496 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -