300636: CF121B. Lucky Transformation
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Lucky Transformation
题意翻译
# 题目描述 Petya喜欢幸运数字。每个人都知道幸运数字是十进制下各位只包含$4$和$7$的正整数。例如数字$47$、$744$和$4$都是幸运数字,但$5$、$17$和$467$不是。 Petya有一个由$n$位数字组成的没有前导零的数。他用一个没有前导零的数组来表示这个数,我们称它为$d$。数组的下标从$1$开始顺序输入。Petya想要进行$k$次如下的变换:找到一个最小的$x(1<=x< n)$使得其满足$d_x=4$并且$d_{x+1}=7$。如果$x$是奇数,那么让$d_x=d_{x+1}=4$,否则让$d_x=d_{x+1}=7$。若没有满足条件的$x$,则数字不变。 给定初始数组和数字$k$,请你帮助Petya得出$k$次操作后的结果。 # 输入输出格式 ## 输入格式 第一行包括两个整数$n$和$k(1<=n<=10^5,0<=k<=10^9)$,分别表示数字个数和操作次数。 第二行用$n$个数字表示数组$d$,数字之间没有空格,以$d_1$开始。保证数字没有前导零。 ## 输出格式 输出一行,为操作后的结果,数字之间没有空格 # 说明 在第一个样例中数字变换成如下序列:$4727447\to4427447\to4427477\to4427447\to4427477$ 在第二个样例中:$4478\to4778\to4478$题目描述
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consisting of $ n $ digits without leading zeroes. He represented it as an array of digits without leading zeroes. Let's call it $ d $ . The numeration starts with $ 1 $ , starting from the most significant digit. Petya wants to perform the following operation $ k $ times: find the minimum $ x $ $ (1<=x<n) $ such that $ d_{x}=4 $ and $ d_{x+1}=7 $ , if $ x $ is odd, then to assign $ d_{x}=d_{x+1}=4 $ , otherwise to assign $ d_{x}=d_{x+1}=7 $ . Note that if no $ x $ was found, then the operation counts as completed and the array doesn't change at all. You are given the initial number as an array of digits and the number $ k $ . Help Petya find the result of completing $ k $ operations.输入输出格式
输入格式
The first line contains two integers $ n $ and $ k $ $ (1<=n<=10^{5},0<=k<=10^{9}) $ — the number of digits in the number and the number of completed operations. The second line contains $ n $ digits without spaces representing the array of digits $ d $ , starting with $ d_{1} $ . It is guaranteed that the first digit of the number does not equal zero.
输出格式
In the single line print the result without spaces — the number after the $ k $ operations are fulfilled.
输入输出样例
输入样例 #1
7 4
4727447
输出样例 #1
4427477
输入样例 #2
4 2
4478
输出样例 #2
4478