ENG  RUS Timus 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 2097. Snowboarding on Spilnaya

Hint
Posted by Jorjia 18 Sep 2018 18:00
x[i] - y[i] = a * i + b

x[i-1] - y[i-1] = a * (i-1) + b

------------------------------------

x[i] - x[i-1]  - ( y [i] - y[i-1] ) = a

Let x1[i] = x[i] - x[i-1], i > 0. and y1[i] = y[i] - y[i-1], for i>0.

so ,

x1[i] - y1[i] = a,  a = x1[0] - y1[0].

x1[i-1] - y1[i-1] = a
-------------------------------
x1[i]  - x1[i-1] - (y1[i ] - y1[i-1]) = 0  or,

x1[i] - x1[i-1] = y1[i] - y1[i-1]

Let x2[i] = x1[i] - x1[i-1] = x[i] - 2*x[i-1] + x[i-2], for i>1. and
y2[i] = y1[i] - y1[i-1] = y[i] - 2*y[i-1] + y[i-2], for i>1.

so  x2[i] = y2[i],  for all 1 < i <= n.

Use KMP.

I didn't try this, yet ).