Submit | All submissions | Best solutions | Back to list |
SUB_PROB - Substring Problem |
String matching is an important problem in computer science research and finds applications in bioinformatics, data mining, pattern recognition, internet security and many more areas.
The problem we consider here is a smaller version of it. You are given a string M and N other strings smaller in length than M. You have to find whether each of these N strings is a substring of M. All strings consist of only alphanumeric characters.
You are required to write a C/CPP code to solve the problem.
Input
Input to the program consists of a series of lines. The first line contains the string M (no more than 100000 characters long). The next line contains an integer N (<1000) the number of query strings. Each of the next N lines contain a string S (each of which is no more than 2000 characters long).
Output
Output should consist of N lines each with a character 'Y' or 'N' indicating whether the string S is a substring of string M or not.
Example
Input: abghABCDE 2 abAB ab Output: N Y
Note: The test data for this problem not only consist of the official test cases from the contest, as well some cases of my own.
A test case was added on 25.7.2010, after rejudging 3 users lose accepted.
Added by: | :(){ :|: & };: |
Date: | 2010-07-02 |
Time limit: | 0.100s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ASM32-GCC MAWK BC C-CLANG C NCSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG C99 COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |
Resource: | Codefest 2010 CW R#2 |
hide comments
|
|||||||
2021-04-25 14:52:04
Used trie with 80 size array but still got wa on test case 8. Any thing wrong with my solution? |
|||||||
2021-04-14 18:30:47
I used Rabin Karp but got the wrong answer on test 8, can somebody provide some more test cases. |
|||||||
2020-11-07 23:23:17
If you want to solve this by Aho-corasick, You need more optimized implementation. Time limit is so strict. I will suggest this https://cp-algorithms.com/string/aho_corasick.html implementation which is enough faster. |
|||||||
2020-11-07 23:17:40
I think dataset was weak...There was a hack case.... Last edit: 2020-11-07 23:37:19 |
|||||||
2020-07-19 10:20:08
After couple of WA finally solved it! I used Rabin-Karp algorithm. You should notice that each character can be uppercase or lowercase letter or numeric digit. |
|||||||
2020-07-18 18:01:54
AC achieved through simple hashing of the substrings of required length |
|||||||
2019-12-19 10:16:42
Good problem to learn suffix tree/trie |
|||||||
2019-12-03 13:08:54
Authors should try to make problem more precise, alphanumeric is so ambiguous here ... |
|||||||
2019-10-03 02:42:03
Tu no tienes mamita, mano? :v |
|||||||
2019-03-28 12:45:20
Getting TLE with Aho-corasick... Any suggestion, please... |