|
|
back to boardWhat's wrong my algo? I got WA2, always. Let C = A + '$*&' + B for string C build Palindrom Tree. calculate frequency of each palindrom : f(A,p) calculate frequency of each palindrom : f(B,p) x = count(f(A,p)>f(B,p)) y = count(f(A,p)==f(B,p) && f(A,p)!=0) z = count(f(A,p)<f(B,p)) //little code: freq[i][0] ---> f(A,p); freq[i][1] --> f(B,p). for(int i = 0; i < a.size(); ++i){ add_letter(a[i]); freq[last][0]++;} add_letter('$'); add_letter('*'); add_letter('&'); for(int i = 0; i < b.size(); ++i){ add_letter(b[i]); freq[last][1]++;} for(int z = sz-1; z > 0; z--){ v = link[z]; freq[v][0] += freq[i][0]; freq[v][1] += freq[i][1]; } int x=0,y=0,z=0; for(int i = 2; i< sz; ++i)// skip roots { x += (bool)(freq[i][0] > freq[i][1]); y += (bool)(freq[i][0] == freq[i][1] && freq[i][0] !=0); z += (bool)(freq[i][0] < freq[i][1]); } |
|
|