#include <bits/stdc++.h>
using namespace std;
const int N=1000006;
pair <int,int> a[N];
bool r[N];
int ans=1;
void check(int i,int mi){
if (r[a[i].second]){
r[a[mi].second+1]=false;
r[a[i].second+1]=true;
}
else{
if (a[i].second < a[mi].second){
r[a[mi].second + 1] = false;
r[a[i].second + 1] = true;
}
else{
r[a[i].second + 1] = true;
}
ans++;
}
}
int main(){
ios_base::sync_with_stdio(false);
//freopen("money.in","r",stdin);
//freopen("money.out","w",stdout);
int n,j,h=0;
cin>>n;
for (int i = 0; i < n; i++){
int k;
cin>>k;
if (h!=0 & k==a[h-1].first){
continue;
}
a[h].first=k;
a[h].second=h;
h++;
}
n=h;
sort(a,a+n);
r[a[0].second+1]=true;
j=1;
while (a[j].first==a[j-1].first){
check(j,j-1);
j++;
}
while(j<n){
//cout<<j<<endl;
int l=j;
j++;
while (a[j].first==a[j-1].first){
j++;
}
j--;
int k=j;
bool mb=false;
//cout<<r[a[4].second]<<endl;
while (r[a[j].second]){
if (j==k){
check(j,l-1);
//cout<<"Alex"<<endl;
mb=true;
}
else check(j,j+1);
j--;
}
for (int i=l;i<=j;i++){
if (i==l && mb){
check(i,j+1);
}
else{
//cout<<"alex"<<endl;
check(i,i-1);
}
}
j=k+1;
}
cout<<ans<<endl;
return 0;
}
Compilation message
money.cpp: In function 'int main()':
money.cpp:35:8: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
if (h!=0 & k==a[h-1].first){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10964 KB |
Output is correct |
2 |
Correct |
0 ms |
10964 KB |
Output is correct |
3 |
Correct |
0 ms |
10964 KB |
Output is correct |
4 |
Correct |
0 ms |
10964 KB |
Output is correct |
5 |
Correct |
0 ms |
10964 KB |
Output is correct |
6 |
Correct |
0 ms |
10964 KB |
Output is correct |
7 |
Correct |
0 ms |
10964 KB |
Output is correct |
8 |
Correct |
0 ms |
10964 KB |
Output is correct |
9 |
Correct |
0 ms |
10964 KB |
Output is correct |
10 |
Correct |
0 ms |
10964 KB |
Output is correct |
11 |
Correct |
0 ms |
10964 KB |
Output is correct |
12 |
Correct |
0 ms |
10964 KB |
Output is correct |
13 |
Correct |
0 ms |
10964 KB |
Output is correct |
14 |
Correct |
0 ms |
10964 KB |
Output is correct |
15 |
Correct |
0 ms |
10964 KB |
Output is correct |
16 |
Incorrect |
0 ms |
10964 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10964 KB |
Output is correct |
2 |
Correct |
0 ms |
10964 KB |
Output is correct |
3 |
Correct |
0 ms |
10964 KB |
Output is correct |
4 |
Correct |
0 ms |
10964 KB |
Output is correct |
5 |
Correct |
0 ms |
10964 KB |
Output is correct |
6 |
Correct |
0 ms |
10964 KB |
Output is correct |
7 |
Correct |
0 ms |
10964 KB |
Output is correct |
8 |
Correct |
0 ms |
10964 KB |
Output is correct |
9 |
Correct |
0 ms |
10964 KB |
Output is correct |
10 |
Correct |
0 ms |
10964 KB |
Output is correct |
11 |
Correct |
0 ms |
10964 KB |
Output is correct |
12 |
Correct |
0 ms |
10964 KB |
Output is correct |
13 |
Correct |
0 ms |
10964 KB |
Output is correct |
14 |
Correct |
0 ms |
10964 KB |
Output is correct |
15 |
Correct |
0 ms |
10964 KB |
Output is correct |
16 |
Incorrect |
0 ms |
10964 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10964 KB |
Output is correct |
2 |
Correct |
0 ms |
10964 KB |
Output is correct |
3 |
Correct |
0 ms |
10964 KB |
Output is correct |
4 |
Correct |
0 ms |
10964 KB |
Output is correct |
5 |
Correct |
0 ms |
10964 KB |
Output is correct |
6 |
Correct |
0 ms |
10964 KB |
Output is correct |
7 |
Correct |
0 ms |
10964 KB |
Output is correct |
8 |
Correct |
0 ms |
10964 KB |
Output is correct |
9 |
Correct |
0 ms |
10964 KB |
Output is correct |
10 |
Correct |
0 ms |
10964 KB |
Output is correct |
11 |
Correct |
0 ms |
10964 KB |
Output is correct |
12 |
Correct |
0 ms |
10964 KB |
Output is correct |
13 |
Correct |
0 ms |
10964 KB |
Output is correct |
14 |
Correct |
0 ms |
10964 KB |
Output is correct |
15 |
Correct |
0 ms |
10964 KB |
Output is correct |
16 |
Incorrect |
0 ms |
10964 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10964 KB |
Output is correct |
2 |
Correct |
0 ms |
10964 KB |
Output is correct |
3 |
Correct |
0 ms |
10964 KB |
Output is correct |
4 |
Correct |
0 ms |
10964 KB |
Output is correct |
5 |
Correct |
0 ms |
10964 KB |
Output is correct |
6 |
Correct |
0 ms |
10964 KB |
Output is correct |
7 |
Correct |
0 ms |
10964 KB |
Output is correct |
8 |
Correct |
0 ms |
10964 KB |
Output is correct |
9 |
Correct |
0 ms |
10964 KB |
Output is correct |
10 |
Correct |
0 ms |
10964 KB |
Output is correct |
11 |
Correct |
0 ms |
10964 KB |
Output is correct |
12 |
Correct |
0 ms |
10964 KB |
Output is correct |
13 |
Correct |
0 ms |
10964 KB |
Output is correct |
14 |
Correct |
0 ms |
10964 KB |
Output is correct |
15 |
Correct |
0 ms |
10964 KB |
Output is correct |
16 |
Incorrect |
0 ms |
10964 KB |
Output isn't correct |