結果
| 問題 |
No.954 Result
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 21:11:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 1,417 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 82,372 KB |
| 実行使用メモリ | 54,056 KB |
| 最終ジャッジ日時 | 2025-03-20 21:12:39 |
| 合計ジャッジ時間 | 2,830 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 7 |
| other | AC * 29 |
ソースコード
# Generate the Fibonacci list up to a sufficiently large number
fib = [1, 1]
while True:
next_val = fib[-1] + fib[-2]
fib.append(next_val)
if next_val > 10**18:
break
# Read input and reverse it to process from the bottom up
s = [int(input()) for _ in range(5)][::-1]
max_n = 0
# Check from n=5 down to n=1
for n in range(5, 0, -1):
sub = s[:n]
# Check non-decreasing
valid_non_decreasing = True
for i in range(len(sub) - 1):
if sub[i] > sub[i + 1]:
valid_non_decreasing = False
break
if not valid_non_decreasing:
continue
# Check Fibonacci conditions
if len(sub) == 1:
# Check if the single element is a Fibonacci number
if sub[0] in fib:
max_n = n
break
else:
a, b = sub[0], sub[1]
# Check if a and b are consecutive Fibonacci numbers
found = False
for i in range(len(fib) - 1):
if fib[i] == a and fib[i + 1] == b:
found = True
break
if not found:
continue
# Check subsequent elements follow the Fibonacci rule
valid_rest = True
for i in range(2, len(sub)):
if sub[i] != sub[i - 1] + sub[i - 2]:
valid_rest = False
break
if valid_rest:
max_n = n
break
print(max_n)
lam6er