답안 #505845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
505845 2022-01-11T08:49:14 Z cig32 Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
201 ms 127436 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define int long long

int rnd(int x, int y) { // random number generator
  int u= uniform_int_distribution<int>(x, y)(rng); return u;
}

void solve(int tc) {
  int N, L;
  cin >> N >> L;
  int x[N+2], t[N+1];
  x[0] = 0, x[N+1] = L;
  for(int i=1; i<=N; i++) {
    cin >> x[i];
  }
  for(int i=1; i<=N; i++) {
    cin >> t[i];
  }
  int dp[N+1][N+1][2][N+1]; 
  for(int i=0; i<=N; i++) {
    for(int j=0; j<=N; j++) {
      for(int k=0; k<2; k++) {
        for(int l=0; l<=N; l++) {
          dp[i][j][k][l] = 1e18;
        }
      }
    }
  }
  dp[0][0][0][0] = dp[0][0][1][0] = 0;
  for(int i=0; i<=N; i++) {
    for(int j=0; j<=N; j++) {
      if(i + j > N) continue;
      // k = 0
      for(int l=0; l<=N; l++) {
        // get
        if(l>0) {
          int hm = 1e18;
          if(i > 0) {
            hm = min(hm, dp[i-1][j][0][l-1] + x[i] - x[i-1]);
            hm = min(hm, dp[i-1][j][1][l-1] + L - x[N+1 - j] + x[i]);
          }
          if(i > 0 && hm <= t[i]) {
            dp[i][j][0][l] = min(dp[i][j][0][l], hm);
          }
          hm = 1e18;
          if(j > 0) {
            hm = min(hm, dp[i][j-1][0][l-1] + 2 * (x[i] + L - x[N+1 - j]));
            hm = min(hm, dp[i][j-1][1][l-1] + x[N+1 - (j-1)] - x[N+1 - j] + L - x[N+1 - j] + x[i]);
          }
          if(j > 0 && hm <= t[N+1 - j]) {
            dp[i][j][0][l] = min(dp[i][j][0][l], hm);
          }
        }
        // no get
        if(i>0) {
          dp[i][j][0][l] = min(dp[i][j][0][l], dp[i-1][j][0][l] + x[i] - x[i-1]);
          dp[i][j][0][l] = min(dp[i][j][0][l], dp[i-1][j][1][l] + L - x[N+1 - j] + x[i]);
        }
        if(j>0) {
          dp[i][j][0][l] = min(dp[i][j][0][l], dp[i][j-1][0][l] + 2 * (x[i] + L - x[N+1 - j]));
          dp[i][j][0][l] = min(dp[i][j][0][l], dp[i][j-1][1][l] + x[N+1 - (j-1)] - x[N+1 - j] + L - x[N+1 - j] + x[i]);
        }
      }
      //k = 1
      for(int l=0; l<=N; l++) {
        // get
        if(l>0) {
          int hm = 1e18;
          if(i > 0) {
            hm = min(hm, dp[i-1][j][0][l-1] + x[i] - x[i-1] + x[i] + L - x[N+1 - j]);
            hm = min(hm, dp[i-1][j][1][l-1] + 2 * (L - x[N+1 - j] + x[i]));
          }
          if(i > 0 && hm <= t[i]) {
            dp[i][j][1][l] = min(dp[i][j][1][l], hm);
          }
          hm = 1e18;
          if(j > 0) {
            hm = min(hm, dp[i][j-1][0][l-1] + x[i] + L - x[N+1 - j]);
            hm = min(hm, dp[i][j-1][1][l-1] + x[N+1 - (j-1)] - x[N+1 - j]);
          }
          if(j > 0 && hm <= t[N+1 - j]) {
            dp[i][j][1][l] = min(dp[i][j][1][l], hm);
          }
        }
        // no get
        if(i>0) {
          dp[i][j][1][l] = min(dp[i][j][1][l], dp[i-1][j][0][l] + x[i] - x[i-1] + x[i] + L - x[N+1 - j]);
          dp[i][j][1][l] = min(dp[i][j][1][l], dp[i-1][j][1][l] + 2 * (L - x[N+1 - j] + x[i]));
        }
        if(j>0) {
          dp[i][j][1][l] = min(dp[i][j][1][l], dp[i][j-1][0][l] + x[i] + L - x[N+1 - j]);
          dp[i][j][1][l] = min(dp[i][j][1][l], dp[i][j-1][1][l] + x[N+1 - (j-1)] - x[N+1 - j]);
        }
      }
    }
  }
  for(int i=N; i>=0; i--) {
    for(int j=0; j<=N; j++) {
      for(int k=0; k<=N; k++) {
        for(int l=0; l<2; l++) {
          if(dp[j][k][l][i] != 1e18) {
            cout << i << "\n";
            return;
          }
        }
      }
    }
  }
}

int32_t main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 108 ms 91608 KB Output is correct
19 Correct 48 ms 43212 KB Output is correct
20 Correct 25 ms 16844 KB Output is correct
21 Correct 46 ms 39676 KB Output is correct
22 Correct 75 ms 58564 KB Output is correct
23 Correct 13 ms 13260 KB Output is correct
24 Correct 11 ms 9164 KB Output is correct
25 Correct 13 ms 12900 KB Output is correct
26 Correct 4 ms 3148 KB Output is correct
27 Correct 15 ms 13632 KB Output is correct
28 Correct 9 ms 8268 KB Output is correct
29 Correct 18 ms 14156 KB Output is correct
30 Correct 13 ms 9932 KB Output is correct
31 Correct 18 ms 12876 KB Output is correct
32 Correct 6 ms 4940 KB Output is correct
33 Correct 16 ms 12900 KB Output is correct
34 Correct 3 ms 2892 KB Output is correct
35 Correct 18 ms 12508 KB Output is correct
36 Correct 5 ms 4172 KB Output is correct
37 Correct 19 ms 13644 KB Output is correct
38 Correct 6 ms 5580 KB Output is correct
39 Correct 20 ms 14540 KB Output is correct
40 Correct 7 ms 6604 KB Output is correct
41 Correct 142 ms 125416 KB Output is correct
42 Correct 95 ms 69348 KB Output is correct
43 Correct 135 ms 125508 KB Output is correct
44 Correct 99 ms 68108 KB Output is correct
45 Correct 133 ms 125540 KB Output is correct
46 Correct 102 ms 69348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 316 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 108 ms 91608 KB Output is correct
37 Correct 48 ms 43212 KB Output is correct
38 Correct 25 ms 16844 KB Output is correct
39 Correct 46 ms 39676 KB Output is correct
40 Correct 75 ms 58564 KB Output is correct
41 Correct 13 ms 13260 KB Output is correct
42 Correct 11 ms 9164 KB Output is correct
43 Correct 13 ms 12900 KB Output is correct
44 Correct 4 ms 3148 KB Output is correct
45 Correct 15 ms 13632 KB Output is correct
46 Correct 9 ms 8268 KB Output is correct
47 Correct 18 ms 14156 KB Output is correct
48 Correct 13 ms 9932 KB Output is correct
49 Correct 18 ms 12876 KB Output is correct
50 Correct 6 ms 4940 KB Output is correct
51 Correct 16 ms 12900 KB Output is correct
52 Correct 3 ms 2892 KB Output is correct
53 Correct 18 ms 12508 KB Output is correct
54 Correct 5 ms 4172 KB Output is correct
55 Correct 19 ms 13644 KB Output is correct
56 Correct 6 ms 5580 KB Output is correct
57 Correct 20 ms 14540 KB Output is correct
58 Correct 7 ms 6604 KB Output is correct
59 Correct 142 ms 125416 KB Output is correct
60 Correct 95 ms 69348 KB Output is correct
61 Correct 135 ms 125508 KB Output is correct
62 Correct 99 ms 68108 KB Output is correct
63 Correct 133 ms 125540 KB Output is correct
64 Correct 102 ms 69348 KB Output is correct
65 Correct 155 ms 107684 KB Output is correct
66 Correct 118 ms 94676 KB Output is correct
67 Correct 114 ms 88592 KB Output is correct
68 Correct 118 ms 78580 KB Output is correct
69 Correct 126 ms 106032 KB Output is correct
70 Correct 104 ms 99420 KB Output is correct
71 Correct 147 ms 100912 KB Output is correct
72 Correct 108 ms 102684 KB Output is correct
73 Correct 109 ms 91580 KB Output is correct
74 Correct 82 ms 82700 KB Output is correct
75 Correct 120 ms 96252 KB Output is correct
76 Correct 129 ms 118176 KB Output is correct
77 Correct 147 ms 118160 KB Output is correct
78 Correct 87 ms 79960 KB Output is correct
79 Correct 100 ms 84204 KB Output is correct
80 Correct 125 ms 114544 KB Output is correct
81 Correct 107 ms 85580 KB Output is correct
82 Correct 127 ms 93140 KB Output is correct
83 Correct 201 ms 125544 KB Output is correct
84 Correct 144 ms 99420 KB Output is correct
85 Correct 131 ms 112836 KB Output is correct
86 Correct 154 ms 109408 KB Output is correct
87 Correct 122 ms 96200 KB Output is correct
88 Correct 123 ms 127424 KB Output is correct
89 Correct 138 ms 127432 KB Output is correct
90 Correct 152 ms 97840 KB Output is correct
91 Correct 124 ms 127436 KB Output is correct
92 Correct 147 ms 127412 KB Output is correct
93 Correct 187 ms 123612 KB Output is correct