답안 #687572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687572 2023-01-26T15:15:01 Z ksjsjsjsjsjsjs Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
340 ms 536 KB
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ers erase
#define bg begin
#define ed end
#define ft front
#define bk back
#define mtp make_tupl
#define sz(x) (int)(x).size()
#define all(x) (x).bg(), (x).ed()
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define str string
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define file "TEST"
mt19937 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 oo = 1e9 + 5;
const int N = 5005;
int k, n, m, a, b, v[N], s[N], t[N], d[N][3], d1[N][3];
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen(file".inp", "r", stdin);
//    freopen(file".out", "w", stdout);
    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];
    FOS(j, m + 1, 1)
    FSN(z, 3) {
        if (z != 2) d1[j][z] = (j <= m? a : 0) + (m - j + 1) * b;
        else d1[j][z] = (m - j + 1) * b;
    }
    int rs = -oo;
    rs = max(rs, a + m * b);
    FOS(i, n, 1) {
        FRN(z, 3) d[m + 1][z] = 0;
        FOS(j, m, 1)
        FRN(z, 3) {
            d[j][z] = -oo;
            if (!z) {
                if (i <= n) d[j][z] = max(d[j][z], d1[j][1] + a + b);
                if (j <= m) d[j][z] = max(d[j][z], d[j + 1][2] + a + b);
                if (j <= m && s[i] == t[j]) d[j][z] = max(d[j][z], d1[j + 1][0] + v[s[i]]);
            }
            else if (z == 1) {
                if (i <= n) d[j][z] = max(d[j][z], d1[j][1] + b);
                d[j][z] = max(d[j][z], d[j][0]);
            }
            else {
                if (j <= m) d[j][z] = max(d[j][z], d[j + 1][2] + b);
                d[j][z] = max(d[j][z], d[j][0]);
            }
//            cerr << i << ' ' << j << ' ' << z << " : " << d[j][z] << '\n';
        }
        rs = max(rs, d[1][0]);
        swap(d, d1);
    }
    cout << rs;
//    cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
/*
1 1 1 -7 -7
3
1
1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 456 KB Output is correct
2 Correct 20 ms 340 KB Output is correct
3 Correct 5 ms 340 KB Output is correct
4 Correct 13 ms 464 KB Output is correct
5 Correct 8 ms 460 KB Output is correct
6 Correct 15 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 6 ms 452 KB Output is correct
9 Correct 16 ms 468 KB Output is correct
10 Correct 25 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 8 ms 464 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 12 ms 468 KB Output is correct
7 Correct 13 ms 460 KB Output is correct
8 Correct 15 ms 472 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 24 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 468 KB Output is correct
2 Correct 42 ms 468 KB Output is correct
3 Correct 135 ms 480 KB Output is correct
4 Correct 214 ms 508 KB Output is correct
5 Correct 75 ms 536 KB Output is correct
6 Correct 105 ms 500 KB Output is correct
7 Correct 242 ms 496 KB Output is correct
8 Correct 78 ms 484 KB Output is correct
9 Correct 128 ms 496 KB Output is correct
10 Correct 284 ms 504 KB Output is correct
11 Correct 260 ms 508 KB Output is correct
12 Correct 264 ms 468 KB Output is correct
13 Correct 267 ms 468 KB Output is correct
14 Correct 282 ms 504 KB Output is correct
15 Correct 288 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 468 KB Output is correct
2 Correct 42 ms 468 KB Output is correct
3 Correct 135 ms 480 KB Output is correct
4 Correct 214 ms 508 KB Output is correct
5 Correct 75 ms 536 KB Output is correct
6 Correct 105 ms 500 KB Output is correct
7 Correct 242 ms 496 KB Output is correct
8 Correct 78 ms 484 KB Output is correct
9 Correct 128 ms 496 KB Output is correct
10 Correct 284 ms 504 KB Output is correct
11 Correct 260 ms 508 KB Output is correct
12 Correct 264 ms 468 KB Output is correct
13 Correct 267 ms 468 KB Output is correct
14 Correct 282 ms 504 KB Output is correct
15 Correct 288 ms 468 KB Output is correct
16 Correct 147 ms 496 KB Output is correct
17 Correct 202 ms 496 KB Output is correct
18 Correct 165 ms 496 KB Output is correct
19 Correct 36 ms 472 KB Output is correct
20 Correct 120 ms 496 KB Output is correct
21 Correct 19 ms 468 KB Output is correct
22 Correct 48 ms 472 KB Output is correct
23 Correct 88 ms 468 KB Output is correct
24 Correct 47 ms 476 KB Output is correct
25 Correct 274 ms 516 KB Output is correct
26 Correct 262 ms 520 KB Output is correct
27 Correct 251 ms 500 KB Output is correct
28 Correct 327 ms 512 KB Output is correct
29 Correct 275 ms 488 KB Output is correct
30 Correct 280 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 468 KB Output is correct
2 Correct 42 ms 468 KB Output is correct
3 Correct 135 ms 480 KB Output is correct
4 Correct 214 ms 508 KB Output is correct
5 Correct 75 ms 536 KB Output is correct
6 Correct 105 ms 500 KB Output is correct
7 Correct 242 ms 496 KB Output is correct
8 Correct 78 ms 484 KB Output is correct
9 Correct 128 ms 496 KB Output is correct
10 Correct 284 ms 504 KB Output is correct
11 Correct 260 ms 508 KB Output is correct
12 Correct 264 ms 468 KB Output is correct
13 Correct 267 ms 468 KB Output is correct
14 Correct 282 ms 504 KB Output is correct
15 Correct 288 ms 468 KB Output is correct
16 Correct 238 ms 492 KB Output is correct
17 Correct 124 ms 468 KB Output is correct
18 Correct 36 ms 468 KB Output is correct
19 Correct 18 ms 468 KB Output is correct
20 Correct 6 ms 468 KB Output is correct
21 Correct 7 ms 376 KB Output is correct
22 Correct 107 ms 496 KB Output is correct
23 Correct 46 ms 468 KB Output is correct
24 Correct 217 ms 492 KB Output is correct
25 Correct 272 ms 520 KB Output is correct
26 Correct 254 ms 500 KB Output is correct
27 Correct 262 ms 508 KB Output is correct
28 Correct 262 ms 500 KB Output is correct
29 Correct 331 ms 484 KB Output is correct
30 Correct 301 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 328 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 3 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 456 KB Output is correct
2 Correct 20 ms 340 KB Output is correct
3 Correct 5 ms 340 KB Output is correct
4 Correct 13 ms 464 KB Output is correct
5 Correct 8 ms 460 KB Output is correct
6 Correct 15 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 6 ms 452 KB Output is correct
9 Correct 16 ms 468 KB Output is correct
10 Correct 25 ms 456 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 8 ms 464 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 12 ms 468 KB Output is correct
17 Correct 13 ms 460 KB Output is correct
18 Correct 15 ms 472 KB Output is correct
19 Correct 6 ms 340 KB Output is correct
20 Correct 24 ms 340 KB Output is correct
21 Correct 55 ms 468 KB Output is correct
22 Correct 42 ms 468 KB Output is correct
23 Correct 135 ms 480 KB Output is correct
24 Correct 214 ms 508 KB Output is correct
25 Correct 75 ms 536 KB Output is correct
26 Correct 105 ms 500 KB Output is correct
27 Correct 242 ms 496 KB Output is correct
28 Correct 78 ms 484 KB Output is correct
29 Correct 128 ms 496 KB Output is correct
30 Correct 284 ms 504 KB Output is correct
31 Correct 260 ms 508 KB Output is correct
32 Correct 264 ms 468 KB Output is correct
33 Correct 267 ms 468 KB Output is correct
34 Correct 282 ms 504 KB Output is correct
35 Correct 288 ms 468 KB Output is correct
36 Correct 147 ms 496 KB Output is correct
37 Correct 202 ms 496 KB Output is correct
38 Correct 165 ms 496 KB Output is correct
39 Correct 36 ms 472 KB Output is correct
40 Correct 120 ms 496 KB Output is correct
41 Correct 19 ms 468 KB Output is correct
42 Correct 48 ms 472 KB Output is correct
43 Correct 88 ms 468 KB Output is correct
44 Correct 47 ms 476 KB Output is correct
45 Correct 274 ms 516 KB Output is correct
46 Correct 262 ms 520 KB Output is correct
47 Correct 251 ms 500 KB Output is correct
48 Correct 327 ms 512 KB Output is correct
49 Correct 275 ms 488 KB Output is correct
50 Correct 280 ms 488 KB Output is correct
51 Correct 238 ms 492 KB Output is correct
52 Correct 124 ms 468 KB Output is correct
53 Correct 36 ms 468 KB Output is correct
54 Correct 18 ms 468 KB Output is correct
55 Correct 6 ms 468 KB Output is correct
56 Correct 7 ms 376 KB Output is correct
57 Correct 107 ms 496 KB Output is correct
58 Correct 46 ms 468 KB Output is correct
59 Correct 217 ms 492 KB Output is correct
60 Correct 272 ms 520 KB Output is correct
61 Correct 254 ms 500 KB Output is correct
62 Correct 262 ms 508 KB Output is correct
63 Correct 262 ms 500 KB Output is correct
64 Correct 331 ms 484 KB Output is correct
65 Correct 301 ms 492 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 1 ms 336 KB Output is correct
69 Correct 2 ms 332 KB Output is correct
70 Correct 1 ms 460 KB Output is correct
71 Correct 2 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 2 ms 340 KB Output is correct
75 Correct 3 ms 328 KB Output is correct
76 Correct 3 ms 456 KB Output is correct
77 Correct 3 ms 340 KB Output is correct
78 Correct 2 ms 340 KB Output is correct
79 Correct 3 ms 340 KB Output is correct
80 Correct 3 ms 328 KB Output is correct
81 Correct 251 ms 516 KB Output is correct
82 Correct 83 ms 472 KB Output is correct
83 Correct 101 ms 484 KB Output is correct
84 Correct 59 ms 480 KB Output is correct
85 Correct 107 ms 500 KB Output is correct
86 Correct 120 ms 496 KB Output is correct
87 Correct 21 ms 468 KB Output is correct
88 Correct 21 ms 468 KB Output is correct
89 Correct 42 ms 468 KB Output is correct
90 Correct 297 ms 492 KB Output is correct
91 Correct 312 ms 504 KB Output is correct
92 Correct 265 ms 504 KB Output is correct
93 Correct 284 ms 504 KB Output is correct
94 Correct 299 ms 500 KB Output is correct
95 Correct 272 ms 492 KB Output is correct
96 Correct 283 ms 508 KB Output is correct
97 Correct 340 ms 468 KB Output is correct
98 Correct 289 ms 488 KB Output is correct
99 Correct 301 ms 504 KB Output is correct
100 Correct 309 ms 492 KB Output is correct