QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9901. 匹配

统计

给定一个字符串 $S$ 和一个与 $S$ 等长的 01 串 $P$,请构造一个非空字符串 $T$($T$ 必须仅包含英文小写字母),满足以下条件:

  • 对于 $1 \leq i \leq |S| - |T| + 1$,$P[i] = 1$ 当且仅当 $T$ 作为子串恰好从 $S$ 的下标 $i$ 开始出现;
  • 对于 $|S| - |T| + 1 < i \leq |S|$,$P[i] = 0$。

若满足条件的 $T$ 存在,输出任意一个长度不超过 $10^6+1$ 的 $T$(这样的 $T$ 一定存在),否则输出 -1

Input

第一行一个由小写英文字母构成的字符串 $S$ ($1 \leq |S| \leq 10^6$)。

第二行一个与 $S$ 等长的 01 串 $P$。

Output

输出一个字符串 $T$ 或 -1。如果有多种可能的 $T$,你可以任意输出一种。

$T$ 必须仅包含英文小写字母。

Example

input

baaababaab
0001010000

output

aba

input

zqjzqj
000000

output

test

input

zqjzqj
100001

output

-1

explanation

对于第一组样例,$T$ 只可能是 aba。

对于第二组样例,$T$ 不是 $S$ 的子串即可。

对于第三组样例,没有合法的 $T$,因此答案为 -1

Scoring

对于 $30\%$ 的测试点: $|S| \leq 10$,且 $S$ 只包含 a 或 b。

对于 $50\%$ 的测试点: $|S| \leq 100$。

对于 $70\%$ 的测试点: $|S| \leq 1000$。

对于 $100\%$ 的测试点: $|S| \leq 10^6$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.