fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define nl "\n"
  6. #define sz(x) x.size()
  7.  
  8. void fastio()
  9. {
  10. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  11. #ifndef ONLINE_JUDGE
  12. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  13. #endif
  14. }
  15.  
  16. bool is_Palindrome(int arr[], int start, int end)
  17. {
  18. if(arr[start] != arr[end])
  19. return false;
  20. is_Palindrome(arr, start + 1, end - 1);
  21. return true;
  22. }
  23.  
  24. void solve()
  25. {
  26. int n; cin >> n;
  27. int arr[n];
  28. for(int i = 0; i < n; i++)
  29. cin >> arr[i];
  30. cout << ((is_Palindrome(arr, 0, n - 1)) ? "YES\n" : "NO\n");
  31. }
  32.  
  33. int main()
  34. {
  35. fastio();
  36. int test = 1;
  37. // cin >> test;
  38. for (int tc = 1; tc <= test; tc++)
  39. solve();
  40. }
Success #stdin #stdout 0.01s 5296KB
stdin
5
1 3 2 3 1
stdout
YES