greateric's blog

By greateric, history, 7 days ago, In English

Think FFT doesn't matter? You're probably right I found an unintended extra speedup to a div 2 E that I thought was funny.

I was practicing and came across 2025E while practicing, a 2200 problem from an educational div2.

If you want, try the problem yourself. Then suppose $$$m = 1000, n = 1000$$$, and see if you can solve it in faster than cubic time.


This is my cubic solution (read this even if you've solved it yourself/seen the editorial since I thought of a slightly different way to do it)

Answer

Now for the fun part.

FFT
Tags fft
  • Vote: I like it
  • +26
  • Vote: I do not like it

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by greateric (previous revision, new revision, compare).

»
7 days ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

you can optimise the convolution portion further: notice that you are convolving dp2 with itself n times (dp is initially [1, 0, 0, ..., 0, 0] which is the identity element for convolutions). Write that as (dp2)^N. The convolution operation is commutative, so you can compute (dp2)^N using binary exponentiation. for n <= 500 this means you can compute the final answer in just 9(!) FFTs. (also because dp2 is just catalan numbers you can solve the whole problem in O(m + 9mlogm) = O(mlogm))

»
6 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it