QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100 Hackable ✓

#285. 查询匹配

Statistics

通过一个人发出的搜索查询,我们可以了解很多关于这个人的信息。

但更具个人特征的是她将搜索查询组织成查询会话的方式。甚至她犯的拼写错误以及她纠正错误的方式都很重要!

基于这一事实,Yandex 正在开发一项具有前所未有功能的新型约会服务:根据用户的搜索引擎查询会话来匹配情侣。

给定两个人的查询会话日志,你的任务是计算他们之间的匹配得分。

在本题的语境下,你可以假设查询会话是用户一系列按键操作的序列。每个查询会话中只有两种类型的按键。当用户按下小写英文字母时,该字母会被追加到查询输入框中当前查询的末尾。当用户按下退格键时,查询输入框中的最后一个字母(最近输入的那个)会消失。如果用户在查询输入框为空时按下退格键,则什么也不会发生。

给定一个搜索查询会话的按键日志,我们可以考虑该搜索查询会话期间出现在查询输入框中的所有非空小写英文字符串的集合。此外,我们可以构建这些字符串的所有非空子串的集合。

考虑两个特定用户的此类子串集合。他们之间的匹配得分是这两个集合中公共子串的数量。

输入格式

输入包含两行,分别表示两个搜索查询会话日志。每个日志是一个完全由小写英文字母和字符 < 组成的字符串。字符 < 表示用户按下了退格键。

每个日志包含的英文字母数量不少于 1 且不超过 100 000。每个日志的总长度不超过 300 000 个字符。

输出格式

输出一个整数,即该问题的答案。

样例

输入 1

g<yandex
yand<<hoo

输出 1

10

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.