CF803E.Roma and Poker

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.

Last evening Roma started to play poker. He decided to spend no more than k virtual bourles — he will stop immediately if the number of his loses exceeds the number of his wins by k. Also Roma will leave the game if he wins enough money for the evening, i.e. if the number of wins exceeds the number of loses by k.

Next morning Roma found a piece of paper with a sequence on it representing his results. Roma doesn't remember the results exactly, and some characters in the sequence are written in a way such that it's impossible to recognize this character, so Roma can't recall whether he won k bourles or he lost.

The sequence written by Roma is a string s consisting of characters W (Roma won the corresponding hand), L (Roma lost), D (draw) and ? (unknown result). Roma wants to restore any valid sequence by changing all ? characters to W, L or D. The sequence is called valid if all these conditions are met:

  • In the end the absolute difference between the number of wins and loses is equal to k;
  • There is no hand such that the absolute difference before this hand was equal to k.

Help Roma to restore any such sequence.

每天晚上,罗玛都会在他最喜爱的网站上玩在线扑克。该网站的扑克规则有些特别:每局游戏始终只有两名玩家,不进行下注,胜者从败者处赢得 1 个虚拟布尔(bourle)。

昨晚,罗玛开始玩扑克。他决定最多只输掉 kk 个虚拟布尔——即一旦他的失败次数超出胜利次数达到 kk,他将立即停止游戏。此外,若他当晚赢够了钱(即胜利次数超出失败次数达到 kk),他也会离开游戏。

第二天早上,罗玛发现了一张纸,上面记录着他昨晚的游戏结果序列。但罗玛已记不清具体结果,且序列中部分字符书写模糊,无法辨认,因此他无法确定自己当时是赢了还是输了。

罗玛写下的序列是一个字符串 ss,由以下字符组成:W(罗玛赢了该局)、L(罗玛输了该局)、D(平局)和 ?(结果未知)。罗玛希望通过对所有 ? 字符替换为 W、L 或 D,还原出任意一个合法序列。该序列被称为合法,当且仅当满足以下两个条件:

  • 最终,胜利次数与失败次数之差的绝对值恰好等于 kk;
  • 在整个序列中,不存在某一手牌使得在该手牌之前(即截至前一手),胜利次数与失败次数之差的绝对值已等于 kk。

请帮助罗玛还原出任意一个满足上述条件的序列。

输入格式

The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000).

The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.

第一行包含两个数字 nn(Roma 序列的长度)和 kk(1≤n,k≤10001 \leq n, k \leq 1000)。

第二行包含一个由字符 W、L、D 和 ? 组成的序列 ss。该序列恰好包含 nn 个字符。

输出格式

If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO.

Otherwise print this sequence. If there are multiple answers, print any of them.

如果无法通过将字符串 s 中的所有 ? 字符替换为 W、L 或 D 来得到一个合法序列,则输出 NO。

否则,输出该序列。若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3 2
    L??

    输出#1

    LDL
  • 输入#2

    3 1
    W??

    输出#2

    NO
  • 输入#3

    20 5
    ?LLLLLWWWWW?????????

    输出#3

    WLLLLLWWWWWWWWLWLWDW

输入解题思路,AI测评打分。不知道怎么写?

首页