답안 #1039528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039528 2024-07-31T03:32:24 Z underwaterkillerwhale Visiting Singapore (NOI20_visitingsingapore) C++17
10 / 100
1416 ms 117332 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N = 5e3 + 7;
const int Mod = 1e9 + 7;
const int szBL = 240;
const int INF = 2e9;
const int BASE = 137;

int n, K, m, A, B;
int dp[N][N];
int V[N];
int T[N], S[N];
int lst[N][N];

inline void maximize (int &A, int B) { if (A < B) A = B; }

void solution () {
    cin >> K >> n >> m >> A >> B;
    rep (i, 1, K) cin >> V[i];
    rep (i, 1, n) cin >> S[i];
    rep (i, 1, m) cin >> T[i];
    rep (i, 1, K)
    rep (j, 1, n) {
        lst[i][j] = (S[j] == i) ? j : lst[i][j - 1];
    }
    memset(dp, -0x3f, sizeof dp);
    dp[0][0] = 0;
    rep (j, 1, n) {
        rep (i, 1, m) {
            if (S[j] == T[i]) {
                if (i == 1) maximize(dp[i][j], V[T[1]]);
                else maximize (dp[i][j], A + B * (i - 1) + V[T[i]]);

                rep (k, 1, i - 1) {
                    int t = lst[T[k]][j - 1];
                    dp[i][j] = max(dp[i][j], dp[k][t] + A * (i - k >= 2) + B * (i - k - 1) + A * (j - t >= 2) + B * (j - t - 1) + V[T[i]]);
                }
//                cout << i <<" "<<j<<" "<<dp[i][j] <<"\n";
            }
        }
    }
    int res = -INF;
    rep (i, 1, m)
    rep (j, 1, n) res = max(res, dp[i][j] + A * (i != m) + B * (m - i));
    cout << res <<"\n";
}
#define file(name) freopen(name".inp", "r", stdin); \
freopen(name".out", "w", stdout);
/*
*/
int main () {
//    file("c");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll num_Test = 1;
//    cin >> num_Test;
    while(num_Test--)
        solution();
}
/*
no bug challenge +2
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 99924 KB Output is correct
2 Correct 1068 ms 100116 KB Output is correct
3 Correct 47 ms 99948 KB Output is correct
4 Correct 42 ms 99920 KB Output is correct
5 Correct 48 ms 99924 KB Output is correct
6 Correct 132 ms 100124 KB Output is correct
7 Correct 43 ms 99920 KB Output is correct
8 Correct 57 ms 99928 KB Output is correct
9 Correct 422 ms 99924 KB Output is correct
10 Correct 1403 ms 100128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 99920 KB Output is correct
2 Correct 46 ms 100116 KB Output is correct
3 Correct 273 ms 99920 KB Output is correct
4 Correct 45 ms 99924 KB Output is correct
5 Correct 89 ms 99932 KB Output is correct
6 Correct 507 ms 100180 KB Output is correct
7 Correct 659 ms 100124 KB Output is correct
8 Correct 829 ms 99904 KB Output is correct
9 Correct 76 ms 99920 KB Output is correct
10 Correct 1416 ms 99920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 105372 KB Output is correct
2 Correct 51 ms 110168 KB Output is correct
3 Correct 441 ms 102312 KB Output is correct
4 Correct 615 ms 111440 KB Output is correct
5 Correct 1365 ms 100432 KB Output is correct
6 Correct 468 ms 104360 KB Output is correct
7 Correct 403 ms 110208 KB Output is correct
8 Correct 86 ms 117332 KB Output is correct
9 Correct 211 ms 114260 KB Output is correct
10 Correct 1331 ms 106196 KB Output is correct
11 Correct 1100 ms 108376 KB Output is correct
12 Correct 722 ms 114256 KB Output is correct
13 Incorrect 87 ms 117076 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 105372 KB Output is correct
2 Correct 51 ms 110168 KB Output is correct
3 Correct 441 ms 102312 KB Output is correct
4 Correct 615 ms 111440 KB Output is correct
5 Correct 1365 ms 100432 KB Output is correct
6 Correct 468 ms 104360 KB Output is correct
7 Correct 403 ms 110208 KB Output is correct
8 Correct 86 ms 117332 KB Output is correct
9 Correct 211 ms 114260 KB Output is correct
10 Correct 1331 ms 106196 KB Output is correct
11 Correct 1100 ms 108376 KB Output is correct
12 Correct 722 ms 114256 KB Output is correct
13 Incorrect 87 ms 117076 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 105372 KB Output is correct
2 Correct 51 ms 110168 KB Output is correct
3 Correct 441 ms 102312 KB Output is correct
4 Correct 615 ms 111440 KB Output is correct
5 Correct 1365 ms 100432 KB Output is correct
6 Correct 468 ms 104360 KB Output is correct
7 Correct 403 ms 110208 KB Output is correct
8 Correct 86 ms 117332 KB Output is correct
9 Correct 211 ms 114260 KB Output is correct
10 Correct 1331 ms 106196 KB Output is correct
11 Correct 1100 ms 108376 KB Output is correct
12 Correct 722 ms 114256 KB Output is correct
13 Incorrect 87 ms 117076 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 100444 KB Output is correct
2 Correct 42 ms 99924 KB Output is correct
3 Correct 43 ms 100308 KB Output is correct
4 Correct 43 ms 100436 KB Output is correct
5 Correct 43 ms 100436 KB Output is correct
6 Correct 45 ms 100012 KB Output is correct
7 Correct 43 ms 100180 KB Output is correct
8 Correct 43 ms 100188 KB Output is correct
9 Correct 46 ms 100248 KB Output is correct
10 Correct 46 ms 100176 KB Output is correct
11 Correct 42 ms 100436 KB Output is correct
12 Correct 49 ms 100168 KB Output is correct
13 Incorrect 46 ms 100200 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 99924 KB Output is correct
2 Correct 1068 ms 100116 KB Output is correct
3 Correct 47 ms 99948 KB Output is correct
4 Correct 42 ms 99920 KB Output is correct
5 Correct 48 ms 99924 KB Output is correct
6 Correct 132 ms 100124 KB Output is correct
7 Correct 43 ms 99920 KB Output is correct
8 Correct 57 ms 99928 KB Output is correct
9 Correct 422 ms 99924 KB Output is correct
10 Correct 1403 ms 100128 KB Output is correct
11 Correct 55 ms 99920 KB Output is correct
12 Correct 46 ms 100116 KB Output is correct
13 Correct 273 ms 99920 KB Output is correct
14 Correct 45 ms 99924 KB Output is correct
15 Correct 89 ms 99932 KB Output is correct
16 Correct 507 ms 100180 KB Output is correct
17 Correct 659 ms 100124 KB Output is correct
18 Correct 829 ms 99904 KB Output is correct
19 Correct 76 ms 99920 KB Output is correct
20 Correct 1416 ms 99920 KB Output is correct
21 Correct 69 ms 105372 KB Output is correct
22 Correct 51 ms 110168 KB Output is correct
23 Correct 441 ms 102312 KB Output is correct
24 Correct 615 ms 111440 KB Output is correct
25 Correct 1365 ms 100432 KB Output is correct
26 Correct 468 ms 104360 KB Output is correct
27 Correct 403 ms 110208 KB Output is correct
28 Correct 86 ms 117332 KB Output is correct
29 Correct 211 ms 114260 KB Output is correct
30 Correct 1331 ms 106196 KB Output is correct
31 Correct 1100 ms 108376 KB Output is correct
32 Correct 722 ms 114256 KB Output is correct
33 Incorrect 87 ms 117076 KB Output isn't correct
34 Halted 0 ms 0 KB -