A14594 | The Sum of Good Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let's call a positive integer good if there is no digit 0 in its decimal representation.
For an array of a good numbers $a$ , one found out that the sum of some two neighboring elements is equal to $x$ (i.e. $x = a_i + a_{i + 1}$ for some $i$ ). $x$ had turned out to be a good number as well.
Then the elements of the array $a$ were written out one after another without separators into one string $s$ . For example, if $a = [12, 5, 6, 133]$ , then $s = 1256133$ .
You are given a string $s$ and a number $x$ . Your task is to determine the positions in the string that correspond to the adjacent elements of the array that have sum $x$ . If there are several possible answers, you can print any of them.
For an array of a good numbers $a$ , one found out that the sum of some two neighboring elements is equal to $x$ (i.e. $x = a_i + a_{i + 1}$ for some $i$ ). $x$ had turned out to be a good number as well.
Then the elements of the array $a$ were written out one after another without separators into one string $s$ . For example, if $a = [12, 5, 6, 133]$ , then $s = 1256133$ .
You are given a string $s$ and a number $x$ . Your task is to determine the positions in the string that correspond to the adjacent elements of the array that have sum $x$ . If there are several possible answers, you can print any of them.
输入格式
The first line contains the string $s$ ( $2 \le |s| \le 5 \cdot 10^5$ ).
The second line contains an integer $x$ ( $2 \le x < 10^{200000}$ ).
An additional constraint on the input: the answer always exists, i.e you can always select two adjacent substrings of the string $s$ so that if you convert these substrings to integers, their sum is equal to $x$ .
The second line contains an integer $x$ ( $2 \le x < 10^{200000}$ ).
An additional constraint on the input: the answer always exists, i.e you can always select two adjacent substrings of the string $s$ so that if you convert these substrings to integers, their sum is equal to $x$ .
输出格式
In the first line, print two integers $l_1$ , $r_1$ , meaning that the first term of the sum ( $a_i$ ) is in the string $s$ from position $l_1$ to position $r_1$ .
In the second line, print two integers $l_2$ , $r_2$ , meaning that the second term of the sum ( $a_{i + 1}$ ) is in the string $s$ from position $l_2$ to position $r_2$ .
In the second line, print two integers $l_2$ , $r_2$ , meaning that the second term of the sum ( $a_{i + 1}$ ) is in the string $s$ from position $l_2$ to position $r_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] = 12$ and $s[3;3] = 5$ , $12+5=17$ .
In the second example $s[2;3] = 54$ and $s[4;6] = 471$ , $54+471=525$ .
In the third example $s[1;1] = 2$ and $s[2;2] = 3$ , $2+3=5$ .
In the fourth example $s[2;7] = 218633$ and $s[8;13] = 757639$ , $218633+757639=976272$ .
In the second example $s[2;3] = 54$ and $s[4;6] = 471$ , $54+471=525$ .
In the third example $s[1;1] = 2$ and $s[2;2] = 3$ , $2+3=5$ .
In the fourth example $s[2;7] = 218633$ and $s[8;13] = 757639$ , $218633+757639=976272$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted