이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define st first
#define nd second
using lint = int64_t;
constexpr int MOD = int(1e9) + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xcfcfcfcf;
constexpr lint LINF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, d;
cin>>n>>d;
vector<int> a(n+1);
vector<int> dp(n+1, -1);
dp[0] = 0;
//dp[i] <-- max se i é o último e i > atrás
map<int,vector<int>> idOfVal;
for(int i=1; i<=n; i++){
cin>>a[i];
idOfVal[a[i]].push_back(i);
}
for(auto &[x, ids]: idOfVal){
reverse(ids.begin(), ids.end());
for(int id: ids){
//cerr<<"id "<<id<<"\n";
int last = id;
for(int j = id-1; j>=0; j--){
if(last - j > d) break;
if(dp[j] != -1){
// cerr<<"j "<<j<<"\n";
dp[id] = max(dp[id], 1 + dp[j]);
last = j;
}
}
//cerr<<"dp["<<id<<"] = "<<dp[id]<<"\n";
}
}
cout<<*max_element(dp.begin(), dp.end())<<"\n";
//j > max before
return 0;
}
/*
[ ]Leu o problema certo???
[ ]Ver se precisa de long long
[ ]Viu o limite dos fors (é n? é m?)
[ ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[ ]Testar sample
[ ]Testar casos de borda
[ ]1LL no 1LL << i
[ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# | 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... |