답안 #1088113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088113 2024-09-14T02:05:17 Z Zero_OP Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
110 ms 135544 KB
#include<bits/stdc++.h>

using namespace std;

#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(v) "[" #v " = " << (v) << "]"
#define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define rep(i, l, r) for(int i = (l); i < (r); ++i)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using ld = long double;

template<typename T> 
    bool minimize(T& a, const T& b){
        if(a > b){
            return a = b, true;
        }  return false;
    }

template<typename T>
    bool maximize(T& a, const T& b){    
        if(a < b){
            return a = b, true;
        } return false;
    }

template<int dimension, typename T>
struct tensor : public vector<tensor<dimension - 1, T>> {
    static_assert(dimension > 0, "Dimension must be positive !\n");
    template<typename... Args>
    tensor(int n = 0, Args... args) : vector<tensor<dimension - 1, T>> (n, tensor<dimension - 1, T>(args...)) {}
};
 
template<typename T>
struct tensor<1, T> : public vector<T> {
    tensor(int n = 0, T val = T()) : vector<T>(n, val) {}
};

const int MAX = 200 + 5;

int N, L, X[MAX], T[MAX];
ll dp[MAX][MAX][MAX][2];

//dp[k][i][j][atR]

void testcase(){
    cin >> N >> L;
    for(int i = 1; i <= N; ++i){
        cin >> X[i];
    }

    for(int i = 1; i <= N; ++i){
        cin >> T[i];
    }

    X[N + 1] = L;
    T[N + 1] = 1e9 + 8;

    memset(dp, 0x3f, sizeof(dp));
    ll inf = dp[0][0][0][0];

    dp[0][0][N + 1][0] = 0;
    dp[0][0][N + 1][1] = 0;

    for(int i = 0; i < N; ++i){
        for(int j = N + 1; j >= i + 2; --j){
            for(int k = 0; k <= N; ++k){
                ll cost = min(dp[k][i][j][0] + X[i + 1] - X[i], dp[k][i][j][1] + L - (X[j] - X[i + 1]));
                minimize(dp[k + (cost <= T[i + 1])][i + 1][j][0], cost);

                cost = min(dp[k][i][j][0] + L - (X[j - 1] - X[i]), dp[k][i][j][1] + (X[j] - X[j - 1]));
                minimize(dp[k + (cost <= T[j - 1])][i][j - 1][1], cost);
            }
        }
    }

    // for(int k = 0; k <= N; ++k){
    //     for(int i = 0; i <= N + 1; ++i){
    //         for(int j = i + 2; j <= N + 1; ++j){
    //             for(int atR = 0; atR < 2; ++atR){
    //                 cout << dbg(k) << dbg(i) << dbg(j) << dbg(atR) << dbg(dp[k][i][j][atR]) << '\n';
    //             }
    //         }
    //     }
    // }

    for(int k = N; k >= 1; --k){
        for(int i = 0; i <= N + 1; ++i){
            for(int j = 0; j <= N + 1; ++j){
                for(int atR = 0; atR < 2; ++atR){
                    if(dp[k][i][j][atR] < inf){
                        cout << k << '\n';
                        return;
                    }
                }
            }
        }
    }

    cout << 0 << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    file("task");

    int T = 1;
    // cin >> T;
    while(T--){
        testcase();
    }

    return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:9:55: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:111:5: note: in expansion of macro 'file'
  111 |     file("task");
      |     ^~~~
ho_t3.cpp:9:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:111:5: note: in expansion of macro 'file'
  111 |     file("task");
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 135252 KB Output is correct
2 Correct 53 ms 135252 KB Output is correct
3 Correct 53 ms 135196 KB Output is correct
4 Correct 55 ms 135248 KB Output is correct
5 Correct 55 ms 135252 KB Output is correct
6 Correct 55 ms 135252 KB Output is correct
7 Correct 56 ms 135248 KB Output is correct
8 Correct 55 ms 135240 KB Output is correct
9 Correct 60 ms 135252 KB Output is correct
10 Correct 55 ms 135248 KB Output is correct
11 Correct 55 ms 135112 KB Output is correct
12 Correct 56 ms 135252 KB Output is correct
13 Correct 55 ms 135248 KB Output is correct
14 Correct 55 ms 135248 KB Output is correct
15 Correct 56 ms 135236 KB Output is correct
16 Correct 63 ms 135132 KB Output is correct
17 Correct 64 ms 135248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 135252 KB Output is correct
2 Correct 53 ms 135252 KB Output is correct
3 Correct 53 ms 135196 KB Output is correct
4 Correct 55 ms 135248 KB Output is correct
5 Correct 55 ms 135252 KB Output is correct
6 Correct 55 ms 135252 KB Output is correct
7 Correct 56 ms 135248 KB Output is correct
8 Correct 55 ms 135240 KB Output is correct
9 Correct 60 ms 135252 KB Output is correct
10 Correct 55 ms 135248 KB Output is correct
11 Correct 55 ms 135112 KB Output is correct
12 Correct 56 ms 135252 KB Output is correct
13 Correct 55 ms 135248 KB Output is correct
14 Correct 55 ms 135248 KB Output is correct
15 Correct 56 ms 135236 KB Output is correct
16 Correct 63 ms 135132 KB Output is correct
17 Correct 64 ms 135248 KB Output is correct
18 Correct 60 ms 135124 KB Output is correct
19 Correct 57 ms 135248 KB Output is correct
20 Correct 61 ms 135252 KB Output is correct
21 Correct 61 ms 135252 KB Output is correct
22 Correct 57 ms 135252 KB Output is correct
23 Correct 65 ms 135252 KB Output is correct
24 Correct 58 ms 135148 KB Output is correct
25 Correct 56 ms 135248 KB Output is correct
26 Correct 59 ms 135216 KB Output is correct
27 Correct 55 ms 135248 KB Output is correct
28 Correct 55 ms 135176 KB Output is correct
29 Correct 55 ms 135148 KB Output is correct
30 Correct 58 ms 135304 KB Output is correct
31 Correct 54 ms 135248 KB Output is correct
32 Correct 56 ms 135436 KB Output is correct
33 Correct 55 ms 135248 KB Output is correct
34 Correct 55 ms 135252 KB Output is correct
35 Correct 59 ms 135064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 135252 KB Output is correct
2 Correct 53 ms 135252 KB Output is correct
3 Correct 53 ms 135196 KB Output is correct
4 Correct 55 ms 135248 KB Output is correct
5 Correct 55 ms 135252 KB Output is correct
6 Correct 55 ms 135252 KB Output is correct
7 Correct 56 ms 135248 KB Output is correct
8 Correct 55 ms 135240 KB Output is correct
9 Correct 60 ms 135252 KB Output is correct
10 Correct 55 ms 135248 KB Output is correct
11 Correct 55 ms 135112 KB Output is correct
12 Correct 56 ms 135252 KB Output is correct
13 Correct 55 ms 135248 KB Output is correct
14 Correct 55 ms 135248 KB Output is correct
15 Correct 56 ms 135236 KB Output is correct
16 Correct 63 ms 135132 KB Output is correct
17 Correct 64 ms 135248 KB Output is correct
18 Correct 82 ms 135312 KB Output is correct
19 Correct 69 ms 135248 KB Output is correct
20 Correct 60 ms 135248 KB Output is correct
21 Correct 67 ms 135248 KB Output is correct
22 Correct 73 ms 135076 KB Output is correct
23 Correct 60 ms 135248 KB Output is correct
24 Correct 57 ms 135236 KB Output is correct
25 Correct 59 ms 135068 KB Output is correct
26 Correct 62 ms 135248 KB Output is correct
27 Correct 61 ms 135248 KB Output is correct
28 Correct 66 ms 135172 KB Output is correct
29 Correct 67 ms 135252 KB Output is correct
30 Correct 64 ms 135136 KB Output is correct
31 Correct 65 ms 135252 KB Output is correct
32 Correct 60 ms 135248 KB Output is correct
33 Correct 69 ms 135112 KB Output is correct
34 Correct 62 ms 135252 KB Output is correct
35 Correct 68 ms 135248 KB Output is correct
36 Correct 58 ms 135248 KB Output is correct
37 Correct 60 ms 135300 KB Output is correct
38 Correct 59 ms 135180 KB Output is correct
39 Correct 70 ms 135252 KB Output is correct
40 Correct 61 ms 135068 KB Output is correct
41 Correct 90 ms 135252 KB Output is correct
42 Correct 80 ms 135248 KB Output is correct
43 Correct 91 ms 135248 KB Output is correct
44 Correct 80 ms 135248 KB Output is correct
45 Correct 92 ms 135252 KB Output is correct
46 Correct 81 ms 135248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 135252 KB Output is correct
2 Correct 53 ms 135252 KB Output is correct
3 Correct 53 ms 135196 KB Output is correct
4 Correct 55 ms 135248 KB Output is correct
5 Correct 55 ms 135252 KB Output is correct
6 Correct 55 ms 135252 KB Output is correct
7 Correct 56 ms 135248 KB Output is correct
8 Correct 55 ms 135240 KB Output is correct
9 Correct 60 ms 135252 KB Output is correct
10 Correct 55 ms 135248 KB Output is correct
11 Correct 55 ms 135112 KB Output is correct
12 Correct 56 ms 135252 KB Output is correct
13 Correct 55 ms 135248 KB Output is correct
14 Correct 55 ms 135248 KB Output is correct
15 Correct 56 ms 135236 KB Output is correct
16 Correct 63 ms 135132 KB Output is correct
17 Correct 64 ms 135248 KB Output is correct
18 Correct 60 ms 135124 KB Output is correct
19 Correct 57 ms 135248 KB Output is correct
20 Correct 61 ms 135252 KB Output is correct
21 Correct 61 ms 135252 KB Output is correct
22 Correct 57 ms 135252 KB Output is correct
23 Correct 65 ms 135252 KB Output is correct
24 Correct 58 ms 135148 KB Output is correct
25 Correct 56 ms 135248 KB Output is correct
26 Correct 59 ms 135216 KB Output is correct
27 Correct 55 ms 135248 KB Output is correct
28 Correct 55 ms 135176 KB Output is correct
29 Correct 55 ms 135148 KB Output is correct
30 Correct 58 ms 135304 KB Output is correct
31 Correct 54 ms 135248 KB Output is correct
32 Correct 56 ms 135436 KB Output is correct
33 Correct 55 ms 135248 KB Output is correct
34 Correct 55 ms 135252 KB Output is correct
35 Correct 59 ms 135064 KB Output is correct
36 Correct 82 ms 135312 KB Output is correct
37 Correct 69 ms 135248 KB Output is correct
38 Correct 60 ms 135248 KB Output is correct
39 Correct 67 ms 135248 KB Output is correct
40 Correct 73 ms 135076 KB Output is correct
41 Correct 60 ms 135248 KB Output is correct
42 Correct 57 ms 135236 KB Output is correct
43 Correct 59 ms 135068 KB Output is correct
44 Correct 62 ms 135248 KB Output is correct
45 Correct 61 ms 135248 KB Output is correct
46 Correct 66 ms 135172 KB Output is correct
47 Correct 67 ms 135252 KB Output is correct
48 Correct 64 ms 135136 KB Output is correct
49 Correct 65 ms 135252 KB Output is correct
50 Correct 60 ms 135248 KB Output is correct
51 Correct 69 ms 135112 KB Output is correct
52 Correct 62 ms 135252 KB Output is correct
53 Correct 68 ms 135248 KB Output is correct
54 Correct 58 ms 135248 KB Output is correct
55 Correct 60 ms 135300 KB Output is correct
56 Correct 59 ms 135180 KB Output is correct
57 Correct 70 ms 135252 KB Output is correct
58 Correct 61 ms 135068 KB Output is correct
59 Correct 90 ms 135252 KB Output is correct
60 Correct 80 ms 135248 KB Output is correct
61 Correct 91 ms 135248 KB Output is correct
62 Correct 80 ms 135248 KB Output is correct
63 Correct 92 ms 135252 KB Output is correct
64 Correct 81 ms 135248 KB Output is correct
65 Correct 88 ms 135248 KB Output is correct
66 Correct 88 ms 135252 KB Output is correct
67 Correct 81 ms 135248 KB Output is correct
68 Correct 83 ms 135312 KB Output is correct
69 Correct 86 ms 135116 KB Output is correct
70 Correct 81 ms 135212 KB Output is correct
71 Correct 90 ms 135248 KB Output is correct
72 Correct 97 ms 135248 KB Output is correct
73 Correct 91 ms 135252 KB Output is correct
74 Correct 86 ms 135188 KB Output is correct
75 Correct 83 ms 135080 KB Output is correct
76 Correct 100 ms 135256 KB Output is correct
77 Correct 108 ms 135252 KB Output is correct
78 Correct 88 ms 135248 KB Output is correct
79 Correct 85 ms 135144 KB Output is correct
80 Correct 88 ms 135248 KB Output is correct
81 Correct 89 ms 135544 KB Output is correct
82 Correct 90 ms 135320 KB Output is correct
83 Correct 110 ms 135252 KB Output is correct
84 Correct 96 ms 135252 KB Output is correct
85 Correct 99 ms 135248 KB Output is correct
86 Correct 102 ms 135160 KB Output is correct
87 Correct 93 ms 135252 KB Output is correct
88 Correct 91 ms 135248 KB Output is correct
89 Correct 91 ms 135248 KB Output is correct
90 Correct 90 ms 135092 KB Output is correct
91 Correct 89 ms 135252 KB Output is correct
92 Correct 92 ms 135308 KB Output is correct
93 Correct 96 ms 135252 KB Output is correct