답안 #889210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889210 2023-12-19T07:56:35 Z CDuong Visiting Singapore (NOI20_visitingsingapore) C++17
100 / 100
1037 ms 21332 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;

#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define ForE(i, a, b) for(int i = (a); i <= (b); ++i)

int K, n, m, A, B;
int hpn[1005], events[5005], mission[5005];
int dp[5005][5005][2][2], nxt[5005][1005], lst[1005];

int cal(int val) {
    if (val == 0) return 0;
    return A + val * B;
}

void chkmax(int &val, int nval) {
    val = (val < nval ? nval : val);
}

void solve() {
    cin >> K >> n >> m >> A >> B;
    for (int i = 1; i <= K; ++i) cin >> hpn[i];
    for (int i = 1; i <= n; ++i) cin >> events[i];
    for (int i = 1; i <= m; ++i) cin >> mission[i];

    memset(nxt[m + 1], -1, sizeof nxt[0]);
    for (int i = m; i >= 1; --i) {
        for (int j = 1; j <= K; ++j) nxt[i][j] = nxt[i + 1][j];
        nxt[i][mission[i]] = i;
    }

    auto get_new_day = [&]() -> void {
        ForE(i, 0, m) For(cont, 0, 2) For(gotA, 0, 2) {
            dp[1][i][cont][gotA] = INT_MIN;
        }
        dp[1][0][1][1] = 0;
    };

    int res = INT_MIN;
    auto getmax = [&]() -> void {
        ForE(i, 0, m) For(cont, 0, 2) For(gotA, 0, 2) if (dp[0][i][cont][gotA] != INT_MIN) {
            chkmax(res, dp[0][i][cont][gotA] + cal(m - i));
        }
    };

    ForE(i, 0, m) For(cont, 0, 2) For(gotA, 0, 2) {
        dp[0][i][cont][gotA] = INT_MIN;
    }
    dp[0][0][1][0] = 0;
    getmax();

    ForE(day, 0, n) {
        get_new_day();
        ForE(i, 0, m) For(cont, 0, 2) For(gotA, 0, 2) if (dp[0][i][cont][gotA] != INT_MIN) {
            int val = dp[0][i][cont][gotA];
            // cout << day << " " << i << " " << cont << " " << gotA << " " << val << endl;
            if (i && nxt[i + 1][mission[i]] != -1) {
                int ni = nxt[i + 1][mission[i]];
                chkmax(dp[0][ni][1][1], val + (ni - i) * B + (gotA ? 0 : A));
            }
            if (day < n && nxt[i + 1][events[day + 1]] != -1) {
                int ni = nxt[i + 1][events[day + 1]];
                chkmax(dp[1][ni][1][(i + 1 != ni)], val + hpn[events[day + 1]] + cal(ni - i - 1));
            }
            chkmax(dp[1][i][0][gotA], val + (cont ? A + B : B));
        }
        // cout << endl;
        getmax();
        memcpy(dp[0], dp[1], sizeof dp[0]);
        getmax();
    }

    // int res = INT_MIN;
    // ForE(day, 0, n) ForE(i, 0, m) For(cont, 0, 2) if (dp[day][i][cont] != INT_MIN) {
    //     chkmax(res, dp[day][i][cont] + cal(m - i));
    // }
    cout << res << endl;
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   // cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   // cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
   // cout << "Check array size pls sir" << endl;
#endif

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 29 ms 6748 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 9 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 4 ms 4700 KB Output is correct
9 Correct 17 ms 6744 KB Output is correct
10 Correct 32 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 8 ms 7000 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 3 ms 4700 KB Output is correct
6 Correct 17 ms 6804 KB Output is correct
7 Correct 16 ms 6748 KB Output is correct
8 Correct 23 ms 6804 KB Output is correct
9 Correct 3 ms 4700 KB Output is correct
10 Correct 32 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 7000 KB Output is correct
2 Correct 21 ms 4700 KB Output is correct
3 Correct 261 ms 12960 KB Output is correct
4 Correct 694 ms 21176 KB Output is correct
5 Correct 194 ms 19116 KB Output is correct
6 Correct 295 ms 17232 KB Output is correct
7 Correct 518 ms 16984 KB Output is correct
8 Correct 144 ms 8852 KB Output is correct
9 Correct 344 ms 17064 KB Output is correct
10 Correct 840 ms 21176 KB Output is correct
11 Correct 847 ms 21180 KB Output is correct
12 Correct 896 ms 21176 KB Output is correct
13 Correct 265 ms 21084 KB Output is correct
14 Correct 860 ms 21176 KB Output is correct
15 Correct 745 ms 21172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 7000 KB Output is correct
2 Correct 21 ms 4700 KB Output is correct
3 Correct 261 ms 12960 KB Output is correct
4 Correct 694 ms 21176 KB Output is correct
5 Correct 194 ms 19116 KB Output is correct
6 Correct 295 ms 17232 KB Output is correct
7 Correct 518 ms 16984 KB Output is correct
8 Correct 144 ms 8852 KB Output is correct
9 Correct 344 ms 17064 KB Output is correct
10 Correct 840 ms 21176 KB Output is correct
11 Correct 847 ms 21180 KB Output is correct
12 Correct 896 ms 21176 KB Output is correct
13 Correct 265 ms 21084 KB Output is correct
14 Correct 860 ms 21176 KB Output is correct
15 Correct 745 ms 21172 KB Output is correct
16 Correct 448 ms 17072 KB Output is correct
17 Correct 492 ms 16988 KB Output is correct
18 Correct 444 ms 15012 KB Output is correct
19 Correct 84 ms 12892 KB Output is correct
20 Correct 356 ms 12956 KB Output is correct
21 Correct 14 ms 4712 KB Output is correct
22 Correct 86 ms 16988 KB Output is correct
23 Correct 201 ms 16984 KB Output is correct
24 Correct 55 ms 6792 KB Output is correct
25 Correct 871 ms 21332 KB Output is correct
26 Correct 844 ms 21172 KB Output is correct
27 Correct 822 ms 21080 KB Output is correct
28 Correct 273 ms 21084 KB Output is correct
29 Correct 763 ms 21196 KB Output is correct
30 Correct 758 ms 21188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 7000 KB Output is correct
2 Correct 21 ms 4700 KB Output is correct
3 Correct 261 ms 12960 KB Output is correct
4 Correct 694 ms 21176 KB Output is correct
5 Correct 194 ms 19116 KB Output is correct
6 Correct 295 ms 17232 KB Output is correct
7 Correct 518 ms 16984 KB Output is correct
8 Correct 144 ms 8852 KB Output is correct
9 Correct 344 ms 17064 KB Output is correct
10 Correct 840 ms 21176 KB Output is correct
11 Correct 847 ms 21180 KB Output is correct
12 Correct 896 ms 21176 KB Output is correct
13 Correct 265 ms 21084 KB Output is correct
14 Correct 860 ms 21176 KB Output is correct
15 Correct 745 ms 21172 KB Output is correct
16 Correct 703 ms 21332 KB Output is correct
17 Correct 312 ms 12892 KB Output is correct
18 Correct 88 ms 12888 KB Output is correct
19 Correct 17 ms 6748 KB Output is correct
20 Correct 8 ms 10716 KB Output is correct
21 Correct 13 ms 19036 KB Output is correct
22 Correct 328 ms 17088 KB Output is correct
23 Correct 44 ms 6744 KB Output is correct
24 Correct 563 ms 17092 KB Output is correct
25 Correct 948 ms 21328 KB Output is correct
26 Correct 824 ms 21208 KB Output is correct
27 Correct 859 ms 21084 KB Output is correct
28 Correct 262 ms 21084 KB Output is correct
29 Correct 759 ms 21196 KB Output is correct
30 Correct 765 ms 21192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 4696 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 29 ms 6748 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 9 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 4 ms 4700 KB Output is correct
9 Correct 17 ms 6744 KB Output is correct
10 Correct 32 ms 6748 KB Output is correct
11 Correct 1 ms 6744 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 8 ms 7000 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 3 ms 4700 KB Output is correct
16 Correct 17 ms 6804 KB Output is correct
17 Correct 16 ms 6748 KB Output is correct
18 Correct 23 ms 6804 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 32 ms 6748 KB Output is correct
21 Correct 60 ms 7000 KB Output is correct
22 Correct 21 ms 4700 KB Output is correct
23 Correct 261 ms 12960 KB Output is correct
24 Correct 694 ms 21176 KB Output is correct
25 Correct 194 ms 19116 KB Output is correct
26 Correct 295 ms 17232 KB Output is correct
27 Correct 518 ms 16984 KB Output is correct
28 Correct 144 ms 8852 KB Output is correct
29 Correct 344 ms 17064 KB Output is correct
30 Correct 840 ms 21176 KB Output is correct
31 Correct 847 ms 21180 KB Output is correct
32 Correct 896 ms 21176 KB Output is correct
33 Correct 265 ms 21084 KB Output is correct
34 Correct 860 ms 21176 KB Output is correct
35 Correct 745 ms 21172 KB Output is correct
36 Correct 448 ms 17072 KB Output is correct
37 Correct 492 ms 16988 KB Output is correct
38 Correct 444 ms 15012 KB Output is correct
39 Correct 84 ms 12892 KB Output is correct
40 Correct 356 ms 12956 KB Output is correct
41 Correct 14 ms 4712 KB Output is correct
42 Correct 86 ms 16988 KB Output is correct
43 Correct 201 ms 16984 KB Output is correct
44 Correct 55 ms 6792 KB Output is correct
45 Correct 871 ms 21332 KB Output is correct
46 Correct 844 ms 21172 KB Output is correct
47 Correct 822 ms 21080 KB Output is correct
48 Correct 273 ms 21084 KB Output is correct
49 Correct 763 ms 21196 KB Output is correct
50 Correct 758 ms 21188 KB Output is correct
51 Correct 703 ms 21332 KB Output is correct
52 Correct 312 ms 12892 KB Output is correct
53 Correct 88 ms 12888 KB Output is correct
54 Correct 17 ms 6748 KB Output is correct
55 Correct 8 ms 10716 KB Output is correct
56 Correct 13 ms 19036 KB Output is correct
57 Correct 328 ms 17088 KB Output is correct
58 Correct 44 ms 6744 KB Output is correct
59 Correct 563 ms 17092 KB Output is correct
60 Correct 948 ms 21328 KB Output is correct
61 Correct 824 ms 21208 KB Output is correct
62 Correct 859 ms 21084 KB Output is correct
63 Correct 262 ms 21084 KB Output is correct
64 Correct 759 ms 21196 KB Output is correct
65 Correct 765 ms 21192 KB Output is correct
66 Correct 1 ms 4700 KB Output is correct
67 Correct 1 ms 2396 KB Output is correct
68 Correct 1 ms 2396 KB Output is correct
69 Correct 1 ms 4700 KB Output is correct
70 Correct 1 ms 2396 KB Output is correct
71 Correct 1 ms 4700 KB Output is correct
72 Correct 1 ms 2648 KB Output is correct
73 Correct 1 ms 2396 KB Output is correct
74 Correct 1 ms 4696 KB Output is correct
75 Correct 1 ms 4700 KB Output is correct
76 Correct 1 ms 4700 KB Output is correct
77 Correct 1 ms 4700 KB Output is correct
78 Correct 1 ms 4700 KB Output is correct
79 Correct 1 ms 4700 KB Output is correct
80 Correct 1 ms 4700 KB Output is correct
81 Correct 711 ms 19284 KB Output is correct
82 Correct 131 ms 10928 KB Output is correct
83 Correct 289 ms 16988 KB Output is correct
84 Correct 161 ms 17188 KB Output is correct
85 Correct 252 ms 14936 KB Output is correct
86 Correct 199 ms 10840 KB Output is correct
87 Correct 29 ms 8792 KB Output is correct
88 Correct 19 ms 6748 KB Output is correct
89 Correct 82 ms 10844 KB Output is correct
90 Correct 1037 ms 21332 KB Output is correct
91 Correct 850 ms 21212 KB Output is correct
92 Correct 862 ms 21216 KB Output is correct
93 Correct 898 ms 21232 KB Output is correct
94 Correct 853 ms 21204 KB Output is correct
95 Correct 261 ms 21204 KB Output is correct
96 Correct 815 ms 21204 KB Output is correct
97 Correct 845 ms 21204 KB Output is correct
98 Correct 800 ms 21192 KB Output is correct
99 Correct 747 ms 21192 KB Output is correct
100 Correct 764 ms 21200 KB Output is correct