답안 #203142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203142 2020-02-19T13:53:21 Z godwind Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
142 ms 127812 KB
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
// #include <random>
#include <iomanip>
#include <bitset>
#include <cassert>
 
using namespace std;

#define int long long
#define y1 y11
#define double long double
#define less less228
#define left left228
#define right right228
#define list list228
 
 
 
template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}
 
 
// random_device rnd;
 
// template<typename T> void shuffle(vector< T > &v) {
//     for (int i = 1; i < (int)v.size(); ++i) {
//         swap(v[rnd() % i], v[i]);
//     }
//     for (int i = (int)v.size() - 1; i; --i) {
//         swap(v[rnd() % i], v[i]);
//     }
// }

const int N = 202;
const int INF = 1e17 + 228;

int n, L;
int x[N], t[N];
int dp[N][N][N][2];

int dist(int x, int y) {
    return min(abs(x - y), L - abs(x - y));
}

signed main() {
    ios_base::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];
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                dp[i][j][k][0] = dp[i][j][k][1] = INF;
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        dp[i][i][0][0] = dp[i][i][0][1] = dist(0, x[i]);
        if (dist(0, x[i]) <= t[i]) {
            dp[i][i][1][0] = dp[i][i][1][1] = dist(0, x[i]);
        }
    }
    for (int LEN = 0; LEN < n - 1; ++LEN) {
        for (int l = 1; l <= n; ++l) {
            int r = l + LEN;
            if (r > n) r -= n;
            // (l, r)
            int bl = l - 1;
            if (bl == 0) bl = n;
            int ar = r + 1;
            if (ar == n + 1) ar = 1;
            for (int k = 0; k <= LEN + 1; ++k) {
                uin(dp[bl][r][k][0], dp[l][r][k][0] + dist(x[l], x[bl]));
                if (dp[l][r][k][0] + dist(x[l], x[bl]) <= t[bl]) {
                    uin(dp[bl][r][k + 1][0], dp[l][r][k][0] + dist(x[l], x[bl]));
                }
                uin(dp[l][ar][k][1], dp[l][r][k][0] + dist(x[l], x[ar]));
                if (dp[l][r][k][0] + dist(x[l], x[ar]) <= t[ar]) {
                    uin(dp[l][ar][k + 1][1], dp[l][r][k][0] + dist(x[l], x[ar]));
                }
                uin(dp[l][ar][k][1], dp[l][r][k][1] + dist(x[r], x[ar]));
                if (dp[l][r][k][1] + dist(x[r], x[ar]) <= t[ar]) {
                    uin(dp[l][ar][k + 1][1], dp[l][r][k][1] + dist(x[r], x[ar]));
                }
                uin(dp[bl][r][k][0], dp[l][r][k][1] + dist(x[r], x[bl]));
                if (dp[l][r][k][1] + dist(x[r], x[bl]) <= t[bl]) {
                    uin(dp[bl][r][k + 1][0], dp[l][r][k][1] + dist(x[r], x[bl]));
                }
            }
        }
    }
    int answer = 0;
    for (int l = 1; l <= n; ++l) {
        for (int r = 1; r <= n; ++r) {
            for (int tet = 0; tet < 2; ++tet) {
                for (int k = 1; k <= n; ++k) {
                    if (dp[l][r][k][tet] < INF / 2) {
                        uax(answer, k);
                    }
                }
            }
        }
    }
    cout << answer << '\n';
    return 0;
}
// RU_023
 
 
/*
6 25
3 4 7 17 21 23
11 7 17 10 8 10
---
4


5 20
4 5 8 13 17
18 23 15 7 10
---
5

4 19
3 7 12 14
2 0 5 4
---
0

10 87
9 23 33 38 42 44 45 62 67 78
15 91 7 27 31 53 12 91 89 46
---
5


*/



# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 764 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 5 ms 508 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 764 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 5 ms 508 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 1016 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 5 ms 760 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 1016 KB Output is correct
24 Correct 5 ms 888 KB Output is correct
25 Correct 6 ms 1016 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 5 ms 1016 KB Output is correct
30 Correct 5 ms 1016 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 5 ms 888 KB Output is correct
33 Correct 5 ms 1016 KB Output is correct
34 Correct 5 ms 1016 KB Output is correct
35 Correct 5 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 764 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 5 ms 508 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 98 ms 102384 KB Output is correct
19 Correct 61 ms 61944 KB Output is correct
20 Correct 32 ms 32888 KB Output is correct
21 Correct 57 ms 58488 KB Output is correct
22 Correct 73 ms 75896 KB Output is correct
23 Correct 27 ms 27896 KB Output is correct
24 Correct 22 ms 21880 KB Output is correct
25 Correct 27 ms 27388 KB Output is correct
26 Correct 12 ms 10360 KB Output is correct
27 Correct 28 ms 28536 KB Output is correct
28 Correct 19 ms 20344 KB Output is correct
29 Correct 27 ms 29176 KB Output is correct
30 Correct 22 ms 22904 KB Output is correct
31 Correct 27 ms 27384 KB Output is correct
32 Correct 14 ms 14328 KB Output is correct
33 Correct 25 ms 27384 KB Output is correct
34 Correct 11 ms 9720 KB Output is correct
35 Correct 24 ms 26876 KB Output is correct
36 Correct 13 ms 12664 KB Output is correct
37 Correct 26 ms 28536 KB Output is correct
38 Correct 16 ms 15608 KB Output is correct
39 Correct 27 ms 29816 KB Output is correct
40 Correct 17 ms 17400 KB Output is correct
41 Correct 127 ms 126456 KB Output is correct
42 Correct 80 ms 84984 KB Output is correct
43 Correct 126 ms 126328 KB Output is correct
44 Correct 88 ms 83960 KB Output is correct
45 Correct 130 ms 126328 KB Output is correct
46 Correct 79 ms 84924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 5 ms 760 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 764 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 5 ms 508 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 5 ms 1016 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 5 ms 760 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 1016 KB Output is correct
24 Correct 5 ms 888 KB Output is correct
25 Correct 6 ms 1016 KB Output is correct
26 Correct 5 ms 1016 KB Output is correct
27 Correct 5 ms 504 KB Output is correct
28 Correct 5 ms 760 KB Output is correct
29 Correct 5 ms 1016 KB Output is correct
30 Correct 5 ms 1016 KB Output is correct
31 Correct 5 ms 1016 KB Output is correct
32 Correct 5 ms 888 KB Output is correct
33 Correct 5 ms 1016 KB Output is correct
34 Correct 5 ms 1016 KB Output is correct
35 Correct 5 ms 1144 KB Output is correct
36 Correct 98 ms 102384 KB Output is correct
37 Correct 61 ms 61944 KB Output is correct
38 Correct 32 ms 32888 KB Output is correct
39 Correct 57 ms 58488 KB Output is correct
40 Correct 73 ms 75896 KB Output is correct
41 Correct 27 ms 27896 KB Output is correct
42 Correct 22 ms 21880 KB Output is correct
43 Correct 27 ms 27388 KB Output is correct
44 Correct 12 ms 10360 KB Output is correct
45 Correct 28 ms 28536 KB Output is correct
46 Correct 19 ms 20344 KB Output is correct
47 Correct 27 ms 29176 KB Output is correct
48 Correct 22 ms 22904 KB Output is correct
49 Correct 27 ms 27384 KB Output is correct
50 Correct 14 ms 14328 KB Output is correct
51 Correct 25 ms 27384 KB Output is correct
52 Correct 11 ms 9720 KB Output is correct
53 Correct 24 ms 26876 KB Output is correct
54 Correct 13 ms 12664 KB Output is correct
55 Correct 26 ms 28536 KB Output is correct
56 Correct 16 ms 15608 KB Output is correct
57 Correct 27 ms 29816 KB Output is correct
58 Correct 17 ms 17400 KB Output is correct
59 Correct 127 ms 126456 KB Output is correct
60 Correct 80 ms 84984 KB Output is correct
61 Correct 126 ms 126328 KB Output is correct
62 Correct 88 ms 83960 KB Output is correct
63 Correct 130 ms 126328 KB Output is correct
64 Correct 79 ms 84924 KB Output is correct
65 Correct 125 ms 114040 KB Output is correct
66 Correct 100 ms 104568 KB Output is correct
67 Correct 109 ms 100088 KB Output is correct
68 Correct 90 ms 92408 KB Output is correct
69 Correct 109 ms 112888 KB Output is correct
70 Correct 127 ms 108152 KB Output is correct
71 Correct 106 ms 109304 KB Output is correct
72 Correct 126 ms 110532 KB Output is correct
73 Correct 100 ms 102392 KB Output is correct
74 Correct 98 ms 95676 KB Output is correct
75 Correct 102 ms 105724 KB Output is correct
76 Correct 130 ms 121336 KB Output is correct
77 Correct 120 ms 121336 KB Output is correct
78 Correct 94 ms 93432 KB Output is correct
79 Correct 106 ms 96760 KB Output is correct
80 Correct 133 ms 119032 KB Output is correct
81 Correct 109 ms 97784 KB Output is correct
82 Correct 100 ms 103544 KB Output is correct
83 Correct 122 ms 126408 KB Output is correct
84 Correct 104 ms 108152 KB Output is correct
85 Correct 113 ms 117844 KB Output is correct
86 Correct 113 ms 115192 KB Output is correct
87 Correct 103 ms 105848 KB Output is correct
88 Correct 142 ms 127608 KB Output is correct
89 Correct 131 ms 127812 KB Output is correct
90 Correct 101 ms 106872 KB Output is correct
91 Correct 132 ms 127608 KB Output is correct
92 Correct 128 ms 127608 KB Output is correct
93 Correct 129 ms 125048 KB Output is correct