-
Notifications
You must be signed in to change notification settings - Fork 6
/
grid challenge.cpp
57 lines (49 loc) · 936 Bytes
/
grid challenge.cpp
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
56
57
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<cstring>
using namespace std;
#define MAX 101
void calculate()
{
int n;
cin>>n;
char arr[n][n];
int flag=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>arr[i][j];
}
}
for(int i=0;i<n;i++)
{
sort(arr[i],arr[i]+n);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1;j++)
{
if((arr[j][i]-'a')>(arr[j+1][i]-'a'))
{
flag=1;
printf("NO\n");
break;
}
}
if(flag==1)
break;
}
if(flag==0)
printf("YES\n");
}
int main() {
int t;
scanf("%d",&t);
while(t--)
calculate();
return 0;
}