#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> a(n);
vector<bool> b(n,0);
for (int i = 0; i < n; i++) cin >> a[i];
int ans = 0;
for (int i = 0; i < n; i++) {
if (b[i]) continue;
b[i] = 1;
int h = a[i] - 1;
for (int j = i + 1; j < n; j++) {
if (a[j] == h && !b[j]) {
b[j] = 1;
h--;
}
}
ans++;
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
444 ms |
3484 KB |
Output is correct |
6 |
Correct |
963 ms |
3868 KB |
Output is correct |
7 |
Correct |
875 ms |
3244 KB |
Output is correct |
8 |
Correct |
879 ms |
3208 KB |
Output is correct |
9 |
Correct |
635 ms |
3364 KB |
Output is correct |
10 |
Correct |
873 ms |
3492 KB |
Output is correct |