This problem seems like a regular expression problem. If the constraints were small, it could be easily handled with dynamic programming I think. But it seems almost impossible with this kind of constraints. Any idea?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
This problem seems like a regular expression problem. If the constraints were small, it could be easily handled with dynamic programming I think. But it seems almost impossible with this kind of constraints. Any idea?
Name |
---|
I think it can be done with String Automata, similar to Aho-Corasick
Can you explain?
This is how I solved this problem:
First you need to tokenize the string with some information. Suppose given string is "1*22#55#8#*#9*". So your tokens will be "1", "22", "55", "8", "9". Now you need some additional information for each token, such as minimum number of digits required, even or odd number of digits required, length of this token etc. So for this token "55" — there should be odd number of digits before this, at least one digit required(since it's odd) etc. And for this token "9" — there should be even number of digits before this, should be at least 2 digits.
Now, for each query string, start finding substring which matches with a token with satisfying other conditions. You just pick the first substring which completely matches with a token. Then start finding next token and so on. If you can find all the tokens in a query string, then the answer is "match", otherwise "not".
You do not require any DP for this, just take the first substring that completely matches with a token and move on to the next token.
See my code for further understanding https://pastebin.com/j9eHmQAP
thanks a lot man