Submission #747463

# Submission time Handle Problem Language Result Execution time Memory
747463 2023-05-24T08:04:39 Z tch1cherin Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
979 ms 448796 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 1;

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

void solve() {
  int N, P;
  cin >> N >> P;
  vector<int> X(N), T(N);
  for (int &v : X) {
    cin >> v;
  }
  for (int &v : T) {
    cin >> v;
  }
  X.insert(X.begin(), 0);
  T.insert(T.begin(), 0);
  N++;
  vector dp(N, vector(N, vector(N, vector(2, INF))));
  dp[0][0][0][0] = 0;
  for (int len = 0; len < N - 1; len++) {
    for (int L = 0; L < N; L++) {
      int R = (L + len) % N;
      for (int ans = 0; ans < N; ans++) {
        for (int w = 0; w < 2; w++) {
          int time = dp[L][R][ans][w];
          if (w == 0) {
            {
              int delta = (X[L] - X[(L + N - 1) % N] + P) % P;
              int add = time + delta <= T[(L + N - 1) % N];
              chmin(dp[(L + N - 1) % N][R][ans + add][0], time + delta); 
            }
            {
              int delta = (X[(R + 1) % N] - X[L] + P) % P;
              int add = time + delta <= T[(R + 1) % N];
              chmin(dp[L][(R + 1) % N][ans + add][1], time + delta);
            }
          } else {
            {
              int delta = (X[R] - X[(L + N - 1) % N] + P) % P;
              int add = time + delta <= T[(L + N - 1) % N];
              chmin(dp[(L + N - 1) % N][R][ans + add][0], time + delta);
            }
            {
              int delta = (X[(R + 1) % N] - X[R] + P) % P;
              int add = time + delta <= T[(R + 1) % N];
              chmin(dp[L][(R + 1) % N][ans + add][1], time + delta);
            }
          }
        }
      }
    } 
  }
  int res = 0;
  for (int L = 0; L < N; L++) {
    for (int R = 0; R < N; R++) {
      for (int ans = 0; ans < N; ans++) {
        for (int w = 0; w < 2; w++) {
          if (dp[L][R][ans][w] != INF) {
            res = max(res, ans);
          }
        }
      } 
    }
  }
  cout << res << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 448 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 572 KB Output is correct
35 Correct 2 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 738 ms 323040 KB Output is correct
19 Correct 354 ms 152520 KB Output is correct
20 Correct 132 ms 59328 KB Output is correct
21 Correct 309 ms 139896 KB Output is correct
22 Correct 412 ms 206336 KB Output is correct
23 Correct 111 ms 46648 KB Output is correct
24 Correct 74 ms 32148 KB Output is correct
25 Correct 100 ms 45080 KB Output is correct
26 Correct 25 ms 10688 KB Output is correct
27 Correct 105 ms 48064 KB Output is correct
28 Correct 65 ms 28964 KB Output is correct
29 Correct 114 ms 49696 KB Output is correct
30 Correct 79 ms 34584 KB Output is correct
31 Correct 101 ms 45092 KB Output is correct
32 Correct 41 ms 17092 KB Output is correct
33 Correct 104 ms 45132 KB Output is correct
34 Correct 20 ms 9684 KB Output is correct
35 Correct 95 ms 43776 KB Output is correct
36 Correct 35 ms 14364 KB Output is correct
37 Correct 122 ms 48056 KB Output is correct
38 Correct 46 ms 19496 KB Output is correct
39 Correct 116 ms 51140 KB Output is correct
40 Correct 53 ms 22972 KB Output is correct
41 Correct 979 ms 442448 KB Output is correct
42 Correct 603 ms 244544 KB Output is correct
43 Correct 939 ms 442444 KB Output is correct
44 Correct 544 ms 239800 KB Output is correct
45 Correct 943 ms 442464 KB Output is correct
46 Correct 511 ms 244428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 448 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 572 KB Output is correct
35 Correct 2 ms 444 KB Output is correct
36 Correct 738 ms 323040 KB Output is correct
37 Correct 354 ms 152520 KB Output is correct
38 Correct 132 ms 59328 KB Output is correct
39 Correct 309 ms 139896 KB Output is correct
40 Correct 412 ms 206336 KB Output is correct
41 Correct 111 ms 46648 KB Output is correct
42 Correct 74 ms 32148 KB Output is correct
43 Correct 100 ms 45080 KB Output is correct
44 Correct 25 ms 10688 KB Output is correct
45 Correct 105 ms 48064 KB Output is correct
46 Correct 65 ms 28964 KB Output is correct
47 Correct 114 ms 49696 KB Output is correct
48 Correct 79 ms 34584 KB Output is correct
49 Correct 101 ms 45092 KB Output is correct
50 Correct 41 ms 17092 KB Output is correct
51 Correct 104 ms 45132 KB Output is correct
52 Correct 20 ms 9684 KB Output is correct
53 Correct 95 ms 43776 KB Output is correct
54 Correct 35 ms 14364 KB Output is correct
55 Correct 122 ms 48056 KB Output is correct
56 Correct 46 ms 19496 KB Output is correct
57 Correct 116 ms 51140 KB Output is correct
58 Correct 53 ms 22972 KB Output is correct
59 Correct 979 ms 442448 KB Output is correct
60 Correct 603 ms 244544 KB Output is correct
61 Correct 939 ms 442444 KB Output is correct
62 Correct 544 ms 239800 KB Output is correct
63 Correct 943 ms 442464 KB Output is correct
64 Correct 511 ms 244428 KB Output is correct
65 Correct 848 ms 379604 KB Output is correct
66 Correct 742 ms 333780 KB Output is correct
67 Correct 741 ms 312336 KB Output is correct
68 Correct 639 ms 276832 KB Output is correct
69 Correct 860 ms 373340 KB Output is correct
70 Correct 797 ms 350320 KB Output is correct
71 Correct 818 ms 356232 KB Output is correct
72 Correct 770 ms 361656 KB Output is correct
73 Correct 688 ms 322948 KB Output is correct
74 Correct 642 ms 291788 KB Output is correct
75 Correct 738 ms 339068 KB Output is correct
76 Correct 892 ms 416520 KB Output is correct
77 Correct 920 ms 416520 KB Output is correct
78 Correct 601 ms 281928 KB Output is correct
79 Correct 638 ms 296624 KB Output is correct
80 Correct 850 ms 404008 KB Output is correct
81 Correct 636 ms 301972 KB Output is correct
82 Correct 710 ms 328108 KB Output is correct
83 Correct 947 ms 442344 KB Output is correct
84 Correct 750 ms 350216 KB Output is correct
85 Correct 855 ms 397452 KB Output is correct
86 Correct 855 ms 385320 KB Output is correct
87 Correct 731 ms 339020 KB Output is correct
88 Correct 953 ms 448644 KB Output is correct
89 Correct 964 ms 448796 KB Output is correct
90 Correct 748 ms 344908 KB Output is correct
91 Correct 950 ms 448776 KB Output is correct
92 Correct 968 ms 448776 KB Output is correct
93 Correct 917 ms 435580 KB Output is correct