이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
const int N = 1e6 + 2;
int n;
int a[N];
vector<int> vec;
bool find(int cl, int cr) {
for (int i = 0; i < vec.size(); i++) {
}
return 0;
}
bool check(int l, int r, int cl, int cr) {
int x = upper_bound(a + l, a + r, a[cl]) - a - l;
int y = lower_bound(a + l, a + r, a[cr]) - a - l;
if (x < (r - l) && x < y)
return false;
else
return true;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = n;
int cl = 1;
vec.push_back(0);
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
ans -= i - cl;
cl = i + 1;
//sort(a + vec.back(), a + cl);
sort(a, a + cl);
continue;
}
if(!check(0, cl, cl, i + 1)) {
ans -= i - cl;
cl = i + 1;
sort(a, a + cl);
}
}
ans -= (n - cl);
cout << ans << endl;
return 0;
}
/*
6
3 6 4 5 1 2
6
1 2 2 3 4 5
4
4 1 4 5
*/
컴파일 시 표준 에러 (stderr) 메시지
money.cpp: In function 'bool find(int, int)':
money.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < vec.size(); i++) {
| ~~^~~~~~~~~~~~| # | 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... |