Submission #892157

#TimeUsernameProblemLanguageResultExecution timeMemory
892157Peter2017Financial Report (JOI21_financial)C++14
0 / 100
286 ms394788 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"

using namespace std;

const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18 + 69;

template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}

int n;
int k;
int D;
int a[N];
int f[(int)7e3 + 2][(int)7e3 + 2];

void load(){
    cin.tie(0)->sync_with_stdio(0);
    if (fopen(name".inp", "r")){
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
}

void input(){
    cin >> n >> D;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
}

void compress(){
    vector <int> value;
    for (int i = 1; i <= n; i++)
        value.push_back(a[i]);
    sort(value.begin(), value.end());
    value.erase(unique(value.begin(), value.end()), value.end());
    for (int i = 1; i <= n; i++)
        a[i] = lower_bound(value.begin(), value.end(), a[i]) - value.begin() + 1;
    k = value.size();
}

void solve(){
    compress();
    mem(f, -0x3f);
    for (int i = 1; i <= n; i++){
        f[i][a[i]] = 1;
        for (int j = i - 1; j >= max(1, i - D); j--){
            if (a[j] < a[i])
                maxi(f[i][a[i]], f[j][a[i] - 1] + 1);
            else maxi(f[i][a[j]], f[j][a[j]]);
        }
        for (int j = 1; j <= k; j++){
            maxi(f[i][j], f[i][j - 1]);
        }
    }
    cout << f[n][k];
}

int main(){
    load();
    input();
    solve();
}

Compilation message (stderr)

Main.cpp: In function 'void load()':
Main.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(name".out", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...