forked from 21171-somesh/CodeforcesSolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1203A.cpp
More file actions
55 lines (52 loc) · 1.01 KB
/
1203A.cpp
File metadata and controls
55 lines (52 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
using namespace std;
int order[201];
int main() {
int t, n;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
scanf("%d", &order[i]);
}
bool dance = true;
for (int i = 0; i < n; ++i)
{
if ( i==n-1){
if (order[i] == n && order[0]==1) continue;
if (order[i]==order[0]-1) continue;
}
if ( order[i] == n && order[i+1] == 1 ) continue;
if ( order[i] == order[i + 1] -1 ) continue;
//printf("en el indice %d salio \n", i);
dance = false;
break;
}
if (dance)
{
printf("YES\n");
continue;
}
dance = true;
for (int i = 0; i < n; ++i)
{
if ( i==n-1){
if (order[i]==order[0]+1) continue;
if (order[i]==1 && order[0]==n) continue;
}
if ( order[i] == 1 && order[i+1] == n ) continue;
if ( order[i] == order[i + 1] +1 ) continue;
//printf("en el indice %d salio \n", i);
dance = false;
break;
}
if (dance)
{
printf("YES\n");
continue;
}
printf("NO\n");
}
}