답안 #609186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
609186 2022-07-27T12:41:28 Z SamAnd Sightseeing in Kyoto (JOI22_kyoto) C++17
0 / 100
3 ms 2388 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005, M = 1003;
const ll INF = 1000000009000000009;

int n, m;
int a[N], b[N];

bool c[M];
ll dp[M][M];

void solv()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= m; ++i)
    {
        cin >> b[i];
    }

    vector<int> aa;
    memset(c, false, sizeof c);
    for (int i = n; i >= 1; --i)
    {
        if (c[a[i]])
            continue;
        aa.push_back(i);
        c[a[i]] = true;
    }
    aa.push_back(1);

    vector<int> bb;
    memset(c, false, sizeof c);
    for (int j = m; j >= 1; --j)
    {
        if (c[b[j]])
            continue;
        bb.push_back(j);
        c[b[j]] = true;
    }
    bb.push_back(1);

    for (int i = 0; i < sz(aa); ++i)
    {
        for (int j = 0; j < sz(bb); ++j)
        {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for (int i = 0; i < sz(aa); ++i)
    {
        for (int j = 0; j < sz(bb); ++j)
        {
            if (i + 1 < sz(aa))
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (aa[i] - aa[i + 1]) * 1LL * b[bb[j]]);
            if (j + 1 < sz(bb))
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (bb[j] - bb[j + 1]) * 1LL * a[aa[i]]);
        }
    }

    cout << dp[sz(aa) - 1][sz(bb) - 1] << "\n";
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);

    int tt = 1;
    //cin >> tt;
    while (tt--)
    {
        solv();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 3 ms 2388 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -