-
Notifications
You must be signed in to change notification settings - Fork 0
/
811-b.cpp
96 lines (88 loc) · 1.78 KB
/
811-b.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
#define A first
#define B second
typedef long long ll;
constexpr int MOD = 1e9 + 7;
template<typename T>
void print(const vector<T> &v, bool add_one = false, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = int(v.size());
for (int i = start; i < end; i++)
cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
void solve(){
int N;
cin >> N;
string S;
cin >> S;
int cnt = 0;
vector<int> twos;
for(int i = 0; i < N; i++) {
if(S[i] == '2') {
cnt++;
twos.push_back(i);
}
}
print(twos);
if(cnt == 1) {
cout << "NO\n";
return;
}
vector<string> ans(N);
for(int i = 0; i < N; i++) {
string T = "";
for(int j = 0; j < N; j++) T += '#';
ans[i] = T;
}
for(int i = 0; i < N; i++) {
ans[i][i] = 'X';
}
for(int i = 0; i < twos.size() - 1; i++) {
ans[twos[i]][twos[i + 1]] = '+';
ans[twos[i + 1]][twos[i]] = '-';
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
if(S[i] == '2') {
if(S[j] == '1') ans[i][j] = '-';
else if(ans[i][j] != '#') ans[i][j] = '=';
} else {
if(S[j] == '2') ans[i][j] = '+';
else ans[i][j] = '=';
}
}
}
cout << "YES\n";
for(int i = 0; i < N; i++) {
cout << ans[i] << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T;
T = 1;
cin >> T;
while(T--){
solve();
}
}