답안 #499887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499887 2021-12-29T22:12:10 Z Lobo Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
435 ms 557344 KB
#include<bits/stdc++.h>
using namespace std;

/*for ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
*/

const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 220

ll n, L, x[2*maxn], t[2*maxn], dist[2*maxn][2*maxn], dp[2*maxn][2*maxn][maxn][2];

void solve() {
    cin >> n >> L;
    for(ii i = 1; i <= n; i++) {
        cin >> x[i];
    }

    for(ii i = 1; i <= n; i++) {
        cin >> t[i];
    }

    for(ii i = 1; i <= n; i++) {
        x[i+n] = x[i];
        t[i+n] = t[i];
    }
    x[0] = 0;

    for(ii i = 0; i <= 2*n; i++) {
        for(ii j = 0; j <= 2*n; j++) {
            dist[i][j] = INFll;

            ll x1 = x[i];
            ll x2 = x[j];
            dist[i][j] = min(dist[i][j],abs(x2-x1));

            x1+= L;
            dist[i][j] = min(dist[i][j],abs(x2-x1));
            x1-= L;

            x2+= L;
            dist[i][j] = min(dist[i][j],abs(x2-x1));
            x2-= L;

            for(ii k = 0; k <= n; k++) {
                dp[i][j][k][0] = dp[i][j][k][1] = INFll;
            }
        }
    }

    //sz = size-1 of (l,r)
    //l = begin
    //r = end
    //k = qtd things catch in (l,r)
    //p = 0 -> l; 1 -> r
    //dp[l][r][k][p] -> min time for cover the interval (l,r)
    // with ans = k now in (0->l, 1->r)
    for(ii i = 1; i <= 2*n; i++) {
        ii k = 0;
        if(dist[i][0] <= t[i]) {
            k++;
        }

        dp[i][i][k][0] = dp[i][i][k][1] = dist[i][0];
    }
    for(ii sz = 0; sz < n; sz++) {
        for(ii l = 1; l+sz <= 2*n; l++) {
            ii r = l+sz;

            for(ii k = 0; k <= n; k++) {
                dp[l][r][k][0] = min(dp[l][r][k][0],dp[l][r][k][1]+dist[l][r]);
                dp[l][r][k][1] = min(dp[l][r][k][1],dp[l][r][k][0]+dist[l][r]);

                for(ii p = 0; p <= 1; p++) {
                    ll tmin = dp[l][r][k][p];
                    if(p == 0 && l-1 >= 1) {
                        //pos = l
                        ii l1 = l-1;
                        ii r1 = r;
                        ii p1 = 0;
                        ll tmin1 = dist[l][l1] + tmin;
                        ii k1 = k;
                        if(tmin1 <= t[l1]) k1++;
                        dp[l1][r1][k1][p1] = min(dp[l1][r1][k1][p1],tmin1);

                    }

                    if(p == 1 && r+1 <= 2*n) {
                        //pos = l
                        ii l1 = l;
                        ii r1 = r+1;
                        ii p1 = 1;
                        ll tmin1 = dist[r][r1] + tmin;
                        ii k1 = k;
                        if(tmin1 <= t[r1]) k1++;
                        dp[l1][r1][k1][p1] = min(dp[l1][r1][k1][p1],tmin1);

                    }
                }
            }
        }
    }

    ii ans = 0;

    for(ii sz = 0; sz < n; sz++) {
        for(ii l = 1; l+sz <= 2*n; l++) {
            ii r = l+sz;

            for(ii k = 0; k <= n; k++) {
                for(ii p = 0; p <= 1; p++) {
                    if(dp[l][r][k][p] != INFll) {
                        // cout << l << " " << r << " " << k << " " << p << " == " << dp[l][r][k][p] << endl;
                        ans = max(ans,k);
                    }
                }
            }
        }
    }


    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);

    ii tt = 1;
    // cin >> tt;
    while(tt--) solve();

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 692 KB Output is correct
2 Correct 0 ms 692 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1996 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 1 ms 2624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 692 KB Output is correct
2 Correct 0 ms 692 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1996 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 1 ms 2624 KB Output is correct
18 Correct 2 ms 3396 KB Output is correct
19 Correct 2 ms 1980 KB Output is correct
20 Correct 1 ms 2608 KB Output is correct
21 Correct 1 ms 3404 KB Output is correct
22 Correct 1 ms 1600 KB Output is correct
23 Correct 2 ms 3788 KB Output is correct
24 Correct 2 ms 3012 KB Output is correct
25 Correct 2 ms 3336 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 1 ms 1356 KB Output is correct
28 Correct 1 ms 1612 KB Output is correct
29 Correct 2 ms 3788 KB Output is correct
30 Correct 2 ms 3788 KB Output is correct
31 Correct 2 ms 3404 KB Output is correct
32 Correct 2 ms 3004 KB Output is correct
33 Correct 2 ms 3788 KB Output is correct
34 Correct 2 ms 3776 KB Output is correct
35 Correct 2 ms 3780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 692 KB Output is correct
2 Correct 0 ms 692 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1996 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 1 ms 2624 KB Output is correct
18 Correct 310 ms 446836 KB Output is correct
19 Correct 169 ms 270408 KB Output is correct
20 Correct 82 ms 143644 KB Output is correct
21 Correct 173 ms 255316 KB Output is correct
22 Correct 217 ms 331516 KB Output is correct
23 Correct 66 ms 122052 KB Output is correct
24 Correct 50 ms 95252 KB Output is correct
25 Correct 69 ms 119416 KB Output is correct
26 Correct 26 ms 45004 KB Output is correct
27 Correct 67 ms 124740 KB Output is correct
28 Correct 47 ms 88508 KB Output is correct
29 Correct 68 ms 127304 KB Output is correct
30 Correct 54 ms 99924 KB Output is correct
31 Correct 65 ms 119476 KB Output is correct
32 Correct 36 ms 62296 KB Output is correct
33 Correct 66 ms 119500 KB Output is correct
34 Correct 21 ms 41972 KB Output is correct
35 Correct 77 ms 116916 KB Output is correct
36 Correct 27 ms 54988 KB Output is correct
37 Correct 68 ms 124712 KB Output is correct
38 Correct 44 ms 67868 KB Output is correct
39 Correct 69 ms 129944 KB Output is correct
40 Correct 43 ms 75776 KB Output is correct
41 Correct 425 ms 551688 KB Output is correct
42 Correct 232 ms 371096 KB Output is correct
43 Correct 400 ms 551788 KB Output is correct
44 Correct 231 ms 366548 KB Output is correct
45 Correct 422 ms 551692 KB Output is correct
46 Correct 245 ms 371040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 692 KB Output is correct
2 Correct 0 ms 692 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1996 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 1 ms 2624 KB Output is correct
18 Correct 2 ms 3396 KB Output is correct
19 Correct 2 ms 1980 KB Output is correct
20 Correct 1 ms 2608 KB Output is correct
21 Correct 1 ms 3404 KB Output is correct
22 Correct 1 ms 1600 KB Output is correct
23 Correct 2 ms 3788 KB Output is correct
24 Correct 2 ms 3012 KB Output is correct
25 Correct 2 ms 3336 KB Output is correct
26 Correct 2 ms 3404 KB Output is correct
27 Correct 1 ms 1356 KB Output is correct
28 Correct 1 ms 1612 KB Output is correct
29 Correct 2 ms 3788 KB Output is correct
30 Correct 2 ms 3788 KB Output is correct
31 Correct 2 ms 3404 KB Output is correct
32 Correct 2 ms 3004 KB Output is correct
33 Correct 2 ms 3788 KB Output is correct
34 Correct 2 ms 3776 KB Output is correct
35 Correct 2 ms 3780 KB Output is correct
36 Correct 310 ms 446836 KB Output is correct
37 Correct 169 ms 270408 KB Output is correct
38 Correct 82 ms 143644 KB Output is correct
39 Correct 173 ms 255316 KB Output is correct
40 Correct 217 ms 331516 KB Output is correct
41 Correct 66 ms 122052 KB Output is correct
42 Correct 50 ms 95252 KB Output is correct
43 Correct 69 ms 119416 KB Output is correct
44 Correct 26 ms 45004 KB Output is correct
45 Correct 67 ms 124740 KB Output is correct
46 Correct 47 ms 88508 KB Output is correct
47 Correct 68 ms 127304 KB Output is correct
48 Correct 54 ms 99924 KB Output is correct
49 Correct 65 ms 119476 KB Output is correct
50 Correct 36 ms 62296 KB Output is correct
51 Correct 66 ms 119500 KB Output is correct
52 Correct 21 ms 41972 KB Output is correct
53 Correct 77 ms 116916 KB Output is correct
54 Correct 27 ms 54988 KB Output is correct
55 Correct 68 ms 124712 KB Output is correct
56 Correct 44 ms 67868 KB Output is correct
57 Correct 69 ms 129944 KB Output is correct
58 Correct 43 ms 75776 KB Output is correct
59 Correct 425 ms 551688 KB Output is correct
60 Correct 232 ms 371096 KB Output is correct
61 Correct 400 ms 551788 KB Output is correct
62 Correct 231 ms 366548 KB Output is correct
63 Correct 422 ms 551692 KB Output is correct
64 Correct 245 ms 371040 KB Output is correct
65 Correct 358 ms 498020 KB Output is correct
66 Correct 333 ms 456924 KB Output is correct
67 Correct 306 ms 437100 KB Output is correct
68 Correct 275 ms 403380 KB Output is correct
69 Correct 339 ms 492640 KB Output is correct
70 Correct 331 ms 471972 KB Output is correct
71 Correct 326 ms 477076 KB Output is correct
72 Correct 327 ms 482372 KB Output is correct
73 Correct 293 ms 446812 KB Output is correct
74 Correct 321 ms 417680 KB Output is correct
75 Correct 303 ms 461948 KB Output is correct
76 Correct 374 ms 529780 KB Output is correct
77 Correct 363 ms 529916 KB Output is correct
78 Correct 288 ms 408108 KB Output is correct
79 Correct 275 ms 422292 KB Output is correct
80 Correct 353 ms 518980 KB Output is correct
81 Correct 277 ms 427268 KB Output is correct
82 Correct 308 ms 451908 KB Output is correct
83 Correct 385 ms 551616 KB Output is correct
84 Correct 345 ms 471948 KB Output is correct
85 Correct 347 ms 513644 KB Output is correct
86 Correct 351 ms 503192 KB Output is correct
87 Correct 303 ms 461984 KB Output is correct
88 Correct 393 ms 557140 KB Output is correct
89 Correct 390 ms 557196 KB Output is correct
90 Correct 328 ms 466916 KB Output is correct
91 Correct 403 ms 557344 KB Output is correct
92 Correct 435 ms 557204 KB Output is correct
93 Correct 385 ms 546332 KB Output is correct