E. Chess Championship

Codeforces
IDCF736E
Time2000ms
Memory256MB
Difficulty
constructive algorithmsflowsgreedymath
English · Original
Chinese · Translation
Formal · Original
Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were _m_ players participating and each pair of players played exactly one game. The victory gives 2 points, draw — 1 points, lose — 0 points. Ostap is lazy, so he never tries to remember the outcome of each game. Instead, he computes the total number of points earned by each of the players (the sum of his points in all games which he took part in), sort these value in non-ascending order and then remembers first _n_ integers in this list. Now the Great Strategist Ostap wonders whether he remembers everything correct. He considers that he is correct if there exists at least one tournament results table such that it will produce the given integers. That means, if we count the sum of points for each player, sort them and take first _n_ elements, the result will coincide with what Ostap remembers. Can you check if such table exists? ## Input The first line of the input contains two integers _m_ and _n_ (1 ≤ _n_ ≤ _m_ ≤ 3000) — the number of participants of the tournament and the number of top results Ostap remembers. The second line contains _n_ integers, provided in non-ascending order — the number of points earned by top participants as Ostap remembers them. It's guaranteed that this integers are non-negative and do not exceed 2·_m_. ## Output If there is no tournament such that Ostap can obtain the given set of integers using the procedure described in the statement, then print "_no_" in the only line of the output. Otherwise, the first line of the output should contain the word "_yes_". Next _m_ lines should provide the description of any valid tournament. Each of these lines must contain _m_ characters '_X_', '_W_', '_D_' and '_L_'. Character '_X_' should always be located on the main diagonal (and only there), that is on the _i_\-th position of the _i_\-th string. Character '_W_' on the _j_\-th position of the _i_\-th string means that the _i_\-th player won the game against the _j_\-th. In the same way character '_L_' means loose and '_D_' means draw. The table you print must be consistent and the points earned by best _n_ participants should match the memory of Ostap. If there are many possible answers, print any of them. [samples]
Ostap 正准备再次下棋,这次他正在做赛前准备。因此,他密切关注了一场最近的国际象棋锦标赛。共有 #cf_span[m] 名选手参赛,每对选手之间恰好进行一场比赛。胜利得 #cf_span[2] 分,平局得 #cf_span[1] 分,失败得 #cf_span[0] 分。 Ostap 很懒,所以他从不试图记住每场比赛的结果。相反,他计算每位选手的总得分(即他参加的所有比赛的得分之和),将这些值按非递增顺序排序,然后只记住排序后列表中的前 #cf_span[n] 个整数。 现在,伟大的战略家 Ostap 想知道他是否记得正确。他认为自己正确,当且仅当存在至少一个锦标赛结果表,使得按照上述过程计算后得到的前 #cf_span[n] 个得分与他记忆中的完全一致。也就是说,如果我们计算每位选手的得分,排序后取前 #cf_span[n] 个元素,结果必须与 Ostap 记忆中的完全一致。你能判断这样的表是否存在吗? 输入的第一行包含两个整数 #cf_span[m] 和 #cf_span[n](#cf_span[1 ≤ n ≤ m ≤ 3000])——锦标赛的参赛人数和 Ostap 记忆的前几名结果的数量。 第二行包含 #cf_span[n] 个整数,按非递增顺序给出——Ostap 记忆中前几名选手的得分。保证这些整数非负,且不超过 #cf_span[2·m]。 如果不存在任何锦标赛结果表能使 Ostap 通过上述过程获得给定的整数集合,则在输出的唯一一行中打印 "_no_"。否则,输出的第一行应为 "_yes_",接下来的 #cf_span[m] 行应描述任意一个有效的锦标赛结果表。每行必须包含 #cf_span[m] 个字符:'_X_'、'_W_'、'_D_' 和 '_L_'。字符 '_X_' 必须始终位于主对角线上(且仅位于主对角线上),即第 #cf_span[i] 个字符串的第 #cf_span[i] 个位置。第 #cf_span[i] 个字符串的第 #cf_span[j] 个位置为 '_W_' 表示第 #cf_span[i] 位选手战胜了第 #cf_span[j] 位选手;'_L_' 表示失败,'_D_' 表示平局。 你输出的表格必须一致,且得分最高的前 #cf_span[n] 名选手的得分必须与 Ostap 的记忆一致。如果有多种可能的答案,输出任意一种即可。 ## Input 输入的第一行包含两个整数 #cf_span[m] 和 #cf_span[n](#cf_span[1 ≤ n ≤ m ≤ 3000])——锦标赛的参赛人数和 Ostap 记忆的前几名结果的数量。第二行包含 #cf_span[n] 个整数,按非递增顺序给出——Ostap 记忆中前几名选手的得分。保证这些整数非负,且不超过 #cf_span[2·m]。 ## Output 如果不存在任何锦标赛结果表能使 Ostap 通过上述过程获得给定的整数集合,则在输出的唯一一行中打印 "_no_"。否则,输出的第一行应为 "_yes_",接下来的 #cf_span[m] 行应描述任意一个有效的锦标赛结果表。每行必须包含 #cf_span[m] 个字符:'_X_'、'_W_'、'_D_' 和 '_L_'。字符 '_X_' 必须始终位于主对角线上(且仅位于主对角线上),即第 #cf_span[i] 个字符串的第 #cf_span[i] 个位置。第 #cf_span[i] 个字符串的第 #cf_span[j] 个位置为 '_W_' 表示第 #cf_span[i] 位选手战胜了第 #cf_span[j] 位选手;'_L_' 表示失败,'_D_' 表示平局。你输出的表格必须一致,且得分最高的前 #cf_span[n] 名选手的得分必须与 Ostap 的记忆一致。如果有多种可能的答案,输出任意一种即可。 [samples]
**Definitions** Let $ m, n \in \mathbb{Z} $ with $ 1 \le n \le m \le 3000 $. Let $ P = (p_1, p_2, \dots, p_n) $ be a non-increasing sequence of non-negative integers, where $ p_i \le 2(m-1) $ for all $ i \in \{1, \dots, n\} $. Let $ G = (V, E) $ be a complete directed graph with $ m $ vertices (players), where each unordered pair $ \{i,j\} $ with $ i \ne j $ has exactly one directed edge: either $ i \to j $ (win for $ i $), $ j \to i $ (win for $ j $), or both $ i \leftrightarrow j $ (draw). Each edge contributes to the point total of its endpoints: - A win gives $ 2 $ points to the winner, $ 0 $ to the loser. - A draw gives $ 1 $ point to each player. Let $ s_i \in \mathbb{Z}_{\ge 0} $ denote the total points of player $ i $, computed as the sum of points from all $ m-1 $ games. **Constraints** 1. For each pair $ i \ne j $, exactly one of the following holds: - $ a_{i,j} = \text{W} $ and $ a_{j,i} = \text{L} $, - $ a_{i,j} = \text{L} $ and $ a_{j,i} = \text{W} $, - $ a_{i,j} = \text{D} $ and $ a_{j,i} = \text{D} $. 2. $ a_{i,i} = \text{X} $ for all $ i \in \{1, \dots, m\} $. 3. The multiset $ \{s_1, s_2, \dots, s_m\} $, when sorted in non-increasing order, has its first $ n $ elements equal to $ P $. **Objective** Determine whether there exists a tournament outcome matrix $ A = (a_{i,j})_{m \times m} $ satisfying the above constraints such that the top $ n $ point totals match $ P $. If yes, output any such matrix; otherwise, output "no".
Samples
Input #1
5 5
8 6 4 2 0
Output #1
yes
XWWWW
LXWWW
LLXWW
LLLXW
LLLLX
Input #2
5 1
9
Output #2
no
API Response (JSON)
{
  "problem": {
    "name": "E. Chess Championship",
    "description": {
      "content": "Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were _m_ players participating and each pair of players ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF736E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Ostap is preparing to play chess again and this time he is about to prepare. Thus, he was closely monitoring one recent chess tournament. There were _m_ players participating and each pair of players ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Ostap 正准备再次下棋,这次他正在做赛前准备。因此,他密切关注了一场最近的国际象棋锦标赛。共有 #cf_span[m] 名选手参赛,每对选手之间恰好进行一场比赛。胜利得 #cf_span[2] 分,平局得 #cf_span[1] 分,失败得 #cf_span[0] 分。\n\nOstap 很懒,所以他从不试图记住每场比赛的结果。相反,他计算每位选手的总得分(即他参加的所有比赛的得分之和),将这些值...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ m, n \\in \\mathbb{Z} $ with $ 1 \\le n \\le m \\le 3000 $.  \nLet $ P = (p_1, p_2, \\dots, p_n) $ be a non-increasing sequence of non-negative integers, where $ p_i \\le 2(m-1) $ for ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments