Submission #589012

# Submission time Handle Problem Language Result Execution time Memory
589012 2022-07-04T08:50:49 Z 박상훈(#8401) Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
205 ms 25256 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const ll INF = 1e18;
int a[100100], b[100100];
ll dp[1010][1010];

ll solve(vector<pair<int, int>> &a, vector<pair<int, int>> &b){
    /*printf("A = ");
    for (auto &[x, y]:a) printf("(%d, %d) ", x, y);
    printf("\n");
    printf("B = ");
    for (auto &[x, y]:b) printf("(%d, %d) ", x, y);
    printf("\n\n");*/

    int n = a.size(), m = b.size();
    --n, --m;
    for (int i=0;i<=n+1;i++) fill(dp[i], dp[i]+m+2, INF);
    dp[1][1] = 0;
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            dp[i][j] = min(dp[i][j], min(dp[i-1][j] + (ll)b[j].first * a[i].second, dp[i][j-1] + (ll)a[i].first * b[j].second));
        }
    }
    return dp[n][m];
}

vector<pair<int, int>> get_v(int s, int e, int a[]){
    int t = 1, mn = 1e9 + 10, cnt = -1;
    vector<pair<int, int>> ret = {{0, 0}};
    if (s>e) t = -1;

    for (int i=s;;i+=t){
        cnt++;
        if (i==e) {ret.emplace_back(a[i], cnt); break;}
        if (mn<=a[i]) continue;

        mn = a[i];
        ret.emplace_back(a[i], cnt);
        cnt = 0;

    }
    return ret;
}

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i=1;i<=n;i++) scanf("%d", a+i);
    for (int i=1;i<=m;i++) scanf("%d", b+i);

    int idxa = min_element(a+1, a+n+1) - a, idxb = min_element(b+1, b+m+1) - b;

    vector<pair<int, int>> A1, A2, B1, B2;
    A1 = get_v(1, idxa, a);
    A2 = get_v(n, idxa, a);
    B1 = get_v(1, idxb, b);
    B2 = get_v(m, idxb, b);

    printf("%lld\n", solve(A1, B1) + solve(A2, B2));
    return 0;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:50:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                            ~~~~~^~~~~~~~~~~
kyoto.cpp:51:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     for (int i=1;i<=m;i++) scanf("%d", b+i);
      |                            ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 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 468 KB Output is correct
13 Correct 4 ms 4436 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 5 ms 6100 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 304 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 2104 KB Output is correct
4 Correct 7 ms 1620 KB Output is correct
5 Correct 7 ms 1352 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 15 ms 1088 KB Output is correct
8 Correct 15 ms 1020 KB Output is correct
9 Correct 19 ms 2488 KB Output is correct
10 Correct 16 ms 2224 KB Output is correct
11 Correct 32 ms 8976 KB Output is correct
12 Correct 17 ms 2388 KB Output is correct
13 Correct 16 ms 2260 KB Output is correct
14 Correct 29 ms 8992 KB Output is correct
15 Correct 21 ms 1072 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 212 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 468 KB Output is correct
13 Correct 4 ms 4436 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 5 ms 6100 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 304 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 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 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 2 ms 2104 KB Output is correct
32 Correct 7 ms 1620 KB Output is correct
33 Correct 7 ms 1352 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 15 ms 1088 KB Output is correct
36 Correct 15 ms 1020 KB Output is correct
37 Correct 19 ms 2488 KB Output is correct
38 Correct 16 ms 2224 KB Output is correct
39 Correct 32 ms 8976 KB Output is correct
40 Correct 17 ms 2388 KB Output is correct
41 Correct 16 ms 2260 KB Output is correct
42 Correct 29 ms 8992 KB Output is correct
43 Correct 21 ms 1072 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 11 ms 1488 KB Output is correct
56 Correct 1 ms 316 KB Output is correct
57 Correct 2 ms 724 KB Output is correct
58 Correct 4 ms 1108 KB Output is correct
59 Correct 33 ms 3004 KB Output is correct
60 Correct 23 ms 3020 KB Output is correct
61 Correct 26 ms 4668 KB Output is correct
62 Correct 31 ms 4424 KB Output is correct
63 Runtime error 205 ms 25256 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -