CF1268A.Long Beautiful Integer

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an integer xx of nn digits a1,a2,…,ana_1, a_2, \ldots, a_n, which make up its decimal notation in order from left to right.

Also, you are given a positive integer k<nk \lt n.

Let's call integer b1,b2,…,bmb_1, b_2, \ldots, b_m beautiful if bi=bi+kb_i = b_{i+k} for each ii, such that 1≤i≤m−k1 \leq i \leq m - k.

You need to find the smallest beautiful integer yy, such that y≥xy \geq x.

给你一个 nn 位整数 xx,其十进制表示从左到右依次为各位数字 a1,a2,…,ana_1, a_2, \ldots, a_n。

同时,你还给定一个正整数 k<nk < n。

我们称整数 b1,b2,…,bmb_1, b_2, \ldots, b_m 是优美的(beautiful),如果对每个满足 1≤i≤m−k1 \leq i \leq m - k 的 ii,均有 bi=bi+kb_i = b_{i+k}。

你需要找出满足 y≥xy \geq x 的最小优美整数 yy。

输入格式

The first line of input contains two integers n,kn, k (2≤n≤200 000,1≤k<n2 \leq n \leq 200\,000, 1 \leq k \lt n): the number of digits in xx and kk.

The next line of input contains nn digits a1,a2,…,ana_1, a_2, \ldots, a_n (a1≠0a_1 \neq 0, 0≤ai≤90 \leq a_i \leq 9): digits of xx.

输入的第一行包含两个整数 n,kn, k(2≤n≤200 000, 1≤k<n2 \leq n \leq 200\,000,\ 1 \leq k \lt n):分别表示 xx 的位数和 kk。

输入的第二行包含 nn 个数字 a1,a2,…,ana_1, a_2, \ldots, a_n(a1≠0, 0≤ai≤9a_1 \neq 0,\ 0 \leq a_i \leq 9):即 xx 的各位数字。

输出格式

In the first line print one integer mm: the number of digits in yy.

In the next line print mm digits b1,b2,…,bmb_1, b_2, \ldots, b_m (b1≠0b_1 \neq 0, 0≤bi≤90 \leq b_i \leq 9): digits of yy.

第一行输出一个整数 mm:yy 的位数。

第二行输出 mm 个数字 b1,b2,…,bmb_1, b_2, \ldots, b_m(其中 b1≠0b_1 \neq 0,且 0≤bi≤90 \leq b_i \leq 9):即 yy 的各位数字。

输入输出样例

  • 输入#1

    3 2
    353

    输出#1

    3
    353
  • 输入#2

    4 2
    1234

    输出#2

    4
    1313

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

首页