Submission #589005

# Submission time Handle Problem Language Result Execution time Memory
589005 2022-07-04T08:48:20 Z 박상훈(#8401) Sightseeing in Kyoto (JOI22_kyoto) C++17
0 / 100
4 ms 4436 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, cnt = -1;
    vector<pair<int, int>> ret = {{0, 0}};
    if (s>e) t = -1;

    for (int i=s;;i+=t){
        cnt++;
        if (mn<=a[i]) continue;

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

        if (i==e) break;
    }
    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 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 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 340 KB Output is correct
13 Incorrect 4 ms 4436 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 236 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 3 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 340 KB Output is correct
13 Incorrect 4 ms 4436 KB Output isn't correct
14 Halted 0 ms 0 KB -