# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
361216 | Sparky_09 | Collecting Stamps 3 (JOI20_ho_t3) | C++17 | 131 ms | 134636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
void usaco(string s){
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const ll inf = 1e18+9;
ll n, l;
ll a[209];
ll b[209];
ll dp[209][209][209][2];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
cin >> n >> l;
for(ll i = 1; i <= n; ++i)
cin >> a[i];
for(ll i = 1; i <= n; ++i)
cin >> b[i];
for(ll i = 0; i <= n+1; ++i)
for(ll j = 0; j <= n+1; ++j)
for(ll k = 0; k <= n+1; ++k)
for(ll m = 0; m < 2; ++m)
dp[i][j][k][m] = inf;
a[n+1] = l;
dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0;
ll ans = 0;
for(ll i = 0; i <= n+1; ++i)
for(ll j = n+1; j >= 0; --j)
for(ll k = 0; k <= n+1; ++k)
for(ll st = 0; st < 2; ++st){
if(dp[i][j][k][st] == inf) continue;
ans = max(ans, k);
if(i+1 >= j) continue;
if(st == 0){
ll t1 = dp[i][j][k][st] + a[i+1] - a[i];
if(t1 <= b[i+1])
dp[i+1][j][k+1][st] = min(dp[i+1][j][k+1][st], t1);
else
dp[i+1][j][k][st] = min(dp[i+1][j][k][st], t1);
ll t2 = dp[i][j][k][st] + a[i] + l-a[j-1];
if(t2 <= b[j-1])
dp[i][j-1][k+1][st^1] = min(dp[i][j-1][k+1][st^1], t2);
else
dp[i][j-1][k][st^1] = min(dp[i][j-1][k][st^1], t2);
}
else{
ll t1 = dp[i][j][k][st] + a[i+1] + l-a[j];
if(t1 <= b[i+1])
dp[i+1][j][k+1][st^1] = min(dp[i+1][j][k+1][st^1], t1);
else
dp[i+1][j][k][st^1] = min(dp[i+1][j][k][st^1], t1);
ll t2 = dp[i][j][k][st] + a[j] - a[j-1];
if(t2 <= b[j-1])
dp[i][j-1][k+1][st] = min(dp[i][j-1][k+1][st], t2);
else
dp[i][j-1][k][st] = min(dp[i][j-1][k][st], t2);
}
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |