/// banii banii banii
/// 2 locuri in masina ca milionarii
#include <iostream>
#include <set>
using namespace std;
int n, v[1000005], ans = 1;
set <int> values;
int solve(int poz)
{
auto it = values.upper_bound(v[poz]);
int aux;
bool ok = 1;
for(aux = poz + 1; aux <= n && ok; aux++)
{
if(v[aux] < v[aux - 1])
ok = 0;
auto it2 = values.upper_bound(v[aux]);
if(it != it2)
ok = 0;
}
if(!ok)
aux--;
for(int i = poz; i < aux; i++)
values.insert(v[i]);
return aux;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> v[i];
int poz = n + 1;
for(int i = 2; i <= n && (poz == n + 1); i++)
if(v[i] < v[i - 1])
poz = i;
for(int i = 1; i < poz; i++)
values.insert(v[i]);
while(poz <= n)
{
poz = solve(poz);
ans++;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
224 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
224 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
224 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
224 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |