# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
512355 |
2022-01-16T09:55:45 Z |
Kaguya |
Po (COCI21_po) |
C++17 |
|
1000 ms |
6992 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
#pragma GCC optimize("-Ofast")
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
bool have = false;
for (auto& t : a) {
cin >> t;
if (t == 0)
have = true;
}
vector<int> ve;
for (int i = 0; i < n; i++)
ve.push_back(a[i]);
sort(ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
for (int i = 0; i < n; i++) {
a[i] = lower_bound(ve.begin(), ve.end(), a[i]) - ve.begin();
}
int ans = 0;
vector<int> se;
vector<bool> vis(n, false);
vector<bool> was(n + 11, false);
for (int i = 0; i < n; i++)
if (!was[a[i]]) {
se.push_back(a[i]);
was[a[i]] = true;
}
sort(se.rbegin(), se.rend());
vector<int> pos[n + 2];
for (int i = 0; i < n; i++)
pos[a[i]].push_back(i);
if (!have) {
ans += 1;
se.pop_back();
}
for (int i = 0; i < n; i++)
if (have && a[i] == 0)
vis[i] = true;
if (have && se.back() == 0)
se.pop_back();
while (!se.empty()) {
int x = se.back();
se.pop_back();
for (auto t : pos[x]) {
if (vis[t])
continue;
vis[t] = true;
int i = t;
ans += 1;
int nw = -1;
int nw1 = -1;
int nw2 = -1;
while (i < n && a[i] >= x) {
if (a[i] > x && nw == -1)
nw = x;
if (a[i] > x && a[i] != nw && nw != -1 && nw1 == -1)
nw1 = x;
if (a[i] > x && a[i] != nw && a[i] != nw1 && nw != -1 && nw1 != -1 && nw2 == -1)
nw2 = x;
if (a[i] == nw) {
vis[i] = true;
}
if (a[i] == nw1)
vis[i] = true;
if (a[i] == nw2)
vis[i] = true;
if (a[i] < nw1)
ans += 1;
if (a[i] < nw2)
ans += 1;
if (a[i] < nw) {
ans += 1;
}
if (a[i] == x)
vis[i] = true;
i++;
}
if (a[i] == x)
vis[i] = true;
}
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
13 ms |
2240 KB |
Output is correct |
5 |
Correct |
16 ms |
3148 KB |
Output is correct |
6 |
Execution timed out |
1093 ms |
5188 KB |
Time limit exceeded |
7 |
Correct |
29 ms |
6992 KB |
Output is correct |