fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define el "\n"
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define se second
  7. #define fi first
  8. #define be begin()
  9. #define en end()
  10. #define Faster cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
  11.  
  12. bool isZicZac(int *a, int n)
  13. {
  14. vector<int> vt;
  15. for(int i = 1; i < n; i++)
  16. {
  17. int x;
  18. if(a[i] > a[i-1]) x = 1;
  19. else if(a[i] < a[i-1]) x = 0;
  20. else return false;
  21. if(vt.size() >= 1 && vt.back() == x) return false;
  22. vt.push_back(x);
  23. }
  24. return true;
  25. }
  26.  
  27. int main()
  28. {
  29. Faster;
  30. int n; cin >> n;
  31. int *a = new int[n];
  32. for(int i = 0; i < n; i++) cin >> a[i];
  33. if(isZicZac(a,n)) cout << "True";
  34. else cout << "False";
  35. return 0;
  36. }
  37.  
  38.  
Success #stdin #stdout 0s 5292KB
stdin
3 1 4 5
stdout
False