이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n, x;
void print(int v[]){
for(int i = 0; i < n; ++i) cout << " " << v[i];
cout << endl;
}
int binarySearch(int x, int arr[]){
int lo = 0, hi = n;
int ans = 0;
while(hi >= lo){
int mid = lo + (hi-lo)/2;
if(arr[mid] <= x) {
lo = mid+1;
ans = mid;
}
else{
hi = mid-1;
}
}
return ans;
}
int main(){
cin >> n >> x;
int V[n];
int endWithLength[n];
for(int i = 0; i < n; ++i) cin >> V[i];
memset(endWithLength, 1e9+1, sizeof(endWithLength));
endWithLength[0] = V[0];
int ans = 0;
for(int i = 1; i < n; ++i){
int pos = binarySearch((long long)V[i], endWithLength);
//cout << "i " << i << " || value " << V[i] << " || pos1 " << pos;
endWithLength[pos] = V[i];
ans = max(ans, pos);
//print(endWithLength);
}
cout << ans+1 << 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... |