제출 #1282199

#제출 시각아이디문제언어결과실행 시간메모리
1282199shirokitoCollecting Stamps 3 (JOI20_ho_t3)C++20
100 / 100
136 ms176396 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 200 + 24; const ll INF = 1e18; int n; ll L; ll x[N], t[N]; ll dp[N][N][2][N]; ll dist(ll px, ll py) { return min(L - abs(px - py), abs(px - py)); } void solve() { cin >> n >> L; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = 1; i <= n; i++) cin >> t[i]; x[0] = L, t[0] = INF; x[n + 1] = L, t[n + 1] = INF; memset(dp, 0x3f, sizeof(dp)); dp[0][n + 1][0][0] = dp[0][n + 1][1][0] = 0; for (int i = 0; i <= n + 1; i++) { for (int j = n + 1; j >= i + 2; j--) { for (int p = 0; p <= 1; p++) { for (int g = 0; g <= i + (n - j + 1); g++) { ll new_t, new_g; new_t = dp[i][j][p][g] + dist(x[(p == 0 ? i : j)], x[j - 1]); new_g = g + (new_t <= t[j - 1]); dp[i][j - 1][p][g] = min(dp[i][j - 1][p][g], new_t); dp[i][j - 1][1][new_g] = min(dp[i][j - 1][1][new_g], new_t); new_t = dp[i][j][p][g] + dist(x[(p == 0 ? i : j)], x[i + 1]); new_g = g + (new_t <= t[i + 1]); dp[i + 1][j][p][g] = min(dp[i + 1][j][p][g], new_t); dp[i + 1][j][0][new_g] = min(dp[i + 1][j][0][new_g], new_t); } } } } for (int g = n; g >= 0; g--) { for (int i = 0; i <= n + 1; i++) { for (int j = n + 1; j >= i + 1; j--) { for (int p = 0; p <= 1; p++) { if (dp[i][j][p][g] < INF) { cout << g << '\n'; return; } } } } } } int main() { cin.tie(0) -> sync_with_stdio(0); #define task "joi20_ho_t3" if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int T = 1; // cin >> T; while (T--) { solve(); } }

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

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...