Submission #769810

# Submission time Handle Problem Language Result Execution time Memory
769810 2023-06-30T09:25:31 Z raysh07 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
103 ms 127484 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 201;
int n, l;
int x[N], t[N];
int dp[N][N][N][2]; 

int f(int x, int y){
    int ans = abs(x - y);
    ans = min(ans, abs(ans - l));
    return ans;
}

void ckmin(int &a, int b){
    a = min(a, b);
}

void Solve() 
{
    cin >> n >> l;
    
    for (int i = 1; i <= n; i++) cin >> x[i];
    for (int i = 1; i <= n; i++) cin >> t[i];
    
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
            for (int k = 0; k < N; k++){
                dp[i][j][k][0] = dp[i][j][k][1] = INF;
            }
        }
    }
    
    int t1 = f(0, x[1]);
    dp[1][n + 1][t1 <= t[1]][0] = t1;
    int t2 = f(0, x[n]);
    dp[0][n][t2 <= t[n]][1] = t2;
    
    for (int sum = 2; sum <= n; sum++){
        for (int i = 0; i < sum; i++){
            int j = sum - 1 - i;
            j = n + 1 - j;
            
            for (int tk = 0; tk < sum; tk++){
                if (i != 0){
                    //last = 0
                    {
                        //go to i + 1
                        t1 = dp[i][j][tk][0] + f(x[i], x[i + 1]);
                        ckmin(dp[i + 1][j][tk + (t1 <= t[i + 1])][0], t1);
                    }
                    
                    {
                        //go to j - 1 
                        t1 = dp[i][j][tk][0] + f(x[i], x[j - 1]);
                        ckmin(dp[i][j - 1][tk + (t1 <= t[j - 1])][1], t1);
                    }
                }
                if (i + 1 != sum){
                    //last = 1
                    {
                        //go to i + 1
                        t1 = dp[i][j][tk][1] + f(x[j], x[i + 1]);
                        ckmin(dp[i + 1][j][tk + (t1 <= t[i + 1])][0], t1);
                    }
                    
                    {
                        //go to j - 1
                        t1 = dp[i][j][tk][1] + f(x[j], x[j - 1]);
                        ckmin(dp[i][j - 1][tk + (t1 <= t[j - 1])][1], t1);
                    }
                }
            }
        }
    }
    
    int ans = 0;
    
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
            for (int k = 0; k < N; k++){
                for (int l = 0; l < 2; l++){
                    if (dp[i][j][k][l] != INF){
                        ans = max(ans, k);
                    }
                }
            }
        }
    }
    
    cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 127332 KB Output is correct
2 Correct 53 ms 127424 KB Output is correct
3 Correct 54 ms 127352 KB Output is correct
4 Correct 53 ms 127432 KB Output is correct
5 Correct 57 ms 127436 KB Output is correct
6 Correct 56 ms 127324 KB Output is correct
7 Correct 62 ms 127432 KB Output is correct
8 Correct 57 ms 127344 KB Output is correct
9 Correct 53 ms 127436 KB Output is correct
10 Correct 54 ms 127436 KB Output is correct
11 Correct 60 ms 127384 KB Output is correct
12 Correct 58 ms 127324 KB Output is correct
13 Correct 54 ms 127440 KB Output is correct
14 Correct 55 ms 127440 KB Output is correct
15 Correct 55 ms 127352 KB Output is correct
16 Correct 54 ms 127408 KB Output is correct
17 Correct 58 ms 127436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 127332 KB Output is correct
2 Correct 53 ms 127424 KB Output is correct
3 Correct 54 ms 127352 KB Output is correct
4 Correct 53 ms 127432 KB Output is correct
5 Correct 57 ms 127436 KB Output is correct
6 Correct 56 ms 127324 KB Output is correct
7 Correct 62 ms 127432 KB Output is correct
8 Correct 57 ms 127344 KB Output is correct
9 Correct 53 ms 127436 KB Output is correct
10 Correct 54 ms 127436 KB Output is correct
11 Correct 60 ms 127384 KB Output is correct
12 Correct 58 ms 127324 KB Output is correct
13 Correct 54 ms 127440 KB Output is correct
14 Correct 55 ms 127440 KB Output is correct
15 Correct 55 ms 127352 KB Output is correct
16 Correct 54 ms 127408 KB Output is correct
17 Correct 58 ms 127436 KB Output is correct
18 Correct 53 ms 127384 KB Output is correct
19 Correct 54 ms 127376 KB Output is correct
20 Correct 54 ms 127436 KB Output is correct
21 Correct 55 ms 127416 KB Output is correct
22 Correct 54 ms 127436 KB Output is correct
23 Correct 55 ms 127424 KB Output is correct
24 Correct 55 ms 127436 KB Output is correct
25 Correct 56 ms 127356 KB Output is correct
26 Correct 55 ms 127432 KB Output is correct
27 Correct 56 ms 127440 KB Output is correct
28 Correct 56 ms 127436 KB Output is correct
29 Correct 56 ms 127436 KB Output is correct
30 Correct 56 ms 127344 KB Output is correct
31 Correct 56 ms 127376 KB Output is correct
32 Correct 56 ms 127408 KB Output is correct
33 Correct 60 ms 127436 KB Output is correct
34 Correct 56 ms 127436 KB Output is correct
35 Correct 55 ms 127392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 127332 KB Output is correct
2 Correct 53 ms 127424 KB Output is correct
3 Correct 54 ms 127352 KB Output is correct
4 Correct 53 ms 127432 KB Output is correct
5 Correct 57 ms 127436 KB Output is correct
6 Correct 56 ms 127324 KB Output is correct
7 Correct 62 ms 127432 KB Output is correct
8 Correct 57 ms 127344 KB Output is correct
9 Correct 53 ms 127436 KB Output is correct
10 Correct 54 ms 127436 KB Output is correct
11 Correct 60 ms 127384 KB Output is correct
12 Correct 58 ms 127324 KB Output is correct
13 Correct 54 ms 127440 KB Output is correct
14 Correct 55 ms 127440 KB Output is correct
15 Correct 55 ms 127352 KB Output is correct
16 Correct 54 ms 127408 KB Output is correct
17 Correct 58 ms 127436 KB Output is correct
18 Correct 84 ms 127352 KB Output is correct
19 Correct 69 ms 127436 KB Output is correct
20 Correct 62 ms 127436 KB Output is correct
21 Correct 68 ms 127444 KB Output is correct
22 Correct 73 ms 127440 KB Output is correct
23 Correct 60 ms 127416 KB Output is correct
24 Correct 60 ms 127428 KB Output is correct
25 Correct 59 ms 127436 KB Output is correct
26 Correct 56 ms 127440 KB Output is correct
27 Correct 60 ms 127324 KB Output is correct
28 Correct 59 ms 127404 KB Output is correct
29 Correct 59 ms 127340 KB Output is correct
30 Correct 71 ms 127372 KB Output is correct
31 Correct 59 ms 127436 KB Output is correct
32 Correct 58 ms 127372 KB Output is correct
33 Correct 60 ms 127360 KB Output is correct
34 Correct 60 ms 127392 KB Output is correct
35 Correct 59 ms 127440 KB Output is correct
36 Correct 57 ms 127440 KB Output is correct
37 Correct 60 ms 127424 KB Output is correct
38 Correct 58 ms 127316 KB Output is correct
39 Correct 60 ms 127436 KB Output is correct
40 Correct 58 ms 127420 KB Output is correct
41 Correct 94 ms 127324 KB Output is correct
42 Correct 77 ms 127436 KB Output is correct
43 Correct 92 ms 127404 KB Output is correct
44 Correct 76 ms 127436 KB Output is correct
45 Correct 93 ms 127420 KB Output is correct
46 Correct 76 ms 127336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 127332 KB Output is correct
2 Correct 53 ms 127424 KB Output is correct
3 Correct 54 ms 127352 KB Output is correct
4 Correct 53 ms 127432 KB Output is correct
5 Correct 57 ms 127436 KB Output is correct
6 Correct 56 ms 127324 KB Output is correct
7 Correct 62 ms 127432 KB Output is correct
8 Correct 57 ms 127344 KB Output is correct
9 Correct 53 ms 127436 KB Output is correct
10 Correct 54 ms 127436 KB Output is correct
11 Correct 60 ms 127384 KB Output is correct
12 Correct 58 ms 127324 KB Output is correct
13 Correct 54 ms 127440 KB Output is correct
14 Correct 55 ms 127440 KB Output is correct
15 Correct 55 ms 127352 KB Output is correct
16 Correct 54 ms 127408 KB Output is correct
17 Correct 58 ms 127436 KB Output is correct
18 Correct 53 ms 127384 KB Output is correct
19 Correct 54 ms 127376 KB Output is correct
20 Correct 54 ms 127436 KB Output is correct
21 Correct 55 ms 127416 KB Output is correct
22 Correct 54 ms 127436 KB Output is correct
23 Correct 55 ms 127424 KB Output is correct
24 Correct 55 ms 127436 KB Output is correct
25 Correct 56 ms 127356 KB Output is correct
26 Correct 55 ms 127432 KB Output is correct
27 Correct 56 ms 127440 KB Output is correct
28 Correct 56 ms 127436 KB Output is correct
29 Correct 56 ms 127436 KB Output is correct
30 Correct 56 ms 127344 KB Output is correct
31 Correct 56 ms 127376 KB Output is correct
32 Correct 56 ms 127408 KB Output is correct
33 Correct 60 ms 127436 KB Output is correct
34 Correct 56 ms 127436 KB Output is correct
35 Correct 55 ms 127392 KB Output is correct
36 Correct 84 ms 127352 KB Output is correct
37 Correct 69 ms 127436 KB Output is correct
38 Correct 62 ms 127436 KB Output is correct
39 Correct 68 ms 127444 KB Output is correct
40 Correct 73 ms 127440 KB Output is correct
41 Correct 60 ms 127416 KB Output is correct
42 Correct 60 ms 127428 KB Output is correct
43 Correct 59 ms 127436 KB Output is correct
44 Correct 56 ms 127440 KB Output is correct
45 Correct 60 ms 127324 KB Output is correct
46 Correct 59 ms 127404 KB Output is correct
47 Correct 59 ms 127340 KB Output is correct
48 Correct 71 ms 127372 KB Output is correct
49 Correct 59 ms 127436 KB Output is correct
50 Correct 58 ms 127372 KB Output is correct
51 Correct 60 ms 127360 KB Output is correct
52 Correct 60 ms 127392 KB Output is correct
53 Correct 59 ms 127440 KB Output is correct
54 Correct 57 ms 127440 KB Output is correct
55 Correct 60 ms 127424 KB Output is correct
56 Correct 58 ms 127316 KB Output is correct
57 Correct 60 ms 127436 KB Output is correct
58 Correct 58 ms 127420 KB Output is correct
59 Correct 94 ms 127324 KB Output is correct
60 Correct 77 ms 127436 KB Output is correct
61 Correct 92 ms 127404 KB Output is correct
62 Correct 76 ms 127436 KB Output is correct
63 Correct 93 ms 127420 KB Output is correct
64 Correct 76 ms 127336 KB Output is correct
65 Correct 86 ms 127432 KB Output is correct
66 Correct 85 ms 127400 KB Output is correct
67 Correct 96 ms 127352 KB Output is correct
68 Correct 80 ms 127440 KB Output is correct
69 Correct 87 ms 127444 KB Output is correct
70 Correct 98 ms 127448 KB Output is correct
71 Correct 89 ms 127380 KB Output is correct
72 Correct 97 ms 127380 KB Output is correct
73 Correct 93 ms 127368 KB Output is correct
74 Correct 82 ms 127360 KB Output is correct
75 Correct 99 ms 127412 KB Output is correct
76 Correct 91 ms 127444 KB Output is correct
77 Correct 90 ms 127440 KB Output is correct
78 Correct 79 ms 127372 KB Output is correct
79 Correct 80 ms 127448 KB Output is correct
80 Correct 91 ms 127444 KB Output is correct
81 Correct 82 ms 127348 KB Output is correct
82 Correct 98 ms 127444 KB Output is correct
83 Correct 98 ms 127444 KB Output is correct
84 Correct 85 ms 127440 KB Output is correct
85 Correct 92 ms 127444 KB Output is correct
86 Correct 89 ms 127396 KB Output is correct
87 Correct 85 ms 127436 KB Output is correct
88 Correct 96 ms 127452 KB Output is correct
89 Correct 98 ms 127356 KB Output is correct
90 Correct 85 ms 127436 KB Output is correct
91 Correct 96 ms 127444 KB Output is correct
92 Correct 103 ms 127428 KB Output is correct
93 Correct 100 ms 127484 KB Output is correct