A10876 | Roma and Poker
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
The second line contains the sequence $s$ consisting of characters W, L, D and ?. There are exactly $n$ characters in this sequence.
输出格式
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.
Otherwise print this sequence. If there are multiple answers, print any of them.
输入输出样例
输入 #1
3 2 L??
输出 #1
LDL
输入 #2
3 1 W??
输出 #2
NO
输入 #3
20 5 ?LLLLLWWWWW?????????
输出 #3
WLLLLLWWWWWWWWLWLWDW
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted