Submission #837461

# Submission time Handle Problem Language Result Execution time Memory
837461 2023-08-25T11:10:04 Z green_gold_dog Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
147 ms 132900 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 1'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
T square(T a) {
        return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
        ll operator() (pair<ll, ll> p) const {
                return ((__int128)p.first * MOD + p.second) % INF64;
        }
};

void solve() {
        ll n, l;
        cin >> n >> l;
        vector<ll> x(n);
        for (ll i = 0; i < n; i++) {
                cin >> x[i];
        }
        n += 2;
        x.push_back(l);
        x.insert(x.begin(), 0);
        vector<ll> need(n, 0);
        for (ll i = 1; i + 1 < n; i++) {
                cin >> need[i];
        }
        vector<vector<vector<ll>>> dp1(n, vector<vector<ll>>(n, vector<ll>(n, INF64))), dp2(n, vector<vector<ll>>(n, vector<ll>(n, INF64)));
        dp1[0][n - 1][0] = 0;
        dp2[0][n - 1][0] = 0;
        ll ans = 0;
        for (ll na = 0; na < n; na++) {
                for (ll i = 0; i < n; i++) {
                        for (ll j = n - 1; j >= 0; j--) {
                                if (i == j) {
                                        break;
                                }
                                if (i != 0 && na && dp1[i - 1][j][na - 1] + x[i] - x[i - 1] <= need[i]) {
                                        assign_min(dp1[i][j][na], dp1[i - 1][j][na - 1] + x[i] - x[i - 1]);
                                }
                                if (j != n - 1 && na && dp2[i][j + 1][na - 1] + x[j + 1] - x[j] <= need[j]) {
                                        assign_min(dp2[i][j][na], dp2[i][j + 1][na - 1] + x[j + 1] - x[j]);
                                }
                                if (i != 0 && na && dp2[i - 1][j][na - 1] + x[i] + l - x[j] <= need[i]) {
                                        assign_min(dp1[i][j][na], dp2[i - 1][j][na - 1] + x[i] + l - x[j]);
                                }
                                if (j != n - 1 && na && dp1[i][j + 1][na - 1] + x[i] + l - x[j] <= need[j]) {
                                        assign_min(dp2[i][j][na], dp1[i][j + 1][na - 1] + x[i] + l - x[j]);
                                }
                                if (i != 0) {
                                        assign_min(dp1[i][j][na], dp1[i - 1][j][na] + x[i] - x[i - 1]);
                                }
                                if (j != n - 1) {
                                        assign_min(dp2[i][j][na], dp2[i][j + 1][na] + x[j + 1] - x[j]);
                                }
                                if (i != 0) {
                                        assign_min(dp1[i][j][na], dp2[i - 1][j][na] + x[i] + l - x[j]);
                                }
                                if (j != n - 1) {
                                        assign_min(dp2[i][j][na], dp1[i][j + 1][na] + x[i] + l - x[j]);
                                }
                                if (dp1[i][j][na] < INF64) {
                                        assign_max(ans, na);
                                }
                                if (dp2[i][j][na] < INF64) {
                                        assign_max(ans, na);
                                }
                        }
                }
        }
        cout << ans << '\n';
}

int main() {
        if (IS_FILE) {
                freopen("", "r", stdin);
                freopen("", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t = 1;
        if (IS_TEST_CASES) {
                cin >> t;
        }
        for (ll i = 0; i < t; i++) {
                solve();
        }
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:112:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:113:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 97 ms 95480 KB Output is correct
19 Correct 45 ms 45524 KB Output is correct
20 Correct 17 ms 18132 KB Output is correct
21 Correct 42 ms 41812 KB Output is correct
22 Correct 60 ms 61864 KB Output is correct
23 Correct 15 ms 14292 KB Output is correct
24 Correct 10 ms 10196 KB Output is correct
25 Correct 14 ms 14112 KB Output is correct
26 Correct 5 ms 3668 KB Output is correct
27 Correct 16 ms 14932 KB Output is correct
28 Correct 9 ms 9044 KB Output is correct
29 Correct 15 ms 15188 KB Output is correct
30 Correct 9 ms 10824 KB Output is correct
31 Correct 14 ms 14024 KB Output is correct
32 Correct 5 ms 5588 KB Output is correct
33 Correct 13 ms 14036 KB Output is correct
34 Correct 3 ms 3284 KB Output is correct
35 Correct 13 ms 13524 KB Output is correct
36 Correct 4 ms 4692 KB Output is correct
37 Correct 15 ms 14920 KB Output is correct
38 Correct 6 ms 6228 KB Output is correct
39 Correct 16 ms 15828 KB Output is correct
40 Correct 6 ms 7252 KB Output is correct
41 Correct 135 ms 130312 KB Output is correct
42 Correct 74 ms 72528 KB Output is correct
43 Correct 132 ms 130320 KB Output is correct
44 Correct 75 ms 71636 KB Output is correct
45 Correct 128 ms 130292 KB Output is correct
46 Correct 70 ms 72532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 97 ms 95480 KB Output is correct
37 Correct 45 ms 45524 KB Output is correct
38 Correct 17 ms 18132 KB Output is correct
39 Correct 42 ms 41812 KB Output is correct
40 Correct 60 ms 61864 KB Output is correct
41 Correct 15 ms 14292 KB Output is correct
42 Correct 10 ms 10196 KB Output is correct
43 Correct 14 ms 14112 KB Output is correct
44 Correct 5 ms 3668 KB Output is correct
45 Correct 16 ms 14932 KB Output is correct
46 Correct 9 ms 9044 KB Output is correct
47 Correct 15 ms 15188 KB Output is correct
48 Correct 9 ms 10824 KB Output is correct
49 Correct 14 ms 14024 KB Output is correct
50 Correct 5 ms 5588 KB Output is correct
51 Correct 13 ms 14036 KB Output is correct
52 Correct 3 ms 3284 KB Output is correct
53 Correct 13 ms 13524 KB Output is correct
54 Correct 4 ms 4692 KB Output is correct
55 Correct 15 ms 14920 KB Output is correct
56 Correct 6 ms 6228 KB Output is correct
57 Correct 16 ms 15828 KB Output is correct
58 Correct 6 ms 7252 KB Output is correct
59 Correct 135 ms 130312 KB Output is correct
60 Correct 74 ms 72528 KB Output is correct
61 Correct 132 ms 130320 KB Output is correct
62 Correct 75 ms 71636 KB Output is correct
63 Correct 128 ms 130292 KB Output is correct
64 Correct 70 ms 72532 KB Output is correct
65 Correct 111 ms 111996 KB Output is correct
66 Correct 103 ms 98524 KB Output is correct
67 Correct 97 ms 92388 KB Output is correct
68 Correct 82 ms 82568 KB Output is correct
69 Correct 118 ms 110836 KB Output is correct
70 Correct 107 ms 104012 KB Output is correct
71 Correct 100 ms 105188 KB Output is correct
72 Correct 105 ms 107336 KB Output is correct
73 Correct 101 ms 95484 KB Output is correct
74 Correct 80 ms 86284 KB Output is correct
75 Correct 102 ms 100788 KB Output is correct
76 Correct 123 ms 122756 KB Output is correct
77 Correct 141 ms 122772 KB Output is correct
78 Correct 82 ms 83508 KB Output is correct
79 Correct 94 ms 88356 KB Output is correct
80 Correct 126 ms 119104 KB Output is correct
81 Correct 97 ms 89292 KB Output is correct
82 Correct 112 ms 97580 KB Output is correct
83 Correct 147 ms 130320 KB Output is correct
84 Correct 95 ms 103960 KB Output is correct
85 Correct 111 ms 117888 KB Output is correct
86 Correct 118 ms 114324 KB Output is correct
87 Correct 96 ms 100768 KB Output is correct
88 Correct 142 ms 132812 KB Output is correct
89 Correct 131 ms 132896 KB Output is correct
90 Correct 98 ms 101848 KB Output is correct
91 Correct 141 ms 132900 KB Output is correct
92 Correct 141 ms 132900 KB Output is correct
93 Correct 123 ms 129040 KB Output is correct