http://codeforces.net/gym/100543 can't believe my eyes.....
# | 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 | 170 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
5 | -is-this-fft- | 158 |
7 | adamant | 154 |
7 | Dominater069 | 154 |
9 | awoo | 153 |
10 | luogu_official | 152 |
http://codeforces.net/gym/100543 can't believe my eyes.....
Name |
---|
Time limit is 30 seconds. O(n2) with small constant can pass...
15s per case, but I don't how many test cases per test file.
965 in second test
218324 in third test
43261 in fourth test
But you should expect that there are not many large cases in test file.
Can you describe your solution please? Your code is too long to analyze it ^.^'
first for each position i,regard it as middle point of a Palindromic Substring then find longest palindromic substring with i is the middle point sg[i].l,sg[i].r, the brute force implement of this part is O(n^2),but there are optimazition,if we know the previous sg[i-1].l,sg[i-1].r
for each point between [i,sg[i-1].r], it is Symmetric with [sg[i-1].l,i-1],so we can use the information [sg[i-1].l,i-1] to optimal [i,sg[i-1].r]. (but in fact for my implement of this optimizition I don't what is the compleixity,maybe it can be optimaled to O(n)),
after we find every sg[i].l,sg[i].r then it is a brutefore dfs with memory search;
just search(0,n-1), when search(left,right), first deal every point left<=i<=right,with its sg[i].l,sg[i].r,record them ,sort them with their decreasing length(sg[i].r-sg[i].l)
then opt(left,right)=min(opt(sg[i].l,i)+1+sg[i].l-left+right-sg[i].r); there is some prunning: lower_bound of opt(left,right) is low[right-left]=log(right-left)+1, so if current_result<=low[i-sg[i].l]+sg[i].l-left+right-sg[i].r then break;
idea is too simple,if you find O(n^2) testcase or even O(n^3) discuss it...
With Manacher's algorithm you can find sg[i-1].l,sg[i-1].r in O(n).
This part works in O(magic), I don't know how to estimate this :)
Anyway it is pretty interesting. Almost nobody tried to solve this problem (maybe everyone is scared of strings) but the testcases seem to be pretty weak, so any correct solution (or even sometimes not correct) with a little bit of optimizations should pass.