A8395 | Abracadabra
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm:
- On the first step the string consists of a single character "a".
- On the $k$ -th step Polycarpus concatenates two copies of the string obtained on the $(k-1)$ -th step, while inserting the $k$ -th character of the alphabet between them. Polycarpus uses the alphabet that consists of lowercase Latin letters and digits (a total of 36 characters). The alphabet characters are numbered like this: the 1-st character is "a", the 2-nd — "b", ..., the 26-th — "z", the 27-th — "0", the 28-th — "1", ..., the 36-th — "9".
Let's have a closer look at the algorithm. On the second step Polycarpus will concatenate two strings "a" and insert the character "b" between them, resulting in "aba" string. The third step will transform it into "abacaba", and the fourth one - into "abacabadabacaba". Thus, the string constructed on the $k$ -th step will consist of $2^{k}-1$ characters.
Polycarpus wrote down the string he got after 30 steps of the given algorithm and chose two non-empty substrings of it. Your task is to find the length of the longest common substring of the two substrings selected by Polycarpus.
A substring $s[i...\ j]$ ( $1<=i<=j<=|s|$ ) of string $s$ = $s_{1}s_{2}...\ s_{|s|}$ is a string $s_{i}s_{i+1}...\ s_{j}$ . For example, substring $s[2...4]$ of string $s$ = "abacaba" equals "bac". The string is its own substring.
The longest common substring of two strings $s$ and $t$ is the longest string that is a substring of both $s$ and $t$ . For example, the longest common substring of "contest" and "systemtesting" is string "test". There can be several common substrings of maximum length.
- On the first step the string consists of a single character "a".
- On the $k$ -th step Polycarpus concatenates two copies of the string obtained on the $(k-1)$ -th step, while inserting the $k$ -th character of the alphabet between them. Polycarpus uses the alphabet that consists of lowercase Latin letters and digits (a total of 36 characters). The alphabet characters are numbered like this: the 1-st character is "a", the 2-nd — "b", ..., the 26-th — "z", the 27-th — "0", the 28-th — "1", ..., the 36-th — "9".
Let's have a closer look at the algorithm. On the second step Polycarpus will concatenate two strings "a" and insert the character "b" between them, resulting in "aba" string. The third step will transform it into "abacaba", and the fourth one - into "abacabadabacaba". Thus, the string constructed on the $k$ -th step will consist of $2^{k}-1$ characters.
Polycarpus wrote down the string he got after 30 steps of the given algorithm and chose two non-empty substrings of it. Your task is to find the length of the longest common substring of the two substrings selected by Polycarpus.
A substring $s[i...\ j]$ ( $1<=i<=j<=|s|$ ) of string $s$ = $s_{1}s_{2}...\ s_{|s|}$ is a string $s_{i}s_{i+1}...\ s_{j}$ . For example, substring $s[2...4]$ of string $s$ = "abacaba" equals "bac". The string is its own substring.
The longest common substring of two strings $s$ and $t$ is the longest string that is a substring of both $s$ and $t$ . For example, the longest common substring of "contest" and "systemtesting" is string "test". There can be several common substrings of maximum length.
输入格式
The input consists of a single line containing four integers $l_{1}$ , $r_{1}$ , $l_{2}$ , $r_{2}$ ( $1<=l_{i}<=r_{i}<=10^{9}$ , $i=1,2$ ). The numbers are separated by single spaces. $l_{i}$ and $r_{i}$ give the indices of the first and the last characters of the $i$ -th chosen substring, correspondingly ( $i=1,2$ ). The characters of string abracadabra are numbered starting from $1$ .
输出格式
Print a single number — the length of the longest common substring of the given strings. If there are no common substrings, print 0.
输入输出样例
输入 #1
3 6 1 4
输出 #1
2
输入 #2
1 1 4 4
输出 #2
0
In the first sample the first substring is "acab", the second one is "abac". These two substrings have two longest common substrings "ac" and "ab", but we are only interested in their length — 2.
In the second sample the first substring is "a", the second one is "c". These two substrings don't have any common characters, so the length of their longest common substring is 0.
In the second sample the first substring is "a", the second one is "c". These two substrings don't have any common characters, so the length of their longest common substring is 0.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted