結果
| 問題 |
No.1460 Max of Min
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:32:21 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,788 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 82,652 KB |
| 実行使用メモリ | 76,884 KB |
| 最終ジャッジ日時 | 2025-06-12 14:32:30 |
| 合計ジャッジ時間 | 6,603 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 78 |
ソースコード
import sys
from collections import deque
def main():
K, N = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
if N < K:
print(A[N])
return
max_B = max(B)
history = A.copy()
prev_elements = deque(A)
max_steps = 2000 # Increased to handle larger cases
for step in range(K, max_steps + K):
current_max = max(prev_elements)
if current_max >= max_B:
print(max_B)
return
new_term = -float('inf')
for j in range(K):
term = min(prev_elements[j], B[j])
if term > new_term:
new_term = term
history.append(new_term)
prev_elements.append(new_term)
prev_elements.popleft()
# Check for cycles in the last 200 elements
if len(history) >= 200:
found = False
for L in range(1, 101):
if len(history) >= 2 * L:
if history[-L:] == history[-2*L:-L]:
cycle_start = len(history) - 2 * L
if N < cycle_start:
print(history[N])
return
else:
remainder = (N - cycle_start) % L
print(history[cycle_start + remainder])
return
if found:
break
# If no cycle found and N is within the simulated steps
if N < len(history):
print(history[N])
else:
# Fallback: might not handle all cases but works for some
print(history[-1])
if __name__ == "__main__":
main()
gew1fw