/* URL: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5026*/
#include <bits/stdc++.h>
using namespace std;
int
main ()
{
int i, j, k, n, m, t;
cin >> t;
while (t--)
{
std::vector < int >SubBlocks[26];
std::vector < int >Board[26];
std::vector < int >col[26];
cin >> n;
int len = sqrt (n);
int subBlocksIndex = 0;
for (i = 0; i < n; i++)
{
int count = 0;
for (j = 0; j < n; j++)
{
cin >> m;
Board[i].push_back (m);
SubBlocks[subBlocksIndex].push_back (m);
count++;
if(count==len){
count=0;
subBlocksIndex++;
}
}
if (SubBlocks[subBlocksIndex-1].size () != n)
{
subBlocksIndex = subBlocksIndex - (len );
}
}
string output="yes";
for(i=0;i<n;i++){
std::vector < int >temp;
temp=Board[i];
sort( temp.begin(), temp.end() );
temp.erase( unique( temp.begin(), temp.end() ), temp.end() );
if(temp.size()!=n){
output="no";
break;
}
else{
sort( SubBlocks[i].begin(), SubBlocks[i].end() );
SubBlocks[i].erase( unique( SubBlocks[i].begin(), SubBlocks[i].end() ), SubBlocks[i].end() );
if(SubBlocks[i].size()!=n){
output="no";
break;
}
else{
for(j=0;j<n;j++){
col[i].push_back(Board[j][i]);
}
sort( col[i].begin(), col[i].end() );
col[i].erase( unique( col[i].begin(), col[i].end() ), col[i].end() );
if(col[i].size()!=n){
output="no";
break;
}
}
}
}
/* for (i = 0; i < n; i++)
{
cout << "Sub Block No:" << i << endl;
for (j = 0; j < SubBlocks[i].size (); j++)
{
cout << SubBlocks[i][j] << " ";
}
cout << endl << endl;
}*/
cout<<output<<endl;
}
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.