답안 #901510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901510 2024-01-09T13:40:07 Z OAleksa Money (IZhO17_money) C++14
0 / 100
1 ms 2548 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int N = 1e6 + 69;
int n, a[N], dp[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1;i <= n;i++) {
  	cin >> a[i];
  	dp[i] = 1e9;
  }
  set<int> st;
  dp[0] = 0;
  for (int i = 1;i <= n;i++) {
  	dp[i] = min(dp[i], dp[i - 1] + 1);
  	auto manji = st.upper_bound(a[i]);
  	auto veci = st.lower_bound(a[i]);
  	int x, y;
  	if (manji == st.begin())
  		x = -1;
  	else
  		x = *--manji;
  	if (veci == st.end())
  		y = 1e9;
  	else
  		y = *veci;
  	int j = i + 1;
  	while (j <= n && a[j] >= x && a[j] <= y && a[j] >= a[j - 1])
  		j++;
  	dp[j - 1] = min(dp[j - 1], dp[i - 1] + 1);
  	st.insert(a[i]);
  }
  cout << dp[n];
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2548 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -