#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1000006;
int n;
int a[N];
bool color[N];
int main()
{
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 1;
bool f = false;
for (int i = n - 1; i > 0; i--) {
color[a[i]] = true;
if (a[i] == a[i - 1] + 1)
continue;
if (a[i - 1] > a[i]) {
ans++;
f = false;
continue;
}
for (int j = a[i - 1] + 1; j <= a[i]; j++) {
if (j == a[i]) {
if (f)
ans++;
f = true;
break;
}
if (!color[j]) {
ans++;
if (i == 1)
ans++;
f = false;
break;
}
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |