이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define v vector
#define int long long
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define ff first
#define ss second
#define inp_v(vec) for (auto &i : vec) cin >> i;
#define prt_v(vec) for (auto i : vec) cout << i << endl;
#define MS(x) memset(x, 0, sizeof(x))
#define gcd(a,b) __gcd(a, b);
#define lcm(a,b) (a*(b/gcd(a,b)))
bool chmin(int &a, int b){return b<a?a=b, true:false;}
bool chmax(int &a, int b){return b>a?a=b, true:false;}
const int maxn=2e5+5;
int N, x;
int ans=1;
void cek(vector<int>A2){
int dpp[N+1];
for(int i=1;i<=N;i++){
dpp[i]=1;
}
for(int i=2;i<=N;i++){
for(int j=i-1;j>=1;j--){
if(A2[i]>A2[j])dpp[i]=max(dpp[i], dpp[j]+1);
}
ans=max(ans, dpp[i]);
}
return;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>N>>x;
vector<int>A(N+1), dp(N+1);
for(int i=1;i<=N;i++)cin>>A[i];
if(N<=50){
for(int i=1;i<=N;i++){
for(int k=-x;k<=x;k++){
auto temp=A;
for(int j=i;j<=N;j++){
temp[j]+=k;
// for(auto isi:temp)cout<<isi<<" ";
// cout<<endl;
cek(temp);
}
}
}
cout<<ans<<endl;
}
else if(!x){
multiset<pair<int, int>>st;
dp[N]=1;
st.insert({A[N], 1});
int ans=1;
for(int i=N-1;i>=1;i--){
if(st.size()==1&&(*st.begin()).first<A[i]){
st.erase(st.begin());
st.insert({A[i], 0});
continue;
}
auto it=st.upper_bound({A[i], 0});
if(it==st.end())dp[i]=1;
else{
dp[i]=(*it).second+1;
}
ans=max(ans, dp[i]);
auto lb=st.lower_bound({A[i], 0});
if(lb!=st.end()&&(*lb).first==A[i])st.erase(lb);
st.insert({A[i], dp[i]});
}
cout<<ans<<endl;
}
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |