CF1446B.Catching Cheaters

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given two strings AA and BB representing essays of two students who are suspected cheaters. For any two strings CC, DD we define their similarity score S(C,D)S(C,D) as 4⋅LCS(C,D)−∣C∣−∣D∣4\cdot LCS(C,D) - |C| - |D|, where LCS(C,D)LCS(C,D) denotes the length of the Longest Common Subsequence of strings CC and DD.

You believe that only some part of the essays could have been copied, therefore you're interested in their substrings.

Calculate the maximal similarity score over all pairs of substrings. More formally, output maximal S(C,D)S(C, D) over all pairs (C,D)(C, D), where CC is some substring of AA, and DD is some substring of BB.

If XX is a string, ∣X∣|X| denotes its length.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

A string aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters.

Pay attention to the difference between the substring and subsequence, as they both appear in the problem statement.

You may wish to read the Wikipedia page about the Longest Common Subsequence problem.

给你两个字符串 AA 和 BB,分别代表两名涉嫌抄袭的学生所写的作文。对于任意两个字符串 CC、DD,我们定义它们的相似度得分 S(C,D)S(C,D) 为 4⋅LCS(C,D)−∣C∣−∣D∣4\cdot LCS(C,D) - |C| - |D|,其中 LCS(C,D)LCS(C,D) 表示字符串 CC 与 DD 的最长公共子序列(Longest Common Subsequence)的长度。

你认为可能仅有作文的某一部分被抄袭,因此你关注的是它们的子串(substring)。

请计算所有子串对的相似度得分的最大值。更准确地说,输出所有满足条件的字符串对 (C,D)(C, D) 中 S(C,D)S(C, D) 的最大值,其中 CC 是 AA 的某个子串,DD 是 BB 的某个子串。

若 XX 是一个字符串,则 ∣X∣|X| 表示其长度。

若字符串 aa 可通过从字符串 bb 的开头删除若干(可能为零个或全部)字符,并从结尾删除若干(可能为零个或全部)字符而得到,则称 aa 是 bb 的子串(substring)。

若字符串 aa 可通过从字符串 bb 中删除若干(可能为零个或全部)字符而得到,则称 aa 是 bb 的子序列(subsequence)。

请注意“子串”与“子序列”的区别,因为本题中两者均会出现。

你或许希望阅读关于最长公共子序列问题的 Wikipedia 页面。

输入格式

The first line contains two positive integers nn and mm (1≤n,m≤50001 \leq n, m \leq 5000) — lengths of the two strings AA and BB.

The second line contains a string consisting of nn lowercase Latin letters — string AA.

The third line contains a string consisting of mm lowercase Latin letters — string BB.

第一行包含两个正整数 nn 和 mm(1≤n,m≤50001 \leq n, m \leq 5000)—— 分别为字符串 AA 和 BB 的长度。

第二行包含一个由 nn 个小写拉丁字母组成的字符串 —— 字符串 AA。

第三行包含一个由 mm 个小写拉丁字母组成的字符串 —— 字符串 BB。

输出格式

Output maximal S(C,D)S(C, D) over all pairs (C,D)(C, D), where CC is some substring of AA, and DD is some substring of BB.

在所有满足 CC 是 AA 的某个子串、DD 是 BB 的某个子串的数对 (C,D)(C, D) 中,输出最大的 S(C,D)S(C, D)。

输入输出样例

  • 输入#1

    4 5
    abba
    babab

    输出#1

    5
  • 输入#2

    8 10
    bbbbabab
    bbbabaaaaa

    输出#2

    12
  • 输入#3

    7 7
    uiibwws
    qhtkxcn

    输出#3

    0

说明/提示

For the first case:

abb from the first string and abab from the second string have LCS equal to abb.

The result is S(abb,abab)=(4⋅∣abb∣S(abb, abab) = (4 \cdot |abb|) - ∣abb∣|abb| - ∣abab∣|abab| = 4⋅3−3−4=54 \cdot 3 - 3 - 4 = 5.

对于第一种情况:

第一个字符串中的 abb 和第二个字符串中的 abab 的最长公共子序列(LCS)等于 abb。

结果为 S(abb,abab)=(4⋅∣abb∣)S(abb, abab) = (4 \cdot |abb|) - ∣abb∣|abb| - ∣abab∣|abab| = 4⋅3−3−4=54 \cdot 3 - 3 - 4 = 5。

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

首页