CF1244F.Chips
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n chips arranged in a circle, numbered from 1 to n.
Initially each chip has black or white color. Then k iterations occur. During each iteration the chips change their colors according to the following rules. For each chip i, three chips are considered: chip i 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 i becomes white. Otherwise, the chip i becomes black.
Note that for each i from 2 to (n−1) two neighbouring chips have numbers (i−1) and (i+1). The neighbours for the chip i=1 are n and 2. The neighbours of i=n are (n−1) and 1.
The following picture describes one iteration with n=6. The chips 1, 3 and 4 are initially black, and the chips 2, 5 and 6 are white. After the iteration 2, 3 and 4 become black, and 1, 5 and 6 become white.

Your task is to determine the color of each chip after k iterations.
有 n 个芯片围成一个圆圈,编号为 1 到 n。
初始时,每个芯片为黑色或白色。随后进行 k 轮迭代。在每轮迭代中,所有芯片根据以下规则同时更新其颜色:对每个芯片 i,考察三个芯片——芯片 i 自身及其两个相邻芯片。若这三个芯片中白色芯片的数量大于黑色芯片的数量,则芯片 i 变为白色;否则,芯片 i 变为黑色。
注意:对每个 i(2≤i≤n−1),其两个相邻芯片的编号分别为 (i−1) 和 (i+1);芯片 i=1 的相邻芯片为 n 和 2;芯片 i=n 的相邻芯片为 (n−1) 和 1。
下图描述了 n=6 时的一轮迭代过程:初始时,芯片 1、3、4 为黑色,芯片 2、5、6 为白色;经过该轮迭代后,芯片 2、3、4 变为黑色,芯片 1、5、6 变为白色。

你的任务是确定经过 k 轮迭代后每个芯片的颜色。
输入格式
The first line contains two integers n and k (3≤n≤200000,1≤k≤109) — the number of chips and the number of iterations, respectively.
The second line contains a string consisting of n characters "W" and "B". If the i-th character is "W", then the i-th chip is white initially. If the i-th character is "B", then the i-th chip is black initially.
第一行包含两个整数 n 和 k(3≤n≤200000,1≤k≤109),分别表示芯片的数量和迭代次数。
第二行包含一个由 n 个字符 "W" 和 "B" 组成的字符串。若第 i 个字符为 "W",则第 i 个芯片初始为白色;若第 i 个字符为 "B",则第 i 个芯片初始为黑色。
输出格式
Print a string consisting of n characters "W" and "B". If after k iterations the i-th chip is white, then the i-th character should be "W". Otherwise the i-th character should be "B".
输出一个由 n 个字符 "W" 和 "B" 组成的字符串。如果经过 k 次迭代后,第 i 个芯片为白色,则该字符串的第 i 个字符应为 "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" → "WWBWBWW" → "WWWBWWW" → "WWWWWWW". So all chips become white.
The third example: "BWBWBW" → "WBWBWB" → "BWBWBW" → "WBWBWB" → "BWBWBW".
第一个示例在题目描述中已给出。
第二个示例:"WBWBWBW" → "WWBWBWW" → "WWWBWWW" → "WWWWWWW"。因此所有棋子均变为白色。
第三个示例:"BWBWBW" → "WBWBWB" → "BWBWBW" → "WBWBWB" → "BWBWBW"。
输入解题思路,AI测评打分。不知道怎么写?