CF161C.Abracadabra
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
Polycarpus 分析一个名为 abracadabra 的字符串。该字符串是通过以下算法构造的:
- 第一步:字符串仅包含单个字符
"a"。 - 第 k 步:Polycarpus 将第 (k−1) 步所得字符串的两个副本拼接起来,并在二者之间插入字母表中的第 k 个字符。Polycarpus 使用的字母表由小写拉丁字母和数字组成(共 36 个字符)。字母表中字符的编号方式如下:第 1 个字符为
"a",第 2 个为"b",……,第 26 个为"z",第 27 个为"0",第 28 个为"1",……,第 36 个为"9"。
我们来更详细地观察该算法:第二步中,Polycarpus 将两个字符串 "a" 拼接,并在中间插入字符 "b",得到字符串 "aba";第三步将其变为 "abacaba";第四步变为 "abacabadabacaba"。因此,在第 k 步所构造出的字符串长度为 2k−1。
Polycarpus 写下了按上述算法执行 30 步后所得的字符串,并从中选取了两个非空子串。你的任务是求出这两个子串的最长公共子串的长度。
字符串 s=s1s2…s∣s∣ 的子串 s[i…j](其中 1≤i≤j≤∣s∣)定义为字符串 sisi+1…sj。例如,字符串 s="abacaba" 的子串 s[2…4] 等于 "bac"。字符串本身也是其自身的子串。
两个字符串 s 和 t 的最长公共子串,是指同时为 s 和 t 的子串的、长度最长的字符串。例如,"contest" 与 "systemtesting" 的最长公共子串是 "test"。可能存在多个长度相同的最长公共子串。
输入格式
The input consists of a single line containing four integers _l_1, _r_1, _l_2, _r_2 (1 ≤ l__i ≤ r__i ≤ 109, 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.
输入仅包含一行,其中有四个整数 l1、r1、l2、r2(1 ≤ li ≤ ri ≤ 109,i = 1, 2),数字之间以单个空格分隔。li 和 ri 分别表示第 i 个所选子串的首字符和末字符的下标(i = 1, 2)。字符串 abracadabra 的字符编号从 1 开始。
输出格式
Print a single number — the length of the longest common substring of the given strings. If there are no common substrings, print 0.
输出一个数字——给定字符串的最长公共子串的长度。如果没有公共子串,则输出 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.
在第一个样例中,第一个子串是 “acab”,第二个子串是 “abac”。这两个子串有两个最长公共子串:“ac” 和 “ab”,但我们只关心其长度——即 2。
在第二个样例中,第一个子串是 “a”,第二个子串是 “c”。这两个子串没有任何公共字符,因此它们的最长公共子串长度为 0。
输入解题思路,AI测评打分。不知道怎么写?