Submission #687505

# Submission time Handle Problem Language Result Execution time Memory
687505 2023-01-26T13:04:21 Z CDuong Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
98 ms 135220 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 int long long
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
using namespace std;

const int mxN = 1e5 + 5;
const int mod = 1e9 + 7;
const int lim = 1e9;
const ll oo = 1e18;

int n, l, ans;
int dp[205][205][205][2];

void solve() {
    cin >> n >> l;
    int x[n + 1], t[n + 1];
    x[0] = t[0] = 0;
    for(int i = 1; i <= n; ++i)
        cin >> x[i];
    for(int i = 1; i <= n; ++i)
        cin >> t[i];

    auto dis = [&](int idx_1, int idx_2) {
        int tmp = abs(x[idx_1] - x[idx_2]);
        return min(tmp, l - tmp);
    };

    memset(dp, -1, sizeof dp);
    dp[0][0][0][0] = dp[0][0][0][1] = 0;
    for(int i = n; i > 0; --i) {
        for(int j = 0; j < i; ++j) {
            int tmp_1 = l - x[i], tmp_2 = x[j];
            int res = tmp_1 + tmp_2;
            if(res + tmp_1 > lim)
                dp[0][i][j][0] = -1;
            else
                dp[0][i][j][0] = res + tmp_1;
            if(res + tmp_2 > lim)
                dp[0][i][j][1] = -1;
            else
                dp[0][i][j][1] = res + tmp_2;
            // cout << 0 << " " << i << " " << j << " " << 0 << " " << dp[0][i][j][0] << endl;
            // cout << 0 << " " << i << " " << j << " " << 1 << " " << dp[0][i][j][1] << endl;
        }
    }
    for(int i = 1; i <= n; ++i)
        dp[0][0][i][1] = x[i];
    // cout << endl;

    auto calc_dp = [&](int i, int st, int en, bool point) {
        int cur_dp = INT_MAX;
        if(point) {
            if(en == 0)
                return (ll)-1;
            int pre_en = (en + n) % (n + 1);
            if(dp[i][st][pre_en][point] != -1)
                cur_dp = min(cur_dp, dp[i][st][pre_en][point] + dis(pre_en, en));
            if(dp[i][st][pre_en][!point] != -1)
                cur_dp = min(cur_dp, dp[i][st][pre_en][!point] + dis(st, en));
            if(dp[i - 1][st][pre_en][point] != -1) {
                int new_time = dp[i - 1][st][pre_en][point] + dis(pre_en, en);
                if(new_time <= t[en])
                    cur_dp = min(cur_dp, new_time);
            }
            if(dp[i - 1][st][pre_en][!point] != -1) {
                int new_time = dp[i - 1][st][pre_en][!point] + dis(st, en);
                if(new_time <= t[en])
                    cur_dp = min(cur_dp, new_time);
            }
            if(cur_dp > lim)
                cur_dp = -1;
            dp[i][st][en][point] = cur_dp;
        }
        else {
            if(st == 0)
                return (ll)-1;
            int nxt_st = (st + 1) % (n + 1);
            if(dp[i][nxt_st][en][point] != -1)
                cur_dp = min(cur_dp, dp[i][nxt_st][en][point] + dis(st, nxt_st));
            if(dp[i][nxt_st][en][!point] != -1)
                cur_dp = min(cur_dp, dp[i][nxt_st][en][!point] + dis(st, en));
            if(dp[i - 1][nxt_st][en][point] != -1) {
                int new_time = dp[i - 1][nxt_st][en][point] + dis(st, nxt_st);
                if(new_time <= t[st])
                    cur_dp = min(cur_dp, new_time);
            }
            if(dp[i - 1][nxt_st][en][!point] != -1) {
                int new_time = dp[i - 1][nxt_st][en][!point] + dis(st, en);
                if(new_time <= t[st])
                    cur_dp = min(cur_dp, new_time);
            }
            if(cur_dp > lim)
                cur_dp = -1;
            dp[i][st][en][point] = cur_dp;
        }
        if(cur_dp != -1)
            return i;
        else
            return (ll)-1;
    };

    for(int i = 1; i <= n; ++i) {
        for(int len = i; len <= n; ++len) {
            for(int en = 0; en <= len; ++en) {
                int st = en - len; if(st < 0) st += n + 1;
                for(int point = 0; point <= 1; ++point) {
                    ans = max(ans, calc_dp(i, st, en, point));
                    // cout << i << " " << st << " " << en << " " << point << " " << dp[i][st][en][point] << endl;
                }
            }
        }
        // cout << endl;
    }
    cout << ans << 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;
#endif

}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 135060 KB Output is correct
2 Correct 51 ms 135068 KB Output is correct
3 Correct 51 ms 135180 KB Output is correct
4 Correct 49 ms 135092 KB Output is correct
5 Correct 50 ms 135116 KB Output is correct
6 Correct 50 ms 135164 KB Output is correct
7 Correct 50 ms 135116 KB Output is correct
8 Correct 51 ms 135124 KB Output is correct
9 Correct 53 ms 135080 KB Output is correct
10 Correct 50 ms 135116 KB Output is correct
11 Correct 51 ms 135164 KB Output is correct
12 Correct 51 ms 135152 KB Output is correct
13 Correct 50 ms 135128 KB Output is correct
14 Correct 50 ms 135056 KB Output is correct
15 Correct 52 ms 135176 KB Output is correct
16 Correct 62 ms 135100 KB Output is correct
17 Correct 52 ms 135116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 135060 KB Output is correct
2 Correct 51 ms 135068 KB Output is correct
3 Correct 51 ms 135180 KB Output is correct
4 Correct 49 ms 135092 KB Output is correct
5 Correct 50 ms 135116 KB Output is correct
6 Correct 50 ms 135164 KB Output is correct
7 Correct 50 ms 135116 KB Output is correct
8 Correct 51 ms 135124 KB Output is correct
9 Correct 53 ms 135080 KB Output is correct
10 Correct 50 ms 135116 KB Output is correct
11 Correct 51 ms 135164 KB Output is correct
12 Correct 51 ms 135152 KB Output is correct
13 Correct 50 ms 135128 KB Output is correct
14 Correct 50 ms 135056 KB Output is correct
15 Correct 52 ms 135176 KB Output is correct
16 Correct 62 ms 135100 KB Output is correct
17 Correct 52 ms 135116 KB Output is correct
18 Correct 53 ms 135136 KB Output is correct
19 Correct 51 ms 135116 KB Output is correct
20 Correct 53 ms 135092 KB Output is correct
21 Correct 51 ms 135144 KB Output is correct
22 Correct 52 ms 135068 KB Output is correct
23 Correct 51 ms 135100 KB Output is correct
24 Correct 52 ms 135168 KB Output is correct
25 Correct 51 ms 135116 KB Output is correct
26 Correct 51 ms 135080 KB Output is correct
27 Correct 52 ms 135116 KB Output is correct
28 Correct 51 ms 135084 KB Output is correct
29 Correct 50 ms 135116 KB Output is correct
30 Correct 52 ms 135080 KB Output is correct
31 Correct 51 ms 135116 KB Output is correct
32 Correct 54 ms 135140 KB Output is correct
33 Correct 52 ms 135116 KB Output is correct
34 Correct 51 ms 135132 KB Output is correct
35 Correct 52 ms 135220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 135060 KB Output is correct
2 Correct 51 ms 135068 KB Output is correct
3 Correct 51 ms 135180 KB Output is correct
4 Correct 49 ms 135092 KB Output is correct
5 Correct 50 ms 135116 KB Output is correct
6 Correct 50 ms 135164 KB Output is correct
7 Correct 50 ms 135116 KB Output is correct
8 Correct 51 ms 135124 KB Output is correct
9 Correct 53 ms 135080 KB Output is correct
10 Correct 50 ms 135116 KB Output is correct
11 Correct 51 ms 135164 KB Output is correct
12 Correct 51 ms 135152 KB Output is correct
13 Correct 50 ms 135128 KB Output is correct
14 Correct 50 ms 135056 KB Output is correct
15 Correct 52 ms 135176 KB Output is correct
16 Correct 62 ms 135100 KB Output is correct
17 Correct 52 ms 135116 KB Output is correct
18 Correct 98 ms 135172 KB Output is correct
19 Correct 83 ms 135088 KB Output is correct
20 Correct 63 ms 135132 KB Output is correct
21 Correct 74 ms 135052 KB Output is correct
22 Correct 85 ms 135168 KB Output is correct
23 Correct 59 ms 135084 KB Output is correct
24 Correct 54 ms 135064 KB Output is correct
25 Correct 61 ms 135132 KB Output is correct
26 Incorrect 52 ms 135128 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 135060 KB Output is correct
2 Correct 51 ms 135068 KB Output is correct
3 Correct 51 ms 135180 KB Output is correct
4 Correct 49 ms 135092 KB Output is correct
5 Correct 50 ms 135116 KB Output is correct
6 Correct 50 ms 135164 KB Output is correct
7 Correct 50 ms 135116 KB Output is correct
8 Correct 51 ms 135124 KB Output is correct
9 Correct 53 ms 135080 KB Output is correct
10 Correct 50 ms 135116 KB Output is correct
11 Correct 51 ms 135164 KB Output is correct
12 Correct 51 ms 135152 KB Output is correct
13 Correct 50 ms 135128 KB Output is correct
14 Correct 50 ms 135056 KB Output is correct
15 Correct 52 ms 135176 KB Output is correct
16 Correct 62 ms 135100 KB Output is correct
17 Correct 52 ms 135116 KB Output is correct
18 Correct 53 ms 135136 KB Output is correct
19 Correct 51 ms 135116 KB Output is correct
20 Correct 53 ms 135092 KB Output is correct
21 Correct 51 ms 135144 KB Output is correct
22 Correct 52 ms 135068 KB Output is correct
23 Correct 51 ms 135100 KB Output is correct
24 Correct 52 ms 135168 KB Output is correct
25 Correct 51 ms 135116 KB Output is correct
26 Correct 51 ms 135080 KB Output is correct
27 Correct 52 ms 135116 KB Output is correct
28 Correct 51 ms 135084 KB Output is correct
29 Correct 50 ms 135116 KB Output is correct
30 Correct 52 ms 135080 KB Output is correct
31 Correct 51 ms 135116 KB Output is correct
32 Correct 54 ms 135140 KB Output is correct
33 Correct 52 ms 135116 KB Output is correct
34 Correct 51 ms 135132 KB Output is correct
35 Correct 52 ms 135220 KB Output is correct
36 Correct 98 ms 135172 KB Output is correct
37 Correct 83 ms 135088 KB Output is correct
38 Correct 63 ms 135132 KB Output is correct
39 Correct 74 ms 135052 KB Output is correct
40 Correct 85 ms 135168 KB Output is correct
41 Correct 59 ms 135084 KB Output is correct
42 Correct 54 ms 135064 KB Output is correct
43 Correct 61 ms 135132 KB Output is correct
44 Incorrect 52 ms 135128 KB Output isn't correct
45 Halted 0 ms 0 KB -