답안 #201409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201409 2020-02-10T12:43:16 Z karma Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
1026 ms 521848 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = 405;
const int inf = (int)2e9;

typedef pair<int, int> pii;

ll f[N][N][203][2];
int n, x[N], t[N], L;

int dis(int s, int t) {return min(abs(x[s] - x[t]), L - abs(x[s] - x[t]));}

ll DP(int l, int r, int k, bool inS) {
   if(l <= 0 || r > n + n + 1 || k < 0) return inf;
   if(f[l][r][k][inS] != -1) return f[l][r][k][inS];
   ll& res = f[l][r][k][inS]; res = inf;
   if(r < l || k > (r - l + 1) || r - l > n) return res;
   ll g;
   g = DP(l + 1, r, k, 1);
   if(g < inf) {
      if(!inS) res = min(res, g + dis(l + 1, l) + dis(r, l));
      else res = min(res, g + dis(l + 1, l));
   }
   g = DP(l + 1, r, k, 0);
   if(g < inf) {
      if(!inS) res = min(res, g + 2 * dis(l, r));
      else res = min(res, g + dis(l, r));
   }
   g = DP(l + 1, r, k - 1, 1);
   if(g < inf && g + dis(l + 1, l) <= t[l]) {
      if(!inS) res = min(res, g + dis(l + 1, l) + dis(r, l));
      else res = min(res, g + dis(l + 1, l));
   }
   g = DP(l + 1, r, k - 1, 0);
   if(g < inf && g + dis(l, r) <= t[l]) {
      if(!inS) res = min(res, g + 2 * dis(l, r));
      else res = min(res, g + dis(l, r));
   }
   ///
   g = DP(l, r - 1, k, 1);
   if(g < inf) {
      if(!inS) res = min(res, g + dis(l, r));
      else res = min(res, g + 2 * dis(l, r));
   }
   g = DP(l, r - 1, k, 0);
   if(g < inf) {
      if(!inS) res = min(res, g + dis(r - 1, r));
      else res = min(res, g + dis(r - 1, r) + dis(l, r));
   }
   g = DP(l, r - 1, k - 1, 1);
   if(g < inf && g + dis(l, r) <= t[r]) {
      if(!inS) res = min(res, g + dis(l, r));
      else res = min(res, g + 2 * dis(l, r));
   }
   g = DP(l, r - 1, k - 1, 0);
   if(g < inf && g + dis(r - 1, r) <= t[r]) {
      if(!inS) res = min(res, g + dis(r - 1, r));
      else res = min(res, g + dis(r - 1, r) + dis(l, r));
   }
   return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> L; x[0] = 1; x[n + 1] = L;
    for(int i = 1; i <= n; ++i) cin >> x[i], x[i + n + 1] = x[i] + L;
    for(int i = 1; i <= n; ++i) cin >> t[i], t[i + n + 1] = t[i];
    memset(&f, -1, sizeof f);
    f[n + 1][n + 1][0][0] = f[n + 1][n + 1][0][1] = 0;
    f[n + 1][n + 1][1][0] = f[n + 1][n + 1][1][1] = inf;
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = n + 1; j <= n + n + 1; ++j) {
            for(int k = 1; k <= n; ++k) {
                for(int d = 0; d < 2; ++d) {
                    if(DP(i, j, k, d) < inf) ans = max(ans, k);
                }
            }
        }
    }
    cout << ans;
}

Compilation message

ho_t3.cpp: In function 'int32_t main()':
ho_t3.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 521564 KB Output is correct
2 Correct 277 ms 521720 KB Output is correct
3 Correct 264 ms 521592 KB Output is correct
4 Correct 278 ms 521592 KB Output is correct
5 Correct 272 ms 521744 KB Output is correct
6 Correct 271 ms 521592 KB Output is correct
7 Correct 280 ms 521848 KB Output is correct
8 Correct 267 ms 521592 KB Output is correct
9 Correct 263 ms 521592 KB Output is correct
10 Correct 273 ms 521720 KB Output is correct
11 Correct 268 ms 521592 KB Output is correct
12 Correct 276 ms 521592 KB Output is correct
13 Correct 275 ms 521592 KB Output is correct
14 Correct 281 ms 521592 KB Output is correct
15 Correct 272 ms 521720 KB Output is correct
16 Correct 269 ms 521596 KB Output is correct
17 Correct 271 ms 521592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 521564 KB Output is correct
2 Correct 277 ms 521720 KB Output is correct
3 Correct 264 ms 521592 KB Output is correct
4 Correct 278 ms 521592 KB Output is correct
5 Correct 272 ms 521744 KB Output is correct
6 Correct 271 ms 521592 KB Output is correct
7 Correct 280 ms 521848 KB Output is correct
8 Correct 267 ms 521592 KB Output is correct
9 Correct 263 ms 521592 KB Output is correct
10 Correct 273 ms 521720 KB Output is correct
11 Correct 268 ms 521592 KB Output is correct
12 Correct 276 ms 521592 KB Output is correct
13 Correct 275 ms 521592 KB Output is correct
14 Correct 281 ms 521592 KB Output is correct
15 Correct 272 ms 521720 KB Output is correct
16 Correct 269 ms 521596 KB Output is correct
17 Correct 271 ms 521592 KB Output is correct
18 Correct 277 ms 521696 KB Output is correct
19 Correct 285 ms 521624 KB Output is correct
20 Correct 289 ms 521648 KB Output is correct
21 Correct 274 ms 521592 KB Output is correct
22 Correct 278 ms 521592 KB Output is correct
23 Correct 277 ms 521720 KB Output is correct
24 Correct 269 ms 521720 KB Output is correct
25 Correct 277 ms 521592 KB Output is correct
26 Correct 281 ms 521592 KB Output is correct
27 Correct 267 ms 521592 KB Output is correct
28 Correct 277 ms 521656 KB Output is correct
29 Correct 275 ms 521592 KB Output is correct
30 Correct 273 ms 521720 KB Output is correct
31 Correct 276 ms 521592 KB Output is correct
32 Correct 271 ms 521592 KB Output is correct
33 Correct 287 ms 521720 KB Output is correct
34 Correct 273 ms 521592 KB Output is correct
35 Correct 291 ms 521592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 521564 KB Output is correct
2 Correct 277 ms 521720 KB Output is correct
3 Correct 264 ms 521592 KB Output is correct
4 Correct 278 ms 521592 KB Output is correct
5 Correct 272 ms 521744 KB Output is correct
6 Correct 271 ms 521592 KB Output is correct
7 Correct 280 ms 521848 KB Output is correct
8 Correct 267 ms 521592 KB Output is correct
9 Correct 263 ms 521592 KB Output is correct
10 Correct 273 ms 521720 KB Output is correct
11 Correct 268 ms 521592 KB Output is correct
12 Correct 276 ms 521592 KB Output is correct
13 Correct 275 ms 521592 KB Output is correct
14 Correct 281 ms 521592 KB Output is correct
15 Correct 272 ms 521720 KB Output is correct
16 Correct 269 ms 521596 KB Output is correct
17 Correct 271 ms 521592 KB Output is correct
18 Correct 771 ms 521592 KB Output is correct
19 Correct 524 ms 521592 KB Output is correct
20 Correct 369 ms 521720 KB Output is correct
21 Correct 484 ms 521600 KB Output is correct
22 Correct 635 ms 521592 KB Output is correct
23 Correct 351 ms 521592 KB Output is correct
24 Correct 325 ms 521720 KB Output is correct
25 Correct 350 ms 521720 KB Output is correct
26 Correct 297 ms 521592 KB Output is correct
27 Correct 352 ms 521596 KB Output is correct
28 Correct 315 ms 521592 KB Output is correct
29 Correct 364 ms 521720 KB Output is correct
30 Correct 322 ms 521592 KB Output is correct
31 Correct 352 ms 521680 KB Output is correct
32 Correct 302 ms 521592 KB Output is correct
33 Correct 350 ms 521720 KB Output is correct
34 Correct 285 ms 521692 KB Output is correct
35 Correct 375 ms 521592 KB Output is correct
36 Correct 296 ms 521720 KB Output is correct
37 Correct 350 ms 521592 KB Output is correct
38 Correct 309 ms 521592 KB Output is correct
39 Correct 348 ms 521592 KB Output is correct
40 Correct 312 ms 521616 KB Output is correct
41 Correct 985 ms 521848 KB Output is correct
42 Correct 606 ms 521592 KB Output is correct
43 Correct 977 ms 521592 KB Output is correct
44 Correct 599 ms 521720 KB Output is correct
45 Correct 996 ms 521720 KB Output is correct
46 Correct 639 ms 521592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 521564 KB Output is correct
2 Correct 277 ms 521720 KB Output is correct
3 Correct 264 ms 521592 KB Output is correct
4 Correct 278 ms 521592 KB Output is correct
5 Correct 272 ms 521744 KB Output is correct
6 Correct 271 ms 521592 KB Output is correct
7 Correct 280 ms 521848 KB Output is correct
8 Correct 267 ms 521592 KB Output is correct
9 Correct 263 ms 521592 KB Output is correct
10 Correct 273 ms 521720 KB Output is correct
11 Correct 268 ms 521592 KB Output is correct
12 Correct 276 ms 521592 KB Output is correct
13 Correct 275 ms 521592 KB Output is correct
14 Correct 281 ms 521592 KB Output is correct
15 Correct 272 ms 521720 KB Output is correct
16 Correct 269 ms 521596 KB Output is correct
17 Correct 271 ms 521592 KB Output is correct
18 Correct 277 ms 521696 KB Output is correct
19 Correct 285 ms 521624 KB Output is correct
20 Correct 289 ms 521648 KB Output is correct
21 Correct 274 ms 521592 KB Output is correct
22 Correct 278 ms 521592 KB Output is correct
23 Correct 277 ms 521720 KB Output is correct
24 Correct 269 ms 521720 KB Output is correct
25 Correct 277 ms 521592 KB Output is correct
26 Correct 281 ms 521592 KB Output is correct
27 Correct 267 ms 521592 KB Output is correct
28 Correct 277 ms 521656 KB Output is correct
29 Correct 275 ms 521592 KB Output is correct
30 Correct 273 ms 521720 KB Output is correct
31 Correct 276 ms 521592 KB Output is correct
32 Correct 271 ms 521592 KB Output is correct
33 Correct 287 ms 521720 KB Output is correct
34 Correct 273 ms 521592 KB Output is correct
35 Correct 291 ms 521592 KB Output is correct
36 Correct 771 ms 521592 KB Output is correct
37 Correct 524 ms 521592 KB Output is correct
38 Correct 369 ms 521720 KB Output is correct
39 Correct 484 ms 521600 KB Output is correct
40 Correct 635 ms 521592 KB Output is correct
41 Correct 351 ms 521592 KB Output is correct
42 Correct 325 ms 521720 KB Output is correct
43 Correct 350 ms 521720 KB Output is correct
44 Correct 297 ms 521592 KB Output is correct
45 Correct 352 ms 521596 KB Output is correct
46 Correct 315 ms 521592 KB Output is correct
47 Correct 364 ms 521720 KB Output is correct
48 Correct 322 ms 521592 KB Output is correct
49 Correct 352 ms 521680 KB Output is correct
50 Correct 302 ms 521592 KB Output is correct
51 Correct 350 ms 521720 KB Output is correct
52 Correct 285 ms 521692 KB Output is correct
53 Correct 375 ms 521592 KB Output is correct
54 Correct 296 ms 521720 KB Output is correct
55 Correct 350 ms 521592 KB Output is correct
56 Correct 309 ms 521592 KB Output is correct
57 Correct 348 ms 521592 KB Output is correct
58 Correct 312 ms 521616 KB Output is correct
59 Correct 985 ms 521848 KB Output is correct
60 Correct 606 ms 521592 KB Output is correct
61 Correct 977 ms 521592 KB Output is correct
62 Correct 599 ms 521720 KB Output is correct
63 Correct 996 ms 521720 KB Output is correct
64 Correct 639 ms 521592 KB Output is correct
65 Correct 874 ms 521848 KB Output is correct
66 Correct 806 ms 521848 KB Output is correct
67 Correct 749 ms 521720 KB Output is correct
68 Correct 699 ms 521592 KB Output is correct
69 Correct 855 ms 521720 KB Output is correct
70 Correct 860 ms 521720 KB Output is correct
71 Correct 823 ms 521848 KB Output is correct
72 Correct 913 ms 521592 KB Output is correct
73 Correct 746 ms 521592 KB Output is correct
74 Correct 757 ms 521720 KB Output is correct
75 Correct 771 ms 521720 KB Output is correct
76 Correct 997 ms 521848 KB Output is correct
77 Correct 895 ms 521720 KB Output is correct
78 Correct 757 ms 521720 KB Output is correct
79 Correct 714 ms 521720 KB Output is correct
80 Correct 990 ms 521720 KB Output is correct
81 Correct 731 ms 521720 KB Output is correct
82 Correct 786 ms 521720 KB Output is correct
83 Correct 934 ms 521720 KB Output is correct
84 Correct 808 ms 521592 KB Output is correct
85 Correct 879 ms 521848 KB Output is correct
86 Correct 869 ms 521720 KB Output is correct
87 Correct 796 ms 521720 KB Output is correct
88 Correct 1026 ms 521720 KB Output is correct
89 Correct 980 ms 521680 KB Output is correct
90 Correct 743 ms 521740 KB Output is correct
91 Correct 992 ms 521720 KB Output is correct
92 Correct 1006 ms 521812 KB Output is correct
93 Correct 895 ms 521848 KB Output is correct