Submission #680990

# Submission time Handle Problem Language Result Execution time Memory
680990 2023-01-12T08:10:13 Z Tuanlinh123 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
807 ms 146076 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
 
using namespace std;
 
#define LOCALIO "C:/Users/admin/Documents/Code/"
 
const ll INF=1000000000000000;
ll n, L, a[205], t[205], res;
ll dp[205][205][205][2];
bool check[205][205][205][2];
 
ll dis(ll l, ll r, ll di)
{
    if (!di)
    {
        if (r<l)
            return a[r]-a[l]+L;
        return a[r]-a[l];
    }
    if (r>l)
        return a[l]-a[r]+L;
    return a[l]-a[r];
}
 
ll calc(ll l, ll r, ll k, ll di)
{
    if (k<0) return INF;
    if (check[l][r][k][di])
        return dp[l][r][k][di];
    if (l==r) 
        return dp[l][r][k][di];
    ll ans=INF;
    if (!di)
    {
        ll A=calc((l+1)%n, r, k-1, 0);
        ll B=calc((l+1)%n, r, k, 0);
        ll C=calc((l+1)%n, r, k-1, 1);
        ll D=calc((l+1)%n, r, k, 1);
        ll dis1=dis((l+1)%n, l, 1), dis2=dis(r, l, 1);
        if (t[l]>=A+dis1)
            ans=min(ans, A+dis1);
        ans=min(ans, B+dis1);
        if (t[l]>=C+dis2)
            ans=min(ans, C+dis2);
        ans=min(ans, D+dis2);
    }
    else
    {
        ll A=calc(l, (r-1+n)%n, k-1, 0);
        ll B=calc(l, (r-1+n)%n, k, 0);
        ll C=calc(l, (r-1+n)%n, k-1, 1);
        ll D=calc(l, (r-1+n)%n, k, 1);
        ll dis1=dis((r-1+n)%n, r, 0), dis2=dis(l, r, 0);
        if (t[r]>=A+dis2)
            ans=min(ans, A+dis2);
        ans=min(ans, B+dis2);
        if (t[r]>=C+dis1)
            ans=min(ans, C+dis1);
        ans=min(ans, D+dis1);
    }
    dp[l][r][k][di]=ans;
    check[l][r][k][di]=1;
    if (l==(r+1)%n && ans!=INF)
        res=max(res, k);
    return ans;
}
 
int main()
{
    #ifdef LOCAL
        freopen( LOCALIO "input.txt","r",stdin) ;
        freopen( LOCALIO "output.txt","w",stdout) ;
    #endif
 
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
//	freopen("FIBONACCI.inp","r",stdin);
//	freopen("FIBONACCI.out","w",stdout);
    cin >> n >> L;
    for (ll i=0; i<n; i++)
        cin >> a[i];
    for (ll i=0; i<n; i++)
        cin >> t[i];
    for (ll i=0; i<n; i++)
        for (ll j=0; j<n; j++)
            for (ll k=0; k<=n; k++)
                for (ll di=0; di<2; di++)
                    dp[i][j][k][di]=INF;
    if (t[0]>=a[0] || t[n-1]>=L-a[n-1])
        res=1;
    dp[0][0][t[0]>=a[0]][0]=a[0];
    dp[0][0][0][0]=a[0];
    dp[n-1][n-1][t[n-1]>=L-a[n-1]][0]=L-a[n-1];
    dp[n-1][n-1][0][0]=L-a[n-1];
    for (ll i=0; i<n; i++)
        for (ll j=0; j<n; j++)
            for (ll k=0; k<=n; k++)
                calc(i, j, k, 0), calc(i, j, k, 1);
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 1096 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 1 ms 1096 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 1 ms 968 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 1108 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 1 ms 1096 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 1224 KB Output is correct
34 Correct 1 ms 1108 KB Output is correct
35 Correct 2 ms 1224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 518 ms 117332 KB Output is correct
19 Correct 254 ms 71072 KB Output is correct
20 Correct 125 ms 37768 KB Output is correct
21 Correct 242 ms 67008 KB Output is correct
22 Correct 318 ms 87072 KB Output is correct
23 Correct 90 ms 32076 KB Output is correct
24 Correct 62 ms 25032 KB Output is correct
25 Correct 95 ms 31428 KB Output is correct
26 Correct 19 ms 11972 KB Output is correct
27 Correct 77 ms 32716 KB Output is correct
28 Correct 53 ms 23296 KB Output is correct
29 Correct 78 ms 33436 KB Output is correct
30 Correct 57 ms 26324 KB Output is correct
31 Correct 92 ms 31412 KB Output is correct
32 Correct 30 ms 16392 KB Output is correct
33 Correct 106 ms 31404 KB Output is correct
34 Correct 18 ms 11092 KB Output is correct
35 Correct 84 ms 30824 KB Output is correct
36 Correct 24 ms 14536 KB Output is correct
37 Correct 81 ms 32760 KB Output is correct
38 Correct 49 ms 17928 KB Output is correct
39 Correct 80 ms 34152 KB Output is correct
40 Correct 39 ms 19984 KB Output is correct
41 Correct 675 ms 144632 KB Output is correct
42 Correct 372 ms 97432 KB Output is correct
43 Correct 685 ms 144472 KB Output is correct
44 Correct 388 ms 96340 KB Output is correct
45 Correct 691 ms 144460 KB Output is correct
46 Correct 390 ms 97408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 1096 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 1 ms 1096 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 1 ms 968 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1108 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Correct 1 ms 1108 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 1 ms 1096 KB Output is correct
32 Correct 1 ms 980 KB Output is correct
33 Correct 1 ms 1224 KB Output is correct
34 Correct 1 ms 1108 KB Output is correct
35 Correct 2 ms 1224 KB Output is correct
36 Correct 518 ms 117332 KB Output is correct
37 Correct 254 ms 71072 KB Output is correct
38 Correct 125 ms 37768 KB Output is correct
39 Correct 242 ms 67008 KB Output is correct
40 Correct 318 ms 87072 KB Output is correct
41 Correct 90 ms 32076 KB Output is correct
42 Correct 62 ms 25032 KB Output is correct
43 Correct 95 ms 31428 KB Output is correct
44 Correct 19 ms 11972 KB Output is correct
45 Correct 77 ms 32716 KB Output is correct
46 Correct 53 ms 23296 KB Output is correct
47 Correct 78 ms 33436 KB Output is correct
48 Correct 57 ms 26324 KB Output is correct
49 Correct 92 ms 31412 KB Output is correct
50 Correct 30 ms 16392 KB Output is correct
51 Correct 106 ms 31404 KB Output is correct
52 Correct 18 ms 11092 KB Output is correct
53 Correct 84 ms 30824 KB Output is correct
54 Correct 24 ms 14536 KB Output is correct
55 Correct 81 ms 32760 KB Output is correct
56 Correct 49 ms 17928 KB Output is correct
57 Correct 80 ms 34152 KB Output is correct
58 Correct 39 ms 19984 KB Output is correct
59 Correct 675 ms 144632 KB Output is correct
60 Correct 372 ms 97432 KB Output is correct
61 Correct 685 ms 144472 KB Output is correct
62 Correct 388 ms 96340 KB Output is correct
63 Correct 691 ms 144460 KB Output is correct
64 Correct 390 ms 97408 KB Output is correct
65 Correct 603 ms 130756 KB Output is correct
66 Correct 522 ms 119988 KB Output is correct
67 Correct 490 ms 114752 KB Output is correct
68 Correct 417 ms 105960 KB Output is correct
69 Correct 608 ms 129380 KB Output is correct
70 Correct 537 ms 124072 KB Output is correct
71 Correct 531 ms 125272 KB Output is correct
72 Correct 807 ms 126628 KB Output is correct
73 Correct 503 ms 117508 KB Output is correct
74 Correct 471 ms 109648 KB Output is correct
75 Correct 510 ms 121352 KB Output is correct
76 Correct 656 ms 139096 KB Output is correct
77 Correct 632 ms 139076 KB Output is correct
78 Correct 435 ms 107164 KB Output is correct
79 Correct 449 ms 110984 KB Output is correct
80 Correct 606 ms 136300 KB Output is correct
81 Correct 461 ms 112260 KB Output is correct
82 Correct 481 ms 118700 KB Output is correct
83 Correct 650 ms 144772 KB Output is correct
84 Correct 529 ms 123960 KB Output is correct
85 Correct 592 ms 134872 KB Output is correct
86 Correct 567 ms 132084 KB Output is correct
87 Correct 506 ms 121340 KB Output is correct
88 Correct 681 ms 145868 KB Output is correct
89 Correct 658 ms 145996 KB Output is correct
90 Correct 515 ms 122664 KB Output is correct
91 Correct 665 ms 146076 KB Output is correct
92 Correct 658 ms 145996 KB Output is correct
93 Correct 634 ms 143180 KB Output is correct