CF1598G.The Sum of Good Numbers

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's call a positive integer good if there is no digit 0 in its decimal representation.

For an array of a good numbers aa, one found out that the sum of some two neighboring elements is equal to xx (i.e. x=ai+ai+1x = a_i + a_{i + 1} for some ii). xx had turned out to be a good number as well.

Then the elements of the array aa were written out one after another without separators into one string ss. For example, if a=[12,5,6,133]a = [12, 5, 6, 133], then s=1256133s = 1256133.

You are given a string ss and a number xx. Your task is to determine the positions in the string that correspond to the adjacent elements of the array that have sum xx. If there are several possible answers, you can print any of them.

我们称一个正整数是“好的”,当且仅当它在十进制表示中不包含数字 0。

对于一个由“好”数组成的数组 aa,已知其中某两个相邻元素之和等于 xx(即存在某个 ii,使得 x=ai+ai+1x = a_i + a_{i + 1})。并且 xx 本身也是一个“好”数。

随后,将数组 aa 的所有元素依次连接(不加任何分隔符)形成一个字符串 ss。例如,若 a=[12,5,6,133]a = [12, 5, 6, 133],则 s=1256133s = 1256133。

现给你一个字符串 ss 和一个数 xx。你的任务是确定字符串中对应于数组中和为 xx 的那对相邻元素的位置。如果存在多种可能的答案,输出任意一种即可。

输入格式

The first line contains the string ss (2≤∣s∣≤5⋅1052 \le |s| \le 5 \cdot 10^5).

The second line contains an integer xx (2≤x<102000002 \le x \lt 10^{200000}).

An additional constraint on the input: the answer always exists, i.e you can always select two adjacent substrings of the string ss so that if you convert these substrings to integers, their sum is equal to xx.

第一行包含字符串 ss(2≤∣s∣≤5⋅1052 \le |s| \le 5 \cdot 10^5)。

第二行包含一个整数 xx(2≤x<102000002 \le x \lt 10^{200000})。

输入的额外约束:答案一定存在,即总能在字符串 ss 中选出两个相邻的子串,使得将这两个子串分别转换为整数后,它们的和等于 xx。

输出格式

In the first line, print two integers l1l_1, r1r_1, meaning that the first term of the sum (aia_i) is in the string ss from position l1l_1 to position r1r_1.

In the second line, print two integers l2l_2, r2r_2, meaning that the second term of the sum (ai+1a_{i + 1}) is in the string ss from position l2l_2 to position r2r_2.

第一行输出两个整数 l1l_1、r1r_1,表示和式中的第一项(aia_i)在字符串 ss 中的位置范围是从第 l1l_1 位到第 r1r_1 位。

第二行输出两个整数 l2l_2、r2r_2,表示和式中的第二项(ai+1a_{i + 1})在字符串 ss 中的位置范围是从第 l2l_2 位到第 r2r_2 位。

输入输出样例

  • 输入#1

    1256133
    17

    输出#1

    1 2
    3 3
  • 输入#2

    9544715561
    525

    输出#2

    2 3
    4 6
  • 输入#3

    239923
    5

    输出#3

    1 1
    2 2
  • 输入#4

    1218633757639
    976272

    输出#4

    2 7
    8 13

说明/提示

In the first example s[1;2]=12s[1;2] = 12 and s[3;3]=5s[3;3] = 5, 12+5=1712+5=17.

In the second example s[2;3]=54s[2;3] = 54 and s[4;6]=471s[4;6] = 471, 54+471=52554+471=525.

In the third example s[1;1]=2s[1;1] = 2 and s[2;2]=3s[2;2] = 3, 2+3=52+3=5.

In the fourth example s[2;7]=218633s[2;7] = 218633 and s[8;13]=757639s[8;13] = 757639, 218633+757639=976272218633+757639=976272.

在第一个例子中,s[1;2]=12s[1;2] = 12 且 s[3;3]=5s[3;3] = 5,12+5=1712+5=17。

在第二个例子中,s[2;3]=54s[2;3] = 54 且 s[4;6]=471s[4;6] = 471,54+471=52554+471=525。

在第三个例子中,s[1;1]=2s[1;1] = 2 且 s[2;2]=3s[2;2] = 3,2+3=52+3=5。

在第四个例子中,s[2;7]=218633s[2;7] = 218633 且 s[8;13]=757639s[8;13] = 757639,218633+757639=976272218633+757639=976272。

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

首页