ENG  RUSTimus 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 1395. Pascal vs. C++. Version 2

an easy method
Posted by Celebrate 20 Aug 2021 13:16
(Please forgive me for my poor English.)
First,use Hash to record ai
Then,enumerate i,j as the first and the second items in the arithmetic sequence.check if 2*a[i]-a[j] exists.If it exists,we stop it immediately because the arithmetic sequence has been found.Otherwise,we find the arithmetic as brute force and mark the longest arithmetic sequence.
At last,it's easy to restore the arithmetic sequence.
So we can solve it in O(n^2).

Edited by author 20.08.2021 13:43