이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n, x, HI;
int binarySearch(int x, vector<int>& V, int d){
int hi = V.size()-1;
int lo = 0;
while(hi >= lo){
int mid = lo + (hi - lo)/2;
if((V[mid]-d) < x) lo = mid+1;
else hi = mid-1;
}
return lo;
}
int main(){
cin >> n >> x;
vector<int> nums(n);
for(int i = 0; i < n; ++i) cin >> nums[i];
vector<vector<int>> dp(2, vector<int>(1));
dp[0][0] = nums[0];
dp[1][0] = nums[0];
for(int i = 1; i < nums.size(); ++i){
int pos = binarySearch(nums[i], dp[0], x);
if(pos == dp[1].size()){
dp[1].push_back(nums[i]);
}
else dp[1][pos] = min(dp[1][pos],nums[i]);
pos = binarySearch(nums[i], dp[0], 0);
if(pos == dp[0].size()){
dp[0].push_back(nums[i]);
}
else dp[0][pos] = nums[i];
//cout << i <<" " << pos << endl;
pos = binarySearch(nums[i], dp[1], 0);
if(pos == dp[1].size()){
dp[1].push_back(nums[i]);
}
else dp[1][pos] = min(dp[1][pos], nums[i]);
}
cout << max(dp[0].size(), dp[1].size()) << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 1; i < nums.size(); ++i){
| ~~^~~~~~~~~~~~~
glo.cpp:28:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(pos == dp[1].size()){
| ~~~~^~~~~~~~~~~~~~~
glo.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if(pos == dp[0].size()){
| ~~~~^~~~~~~~~~~~~~~
glo.cpp:42:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(pos == dp[1].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... |