Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n;
- cin >> n;
- vector <int> a(n);
- for(int i = 0;i<n;++i){
- cin >> a[i];
- }
- int cur = 0;
- int ans = 1;
- int k;
- for(int i = 1;i<n;++i){
- if(i==1){
- k = a[i]-a[i-1];
- if(k%2!=0 || k==0){
- k = a[i+1]-a[i];
- ans++;
- }
- }
- else{
- if((a[i]-a[i-1])%2!=0){
- ans++;
- if(i==n-1)
- break;
- k = a[i+1]-a[i];
- }
- else{
- int kl = a[i]-a[i-1];
- if(kl!=k || k==0){
- ans++;
- if(i==n-1)
- break;
- k = a[i+1]-a[i];
- }
- }
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement