제출 #1265055

#제출 시각아이디문제언어결과실행 시간메모리
1265055baotoan655Collecting Stamps 3 (JOI20_ho_t3)C++20
100 / 100
84 ms131656 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;

const int N = 205;
const long long INF = 4e18;

int n;
long long L;

long long X[N], Tm[N];

long long rightd[N], leftd[N];

int idxR[N], idxL[N];

long long dpL[N][N][N];
long long dpR[N][N][N]; 

long long distLR(long long aL, long long bR) {
    long long s = aL + bR;
    return min(s, L - s);
}

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

    file("A") else file("task");

    cin >> n >> L;
    for (int i = 1; i <= n; ++i) cin >> X[i];
    for (int i = 1; i <= n; ++i) cin >> Tm[i];

    rightd[0] = 0;
    for (int j = 1; j <= n; ++j) {
        rightd[j] = X[j];
        idxR[j] = j;
    }

    leftd[0] = 0;
    for (int i = 1; i <= n; ++i) {
        leftd[i] = L - X[n - i + 1];
        idxL[i] = n - i + 1;
    }

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                dpL[i][j][k] = dpR[i][j][k] = INF;
            }
        }
    }

    dpL[0][0][0] = dpR[0][0][0] = 0;

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j + i <= n; ++j) {
            int visited = i + j;
            for (int k = 0; k <= visited; ++k) {

                long long cur = dpL[i][j][k];
                if (cur < INF && visited < n) {
                    long long arrive = cur + (leftd[i + 1] - leftd[i]);
                    int id = idxL[i + 1];
                    int nk = k + (arrive <= Tm[id] ? 1 : 0);
                    if (dpL[i + 1][j][nk] > arrive) dpL[i + 1][j][nk] = arrive;

                    arrive = cur + distLR(leftd[i], rightd[j + 1]);
                    id = idxR[j + 1];
                    nk = k + (arrive <= Tm[id] ? 1 : 0);
                    if (dpR[i][j + 1][nk] > arrive) dpR[i][j + 1][nk] = arrive;
                }

                cur = dpR[i][j][k];
                if (cur < INF && visited < n) {
                    long long arrive = cur + (rightd[j + 1] - rightd[j]);
                    int id = idxR[j + 1];
                    int nk = k + (arrive <= Tm[id] ? 1 : 0);
                    if (dpR[i][j + 1][nk] > arrive) dpR[i][j + 1][nk] = arrive;

                    arrive = cur + distLR(leftd[i + 1], rightd[j]);
                    id = idxL[i + 1];
                    nk = k + (arrive <= Tm[id] ? 1 : 0);
                    if (dpL[i + 1][j][nk] > arrive) dpL[i + 1][j][nk] = arrive;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j + i <= n; ++j) {
            for (int k = 0; k <= n; ++k) {
                if (dpL[i][j][k] < INF || dpR[i][j][k] < INF) ans = max(ans, k);
            }
        }
    }

    cout << ans << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:29:5: note: in expansion of macro 'file'
   29 |     file("A") else file("task");
      |     ^~~~
ho_t3.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:29:5: note: in expansion of macro 'file'
   29 |     file("A") else file("task");
      |     ^~~~
ho_t3.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:29:20: note: in expansion of macro 'file'
   29 |     file("A") else file("task");
      |                    ^~~~
ho_t3.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:29:20: note: in expansion of macro 'file'
   29 |     file("A") else file("task");
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...