-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
56 lines (55 loc) · 1.57 KB
/
B.cpp
File metadata and controls
56 lines (55 loc) · 1.57 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
#include<bits/stdc++.h>
using namespace std;
#define no {cout<<"NO"<<endl;return;};
const int N = 100;
char grid[N][N];
void solve(){
memset(grid,'.',sizeof grid);
long long n;
cin >> n ;
string s;
cin >> s ;
vector<long long int >indices;
long long counter = 0;
for(int i=0;i<n;i++) {
if (s[i] != '2')
continue;
counter++;
indices.push_back(i);
}
for (int i = 0; i < s.size(); i++) {
if (s[i] != '1') continue;
for (int j2 = 0; j2 < n; j2++) {
grid[i][j2] = '=';
grid[j2][i] = '=';
}
}
for (int i = 0; i < indices.size(); i++) {
for (int j = 0; j < indices.size(); j++) {
if (i != j) {
if (grid[indices[i]][indices[j]] == '.') {
grid[indices[i]][indices[j]] = '=';
grid[indices[i]][indices[j]] = '=';
}
}
}
if (i != indices.size() - 1) {
grid[indices[i]][indices[i + 1]] = '+';
grid[indices[i + 1]][indices[i]] = '-';
} else {
grid[indices[i]][indices[0]] = '+';
grid[indices[0]][indices[i]] = '-';
}
}
if (counter <= 2 && counter)no;
cout << "YES"<<endl;
for (int i = 0; i < n; i++) {
grid[i][i] = 'X';
for (int j = 0; j < n; j++)cout << grid[i][j];cout<<endl;
}
}
signed main() {
int t;
cin>>t;
while(t--)solve();
}