1569B.md (1946B)
1 Source: https://codeforces.com/problemset/problem/1569/B 2 3 B. Chess Tournament 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 A chess tournament will be held soon, where $n$ 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. 22 23 Each of the players has their own expectations about the tournament, they can be one of two types: 24 25 1. a player wants not to lose any game (i. e. finish the tournament with zero losses); 26 2. a player wants to win at least one game. 27 28 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. 29 30 Input 31 32 The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. 33 34 The first line of each test case contains one integer $n$ ($2 \le n \le 50$) — the number of chess players. 35 36 The second line contains the string $s$ ($|s| = n$; $s_i \in \{1, 2\}$). If $s_i = 1$, then the $i$-th player has expectations of the first type, otherwise of the second type. 37 38 Output 39 40 For each test case, print the answer in the following format: 41 42 In the first line, print NO if it is impossible to meet the expectations of all players. 43 44 Otherwise, print YES, and the matrix of size $n \times n$ in the next $n$ lines. 45 46 The matrix element in the $i$-th row and $j$-th column should be equal to: 47 48 * +, if the $i$-th player won in a game against the $j$-th player; 49 * -, if the $i$-th player lost in a game against the $j$-th player; 50 * =, if the $i$-th and $j$-th players' game resulted in a draw; 51 * X, if $i = j$. 52 53 Example 54 55 Input 56 57 ``` 58 3 59 3 60 111 61 2 62 21 63 4 64 2122 65 ``` 66 67 Output 68 69 ``` 70 YES 71 X== 72 =X= 73 ==X 74 NO 75 YES 76 X--+ 77 +X++ 78 +-X- 79 --+X 80 ```