POLEVAL - Evaluate the polynomial
Your task consists of evaluate a polynomial of degree n (0 <= n <= 999) represented by its n+1 coefficients of the form:
in each one of the k (1 <= k <= 100) points x1, x2, …, xk. The coefficients of the polynomial and the values where they will be evaluated are integers in the interval [-100, 100] that guarantees that the polynomial's evaluation is at the most 263 – 1.
There will be multiple test cases, each one with 4 lines that are described below
n: degree of polynomial.
cn cn-1 … c2 c1 c0: coefficients of the polynomial separated by a single space.
k: number of points to evaluate the polynomial.
x1 x2 … xk-1 xk: points to evaluate the polynomial separated by a single space.
The final test case is a single line where n = -1 and this case should not be processed.
For each test case you should print k + 1 lines of output, the very first line containing the case number and the following k lines with the result of the polynomial's evaluation in each one of the k given points. See the sample.
1 -2 -1
0 1 -1 2 -2
2 1 -2 -1
0 -1 2 -2
Output: Case 1:
AC in one Go!
Possible with pure Python, albeit just at the limit (same solution that got AC, TLEs sometimes). Code too short to talk about any optimizations. Pythonists are advised to use PyPy here.
Basically unsolvable with Python3, Horner + optimization = TLE
AC in one GO
implement horner & get AC
Naive approach works fine, AC in ONE GO!
Using Naive approach got TLE but AC using Horner's method :)
Simple yet very, very beautiful problem :D
if you get TLE ,