이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// IN THE NAME OF GOD
#include<bits/stdc++.h>
//#pragma GCC optimize ("O2,unroll-loops,O3,Ofast,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define endl '\n';
#define file_reading freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
typedef long double dll;
typedef unsigned long long ull;
const ll B = 2e5+7, inf = 1e18;
ll arr[B],arr2[B];
ll n,x;
ll ans_(){
vector<ll> dp(n+1,inf);
dp[0] = -inf;
dp[1] = arr[1];
ll ans = 1;
for(ll i=2; i<=n; i++){
ll ind = lower_bound(dp.begin(),dp.end(),arr[i])-dp.begin();
dp[ind] = arr[i];
ans = max(ans,ind);
}
return ans;
}
void sub1_2(){
ll ans = 1;
for(ll i=1; i<=n; i++){
for(ll j=i; j<=n; j++){
for(ll change = -x; change <= x; change++){
arr[j] = arr2[j];
arr[j]+=change;
ans = max(ans,ans_());
}
}
for(ll k=i; k<=n; k++){arr[k] = arr2[k];}
}
cout << ans << endl;
}
void sub3(){
ll ans = 1;
for(ll i=1; i<=n; i++){
vector<ll> dp;
for(ll j=1; j<=n; j++){
ll make = arr[j] + (j <= i) * -1 * x;
ll ind = lower_bound(dp.begin(),dp.end(),make)-dp.begin();
ll tool = dp.size();
if (ind < tool){dp[ind] = make;}
else{dp.push_back(make);}
}
ll tool = dp.size();
ans = max(ans,tool);
}
cout << ans << endl;
}
void solve(){
cin >> n >> x;
for(ll i=1; i<=n; i++){cin >> arr[i]; arr2[i] = arr[i];}
if (x == 0){cout << ans_() << endl; return;}
if (n <= 50 && x <= 50){sub1_2(); return;}
if (n <= 1000){sub3(); return;}
cout << 0 << endl; // cry about it
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t; t=1;
while(t--){solve();}
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... |