fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int t;
  5. scanf("%d",&t);
  6. while(t--){
  7. int n,i,prev=0,j,c=0;
  8. scanf("%d",&n);
  9. int arr[n];
  10. for(i=0;i<n;i++)
  11. scanf("%d",&arr[i]);
  12. if(n%2 != 0){
  13. for(i=0,j=n-1;i<j;i++,j--){
  14. if(i==0){
  15. if(arr[i]==arr[j] && (arr[i]-prev == 1))
  16. c++;
  17. }
  18. else{
  19. if(arr[i]==arr[j] && (arr[i]-arr[i-1] == 1))
  20. c++;
  21. }
  22. }
  23. if(c == n/2)
  24. printf("yes\n");
  25. else
  26. printf("no\n");
  27. }else{
  28. printf("no\n");
  29. }
  30.  
  31. }
  32. // your code goes here
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 9432KB
stdin
7
5
1 2 3 2 1
7
2 3 4 5 4 3 2
5
1 2 3 4 3
5
1 3 5 3 1
7
1 2 3 4 3 2 1
4
1 2 3 2
4
1 2 2 1
stdout
yes
no
no
no
yes
no
no