Submission #364275

# Submission time Handle Problem Language Result Execution time Memory
364275 2021-02-08T17:54:55 Z tushar_2658 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
179 ms 132204 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 205;
using ll = long long;
ll inf = 1e18;

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

int main(int argc, char const *argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> L;
  for(int i = 1; i <= n; ++i){
    cin >> x[i];
  }
  for(int i = 1; i <= n; ++i){
    cin >> t[i];
  }
  x[0] = 0;
  x[n + 1] = L;
  t[n + 1] = -1;
  t[0] = -1;
  for(int i = 0; i <= n + 1; ++i)for(int j = 0; j <= n + 1; ++j)for(int k = 0; k <= n + 1; ++k)for(int l = 0; l < 2; ++l)dp[i][j][k][l] = inf;
  dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
  for(int l = n + 1; l > 1; --l){
    for(int i = 0, j = i + l; j <= n + 1; ++i, ++j){
      for(int k = 0; k <= n + 1; ++k){
        for(int pos = 0; pos < 2; ++pos){
          if(pos == 0){
            ll mn = dp[i][j][k][pos];
            if(t[i + 1] >= mn + llabs(x[i + 1] - x[i])){
              dp[i + 1][j][k + 1][pos] = min(dp[i + 1][j][k + 1][pos], mn + llabs(x[i + 1] - x[i]));
            }else {
              dp[i + 1][j][k][pos] = min(dp[i + 1][j][k][pos], mn + llabs(x[i + 1] - x[i]));
            }
            if(t[j - 1] >= mn + L - llabs(x[j - 1] - x[i])){
              dp[i][j - 1][k + 1][1] = min(dp[i][j - 1][k + 1][1], mn + L - llabs(x[j - 1] - x[i]));
            }else {
              dp[i][j - 1][k][1] = min(dp[i][j - 1][k][1], mn + L - llabs(x[j - 1] - x[i]));
            }
          }else {
            ll mn = dp[i][j][k][pos];
            ll X = mn + L - llabs(x[j] - x[i + 1]);
            if(t[i + 1] >= X){
              dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0], X);
            }else {
              dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], X);
            }
            X = mn + x[j] - x[j - 1];
            if(t[j - 1] >= X){
              dp[i][j - 1][k + 1][pos] = min(dp[i][j - 1][k + 1][pos], X);
            }else {
              dp[i][j - 1][k][pos] = min(dp[i][j - 1][k][pos], X);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for(int k = 0; k <= n; ++k){
    for(int i = 0; i <= n + 1; ++i){
      for(int j = i + 1; j <= n + 1; ++j){
        for(int pos = 0; pos < 2; ++pos){
          if(dp[i][j][k][pos] < inf){
            ans = max(ans, k);
          }
        }
      }
    }
  }
  cout << ans << '\n';

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1020 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1020 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 1004 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 748 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1132 KB Output is correct
25 Correct 1 ms 1152 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 748 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 1 ms 1260 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1132 KB Output is correct
33 Correct 1 ms 1388 KB Output is correct
34 Correct 3 ms 1260 KB Output is correct
35 Correct 1 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1020 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 113 ms 106092 KB Output is correct
19 Correct 67 ms 64620 KB Output is correct
20 Correct 37 ms 34668 KB Output is correct
21 Correct 64 ms 61036 KB Output is correct
22 Correct 88 ms 78956 KB Output is correct
23 Correct 25 ms 29548 KB Output is correct
24 Correct 19 ms 23276 KB Output is correct
25 Correct 26 ms 28908 KB Output is correct
26 Correct 8 ms 11244 KB Output is correct
27 Correct 27 ms 30188 KB Output is correct
28 Correct 20 ms 21600 KB Output is correct
29 Correct 27 ms 30828 KB Output is correct
30 Correct 21 ms 24300 KB Output is correct
31 Correct 25 ms 28908 KB Output is correct
32 Correct 16 ms 15360 KB Output is correct
33 Correct 27 ms 28908 KB Output is correct
34 Correct 10 ms 10476 KB Output is correct
35 Correct 24 ms 28396 KB Output is correct
36 Correct 13 ms 13676 KB Output is correct
37 Correct 25 ms 30188 KB Output is correct
38 Correct 14 ms 16748 KB Output is correct
39 Correct 30 ms 31468 KB Output is correct
40 Correct 17 ms 18540 KB Output is correct
41 Correct 159 ms 130796 KB Output is correct
42 Correct 97 ms 88300 KB Output is correct
43 Correct 175 ms 130796 KB Output is correct
44 Correct 97 ms 87300 KB Output is correct
45 Correct 160 ms 130856 KB Output is correct
46 Correct 97 ms 88300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 1020 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 1004 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 640 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 1 ms 1004 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 1004 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 748 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1132 KB Output is correct
25 Correct 1 ms 1152 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 748 KB Output is correct
29 Correct 1 ms 1260 KB Output is correct
30 Correct 1 ms 1260 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1132 KB Output is correct
33 Correct 1 ms 1388 KB Output is correct
34 Correct 3 ms 1260 KB Output is correct
35 Correct 1 ms 1260 KB Output is correct
36 Correct 113 ms 106092 KB Output is correct
37 Correct 67 ms 64620 KB Output is correct
38 Correct 37 ms 34668 KB Output is correct
39 Correct 64 ms 61036 KB Output is correct
40 Correct 88 ms 78956 KB Output is correct
41 Correct 25 ms 29548 KB Output is correct
42 Correct 19 ms 23276 KB Output is correct
43 Correct 26 ms 28908 KB Output is correct
44 Correct 8 ms 11244 KB Output is correct
45 Correct 27 ms 30188 KB Output is correct
46 Correct 20 ms 21600 KB Output is correct
47 Correct 27 ms 30828 KB Output is correct
48 Correct 21 ms 24300 KB Output is correct
49 Correct 25 ms 28908 KB Output is correct
50 Correct 16 ms 15360 KB Output is correct
51 Correct 27 ms 28908 KB Output is correct
52 Correct 10 ms 10476 KB Output is correct
53 Correct 24 ms 28396 KB Output is correct
54 Correct 13 ms 13676 KB Output is correct
55 Correct 25 ms 30188 KB Output is correct
56 Correct 14 ms 16748 KB Output is correct
57 Correct 30 ms 31468 KB Output is correct
58 Correct 17 ms 18540 KB Output is correct
59 Correct 159 ms 130796 KB Output is correct
60 Correct 97 ms 88300 KB Output is correct
61 Correct 175 ms 130796 KB Output is correct
62 Correct 97 ms 87300 KB Output is correct
63 Correct 160 ms 130856 KB Output is correct
64 Correct 97 ms 88300 KB Output is correct
65 Correct 157 ms 118124 KB Output is correct
66 Correct 130 ms 108524 KB Output is correct
67 Correct 120 ms 103788 KB Output is correct
68 Correct 105 ms 95980 KB Output is correct
69 Correct 138 ms 117228 KB Output is correct
70 Correct 160 ms 112108 KB Output is correct
71 Correct 127 ms 113312 KB Output is correct
72 Correct 125 ms 114540 KB Output is correct
73 Correct 119 ms 106220 KB Output is correct
74 Correct 118 ms 99308 KB Output is correct
75 Correct 122 ms 109676 KB Output is correct
76 Correct 142 ms 125676 KB Output is correct
77 Correct 153 ms 125804 KB Output is correct
78 Correct 115 ms 97260 KB Output is correct
79 Correct 110 ms 100460 KB Output is correct
80 Correct 139 ms 123116 KB Output is correct
81 Correct 117 ms 101612 KB Output is correct
82 Correct 125 ms 107372 KB Output is correct
83 Correct 154 ms 130992 KB Output is correct
84 Correct 133 ms 112236 KB Output is correct
85 Correct 154 ms 121868 KB Output is correct
86 Correct 139 ms 119404 KB Output is correct
87 Correct 122 ms 109804 KB Output is correct
88 Correct 168 ms 132076 KB Output is correct
89 Correct 164 ms 132060 KB Output is correct
90 Correct 123 ms 110828 KB Output is correct
91 Correct 159 ms 132204 KB Output is correct
92 Correct 179 ms 132204 KB Output is correct
93 Correct 147 ms 129516 KB Output is correct