# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1174172 | InvMOD | Global Warming (CEOI18_glo) | C++20 | 37 ms | 3780 KiB |
#include<bits/stdc++.h>
using namespace std;
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
void solve()
{
int n,x; cin >> n >> x;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
/*
+ it's optimal to increase / decrease prefix or suffix of array
+ increase is the same as decrease
+ -> prefix LIS and suffix LDS <(")
*/
vector<int> lis, pref(n + 1), suf(n + 1);
for(int i = 1; i <= n; i++){
if(!sz(lis)){
pref[i] = 1;
lis.push_back(a[i]);
}
else{
int p = lower_bound(all(lis), a[i]) - lis.begin();
pref[i] = p + 1;
if(p == sz(lis)){
lis.push_back(a[i]);
}
else lis[p] = a[i];
}
}
vector<int> lds;
for(int i = n; i >= 1; i--){
if(!sz(lds)){
suf[i] = 1;
// increase all suffix by x
lds.push_back(-(a[i] + x));
}
else{
int place_i = lower_bound(all(lds), -a[i]) - lds.begin() - 1;
suf[i] = place_i + 2;
int p = lower_bound(all(lds), -(a[i] + x)) - lds.begin();
if(p == sz(lds)){
lds.push_back(-(a[i] + x));
}
else lds[p] = -(a[i] + x);
}
}
int answer = 0;
for(int i = 1; i <= n; i++){
answer = max(answer, pref[i] + suf[i] - 1);
}
cout << answer << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |