Chess Tournament codeforces solution

For Solution

Click Here!

A chess tournament will be held soon, where nn chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.

Each of the players has their own expectations about the tournament, they can be one of two types:

  1. a player wants not to lose any game (i. e. finish the tournament with zero losses);
  2. a player wants to win at least one game.

You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it’s impossible.

Chess Tournament solution codeforces

The first line contains a single integer tt (1t2001≤t≤200) — the number of test cases.

The first line of each test case contains one integer nn (2n502≤n≤50) — the number of chess players.

The second line contains the string ss (|s|=n|s|=nsi{1,2}si∈{1,2}). If si=1si=1, then the ii-th player has expectations of the first type, otherwise of the second type.

Output

For each test case, print the answer in the following format:

In the first line, print NO if it is impossible to meet the expectations of all players.

Otherwise, print YES, and the matrix of size n×nn×n in the next nn lines.

The matrix element in the ii-th row and jj-th column should be equal to:

  • +, if the ii-th player won in a game against the jj-th player;
  • , if the ii-th player lost in a game against the jj-th player;
  • =, if the ii-th and jj-th players’ game resulted in a draw;
  • X, if i=ji=j.

Chess Tournament solution codeforces

input

Copy
3
3
111
2
21
4
2122

output

Chess Tournament solution codeforces

YES
X==
=X=
==X
NO
YES
X--+
+X++
+-X-
--+X

For Solution

Click Here!

Leave a Comment