CF365B.The Fibonacci Segment
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have array _a_1, _a_2, ..., a__n. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if a__i = a__i - 1 + a__i - 2, for all i (l + 2 ≤ i ≤ r).
Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [_l_1, _r_1], is longer than segment [_l_2, _r_2], if len([_l_1, _r_1]) > len([_l_2, _r_2]).
Your task is to find a good segment of the maximum length in array a. Note that a segment of length 1 or 2 is always good.
你有一个数组 a1,a2,…,an。区间 [l,r](其中 1≤l≤r≤n)被称为“好区间”,当且仅当对所有 i(满足 l+2≤i≤r),都有 ai=ai−1+ai−2。
定义 len([l,r])=r−l+1,即区间 [l,r] 的长度。若 len([l1,r1])>len([l2,r2]),则称区间 [l1,r1] 比区间 [l2,r2] 更长。
你的任务是在数组 a 中找出一个长度最大的“好区间”。注意:长度为 1 或 2 的区间总是“好区间”。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of elements in the array. The second line contains integers: _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 109).
第一行包含一个整数 n(1≤n≤105)—— 数组中元素的个数。
第二行包含 n 个整数:a1, a2, …, an(0≤ai≤109)。
输出格式
Print the length of the longest good segment in array a.
输出数组 a 中最长“好”区间的长度。
输入输出样例
输入#1
10 1 2 3 5 8 13 21 34 55 89
输出#1
10
输入#2
5 1 1 1 1 1
输出#2
2
输入解题思路,AI测评打分。不知道怎么写?