#include <bits/stdc++.h> using namespace std; typedef long long int ll; int a[50009]; int temp[50009]; constexpr int oo=1'000'000'009; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,best,odp; cin >> n; for (int x=0;x<n;x++){ cin >> a[x]; temp[x] = a[x]; } best = n; for (int typ=0;typ<2;typ++){ odp = 0; for (int x=0;x<n-1;x++){ if (x%2==typ){ if (temp[x] >= temp[x+1]){ temp[x+1] = oo; odp += 1; } } else{ if (temp[x] <= temp[x+1]){ temp[x+1] = -oo; odp += 1; } } } for (int x=0;x<=n;x++){ temp[x] = a[x]; } best = min(odp,best); } cout << best << '\n'; return 0; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long int ll; int a[50009]; int temp[50009]; constexpr int oo=1'000'000'009; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,best,odp; cin >> n; for (int x=0;x<n;x++){ cin >> a[x]; temp[x] = a[x]; } best = n; for (int typ=0;typ<2;typ++){ odp = 0; for (int x=0;x<n-1;x++){ if (x%2==typ){ if (temp[x] >= temp[x+1]){ temp[x+1] = oo; odp += 1; } } else{ if (temp[x] <= temp[x+1]){ temp[x+1] = -oo; odp += 1; } } } for (int x=0;x<=n;x++){ temp[x] = a[x]; } best = min(odp,best); } cout << best << '\n'; return 0; } |