이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
#define problemname "glo"
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define MOD (int)1e9+7
#define ll long long
#define ff first
#define ss second
bool ckmin(int& a, int b) {return a>b?a=b,true:false;}
bool ckmax(int& a, int b) {return a<b?a=b,true:false;}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen (problemname ".in", "r", stdin); freopen(problemname ".out", "w", stdout);
int n,x;cin>>n>>x;
vi a(n); for(auto& x: a) cin>>x;
vi left;
vi dp;
int ans = 0;
for(auto lmao:a) {
int pos = lower_bound(dp.begin(), dp.end(), lmao) - dp.begin();
if(pos == dp.size()) {
dp.pb(lmao);
} else {
dp[pos]=lmao;
}
left.pb(pos);
// cout<<lmao << ' '<<pos<<endl;
ckmax(ans, left[left.size()-1]);
}
// for(auto x:dp) cout<<x<<' ';
// cout<<endl;
// cout<<ans<<endl;
// cout<<"---------------"<<endl;
dp.clear();
vi right;
for(int i=n-1; i>=0; i--) {
a[i]=-a[i];
int pos = lower_bound(dp.begin(), dp.end(), a[i] + x) - dp.begin();
int ins = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(ins == dp.size()) {
dp.pb(a[i]);
} else {
dp[ins]=a[i];
}
right.pb(dp.size());
a[i]=-a[i];
ckmax(ans, left[i]+pos);
// cout<<ans<<' '<<i<<endl;
}
cout<<ans+1<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:29:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(pos == dp.size()) {
| ~~~~^~~~~~~~~~~~
glo.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if(ins == dp.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |