Submission #796992

# Submission time Handle Problem Language Result Execution time Memory
796992 2023-07-29T03:23:24 Z 12345678 Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 468 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=8;
int n, m, h[nx], v[nx], c, dp[nx], ans;

struct fenwick
{
    int d[nx];
    void add(int idx, int val)
    {
        while (idx<nx) d[idx]=min(d[idx], val), idx+=(idx&-idx);
    }
    int find(int idx)
    {
        int tmp=INT_MAX;
        while (idx>0) tmp=min(tmp, d[idx]), idx-=(idx&-idx);
        return tmp;
    }
} f;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    ans=n;
    for (int i=1; i<=n; i++) cin>>h[i], h[i]-=i*m, h[i]=-h[i], v[i]=h[i];
    for (int i=0; i<nx; i++) f.d[i]=1e9;
    sort(v, v+n+1);
    int id=lower_bound(v, v+n+1, 0)-v+1;
    f.add(id, -1);
    for (int i=1; i<=n; i++)
    {
        auto idx=lower_bound(v, v+n+1, h[i])-v+1;
        dp[i]=f.find(idx)+i;
        //cout<<i<<' '<<idx<<' '<<f.find(idx)<<' '<<dp[i]<<' '<<h[i]<<'\n';
        f.add(idx, dp[i]-i-1);
        ans=min(ans, dp[i]+n-i);
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Runtime error 1 ms 468 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -