fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define ld long double
  7.  
  8. void Free_palestine() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(NULL);
  11. cout.tie(NULL);
  12. }
  13.  
  14. const int N = 2e5 + 5;
  15. const int MOD = 1e9 + 7;
  16. const int MAXN = 1e5 + 5;
  17. int arr[MAXN];
  18.  
  19. signed main(){
  20. Free_palestine();
  21. int n; cin>>n;
  22.  
  23.  
  24. for(int i = 0; i < n; i++){
  25. cin>>arr[i];
  26. }
  27.  
  28. int left = 0;
  29. int right = n - 1;
  30. bool is_palindrome = true;
  31.  
  32. while (left < right) {
  33. if (arr[left] != arr[right]) {
  34. is_palindrome = false;
  35. break;
  36. }
  37. left++;
  38. right--;
  39. }
  40.  
  41. if (is_palindrome) {
  42. cout << "YES\n";
  43. } else {
  44. cout << "NO\n";
  45. }
  46. }
Success #stdin #stdout 0s 5320KB
stdin
5
1 3 2 3 1
stdout
YES