답안 #579611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579611 2022-06-19T13:28:25 Z LOLOLO Rabbit Carrot (LMIO19_triusis) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
vector<ll>fen;
ll sz;
void upd(ll i,ll x){
    while(i<sz){
        fen[i]=min(fen[i],x);
        i+=i&(-i);
    }
}

int cal(int i){
    ll v=1e9;
    while(i<sz){
        v=min(v,fen[i]);
        i+=i&(-i);
    }
    return v;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>A;
    vector<int>h(n+1);
    A.push_back(0);
    A.push_back(-(n+1)*m);
    for(int i=1;i<=n;i++){
        cin>>h[i];
        A.push_back(h[i]-i*m);
    }
    h.push_back(0);

    sort(A.begin(),A.end());
    vector<ll>dp(n+10000+1,1e9);
    fen=dp;
    sz=n+10000+1;
    fen=dp;
    dp[0]=0;
    upd(upper_bound(A.begin(),A.end(),0)-A.begin(),0);
    for(int i=1;i<=n+1;i++){
        ll pos=upper_bound(A.begin(),A.end(),h[i])-A.begin();
        ll val=cal(pos);
        dp[i]=val+i;
        upd(pos,dp[i]-i-1);
    }
    cout<<dp[n+1]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -