# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480188 | NachoLibre | Po (COCI21_po) | C++17 | 53 ms | 6084 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define sz(x) ((int)x.size())
using namespace std;
// mt19937 rnd(time(0));
// int R(int l, int r) {
// return l + rnd() % (r - l + 1);
// }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; // n = 5;
cin >> n;
vector<int> a(n + 1);
vector<pair<int, int>> b(n + 1);
for(int i = 1; i <= n; ++i) {
// a[i] = R(0, 10);
cin >> a[i];
b[i].first = a[i];
b[i].second = i;
}
sort(b.begin() + 1, b.end());
set<int> s;
s.insert(n + 1);
int ans = 0;
for(int i = 1; i <= n; ) {
int j = i;
for(int k = i; k <= n; ++k) {
if(b[k].first != b[i].first) break;
j = k;
}
if(b[i].first) ++ans;
for(int k = i + 1; k <= j; ++k) {
int x = *s.upper_bound(b[k - 1].second);
int y = *s.upper_bound(b[k].second);
ans += (x != y);
}
for(int k = i; k <= j; ++k) {
s.insert(b[k].second);
}
i = j + 1;
}
cout << ans << endl;
// vector<vector<int>> dp(n + 1, vector<int>(n + 1));
// for(int z = 0; z < n; ++z) {
// for(int i = 1; i + z <= n; ++i) {
// int j = i + z;
// int mn = 1e9;
// for(int k = i; k <= j; ++k) {
// mn = min(mn, a[k]);
// }
// if(mn) dp[i][j] = 1;
// int w = i;
// for(int k = i; k <= j + 1; ++k) {
// if(a[k] == mn || k == j + 1) {
// if(w < k) {
// dp[i][j] += dp[w][k - 1];
// }
// w = k + 1;
// }
// }
// for(int k = i; k < j; ++k) {
// dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
// }
// }
// }
// cout << dp[1][n] << endl;
// for(int i = 1; i <= n; ++i) {
// cout << a[i] << " ";
// }
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |