답안 #687482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687482 2023-01-26T12:43:23 Z CDuong Collecting Stamps 3 (JOI20_ho_t3) C++17
15 / 100
77 ms 67816 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 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][2] = 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;
        }
    }
    // cout << endl;

    auto calc_dp = [&](int i, int st, int en, bool point) {
        int cur_dp = INT_MAX;
        if(point) {
            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 {
            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 -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

}

Compilation message

ho_t3.cpp: In function 'void solve()':
ho_t3.cpp:41:35: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   41 |     dp[0][0][0][0] = dp[0][0][0][2] = 0;
      |                      ~~~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 67668 KB Output is correct
2 Correct 27 ms 67736 KB Output is correct
3 Correct 31 ms 67680 KB Output is correct
4 Correct 33 ms 67684 KB Output is correct
5 Correct 29 ms 67744 KB Output is correct
6 Correct 28 ms 67728 KB Output is correct
7 Correct 28 ms 67660 KB Output is correct
8 Correct 28 ms 67668 KB Output is correct
9 Correct 30 ms 67796 KB Output is correct
10 Correct 34 ms 67736 KB Output is correct
11 Correct 28 ms 67816 KB Output is correct
12 Correct 31 ms 67680 KB Output is correct
13 Correct 31 ms 67660 KB Output is correct
14 Correct 27 ms 67668 KB Output is correct
15 Correct 28 ms 67664 KB Output is correct
16 Correct 28 ms 67724 KB Output is correct
17 Correct 28 ms 67656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 67668 KB Output is correct
2 Correct 27 ms 67736 KB Output is correct
3 Correct 31 ms 67680 KB Output is correct
4 Correct 33 ms 67684 KB Output is correct
5 Correct 29 ms 67744 KB Output is correct
6 Correct 28 ms 67728 KB Output is correct
7 Correct 28 ms 67660 KB Output is correct
8 Correct 28 ms 67668 KB Output is correct
9 Correct 30 ms 67796 KB Output is correct
10 Correct 34 ms 67736 KB Output is correct
11 Correct 28 ms 67816 KB Output is correct
12 Correct 31 ms 67680 KB Output is correct
13 Correct 31 ms 67660 KB Output is correct
14 Correct 27 ms 67668 KB Output is correct
15 Correct 28 ms 67664 KB Output is correct
16 Correct 28 ms 67724 KB Output is correct
17 Correct 28 ms 67656 KB Output is correct
18 Correct 28 ms 67640 KB Output is correct
19 Correct 28 ms 67728 KB Output is correct
20 Correct 27 ms 67620 KB Output is correct
21 Correct 29 ms 67760 KB Output is correct
22 Correct 28 ms 67752 KB Output is correct
23 Correct 28 ms 67644 KB Output is correct
24 Correct 28 ms 67708 KB Output is correct
25 Correct 27 ms 67720 KB Output is correct
26 Correct 27 ms 67700 KB Output is correct
27 Correct 27 ms 67720 KB Output is correct
28 Correct 28 ms 67736 KB Output is correct
29 Correct 31 ms 67668 KB Output is correct
30 Correct 28 ms 67660 KB Output is correct
31 Correct 28 ms 67668 KB Output is correct
32 Correct 28 ms 67716 KB Output is correct
33 Correct 29 ms 67648 KB Output is correct
34 Correct 28 ms 67748 KB Output is correct
35 Correct 29 ms 67740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 67668 KB Output is correct
2 Correct 27 ms 67736 KB Output is correct
3 Correct 31 ms 67680 KB Output is correct
4 Correct 33 ms 67684 KB Output is correct
5 Correct 29 ms 67744 KB Output is correct
6 Correct 28 ms 67728 KB Output is correct
7 Correct 28 ms 67660 KB Output is correct
8 Correct 28 ms 67668 KB Output is correct
9 Correct 30 ms 67796 KB Output is correct
10 Correct 34 ms 67736 KB Output is correct
11 Correct 28 ms 67816 KB Output is correct
12 Correct 31 ms 67680 KB Output is correct
13 Correct 31 ms 67660 KB Output is correct
14 Correct 27 ms 67668 KB Output is correct
15 Correct 28 ms 67664 KB Output is correct
16 Correct 28 ms 67724 KB Output is correct
17 Correct 28 ms 67656 KB Output is correct
18 Correct 77 ms 67736 KB Output is correct
19 Correct 53 ms 67736 KB Output is correct
20 Correct 37 ms 67648 KB Output is correct
21 Correct 52 ms 67736 KB Output is correct
22 Correct 68 ms 67788 KB Output is correct
23 Correct 36 ms 67736 KB Output is correct
24 Correct 32 ms 67668 KB Output is correct
25 Correct 50 ms 67700 KB Output is correct
26 Incorrect 32 ms 67628 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 67668 KB Output is correct
2 Correct 27 ms 67736 KB Output is correct
3 Correct 31 ms 67680 KB Output is correct
4 Correct 33 ms 67684 KB Output is correct
5 Correct 29 ms 67744 KB Output is correct
6 Correct 28 ms 67728 KB Output is correct
7 Correct 28 ms 67660 KB Output is correct
8 Correct 28 ms 67668 KB Output is correct
9 Correct 30 ms 67796 KB Output is correct
10 Correct 34 ms 67736 KB Output is correct
11 Correct 28 ms 67816 KB Output is correct
12 Correct 31 ms 67680 KB Output is correct
13 Correct 31 ms 67660 KB Output is correct
14 Correct 27 ms 67668 KB Output is correct
15 Correct 28 ms 67664 KB Output is correct
16 Correct 28 ms 67724 KB Output is correct
17 Correct 28 ms 67656 KB Output is correct
18 Correct 28 ms 67640 KB Output is correct
19 Correct 28 ms 67728 KB Output is correct
20 Correct 27 ms 67620 KB Output is correct
21 Correct 29 ms 67760 KB Output is correct
22 Correct 28 ms 67752 KB Output is correct
23 Correct 28 ms 67644 KB Output is correct
24 Correct 28 ms 67708 KB Output is correct
25 Correct 27 ms 67720 KB Output is correct
26 Correct 27 ms 67700 KB Output is correct
27 Correct 27 ms 67720 KB Output is correct
28 Correct 28 ms 67736 KB Output is correct
29 Correct 31 ms 67668 KB Output is correct
30 Correct 28 ms 67660 KB Output is correct
31 Correct 28 ms 67668 KB Output is correct
32 Correct 28 ms 67716 KB Output is correct
33 Correct 29 ms 67648 KB Output is correct
34 Correct 28 ms 67748 KB Output is correct
35 Correct 29 ms 67740 KB Output is correct
36 Correct 77 ms 67736 KB Output is correct
37 Correct 53 ms 67736 KB Output is correct
38 Correct 37 ms 67648 KB Output is correct
39 Correct 52 ms 67736 KB Output is correct
40 Correct 68 ms 67788 KB Output is correct
41 Correct 36 ms 67736 KB Output is correct
42 Correct 32 ms 67668 KB Output is correct
43 Correct 50 ms 67700 KB Output is correct
44 Incorrect 32 ms 67628 KB Output isn't correct
45 Halted 0 ms 0 KB -