Submission #526819

# Submission time Handle Problem Language Result Execution time Memory
526819 2022-02-16T08:13:50 Z shark25361 Rabbit Carrot (LMIO19_triusis) C++14
0 / 100
1 ms 460 KB
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;

#define FIO ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define for_t ll T;cin>>T;while(T--)
#define endl "\n"
#define F(a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define pb push_back

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,std::less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
*/

void sol()
{
    ll n,m;
    cin >> n >> m;
    ll a[n + 1];
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    a[0] = 0;
    vector<bool> valid(n + 1,true);
    for(int i = 1;i <= n;i++)
    {
        if(a[i] > m * i)
        {
            valid[i] = false;
        }
    }
    vector<pair<ll,ll>> dp;
    for(int i = 1;i <= n;i++)
    {
        if(valid[i])
        {
            if(dp.size() == 0)
            {
                dp.pb({a[i],i});
            }
            else
            {
                pair<ll,ll> temp = dp.back();
                if(a[i] - temp.first <= (((i) - temp.second) * m))
                {
                    dp.pb({a[i],i});
                }
                else
                {
                    ll low = 0;
                    ll high = dp.size() - 1;
                    ll ans = 0;
                    while(low <= high)
                    {
                        ll mid = (low + high)/2;
                        pair<ll,ll> temp = dp[mid];
                        if(a[i] - temp.first <= ((i - temp.second) * m))
                        {
                            ans = mid;
                            low = mid + 1;
                        }
                        else
                        {
                            high = mid - 1;
                        }
                    }
                    dp[ans + 1] = {a[i],i};
                }
            }
        }
    }
    cout << n - dp.size() << endl;
}

int main()
{
    FIO
    //freopen("time.in","r",stdin);
    //freopen("time.out","w",stdout);
    //iota(all(link),0);
    sol();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Runtime error 1 ms 460 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Runtime error 1 ms 460 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Runtime error 1 ms 460 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Runtime error 1 ms 460 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -