제출 #1257304

#제출 시각아이디문제언어결과실행 시간메모리
1257304proofyMoney (IZhO17_money)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>; // find_by_order((int)k) returns iterator of the kth element // order_of_key((T)key) returns the number of elements less than this key int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int& u : a) cin >> u; map<int, int> st; for (int i = 0; i < n; i++) st[a[i]] += 1; a.insert(a.begin(), 0); auto adjacent = [&](int x, int y) { if (x == y) return st[x] >= 2; if (x > y) swap(x, y); auto iter = st.lower_bound(y); if (iter == st.begin()) return false; return prev(iter)->first == x; }; auto erase_element = [&](int x) { st[x] -= 1; if (st[x] == 0) st.erase(x); }; function<int(int)> solve = [&](int i) { if (i == 0) return 0; int j = i; while (j - 1 >= 1 && a[j - 1] <= a[j] && adjacent(a[j - 1], a[j])) j -= 1; for (int k = j; k <= i; k++) erase_element(a[k]); return 1 + solve(j - 1); }; cout << solve(n) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...