Solution #1: AC in 0.8 sec
Just calculate sum using Gauss's method.
Int[-1..1] f(x)dx ~= (5*f(-sqrt(3/5)) + 8*f(0) + 5*f(+sqrt(3/5))) / 9
Number of parts, N = (int)7e6
Length of part number i = (1e-4)*koef^i, where koef = 1 + x/N. Try some different x = 0.1 ... 10, and get AC =)
Solution #2: WA 11 on MSVC or AC on Java, Pascal, GNU C++
http://en.wikipedia.org/wiki/Residue_theorem says that we have to find all complex roots of the polynom.
I do not like exact formulas for degree 3 and 4.
There is numerical way to find all complex roots for any degree of polynom.
Just take point z = (0,0) and shift it to any direction in such a way that |P(z+shift)| < |P(z)|. Shift it while |P(z)| > eps. Now z is a root. This method works not only for polynoms, it works even for arbitrary "holomorphic function" (see Complex Analysis). Prove is smth like this
http://en.wikipedia.org/wiki/Maximum_modulus_principle The only thing that I need now -- to calculate f(z) for any complex z.
And using only "double" of Microsoft Visual C++ I can't. I have no enough precision and get WA 11 =(
Using BigDecimal (java), extended (pascal) or long double (GNU C/C++) this method gets AC (the task is from Petrozavodsk, so I have original tests).
P.S. 2 Admins: Ну сколько можно добавлять задачки с контестов, где у С++ программистов был под рукой long double, и это было важно. Даешь GNU C/C++!
Edited by author 27.10.2012 08:08