forked from shauryas1ngh/codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADAMAT.cp
More file actions
77 lines (61 loc) · 1.27 KB
/
ADAMAT.cp
File metadata and controls
77 lines (61 loc) · 1.27 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<bits/stdc++.h>
#define pi 3.14159265359
#define ll long long
#define wh(t) int t;cin>>t; while(t--)
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i,a,b) for(int i=a;i<b;i++)
using namespace std;
#include<string.h>
//aditya ranaut- phoenix_aditya
const int mxn=65;
ll arr[mxn][mxn];
int checker[mxn];
void solve()
{
memset(arr,0,sizeof(arr));
memset(checker,0,sizeof(checker));
int n;
cin>>n;
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++)
{
if(arr[0][i]==(i+1))
{checker[i]=1;}
else
checker[i]=0;
}
// checker loop
// for(int i=0;i<n;i++)
// cout<<checker[i];
// cout<<endl;
// code working before this point
int curr=checker[1];
int ans=0;
for(int i=1;i<n;i++)
{
if(checker[i]==curr)
continue;
else
{
ans+=1;
curr=checker[i];
}
}
if(curr==0)
ans+=1;
cout<<ans<<endl;
}
int main()
{
speed;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
wh(t)
{solve();}
return 0;
}