#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1000003;
const int MOD = 1e9 + 7;
void solve(){
int n;
cin >> n;
ll mn = 1e14;
vector<ll> a(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
mn = min(mn, a[i]);
}
map<int, vector<int> > pos;
for(int i = 0; i < n; ++i)
pos[a[i]].push_back(i);
int x = 0;
for(int j = 0; j < n; ++j){
int cur = j;
while(a[cur] > mn and cur < n)
++cur;
if(cur != j){
j = cur - 1;
++x;
}
}
unordered_map<int, bool> mp;
for(auto k : pos[mn])
mp[k] = true;
int ans = x;
sort(a.begin(), a.end());
for(int i = 1; i < n; ++i){
if(a[i] == a[i - 1]) continue;
for(auto k : pos[a[i]]){
if(k >= 1 and mp[k - 1] and mp[k + 1]){
--x;
mp[k] = true;
continue;
}
if(k >= 1 and mp[k - 1]){
if(k == n - 1) --x;
mp[k] = true;
continue;
}
if(mp[k + 1]){
if(k == 0) --x;
mp[k] = true;
continue;
}
if(k != 0 and k != n - 1)
x++;
mp[k] = true;
}
ans = max(ans, x);
}
cout << ans << "\n";
}
int main(){
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
6272 KB |
Output is correct |
2 |
Correct |
42 ms |
6264 KB |
Output is correct |
3 |
Correct |
38 ms |
6332 KB |
Output is correct |
4 |
Correct |
33 ms |
6236 KB |
Output is correct |
5 |
Correct |
33 ms |
6364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
16692 KB |
Output is correct |
2 |
Correct |
73 ms |
16636 KB |
Output is correct |
3 |
Correct |
118 ms |
16712 KB |
Output is correct |
4 |
Correct |
115 ms |
16672 KB |
Output is correct |
5 |
Correct |
114 ms |
16724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
586 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
934 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |