답안 #554061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554061 2022-04-27T15:44:37 Z tht2005 Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
127 ms 67176 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const LL INF = numeric_limits<LL>::max();

const int N = 100005;
const int W = 2003;

int w, h, a[N], b[N], n, m, c[W], d[W];
LL f[W][W];

int main() {
    scanf("%d %d", &w, &h);
    for(int i = 1; i <= w; ++i) {
        scanf("%d", a + i);
    }
    n = 0;
    for(int i = 1; i <= w; ++i) {
        c[++n] = i;
        if(i != 1 && i != w) {
            while(n > 1) {
                if(a[c[n]] < a[c[n - 1]] || a[c[n]] < a[i + 1])
                    break;
                --n;
            }
        }
    }
    for(int i = 1; i <= h; ++i) {
        scanf("%d", b + i);
    }
    m = 0;
    for(int i = 1; i <= h; ++i) {
        d[++m] = i;
        if(i != 1 && i != h) {
            while(m > 1) {
                if(b[d[m]] < b[d[m - 1]] || b[d[m]] < b[i + 1])
                    break;
                --m;
            }
        }
    }
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            f[i][j] = INF;
        }
    }
    f[1][1] = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            if(i != 1) f[i][j] = min(f[i][j], f[i - 1][j] + (LL)b[d[j]] * (c[i] - c[i - 1]));
            if(j != 1) f[i][j] = min(f[i][j], f[i][j - 1] + (LL)a[c[i]] * (d[j] - d[j - 1]));
        }
    }
    printf("%lld", f[n][m]);
    return 0;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d", &w, &h);
      |     ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
kyoto.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d", b + i);
      |         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 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 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 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 10 ms 12172 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 10 ms 12172 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 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 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 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 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 3924 KB Output is correct
4 Correct 8 ms 2372 KB Output is correct
5 Correct 9 ms 2748 KB Output is correct
6 Correct 5 ms 540 KB Output is correct
7 Correct 17 ms 1748 KB Output is correct
8 Correct 17 ms 1840 KB Output is correct
9 Correct 18 ms 4052 KB Output is correct
10 Correct 19 ms 3912 KB Output is correct
11 Correct 45 ms 32972 KB Output is correct
12 Correct 20 ms 4520 KB Output is correct
13 Correct 21 ms 4520 KB Output is correct
14 Correct 49 ms 32588 KB Output is correct
15 Correct 17 ms 1888 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 308 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 468 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 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 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 10 ms 12172 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 10 ms 12172 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 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 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 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 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 4 ms 3924 KB Output is correct
32 Correct 8 ms 2372 KB Output is correct
33 Correct 9 ms 2748 KB Output is correct
34 Correct 5 ms 540 KB Output is correct
35 Correct 17 ms 1748 KB Output is correct
36 Correct 17 ms 1840 KB Output is correct
37 Correct 18 ms 4052 KB Output is correct
38 Correct 19 ms 3912 KB Output is correct
39 Correct 45 ms 32972 KB Output is correct
40 Correct 20 ms 4520 KB Output is correct
41 Correct 21 ms 4520 KB Output is correct
42 Correct 49 ms 32588 KB Output is correct
43 Correct 17 ms 1888 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 304 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 308 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 11 ms 1460 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 2 ms 980 KB Output is correct
58 Correct 5 ms 1600 KB Output is correct
59 Correct 26 ms 2924 KB Output is correct
60 Correct 25 ms 2744 KB Output is correct
61 Correct 25 ms 5452 KB Output is correct
62 Correct 29 ms 5948 KB Output is correct
63 Runtime error 127 ms 67176 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -