J. Stepan's Series

Codeforces
IDCF795J
Time2000ms
Memory256MB
Difficulty
dp
English · Original
Chinese · Translation
Formal · Original
Well, the series which Stepan watched for a very long time, ended. In total, the series had _n_ episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the **maximum** number of consecutive series that Stepan did not watch. Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to _k_. ## Input The first line contains two integers _n_ and _k_ (1 ≤ _n_ ≤ 100, 0 ≤ _k_ ≤ _n_) — the number of episodes in the series and the dissatisfaction which should be checked. The second line contains the sequence which consists of _n_ symbols "_Y_", "_N_" and "_?_". If the _i_\-th symbol equals "_Y_", Stepan remembers that he has watched the episode number _i_. If the _i_\-th symbol equals "_N_", Stepan remembers that he hasn't watched the epizode number _i_. If the _i_\-th symbol equals "_?_", Stepan doesn't exactly remember if he has watched the episode number _i_ or not. ## Output If Stepan's dissatisfaction can be exactly equal to _k_, then print "_YES_" (without qoutes). Otherwise print "_NO_" (without qoutes). [samples] ## Note In the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row — the episode number 3 and the episode number 4. The answer is "_YES_", because _k_ = 2. In the second test _k_ = 1, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row — number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive.
好吧,Stepan 长时间观看的这部剧集终于结束了。该剧集总共有 #cf_span[n] 集。对于每一集,Stepan 记得自己要么肯定看过,要么肯定没看过,要么不确定是否看过。 Stepan 的不满值定义为他未观看的连续剧集的最大数量。 你的任务是根据 Stepan 的记忆,判断他的不满值是否可能恰好等于 #cf_span[k]。 第一行包含两个整数 #cf_span[n] 和 #cf_span[k](#cf_span[1 ≤ n ≤ 100],#cf_span[0 ≤ k ≤ n])——分别表示剧集总数和需要检查的不满值。 第二行包含一个由 #cf_span[n] 个字符 "_Y_"、"_N_" 和 "_?_" 组成的序列。如果第 #cf_span[i] 个字符为 "_Y_",表示 Stepan 记得他看过第 #cf_span[i] 集;如果为 "_N_",表示他记得没看过第 #cf_span[i] 集;如果为 "_?_",表示他不确定是否看过第 #cf_span[i] 集。 如果 Stepan 的不满值可以恰好等于 #cf_span[k],则输出 "_YES_"(不带引号);否则输出 "_NO_"(不带引号)。 在第一个测试用例中,Stepan 记得了所有剧集是否观看过。他的不满值为 #cf_span[2],因为他连续没看两集——第 #cf_span[3] 集和第 #cf_span[4] 集。由于 #cf_span[k = 2],答案是 "_YES_"。 在第二个测试用例中,#cf_span[k = 1],但 Stepan 的不满值至少为 #cf_span[2](因为他记得至少连续两集没看过——第 #cf_span[5] 集和第 #cf_span[6] 集),即使他观看了第 1 到第 4 集也是如此。 ## Input 第一行包含两个整数 #cf_span[n] 和 #cf_span[k](#cf_span[1 ≤ n ≤ 100],#cf_span[0 ≤ k ≤ n])——分别表示剧集总数和需要检查的不满值。第二行包含一个由 #cf_span[n] 个字符 "_Y_"、"_N_" 和 "_?_" 组成的序列。如果第 #cf_span[i] 个字符为 "_Y_",表示 Stepan 记得他看过第 #cf_span[i] 集;如果为 "_N_",表示他记得没看过第 #cf_span[i] 集;如果为 "_?_",表示他不确定是否看过第 #cf_span[i] 集。 ## Output 如果 Stepan 的不满值可以恰好等于 #cf_span[k],则输出 "_YES_"(不带引号);否则输出 "_NO_"(不带引号)。 [samples] ## Note 在第一个测试用例中,Stepan 记得了所有剧集是否观看过。他的不满值为 #cf_span[2],因为他连续没看两集——第 #cf_span[3] 集和第 #cf_span[4] 集。由于 #cf_span[k = 2],答案是 "_YES_"。 在第二个测试用例中,#cf_span[k = 1],但 Stepan 的不满值至少为 #cf_span[2](因为他记得至少连续两集没看过——第 #cf_span[5] 集和第 #cf_span[6] 集),即使他观看了第 1 到第 4 集也是如此。
**Definitions:** - Let $ n \in \mathbb{N} $, $ k \in \mathbb{Z}_{\geq 0} $, with $ 1 \leq n \leq 100 $, $ 0 \leq k \leq n $. - Let $ s \in \{ \text{Y}, \text{N}, \text{?} \}^n $ be a sequence of length $ n $, where: - $ s_i = \text{Y} $: episode $ i $ is definitely watched. - $ s_i = \text{N} $: episode $ i $ is definitely not watched. - $ s_i = \text{?} $: episode $ i $'s status is unknown (can be assigned Y or N). **Constraints:** - For each $ i \in \{1, \dots, n\} $: - If $ s_i = \text{Y} $, then the episode is watched. - If $ s_i = \text{N} $, then the episode is not watched. - If $ s_i = \text{?} $, then the episode may be assigned either watched or not watched. **Objective:** Determine whether there exists an assignment of values to all $ s_i = \text{?} $ such that the **maximum number of consecutive unwatched episodes** is **exactly** $ k $. **Formal Statement:** Does there exist an assignment $ a \in \{0,1\}^n $ such that: - $ \forall i \in \{1,\dots,n\} $: - if $ s_i = \text{Y} $, then $ a_i = 1 $; - if $ s_i = \text{N} $, then $ a_i = 0 $; - if $ s_i = \text{?} $, then $ a_i \in \{0,1\} $ (arbitrary). - Let $ L = \max \{ \ell \in \mathbb{N} \mid \exists i \text{ s.t. } a_i = a_{i+1} = \dots = a_{i+\ell-1} = 0 \} $ (length of longest consecutive 0-run). - Then $ L = k $. **Output:** YES if such an assignment exists; NO otherwise.
Samples
Input #1
5 2
NYNNY
Output #1
YES
Input #2
6 1
????NN
Output #2
NO
API Response (JSON)
{
  "problem": {
    "name": "J. Stepan's Series",
    "description": {
      "content": "Well, the series which Stepan watched for a very long time, ended. In total, the series had _n_ episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he defini",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF795J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Well, the series which Stepan watched for a very long time, ended. In total, the series had _n_ episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he defini...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "好吧,Stepan 长时间观看的这部剧集终于结束了。该剧集总共有 #cf_span[n] 集。对于每一集,Stepan 记得自己要么肯定看过,要么肯定没看过,要么不确定是否看过。\n\nStepan 的不满值定义为他未观看的连续剧集的最大数量。\n\n你的任务是根据 Stepan 的记忆,判断他的不满值是否可能恰好等于 #cf_span[k]。\n\n第一行包含两个整数 #cf_span[n] 和 #cf_s...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions:**\n- Let $ n \\in \\mathbb{N} $, $ k \\in \\mathbb{Z}_{\\geq 0} $, with $ 1 \\leq n \\leq 100 $, $ 0 \\leq k \\leq n $.\n- Let $ s \\in \\{ \\text{Y}, \\text{N}, \\text{?} \\}^n $ be a sequence of lengt...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments