제출 #201409

#제출 시각아이디문제언어결과실행 시간메모리
201409karmaCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
1026 ms521848 KiB
#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; }

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

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);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...