fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool solution(vector<int> a)
  6. {
  7. int n = a.size(), p = -1, c = 0;
  8. for (int i = 1; i < n; i++)
  9. if (a[i - 1] >= a[i])
  10. p = i, c++;
  11. if (c > 1)
  12. return 0;
  13. if (c == 0)
  14. return 1;
  15. if (p == n - 1 || p == 1)
  16. return 1;
  17. if (a[p - 1] < a[p + 1])
  18. return 1;
  19. if (a[p - 2] < a[p])
  20. return 1;
  21. return 0;
  22. }
  23.  
  24. int main() {
  25. vector<int> vecInts{1, 1, 2, 3, 4, 4};
  26. cout << solution(vecInts) << endl;
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5504KB
stdin
Standard input is empty
stdout
0