This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #cheat_when_I_was_young
// #cheatkhitacontre #khionhatoicheat
// #thaycuckythatvong
#include "bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
const int NM = 3e5 + 5;
int n, d, a[NM], res;
vector<int> lis, tmp = {0}, in = {0};
int value() {
int m = tmp.size() - 1;
int ma[m+1];
ma[0] = 0;
for (int i = 2; i <= m; ++i) if (in[i] - in[i-1] > d) return 0;
for (int i = 1; i <= m; ++i) ma[i] = max(ma[i-1], tmp[i]);
int ans = 0;
for (int i = 1; i <= m; ++i) if (tmp[i] > ma[i-1]) ++ans;
return ans;
}
void backtrack(int x) {
if (x == n) {
tmp.push_back(a[n]);
in.push_back(n);
res = max(res, value());
tmp.pop_back();
in.pop_back();
return;
}
backtrack(x+1);
tmp.push_back(a[x]);
in.push_back(x);
backtrack(x+1);
tmp.pop_back();
in.pop_back();
}
signed main() {
IOS;
cin >> n >> d;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n <= 20) {
backtrack(1);
cout << res;
return 0;
}
if (d == n) {
for (int i = 1; i <= n; ++i) {
if (!lis.size() || lis.back() < a[i]) lis.push_back(a[i]);
else *lower_bound(lis.begin(), lis.end(), a[i]) = a[i];
}
cout << lis.size();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |