Monk and Inversions






using System;
public class Solution
{
public static void Main()
{
int T = Convert.ToInt32(Console.ReadLine());
for(int i=0; i<T; i++)
{
int N= Convert.ToInt32(Console.ReadLine());
int row= N;
int col=N;
int[ , ] M = new int[row,col];
//for( int line=0; line < N;line++)
//{
for ( int l = 0; l < row; i++ )
{
for ( int j = 0; j < col; j++ )
{
//M[ i, j ] = Convert.ToInt32(Console.Read());
M[ l, j ] = Convert.ToInt32(Console.ReadLine());

}
}
// }
int count = 0;
for(int d =0; i<row;i++)
{
for(int j=0;j<col;j++)
{
if((d <= d+1) && (j <= j+1))
{
if(M[d,j] > M[i+1, j+1])
{
count = count+1;
}
}
}
}
/*
int count = 0;
for(int j=0; j<row; j++)
{
for(int k=0; k<col; k++)
{
for(int l=j; l<row; l++)
{
for(int m=k; m<col; m++)
{
if(M[j][k] >= M[l][m])
{
count++;
}
}
}
}
}
*/
Console.WriteLine(count);
}
}
}

No comments:

Post a Comment

Monk and Inversions

using System; public class Solution { public static void Main () { int T = Convert . ToInt32 ( Console . ReadLine...