PLCS
Time limit1sMemory limit16 MB
Find the longest common subsequence of A and B that contains X, excludes Y, and has prime length, or report -1.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String, Number theory
- Solved
- No attempts yet
Problem
The PLCS (Prime Longest Common Subsequence) problem gives two sequences and asks for the longest common subsequence of both whose length is prime.
Given strings and , a character that must be included in the PLCS, and a character that must not be included in the PLCS, print the length of the longest common subsequence of and that contains , does not contain , and has prime length. If no such subsequence exists, print -1.
The strings and and the characters and consist of lowercase English letters. Each of and contains exactly one .
Input
The first line contains the string .
The second line contains the string .
The third line contains the character .
The fourth line contains the character .
Output
On the first line, print the length of the longest common subsequence of and that contains , does not contain , and has prime length. If no such subsequence exists, print -1.