My Solution to 253C - Text Editor is producing TLE? here is the link to solution 2797003
# | 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 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
Name |
---|
because there is n ( <= 100 ) lines of text with length <= 100 000 (10^5) total your bfs produces 10^9 states (~ vertices of graph).
10^2 * 10^5 aren't 10^9. BFS is not the best solution, but it should pass the time limit if it is implemented correctly.
Don't push the new nodes to the queue if you have already visited them. Then it should pass...
Oh, yes. you are right. I thought there was 10^7 limitations, but copy & paste method shows i was wrong. Anyway 10^7 is pretty much, it can pass Time Limit, but my solution works for my limitations too. As you can see, it is don't matter how big limitations are, for the length of particular string. You can run BFS only for states where second coordinate(Y) is equal to length of one of the n strings. So there will be totally O(n^2) states. then for each of states you should to calculate the number of moves you need? if you can't go to another line. this task can be solved in O(1) time. Answer for this question is just | r1 — r2 |.
**Upd** Ok you can't see until my solutions published. you should use only points with coordinates (i, len[j]) where 0 <= i < n && 0 <= j && j <= n — 1
I successfully solved this problem using BFS 2726786
then how can this pass 2801412
Look this: if(Dp[NX][NY] == -1) Dp[NX][NY] = Dp[X][Y] + 1, Q.push(Pii(NX, NY))
Each node will be pushed to the queue at most one time.
Also TLE is The Leading Edge Ltd. Thank you very much for your useful information.