CF121B.Lucky Transformation

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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.

佩蒂亚喜欢幸运数字。众所周知,幸运数字是指十进制表示中仅包含幸运数字 4 和 7 的正整数。例如,47、744、4 是幸运数字,而 5、17、467 不是。

佩蒂亚有一个由 nn 位数字组成的数,且不含前导零。他将该数表示为一个不含前导零的数字数组,记作 dd。数组下标从 1 开始,即最左边(最高位)的数字下标为 1。佩蒂亚希望执行以下操作 kk 次:找出最小的 xx(满足 1≤x<n1 \le x < n),使得 dx=4d_x = 4 且 dx+1=7d_{x+1} = 7;若找到这样的 xx,则:若 xx 为奇数,令 dx=dx+1=4d_x = d_{x+1} = 4;否则(即 xx 为偶数),令 dx=dx+1=7d_x = d_{x+1} = 7。注意:若未找到满足条件的 xx,则本次操作视为已完成,数组不发生任何变化。

给定初始数字对应的数字数组以及整数 kk,请帮助佩蒂亚求出执行 kk 次操作后的结果。

输入格式

The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 109) — 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.

第一行包含两个整数 nn 和 kk(1≤n≤1051 \leq n \leq 10^5,0≤k≤1090 \leq k \leq 10^9)—— 分别表示该数字的位数以及已完成的操作次数。
第二行包含 nn 个无空格分隔的数字,表示数字数组 dd,其中第一个数字为 d1d_1。保证该数字的首位不为零。

输出格式

In the single line print the result without spaces — the number after the k operations are fulfilled.

在单行中输出结果(不包含空格)——即执行完 kk 次操作后的数值。

输入输出样例

  • 输入#1

    7 4
    4727447

    输出#1

    4427477
  • 输入#2

    4 2
    4478

    输出#2

    4478

说明/提示

In the first sample the number changes in the following sequence: 4727447 → 4427447 → 4427477 → 4427447 → 4427477.

In the second sample: 4478 → 4778 → 4478.

在第一个样例中,数字按以下序列变化:4727447 → 4427447 → 4427477 → 4427447 → 4427477。

在第二个样例中:4478 → 4778 → 4478。

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

首页