Submission #676742

#TimeUsernameProblemLanguageResultExecution timeMemory
676742asteilindRabbit Carrot (LMIO19_triusis)C++17
0 / 100
1 ms256 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <set>
#include <numeric>
#include <bitset>
#include <climits>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define MOD 1000000007
using namespace std;
void setIO(string name = "") { // name is nonempty for USACO file I/O
    ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
    if(name.length()){
        freopen((name+".in").c_str(), "r", stdin); // see Input & Output
        freopen((name+".out").c_str(), "w", stdout);
    }
}
void solve()
{
    ll n; cin >> n; ll ju; cin >> ju;
    vector<ll> poles(n+1);
    vector<ll> dp(n+1,0);
    poles[0] = 0;
    forn(i,n)
    {
        cin >> poles[i+1];
    }
    dp[0] = 1;
    ll maxv = 0;
    for (int i=1 ; n>=i ; i++)
    {
        for (int j=0 ; i>j ; j++)
        {
            
            if (dp[j] != 0 && poles[i]-poles[j] <= ju)
            {
                dp[i] = max(dp[i],dp[j]+1);
                maxv = max(dp[i],maxv)-1;
            }
        }
    }
    cout << n-maxv << endl;
    }

int main()
{
    setIO();
    solve();
}


Compilation message (stderr)

triusis.cpp: In function 'void setIO(std::string)':
triusis.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name+".in").c_str(), "r", stdin); // see Input & Output
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen((name+".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...