답안 #208936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208936 2020-03-12T15:35:13 Z eriksuenderhauf Collecting Stamps 3 (JOI20_ho_t3) C++11
100 / 100
162 ms 135444 KB
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)(x).size()
#define trav(x, a) for (const auto& x: a)
#define pii pair<int,int>
#define st first
#define nd second
using namespace std;
typedef long long ll;
const int N = 2e2 + 5;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int X[N], T[N];
ll dp[N][N][N][2];
int n, l;

ll dist(int i, int j) {
  return min(abs(X[i]-X[j]), l - abs(X[i]-X[j]));
}

int main() {
  scanf("%d %d", &n, &l);
  for (int i = 1; i <= n; i++)
    scanf("%d", X+i);
  for (int i = 1; i <= n; i++)
    scanf("%d", T+i);
  memset(dp, 0x3f, sizeof dp);
  int ans = 0;
  dp[0][0][0][0] = dp[0][0][0][1] = 0;
  for (int i = 0; i < n; i++) {
    for (int r = 0; r <= i; r++) {
      int l = i-r, fl;
      for (int k = 0; k <= i; k++) {
        fl = dp[l][r][k][0] + dist(n+1-l, n+1-(l+1)) <= T[n+1-(l+1)];
        dp[l+1][r][k+fl][0] = min(dp[l+1][r][k+fl][0], dp[l][r][k][0] + dist(n+1-l, n+1-(l+1)));
        fl = dp[l][r][k][0] + dist(n+1-l, r+1) <= T[r+1];
        dp[l][r+1][k+fl][1] = min(dp[l][r+1][k+fl][1], dp[l][r][k][0] + dist(n+1-l, r+1));

        fl = dp[l][r][k][1] + dist(r, n+1-(l+1)) <= T[n+1-(l+1)];
        dp[l+1][r][k+fl][0] = min(dp[l+1][r][k+fl][0], dp[l][r][k][1] + dist(r, n+1-(l+1)));
        fl = dp[l][r][k][1] + dist(r, r+1) <= T[r+1];
        dp[l][r+1][k+fl][1] = min(dp[l][r+1][k+fl][1], dp[l][r][k][1] + dist(r, r+1));
      }
    }
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = 0; k <= n; k++)
        for (int f = 0; f < 2; f++)
          if (dp[i][j][k][f] != inf)
            ans = max(ans, k);
  printf("%d\n", ans);
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &l);
   ~~~~~^~~~~~~~~~~~~~~~~
ho_t3.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", X+i);
     ~~~~~^~~~~~~~~~~
ho_t3.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", T+i);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 135160 KB Output is correct
2 Correct 77 ms 135160 KB Output is correct
3 Correct 76 ms 135160 KB Output is correct
4 Correct 76 ms 135160 KB Output is correct
5 Correct 77 ms 135160 KB Output is correct
6 Correct 76 ms 135220 KB Output is correct
7 Correct 77 ms 135164 KB Output is correct
8 Correct 82 ms 135160 KB Output is correct
9 Correct 79 ms 135160 KB Output is correct
10 Correct 82 ms 135444 KB Output is correct
11 Correct 78 ms 135160 KB Output is correct
12 Correct 79 ms 135160 KB Output is correct
13 Correct 79 ms 135160 KB Output is correct
14 Correct 79 ms 135160 KB Output is correct
15 Correct 79 ms 135288 KB Output is correct
16 Correct 78 ms 135160 KB Output is correct
17 Correct 75 ms 135160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 135160 KB Output is correct
2 Correct 77 ms 135160 KB Output is correct
3 Correct 76 ms 135160 KB Output is correct
4 Correct 76 ms 135160 KB Output is correct
5 Correct 77 ms 135160 KB Output is correct
6 Correct 76 ms 135220 KB Output is correct
7 Correct 77 ms 135164 KB Output is correct
8 Correct 82 ms 135160 KB Output is correct
9 Correct 79 ms 135160 KB Output is correct
10 Correct 82 ms 135444 KB Output is correct
11 Correct 78 ms 135160 KB Output is correct
12 Correct 79 ms 135160 KB Output is correct
13 Correct 79 ms 135160 KB Output is correct
14 Correct 79 ms 135160 KB Output is correct
15 Correct 79 ms 135288 KB Output is correct
16 Correct 78 ms 135160 KB Output is correct
17 Correct 75 ms 135160 KB Output is correct
18 Correct 76 ms 135160 KB Output is correct
19 Correct 83 ms 135160 KB Output is correct
20 Correct 77 ms 135160 KB Output is correct
21 Correct 78 ms 135160 KB Output is correct
22 Correct 76 ms 135160 KB Output is correct
23 Correct 77 ms 135160 KB Output is correct
24 Correct 75 ms 135120 KB Output is correct
25 Correct 80 ms 135160 KB Output is correct
26 Correct 77 ms 135160 KB Output is correct
27 Correct 75 ms 135160 KB Output is correct
28 Correct 76 ms 135160 KB Output is correct
29 Correct 77 ms 135164 KB Output is correct
30 Correct 81 ms 135160 KB Output is correct
31 Correct 77 ms 135160 KB Output is correct
32 Correct 75 ms 135160 KB Output is correct
33 Correct 76 ms 135160 KB Output is correct
34 Correct 78 ms 135160 KB Output is correct
35 Correct 80 ms 135160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 135160 KB Output is correct
2 Correct 77 ms 135160 KB Output is correct
3 Correct 76 ms 135160 KB Output is correct
4 Correct 76 ms 135160 KB Output is correct
5 Correct 77 ms 135160 KB Output is correct
6 Correct 76 ms 135220 KB Output is correct
7 Correct 77 ms 135164 KB Output is correct
8 Correct 82 ms 135160 KB Output is correct
9 Correct 79 ms 135160 KB Output is correct
10 Correct 82 ms 135444 KB Output is correct
11 Correct 78 ms 135160 KB Output is correct
12 Correct 79 ms 135160 KB Output is correct
13 Correct 79 ms 135160 KB Output is correct
14 Correct 79 ms 135160 KB Output is correct
15 Correct 79 ms 135288 KB Output is correct
16 Correct 78 ms 135160 KB Output is correct
17 Correct 75 ms 135160 KB Output is correct
18 Correct 140 ms 135160 KB Output is correct
19 Correct 108 ms 135160 KB Output is correct
20 Correct 98 ms 135116 KB Output is correct
21 Correct 107 ms 135160 KB Output is correct
22 Correct 119 ms 135160 KB Output is correct
23 Correct 88 ms 135160 KB Output is correct
24 Correct 84 ms 135160 KB Output is correct
25 Correct 90 ms 135164 KB Output is correct
26 Correct 80 ms 135160 KB Output is correct
27 Correct 97 ms 135288 KB Output is correct
28 Correct 84 ms 135160 KB Output is correct
29 Correct 86 ms 135164 KB Output is correct
30 Correct 85 ms 135160 KB Output is correct
31 Correct 89 ms 135160 KB Output is correct
32 Correct 81 ms 135340 KB Output is correct
33 Correct 88 ms 135160 KB Output is correct
34 Correct 80 ms 135160 KB Output is correct
35 Correct 85 ms 135160 KB Output is correct
36 Correct 81 ms 135160 KB Output is correct
37 Correct 90 ms 135288 KB Output is correct
38 Correct 79 ms 135160 KB Output is correct
39 Correct 86 ms 135160 KB Output is correct
40 Correct 82 ms 135160 KB Output is correct
41 Correct 157 ms 135160 KB Output is correct
42 Correct 129 ms 135160 KB Output is correct
43 Correct 147 ms 135160 KB Output is correct
44 Correct 132 ms 135224 KB Output is correct
45 Correct 154 ms 135160 KB Output is correct
46 Correct 128 ms 135160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 135160 KB Output is correct
2 Correct 77 ms 135160 KB Output is correct
3 Correct 76 ms 135160 KB Output is correct
4 Correct 76 ms 135160 KB Output is correct
5 Correct 77 ms 135160 KB Output is correct
6 Correct 76 ms 135220 KB Output is correct
7 Correct 77 ms 135164 KB Output is correct
8 Correct 82 ms 135160 KB Output is correct
9 Correct 79 ms 135160 KB Output is correct
10 Correct 82 ms 135444 KB Output is correct
11 Correct 78 ms 135160 KB Output is correct
12 Correct 79 ms 135160 KB Output is correct
13 Correct 79 ms 135160 KB Output is correct
14 Correct 79 ms 135160 KB Output is correct
15 Correct 79 ms 135288 KB Output is correct
16 Correct 78 ms 135160 KB Output is correct
17 Correct 75 ms 135160 KB Output is correct
18 Correct 76 ms 135160 KB Output is correct
19 Correct 83 ms 135160 KB Output is correct
20 Correct 77 ms 135160 KB Output is correct
21 Correct 78 ms 135160 KB Output is correct
22 Correct 76 ms 135160 KB Output is correct
23 Correct 77 ms 135160 KB Output is correct
24 Correct 75 ms 135120 KB Output is correct
25 Correct 80 ms 135160 KB Output is correct
26 Correct 77 ms 135160 KB Output is correct
27 Correct 75 ms 135160 KB Output is correct
28 Correct 76 ms 135160 KB Output is correct
29 Correct 77 ms 135164 KB Output is correct
30 Correct 81 ms 135160 KB Output is correct
31 Correct 77 ms 135160 KB Output is correct
32 Correct 75 ms 135160 KB Output is correct
33 Correct 76 ms 135160 KB Output is correct
34 Correct 78 ms 135160 KB Output is correct
35 Correct 80 ms 135160 KB Output is correct
36 Correct 140 ms 135160 KB Output is correct
37 Correct 108 ms 135160 KB Output is correct
38 Correct 98 ms 135116 KB Output is correct
39 Correct 107 ms 135160 KB Output is correct
40 Correct 119 ms 135160 KB Output is correct
41 Correct 88 ms 135160 KB Output is correct
42 Correct 84 ms 135160 KB Output is correct
43 Correct 90 ms 135164 KB Output is correct
44 Correct 80 ms 135160 KB Output is correct
45 Correct 97 ms 135288 KB Output is correct
46 Correct 84 ms 135160 KB Output is correct
47 Correct 86 ms 135164 KB Output is correct
48 Correct 85 ms 135160 KB Output is correct
49 Correct 89 ms 135160 KB Output is correct
50 Correct 81 ms 135340 KB Output is correct
51 Correct 88 ms 135160 KB Output is correct
52 Correct 80 ms 135160 KB Output is correct
53 Correct 85 ms 135160 KB Output is correct
54 Correct 81 ms 135160 KB Output is correct
55 Correct 90 ms 135288 KB Output is correct
56 Correct 79 ms 135160 KB Output is correct
57 Correct 86 ms 135160 KB Output is correct
58 Correct 82 ms 135160 KB Output is correct
59 Correct 157 ms 135160 KB Output is correct
60 Correct 129 ms 135160 KB Output is correct
61 Correct 147 ms 135160 KB Output is correct
62 Correct 132 ms 135224 KB Output is correct
63 Correct 154 ms 135160 KB Output is correct
64 Correct 128 ms 135160 KB Output is correct
65 Correct 148 ms 135160 KB Output is correct
66 Correct 137 ms 135160 KB Output is correct
67 Correct 140 ms 135160 KB Output is correct
68 Correct 131 ms 135160 KB Output is correct
69 Correct 148 ms 135160 KB Output is correct
70 Correct 142 ms 135160 KB Output is correct
71 Correct 148 ms 135372 KB Output is correct
72 Correct 143 ms 135160 KB Output is correct
73 Correct 138 ms 135160 KB Output is correct
74 Correct 120 ms 135160 KB Output is correct
75 Correct 144 ms 135288 KB Output is correct
76 Correct 153 ms 135164 KB Output is correct
77 Correct 155 ms 135160 KB Output is correct
78 Correct 130 ms 135160 KB Output is correct
79 Correct 135 ms 135288 KB Output is correct
80 Correct 153 ms 135120 KB Output is correct
81 Correct 133 ms 135160 KB Output is correct
82 Correct 134 ms 135160 KB Output is correct
83 Correct 155 ms 135136 KB Output is correct
84 Correct 143 ms 135160 KB Output is correct
85 Correct 153 ms 135160 KB Output is correct
86 Correct 153 ms 135288 KB Output is correct
87 Correct 141 ms 135160 KB Output is correct
88 Correct 159 ms 135160 KB Output is correct
89 Correct 149 ms 135160 KB Output is correct
90 Correct 143 ms 135340 KB Output is correct
91 Correct 162 ms 135160 KB Output is correct
92 Correct 159 ms 135160 KB Output is correct
93 Correct 159 ms 135160 KB Output is correct