이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |