Go with the Flow

From programming_contest
Revision as of 05:10, 5 November 2018 by Kmk21 (talk | contribs) (Created page with "This problem asks us to take a string of text, and flow it using some line length to get long vertical sequences of whitespace. The nature of flowing lines means that small c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This problem asks us to take a string of text, and flow it using some line length to get long vertical sequences of whitespace.

The nature of flowing lines means that small changes at the top of the text may have major nearly unpredictable effects lower. This makes it impractical to have much cleverness, so we try brute force over all 80 * 2500 possible line lengths. Flowing the text takes another 2500, and naively, checking the "rivers" is 80 * 2500. 80^2 * 2500^2 is obviously too slow. The simplest optimization is just to optimize checking for rivers by only looking at the ends of each word. This reduces the complexity to 80 * 2500^2 = 500 million, which is borderline, but should be fast enough. If we're still worried, we can do some other optimizations like instead of evaluating all 80 * 2500 line lengths, remember the next line length that will cause any words to move, and skip to that. We could also short circuit evaluate when the number of lines is fewer than the maximum river we've already found. This should cause us to stop when we're down to at least 2 lines, which is plenty enough if we thought we were on the border already.