Can somebody explain me how to solve Matrix Matcher using Hashing. link : https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1960
Thanks in advance.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
Can somebody explain me how to solve Matrix Matcher using Hashing. link : https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1960
Thanks in advance.
Название |
---|
Auto comment: topic has been updated by AreluF (previous revision, new revision, compare).
Hash of symbols on $$$i$$$ line at $$$j$$$ position equal: $$$h(a_{ij})=a_{ij}\cdot P^i \cdot Q^j \mod M$$$, where $$$P, Q, M$$$ mutually prime numbers (for example $$$P=10007, Q = 10009, M=1000000007$$$).
Hash of matrix equals to the sum of all elements: $$$H(a)=\sum_{i=0}^{n-1} \sum_{j=0}^{m-1}h(a_{ij}) \mod M$$$, where $$$n$$$ — count rows, $$$m$$$ — count columns.
Calculate the prefix sum $$$p$$$ for hash of matrix $$$a$$$: $$$p_{ij}= \sum_{i_1=0}^{i-1} \sum_{j_1=0}^{j-1}h(a_{i_1j_1}) \mod M$$$. Then hash of submatrix starting in element $$$a_{i_1j_1}$$$and ending of element $$$a_{i_2j_2}$$$ equal: $$$\frac{p_{i_2+1j_2+1} - p_{i_1j_2+1} - p_{i_2+1j_1} + p_{i_1j_1}}{P^{i_{1}}\cdot Q^{j_{1}}} \mod M$$$.
You can iterate over all starting elements and compare hash submatrix and matrix $$$b$$$. Moreover, you may not implement modulo division if you replace it with multiplication.