답안 #843820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843820 2023-09-04T15:27:14 Z fanwen Visiting Singapore (NOI20_visitingsingapore) C++17
100 / 100
328 ms 1048 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

template <class A, class B> bool minimize(A &a, B b)  { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b)  { if (a < b) { a = b; return true; } return false; }
template <class T> T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }
template <class T> T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

#define int long long

const int MAXN = 5e3 + 5;

int N, M, K, A, B;
int v[MAXN], s[MAXN], t[MAXN];
int dp[MAXN], Max[MAXN], Max_j[MAXN];

void you_make_it(void) {
    cin >> K >> N >> M >> A >> B;
    FOR(i, 1, K) cin >> v[i];
    FOR(i, 1, N) cin >> s[i];
    FOR(i, 1, M) cin >> t[i];
    memset(dp, -0x3f, sizeof dp);
    memset(Max, -0x3f, sizeof Max);
    memset(Max_j, -0x3f, sizeof Max_j);
    long long ans = M * B + A;
    FOR(i, 1, N) {
        vector <int> pre_dp(dp, dp + M + 1), pre_Max(Max, Max + M + 1), pre_Max_j(Max_j, Max_j + M + 1);
        memset(dp, -0x3f, sizeof dp);
        memset(Max, -0x3f, sizeof Max);
        memset(Max_j, -0x3f, sizeof Max_j);
        vector <int> Max_i(M + 1, -1e18);
        FOR(j, 1, M) {
            maximize(dp[j], max(pre_Max[j - 1] + (i + j) * B + 2 * A, Max_i[j - 1] + (i + j) * B + A, pre_Max_j[j] + (i + j) * B + A));
            if(s[i] == t[j]) {
                maximize(dp[j], v[s[i]] + A * (j != 1) + (j - 1) * B);
                maximize(dp[j], pre_dp[j - 1] + v[s[i]]);
                maximize(ans, dp[j] + A * (j != M) + (M - j) * B);
            }
            Max[j] = max(pre_Max[j], Max[j - 1], dp[j] - (i + j) * B);
            Max_i[j] = max(dp[j] - (i + j) * B, Max_i[j - 1]);
            Max_j[j] = max(dp[j] - (i + j) * B, pre_Max_j[j]);
        }
    }
    cout << ans;
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 10 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 7 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 10 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 604 KB Output is correct
2 Correct 13 ms 604 KB Output is correct
3 Correct 67 ms 680 KB Output is correct
4 Correct 236 ms 800 KB Output is correct
5 Correct 47 ms 604 KB Output is correct
6 Correct 66 ms 720 KB Output is correct
7 Correct 124 ms 736 KB Output is correct
8 Correct 43 ms 600 KB Output is correct
9 Correct 79 ms 604 KB Output is correct
10 Correct 290 ms 892 KB Output is correct
11 Correct 296 ms 1048 KB Output is correct
12 Correct 301 ms 812 KB Output is correct
13 Correct 289 ms 812 KB Output is correct
14 Correct 324 ms 812 KB Output is correct
15 Correct 321 ms 808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 604 KB Output is correct
2 Correct 13 ms 604 KB Output is correct
3 Correct 67 ms 680 KB Output is correct
4 Correct 236 ms 800 KB Output is correct
5 Correct 47 ms 604 KB Output is correct
6 Correct 66 ms 720 KB Output is correct
7 Correct 124 ms 736 KB Output is correct
8 Correct 43 ms 600 KB Output is correct
9 Correct 79 ms 604 KB Output is correct
10 Correct 290 ms 892 KB Output is correct
11 Correct 296 ms 1048 KB Output is correct
12 Correct 301 ms 812 KB Output is correct
13 Correct 289 ms 812 KB Output is correct
14 Correct 324 ms 812 KB Output is correct
15 Correct 321 ms 808 KB Output is correct
16 Correct 107 ms 728 KB Output is correct
17 Correct 124 ms 604 KB Output is correct
18 Correct 109 ms 604 KB Output is correct
19 Correct 26 ms 716 KB Output is correct
20 Correct 79 ms 604 KB Output is correct
21 Correct 6 ms 604 KB Output is correct
22 Correct 25 ms 604 KB Output is correct
23 Correct 49 ms 604 KB Output is correct
24 Correct 20 ms 604 KB Output is correct
25 Correct 299 ms 888 KB Output is correct
26 Correct 296 ms 912 KB Output is correct
27 Correct 287 ms 844 KB Output is correct
28 Correct 313 ms 980 KB Output is correct
29 Correct 303 ms 832 KB Output is correct
30 Correct 328 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 604 KB Output is correct
2 Correct 13 ms 604 KB Output is correct
3 Correct 67 ms 680 KB Output is correct
4 Correct 236 ms 800 KB Output is correct
5 Correct 47 ms 604 KB Output is correct
6 Correct 66 ms 720 KB Output is correct
7 Correct 124 ms 736 KB Output is correct
8 Correct 43 ms 600 KB Output is correct
9 Correct 79 ms 604 KB Output is correct
10 Correct 290 ms 892 KB Output is correct
11 Correct 296 ms 1048 KB Output is correct
12 Correct 301 ms 812 KB Output is correct
13 Correct 289 ms 812 KB Output is correct
14 Correct 324 ms 812 KB Output is correct
15 Correct 321 ms 808 KB Output is correct
16 Correct 224 ms 996 KB Output is correct
17 Correct 77 ms 684 KB Output is correct
18 Correct 24 ms 604 KB Output is correct
19 Correct 10 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 74 ms 724 KB Output is correct
23 Correct 17 ms 600 KB Output is correct
24 Correct 133 ms 736 KB Output is correct
25 Correct 288 ms 824 KB Output is correct
26 Correct 289 ms 808 KB Output is correct
27 Correct 296 ms 812 KB Output is correct
28 Correct 296 ms 948 KB Output is correct
29 Correct 320 ms 812 KB Output is correct
30 Correct 327 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 8 ms 604 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 10 ms 600 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 5 ms 604 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 7 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 10 ms 632 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 13 ms 604 KB Output is correct
23 Correct 67 ms 680 KB Output is correct
24 Correct 236 ms 800 KB Output is correct
25 Correct 47 ms 604 KB Output is correct
26 Correct 66 ms 720 KB Output is correct
27 Correct 124 ms 736 KB Output is correct
28 Correct 43 ms 600 KB Output is correct
29 Correct 79 ms 604 KB Output is correct
30 Correct 290 ms 892 KB Output is correct
31 Correct 296 ms 1048 KB Output is correct
32 Correct 301 ms 812 KB Output is correct
33 Correct 289 ms 812 KB Output is correct
34 Correct 324 ms 812 KB Output is correct
35 Correct 321 ms 808 KB Output is correct
36 Correct 107 ms 728 KB Output is correct
37 Correct 124 ms 604 KB Output is correct
38 Correct 109 ms 604 KB Output is correct
39 Correct 26 ms 716 KB Output is correct
40 Correct 79 ms 604 KB Output is correct
41 Correct 6 ms 604 KB Output is correct
42 Correct 25 ms 604 KB Output is correct
43 Correct 49 ms 604 KB Output is correct
44 Correct 20 ms 604 KB Output is correct
45 Correct 299 ms 888 KB Output is correct
46 Correct 296 ms 912 KB Output is correct
47 Correct 287 ms 844 KB Output is correct
48 Correct 313 ms 980 KB Output is correct
49 Correct 303 ms 832 KB Output is correct
50 Correct 328 ms 924 KB Output is correct
51 Correct 224 ms 996 KB Output is correct
52 Correct 77 ms 684 KB Output is correct
53 Correct 24 ms 604 KB Output is correct
54 Correct 10 ms 604 KB Output is correct
55 Correct 4 ms 604 KB Output is correct
56 Correct 5 ms 604 KB Output is correct
57 Correct 74 ms 724 KB Output is correct
58 Correct 17 ms 600 KB Output is correct
59 Correct 133 ms 736 KB Output is correct
60 Correct 288 ms 824 KB Output is correct
61 Correct 289 ms 808 KB Output is correct
62 Correct 296 ms 812 KB Output is correct
63 Correct 296 ms 948 KB Output is correct
64 Correct 320 ms 812 KB Output is correct
65 Correct 327 ms 876 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 157 ms 804 KB Output is correct
82 Correct 38 ms 604 KB Output is correct
83 Correct 70 ms 604 KB Output is correct
84 Correct 37 ms 604 KB Output is correct
85 Correct 68 ms 604 KB Output is correct
86 Correct 54 ms 708 KB Output is correct
87 Correct 12 ms 604 KB Output is correct
88 Correct 7 ms 628 KB Output is correct
89 Correct 23 ms 672 KB Output is correct
90 Correct 302 ms 904 KB Output is correct
91 Correct 297 ms 848 KB Output is correct
92 Correct 286 ms 848 KB Output is correct
93 Correct 307 ms 856 KB Output is correct
94 Correct 299 ms 932 KB Output is correct
95 Correct 299 ms 832 KB Output is correct
96 Correct 301 ms 1004 KB Output is correct
97 Correct 293 ms 844 KB Output is correct
98 Correct 312 ms 988 KB Output is correct
99 Correct 308 ms 992 KB Output is correct
100 Correct 310 ms 844 KB Output is correct