#include<iostream>
using namespace std;
int n,wynik,w;
int tab[100000];
int T[100000];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int j=1;j<=n;j++)
cin>>tab[j];
for(int j=1;j<n;j++){
if(tab[j]==tab[j+1]){
//cout<<"row"<<endl;
T[j]=0;}
else if(tab[j]<tab[j+1]){
//cout<<"ros"<<endl;
T[j]=1;}
else{
//cout<<"mal"<<endl;
T[j]=-1;}
}
// jeden
for(int j=1;j<n;j++)
if(T[j-1]==2){
}
else if(j%2==0)
{
if(T[j]==1){}
//cout<<"spoko";
else{
//cout<<"chuj";
wynik++;
if(tab[j+1]!=1000000)
T[j]=2;
}
}
else
{
if(T[j]==-1){}
//cout<<"spoko";
else{
//cout<<"chuj";
wynik++;
if(tab[j+1]!=-1000000)
T[j]=2;
}
}
w=wynik;
wynik=0;
for(int j=1;j<n;j++){
if(tab[j]==tab[j+1]){
//cout<<"row"<<endl;
T[j]=0;}
else if(tab[j]<tab[j+1]){
//cout<<"ros"<<endl;
T[j]=1;}
else{
//cout<<"mal"<<endl;
T[j]=-1;}
}
for(int j=1;j<n;j++)
if(T[j-1]==2){
}
else if(j%2==1)
{
if(T[j]==1){}
//cout<<"spoko";
else{
//cout<<"chuj";
wynik++;
if(tab[j+1]!=1000000)
T[j]=2;
}
}
else
{
if(T[j]==-1){}
//cout<<"spoko";
else{
//cout<<"chuj";
wynik++;
if(tab[j+1]!=-1000000)
T[j]=2;
}
}
/*for(int j=1;j<n;j++)
cout<<T[j]<<" ";*/
//cout<<endl<<w<<" "<<wynik;
cout<<min(w,wynik);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include<iostream> using namespace std; int n,wynik,w; int tab[100000]; int T[100000]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int j=1;j<=n;j++) cin>>tab[j]; for(int j=1;j<n;j++){ if(tab[j]==tab[j+1]){ //cout<<"row"<<endl; T[j]=0;} else if(tab[j]<tab[j+1]){ //cout<<"ros"<<endl; T[j]=1;} else{ //cout<<"mal"<<endl; T[j]=-1;} } // jeden for(int j=1;j<n;j++) if(T[j-1]==2){ } else if(j%2==0) { if(T[j]==1){} //cout<<"spoko"; else{ //cout<<"chuj"; wynik++; if(tab[j+1]!=1000000) T[j]=2; } } else { if(T[j]==-1){} //cout<<"spoko"; else{ //cout<<"chuj"; wynik++; if(tab[j+1]!=-1000000) T[j]=2; } } w=wynik; wynik=0; for(int j=1;j<n;j++){ if(tab[j]==tab[j+1]){ //cout<<"row"<<endl; T[j]=0;} else if(tab[j]<tab[j+1]){ //cout<<"ros"<<endl; T[j]=1;} else{ //cout<<"mal"<<endl; T[j]=-1;} } for(int j=1;j<n;j++) if(T[j-1]==2){ } else if(j%2==1) { if(T[j]==1){} //cout<<"spoko"; else{ //cout<<"chuj"; wynik++; if(tab[j+1]!=1000000) T[j]=2; } } else { if(T[j]==-1){} //cout<<"spoko"; else{ //cout<<"chuj"; wynik++; if(tab[j+1]!=-1000000) T[j]=2; } } /*for(int j=1;j<n;j++) cout<<T[j]<<" ";*/ //cout<<endl<<w<<" "<<wynik; cout<<min(w,wynik); } |
English