Submission #676749

#TimeUsernameProblemLanguageResultExecution timeMemory
676749asteilindRabbit Carrot (LMIO19_triusis)C++17
100 / 100
27 ms8388 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);
    poles[0] = 0;
    forn(i,n)
    {
        cin >> poles[i+1];
    }
    vector<ll> b;
    for (int i=1 ; n>=i ; i++)
    {
        if (poles[i] <= ju*i)
        {
            b.push_back((i*ju-poles[i]));
        }
    }
    vector<ll> dp;
    for (int i=0 ; b.size()>i ; i++)
    {
        int pos = upper_bound(dp.begin(),dp.end(),b[i])-dp.begin();
        if (pos == dp.size())
        {
            dp.push_back(b[i]);
        }
        else
        {
            dp[pos] = b[i];
        }
    }
    cout << n-dp.size() << endl;

}

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


Compilation message (stderr)

triusis.cpp: In function 'void solve()':
triusis.cpp:45:28: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |     for (int i=0 ; b.size()>i ; i++)
      |                    ~~~~~~~~^~
triusis.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         if (pos == dp.size())
      |             ~~~~^~~~~~~~~~~~
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...