답안 #684661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684661 2023-01-22T09:26:08 Z vicious Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 980 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 210;
const ll INF=1e18;
int n,l;
int a[N],t[N];
ll dp[N][N][N][2],opt[N],ans;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(ios::badbit|ios::failbit);
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> t[i];
    for (int i = 0; i <= n+1; ++i) {
        for (int j = 0; j <= n+1; ++j) {
            for (int k = 0; k <= n+1; ++k) {
                dp[i][j][k][0]=INF;
                dp[i][j][k][1]=INF;
            }
        }
    }
    a[n+1]=l;
    dp[0][n+1][0][0]=0;
    dp[0][n+1][0][1]=0;
    for (int i = 0; i <= n; ++i) {
        for (int j = n+1; j >= 1; --j) {
            for (int take = 1; take <= n; ++take) {
                if (i==0 && j==n+1) continue;
                if (take>n-j+i+1) continue;
                if (i && take) { // go to pref
                    ll now = dp[i-1][j][take-1][0]+a[i]-a[i-1];
                    chmin(now, dp[i-1][j][take-1][1]+l-a[j]+a[i]);
                    if (now <= t[i]) chmin(dp[i][j][take][0], now);
                    else chmin(dp[i][j][take-1][0], now);
                } 
                if (j<n+1 && take) { // go to suff
                    ll now = dp[i][j+1][take-1][1]+a[j+1]-a[j];
                    chmin(now, dp[i][j+1][take-1][0]+l-a[j]+a[i]);
                    if (now <= t[j]) chmin(dp[i][j][take][1], now);
                    else chmin(dp[i][j][take-1][1], now);
                }
            }
        }
    }
    for (int x = 1; x <= n; ++x) {
        opt[x]=INF;
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= n+1; ++j) {
                chmin(opt[x],min(dp[i][j][x][0],dp[i][j][x][1]));
            }
        }
        if (opt[x]!=INF) ans = x;
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Incorrect 1 ms 980 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Incorrect 1 ms 980 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Incorrect 1 ms 980 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Incorrect 1 ms 980 KB Output isn't correct
17 Halted 0 ms 0 KB -