답안 #940929

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940929 2024-03-08T02:31:40 Z LittleOrange Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 604 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll big = 1e18;
struct BIT{
    ll n;
    vector<ll> a;
    BIT(ll N):n(N),a(N+1,0){}
    void add(ll i, ll v){
        for(;i<=n;i+=i&-i) a[i] += v;
    }
    ll get(ll i){
        ll r = 0;
        for(;i;i-=i&-i) r += a[i];
        return r;
    }
    ll get(ll l, ll r){
        if(l>r) return 0;
        return get(r)-get(l-1);
    }
};
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    ll n,l;
    cin >> n >> l;
    vector<ll> x(n),t(n);
    for(ll &i : x) cin >> i;
    for(ll &i : t) cin >> i;
    for(ll i = 0;i<n;i++) x.push_back(x[i]+l);
    for(ll i = 0;i<n;i++) t.push_back(t[i]);
    ll n2 = n*2;
    vector<vector<vector<ll>>> dpL(n+1,vector<vector<ll>>(n2,vector<ll>(n2,big))); // l r c
    vector<vector<vector<ll>>> dpR(n+1,vector<vector<ll>>(n2,vector<ll>(n2,big))); // l r c
    for(ll i = 0;i<n;i++){
        if (abs(x[i+n]-l)<=t[i+n]) dpR[1][n][i+n] = abs(x[i+n]-l);
        if (abs(l-x[i])<=t[i]) dpL[1][i][n-1] = abs(l-x[i]);
        for(ll a = n2-1;a>=0;a--){
            for(ll b = a+1;b<n2;b++){
                dpL[1][a][b] = min({dpL[1][a][b],dpL[1][a][b-1],dpL[1][a+1][b]+abs(x[a]-x[a+1])});
                dpR[1][a][b] = min({dpR[1][a][b],dpR[1][a+1][b],dpR[1][a][b-1]+abs(x[b]-x[b-1])});
            }
        }
    }
    for(ll c = 2;c<=n;c++){
        for(ll a = 0;a<n2;a++){
            for(ll b = a+1;b<n2;b++){
                ll t0 = dpR[c-1][a+1][b]+abs(x[b]-x[a]);
                if(t0<=t[a]) dpL[c][a][b] = min(dpL[c][a][b],t0);
                ll t1 = dpL[c-1][a][b-1]+abs(x[b]-x[a]);
                if(t1<=t[b]) dpR[c][a][b] = min(dpR[c][a][b],t1);
                ll t2 = dpL[c-1][a+1][b]+abs(x[a+1]-x[a]);
                if(t2<=t[a]) dpL[c][a][b] = min(dpL[c][a][b],t2);
                ll t3 = dpR[c-1][a][b-1]+abs(x[b]-x[b-1]);
                if(t3<=t[b]) dpR[c][a][b] = min(dpR[c][a][b],t3);
            }
        }
        for(ll a = n2-1;a>=0;a--){
            for(ll b = a+1;b<n2;b++){
                dpL[c][a][b] = min({dpL[c][a][b],dpL[c][a][b-1],dpL[c][a+1][b]+abs(x[a]-x[a+1])});
                dpR[c][a][b] = min({dpR[c][a][b],dpR[c][a+1][b],dpR[c][a][b-1]+abs(x[b]-x[b-1])});
            }
        }
    }
    ll ans = 0;
    for(ll c = 1;c<=n;c++){
        for(ll a = 0;a<n2;a++){
            for(ll b = a;b<n2;b++){
                if (min(dpL[c][a][b],dpR[c][a][b])<big) ans = max(ans,c);
            }
        }
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 1 ms 604 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 1 ms 604 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 1 ms 604 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 1 ms 604 KB Output isn't correct
17 Halted 0 ms 0 KB -