Untitled
unknown
plain_text
a year ago
1.2 kB
6
Indexable
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string x, d = "1111";
int n;
cin >> n;
cin >> x;
int c = sqrt(n);
char m[c][c];
if (c * c != n)
cout << "No\n";
else if (n == 4 && x == d)
cout << "Yes\n";
else {
int z = 0;
for (int i = 0; i < c; i++) {
for (int k = 0; k < c; k++) {
m[i][k] = x[z++];
}
}
bool f = true;
for (int i = 0; i < c; ++i) {
if (m[0][i] != '1' || m[i][0] != '1' || m[c - 1][i] != '1' || m[i][c - 1] != '1')
f = false;
}
for (int b = 1; b < (c - 1); b++) {
for (int j = 1; j < (c - 1); j++) {
if (m[b][j] != '0')
f = false;
}
}
if (f)
cout << "Yes\n";
else
cout << "No\n";
}
}
return 0;
}
Editor is loading...
Leave a Comment