Guest User

Untitled

a guest
Aug 26th, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Created by lyuba on 26.08.2019.
  3. //
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main(){
  8. int q, n;
  9. int ind_min;
  10. bool flag;
  11. int arr[201];
  12. cin >> q;
  13. for (int i = 0; i < q; i++) {
  14. cin >> n;
  15. for (int j = 0; j < n; j++) {
  16. cin >> arr[j];
  17. }
  18. if (n == 1){
  19. cout << "YES";
  20. continue;
  21. }
  22. ind_min = 0;
  23. for (int j = 1; j < n; j++){
  24. if (arr[j] < arr[ind_min])
  25. ind_min = j;
  26. }
  27. flag = false;
  28. int j = ind_min + 1;
  29. while((j % n) != ind_min ){
  30. if (arr[(j) % n] == arr[(j - 1) % n] + 1)
  31. j++;
  32. else
  33. break;
  34. }
  35. if ((j % n) == ind_min){
  36. cout << "YES\n";
  37. continue;
  38. }
  39. if(ind_min == 0)
  40. j = n - 1;
  41. else
  42. j = ind_min - 1;
  43. while((j % n) != ind_min){
  44. if (arr[(j) % n] == arr[(j + 1) % n] + 1)
  45. if (j - 1 < 0)
  46. j = n - 1;
  47. else
  48. j--;
  49. else
  50. break;
  51. }
  52. if ((j % n) == ind_min){
  53. cout << "YES\n";
  54. } else
  55. cout << "NO\n";
  56. }
  57. return 0;
  58. }
RAW Paste Data