Submission #888966

# Submission time Handle Problem Language Result Execution time Memory
888966 2023-12-18T13:27:56 Z CDuong Visiting Singapore (NOI20_visitingsingapore) C++17
29 / 100
265 ms 216236 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], nxt[5005][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;
    }

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

    For(day, 0, n) ForE(i, 0, m) For(cont, 0, 2) if (dp[day][i][cont] != INT_MIN) {
        int val = dp[day][i][cont];
        if (nxt[i + 1][events[day + 1]] != -1) {
            int ni = nxt[i + 1][events[day + 1]];
            chkmax(dp[day + 1][ni][1], val + hpn[events[day + 1]] + cal(ni - i - 1));
        }
        chkmax(dp[day + 1][i][0], val + (cont ? A + B : B));
    }

    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

}

Compilation message

VisitingSingapore.cpp: In function 'void solve()':
VisitingSingapore.cpp:52:35: warning: operation on 'dp[day][0][1]' may be undefined [-Wsequence-point]
   52 |     ForE(day, 0, n) dp[day][0][1] = dp[day][0][1] = 0;
      |                     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Correct 10 ms 43612 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 4 ms 37468 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 6 ms 35420 KB Output is correct
7 Correct 1 ms 10844 KB Output is correct
8 Correct 3 ms 23132 KB Output is correct
9 Correct 7 ms 37476 KB Output is correct
10 Correct 11 ms 45656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 7 ms 31436 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 8 ms 39516 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 13 ms 45800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 111452 KB Output is correct
2 Correct 16 ms 103260 KB Output is correct
3 Correct 78 ms 162756 KB Output is correct
4 Correct 179 ms 197460 KB Output is correct
5 Correct 49 ms 76576 KB Output is correct
6 Correct 76 ms 111452 KB Output is correct
7 Correct 121 ms 201752 KB Output is correct
8 Correct 51 ms 146520 KB Output is correct
9 Correct 92 ms 131932 KB Output is correct
10 Correct 210 ms 216116 KB Output is correct
11 Correct 190 ms 215892 KB Output is correct
12 Correct 265 ms 216236 KB Output is correct
13 Correct 123 ms 215888 KB Output is correct
14 Correct 189 ms 216116 KB Output is correct
15 Correct 178 ms 216120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 111452 KB Output is correct
2 Correct 16 ms 103260 KB Output is correct
3 Correct 78 ms 162756 KB Output is correct
4 Correct 179 ms 197460 KB Output is correct
5 Correct 49 ms 76576 KB Output is correct
6 Correct 76 ms 111452 KB Output is correct
7 Correct 121 ms 201752 KB Output is correct
8 Correct 51 ms 146520 KB Output is correct
9 Correct 92 ms 131932 KB Output is correct
10 Correct 210 ms 216116 KB Output is correct
11 Correct 190 ms 215892 KB Output is correct
12 Correct 265 ms 216236 KB Output is correct
13 Correct 123 ms 215888 KB Output is correct
14 Correct 189 ms 216116 KB Output is correct
15 Correct 178 ms 216120 KB Output is correct
16 Correct 117 ms 170836 KB Output is correct
17 Correct 128 ms 205660 KB Output is correct
18 Correct 113 ms 207904 KB Output is correct
19 Correct 32 ms 58192 KB Output is correct
20 Correct 85 ms 158544 KB Output is correct
21 Correct 9 ms 55900 KB Output is correct
22 Correct 35 ms 54020 KB Output is correct
23 Correct 59 ms 90932 KB Output is correct
24 Correct 29 ms 117596 KB Output is correct
25 Correct 191 ms 215968 KB Output is correct
26 Correct 223 ms 215888 KB Output is correct
27 Correct 186 ms 216120 KB Output is correct
28 Correct 121 ms 215900 KB Output is correct
29 Correct 179 ms 216148 KB Output is correct
30 Correct 184 ms 215892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 111452 KB Output is correct
2 Correct 16 ms 103260 KB Output is correct
3 Correct 78 ms 162756 KB Output is correct
4 Correct 179 ms 197460 KB Output is correct
5 Correct 49 ms 76576 KB Output is correct
6 Correct 76 ms 111452 KB Output is correct
7 Correct 121 ms 201752 KB Output is correct
8 Correct 51 ms 146520 KB Output is correct
9 Correct 92 ms 131932 KB Output is correct
10 Correct 210 ms 216116 KB Output is correct
11 Correct 190 ms 215892 KB Output is correct
12 Correct 265 ms 216236 KB Output is correct
13 Correct 123 ms 215888 KB Output is correct
14 Correct 189 ms 216116 KB Output is correct
15 Correct 178 ms 216120 KB Output is correct
16 Incorrect 161 ms 211796 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12888 KB Output is correct
2 Correct 10 ms 43612 KB Output is correct
3 Correct 2 ms 12888 KB Output is correct
4 Correct 4 ms 37468 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 6 ms 35420 KB Output is correct
7 Correct 1 ms 10844 KB Output is correct
8 Correct 3 ms 23132 KB Output is correct
9 Correct 7 ms 37476 KB Output is correct
10 Correct 11 ms 45656 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 3 ms 19036 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 7 ms 31436 KB Output is correct
17 Correct 6 ms 27224 KB Output is correct
18 Correct 8 ms 39516 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 13 ms 45800 KB Output is correct
21 Correct 30 ms 111452 KB Output is correct
22 Correct 16 ms 103260 KB Output is correct
23 Correct 78 ms 162756 KB Output is correct
24 Correct 179 ms 197460 KB Output is correct
25 Correct 49 ms 76576 KB Output is correct
26 Correct 76 ms 111452 KB Output is correct
27 Correct 121 ms 201752 KB Output is correct
28 Correct 51 ms 146520 KB Output is correct
29 Correct 92 ms 131932 KB Output is correct
30 Correct 210 ms 216116 KB Output is correct
31 Correct 190 ms 215892 KB Output is correct
32 Correct 265 ms 216236 KB Output is correct
33 Correct 123 ms 215888 KB Output is correct
34 Correct 189 ms 216116 KB Output is correct
35 Correct 178 ms 216120 KB Output is correct
36 Correct 117 ms 170836 KB Output is correct
37 Correct 128 ms 205660 KB Output is correct
38 Correct 113 ms 207904 KB Output is correct
39 Correct 32 ms 58192 KB Output is correct
40 Correct 85 ms 158544 KB Output is correct
41 Correct 9 ms 55900 KB Output is correct
42 Correct 35 ms 54020 KB Output is correct
43 Correct 59 ms 90932 KB Output is correct
44 Correct 29 ms 117596 KB Output is correct
45 Correct 191 ms 215968 KB Output is correct
46 Correct 223 ms 215888 KB Output is correct
47 Correct 186 ms 216120 KB Output is correct
48 Correct 121 ms 215900 KB Output is correct
49 Correct 179 ms 216148 KB Output is correct
50 Correct 184 ms 215892 KB Output is correct
51 Incorrect 161 ms 211796 KB Output isn't correct
52 Halted 0 ms 0 KB -