CF1244F.Chips

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn chips arranged in a circle, numbered from 11 to nn.

Initially each chip has black or white color. Then kk iterations occur. During each iteration the chips change their colors according to the following rules. For each chip ii, three chips are considered: chip ii itself and two its neighbours. If the number of white chips among these three is greater than the number of black chips among these three chips, then the chip ii becomes white. Otherwise, the chip ii becomes black.

Note that for each ii from 22 to (n−1)(n - 1) two neighbouring chips have numbers (i−1)(i - 1) and (i+1)(i + 1). The neighbours for the chip i=1i = 1 are nn and 22. The neighbours of i=ni = n are (n−1)(n - 1) and 11.

The following picture describes one iteration with n=6n = 6. The chips 11, 33 and 44 are initially black, and the chips 22, 55 and 66 are white. After the iteration 22, 33 and 44 become black, and 11, 55 and 66 become white.

Your task is to determine the color of each chip after kk iterations.

有 nn 个芯片围成一个圆圈,编号为 11 到 nn。

初始时,每个芯片为黑色或白色。随后进行 kk 轮迭代。在每轮迭代中,所有芯片根据以下规则同时更新其颜色:对每个芯片 ii,考察三个芯片——芯片 ii 自身及其两个相邻芯片。若这三个芯片中白色芯片的数量大于黑色芯片的数量,则芯片 ii 变为白色;否则,芯片 ii 变为黑色。

注意:对每个 ii(2≤i≤n−12 \le i \le n-1),其两个相邻芯片的编号分别为 (i−1)(i-1) 和 (i+1)(i+1);芯片 i=1i = 1 的相邻芯片为 nn 和 22;芯片 i=ni = n 的相邻芯片为 (n−1)(n-1) 和 11。

下图描述了 n=6n = 6 时的一轮迭代过程:初始时,芯片 11、33、44 为黑色,芯片 22、55、66 为白色;经过该轮迭代后,芯片 22、33、44 变为黑色,芯片 11、55、66 变为白色。

你的任务是确定经过 kk 轮迭代后每个芯片的颜色。

输入格式

The first line contains two integers nn and kk (3≤n≤200 000,1≤k≤109)(3 \le n \le 200\,000, 1 \le k \le 10^{9}) — the number of chips and the number of iterations, respectively.

The second line contains a string consisting of nn characters "W" and "B". If the ii-th character is "W", then the ii-th chip is white initially. If the ii-th character is "B", then the ii-th chip is black initially.

第一行包含两个整数 nn 和 kk(3≤n≤200 0003 \le n \le 200\,000,1≤k≤1091 \le k \le 10^{9}),分别表示芯片的数量和迭代次数。

第二行包含一个由 nn 个字符 "W" 和 "B" 组成的字符串。若第 ii 个字符为 "W",则第 ii 个芯片初始为白色;若第 ii 个字符为 "B",则第 ii 个芯片初始为黑色。

输出格式

Print a string consisting of nn characters "W" and "B". If after kk iterations the ii-th chip is white, then the ii-th character should be "W". Otherwise the ii-th character should be "B".

输出一个由 nn 个字符 "W" 和 "B" 组成的字符串。如果经过 kk 次迭代后,第 ii 个芯片为白色,则该字符串的第 ii 个字符应为 "W";否则应为 "B"。

输入输出样例

  • 输入#1

    6 1
    BWBBWW

    输出#1

    WBBBWW
  • 输入#2

    7 3
    WBWBWBW

    输出#2

    WWWWWWW
  • 输入#3

    6 4
    BWBWBW

    输出#3

    BWBWBW

说明/提示

The first example is described in the statement.

The second example: "WBWBWBW" →\rightarrow "WWBWBWW" →\rightarrow "WWWBWWW" →\rightarrow "WWWWWWW". So all chips become white.

The third example: "BWBWBW" →\rightarrow "WBWBWB" →\rightarrow "BWBWBW" →\rightarrow "WBWBWB" →\rightarrow "BWBWBW".

第一个示例在题目描述中已给出。

第二个示例:"WBWBWBW" →\rightarrow "WWBWBWW" →\rightarrow "WWWBWWW" →\rightarrow "WWWWWWW"。因此所有棋子均变为白色。

第三个示例:"BWBWBW" →\rightarrow "WBWBWB" →\rightarrow "BWBWBW" →\rightarrow "WBWBWB" →\rightarrow "BWBWBW"。

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

首页