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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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