Submission #901508

# Submission time Handle Problem Language Result Execution time Memory
901508 2024-01-09T13:37:57 Z OAleksa Money (IZhO17_money) C++14
0 / 100
1 ms 2396 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++) {
  	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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -