Advertisement
Dennnhhhickk

Untitled

May 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. ll a[10000], n;
  6. int view(){
  7. cout << "No" << endl;
  8. exit(0);
  9. }
  10. int swp(ll i){
  11. ll temp;
  12. temp = a[i + 2];
  13. a[i + 2] = a[i + 1];
  14. a[i + 1] = a[i];
  15. a[i] = temp;
  16. }
  17. int swp1(ll i){
  18. if (i >= n - 2)
  19. view();
  20. ll temp;
  21. temp = a[i];
  22. a[i] = a[i + 1];
  23. a[i + 1] = a[i + 2];
  24. a[i + 2] = temp;
  25. }
  26. int doo(int i){
  27. for (int j = i; j >= 0; j -= 2){
  28. if (j >= 2 && a[j] < a[j - 2]){
  29. swp(j - 2);
  30. }
  31. else
  32. if (j >= 1 && a[j] < a[j - 1]){
  33. swp1(j - 1);
  34. break;
  35. }
  36. else
  37. if (j && a[j - 1] > a[j])
  38. view();
  39. }
  40. }
  41.  
  42. int main()
  43. {
  44. ll ind;
  45. cin >> n;
  46. for (int i = 0; i < n; i++)
  47. cin >> a[i];
  48. for (int i = 2; i < n; i++){
  49. if (a[i - 1] > a[i])
  50. doo(i);
  51. }
  52. for (int i = 2; i < n; i++){
  53. if (a[i - 1] > a[i])
  54. doo(i);
  55. }
  56. cout << "Yes" << endl;
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement