ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1158. Censored!

How to solve this problem(1158)? It's too hard....
Posted by Sa Lang Hae 23 Feb 2005 07:51
I have been working on it for a week....
DP of extreme difficulty. Can not be easily explained (-)
Posted by Dmitry 'Diman_YES' Kovalioff 23 Feb 2005 10:53
Re: DP of extreme difficulty. Can not be easily explained (-)
Posted by Vladimir Yakovlev (USU) 23 Feb 2005 15:05
Why extreme difficulty? My DP is about 30 lines. Idea is very simple. But it's hard to discover as well :)
For instance, Ural-1342 is 8-lines DP... (+)
Posted by Dmitry 'Diman_YES' Kovalioff 23 Feb 2005 15:17
I mean no true DP solution is really large, but this very DP is rather difficult to find and understand.
Re: DP of extreme difficulty. Can not be easily explained (-)
Posted by Sa Lang Hae 23 Feb 2005 18:01
would you please tell me your method? I think only a big-number code will use more than 30 lines...
Re: DP of extreme difficulty. Can not be easily explained (-)
Posted by Ilya Rasenstein (9 class) 6 Mar 2005 14:53
I think Aho-Korasick+DP
This seems pretty interesting.. Could you give me a link where I can read more about this algo?
Posted by Jiang Xu 16 Aug 2005 17:10
I solved it with a dfa + dp, but my source is very big (180 lines).. How to do it in 30 lines?
Posted by Jiang Xu 16 Aug 2005 17:12
Re: I solved it with a dfa + dp, but my source is very big (180 lines).. How to do it in 30 lines?
Posted by Denis Koshman 5 Aug 2008 04:24
ALGO IS HERE:

1. Remove all words which contain some other word as a substring. They do not affect anything, but make further things more difficult.

2. Build characters tree from forbidden words. E.g. for set "aabc, abd, bcd" it will be like that:
root(a(a(b(c)),b(d)),b(c(d)))

positions in this tree will represent history (recent placed letters) and its size will be <= 100 (total amount of letters in all forbidden words)

A path from root to node is safe if it does not end in a leaf (otherwise you're in jail for 10 years). Any sub-paths of a safe path are also safe because we removed all words which could lead to such paths. So, we have a good test for path safety - it shouldn't be a leaf, and that's enough.

While we place letters, we are allowed to make only safe steps - we can't step into a leaf.

If we attempt to perform a step outside of the tree, we should apply 1st postfix of history to that tree to find where will we get after forgetting that least recent placed letter. For example, if the string 'aabce' falls out from the tree after 'aab' (i.e. there is no forbidden word starting with 'aabc'), then we will search for 'abce' (1st postfix of 'aabce') in the same manner, recursively. All this information can be precalculated (which state leads where after adding some particular letter). It's like prebuilding automaton for multi-substring search and then calculate number of programs which do not lead to terminal states.

This gave me AC in 0.031 sec and final understanding of KMP which I used blindly before :)

Edited by author 05.08.2008 04:24
Re: I solved it with a dfa + dp, but my source is very big (180 lines).. How to do it in 30 lines?
Posted by NotImplemented 14 Feb 2014 00:35
The limits are not very strict. I did not perform precalculation and did not build automata.