-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathADAMAT.java
More file actions
43 lines (41 loc) · 1.11 KB
/
Copy pathADAMAT.java
File metadata and controls
43 lines (41 loc) · 1.11 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
import java.util.*;
class Codechef {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int q = 0; q < t; q++) {
int n = sc.nextInt();
int mat[][] = new int[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
mat[i][j] = sc.nextInt();
}
}
int count=0;
int res=0;
for(int i=1; i<=n; i++){
if(mat[0][i-1]==i){
if(count>0){
if(i-count==2){
res++;
}
else{
res=res+2;
}
}
count=0;
}
else{
count++;
}
}
if(count>0 && count==n-1){
res++;
}
if(count>0 && count!=n-1){
res=res+2;
}
System.out.println(res);
}
}
}