結果
問題 |
No.1460 Max of Min
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:34:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,438 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 522,436 KB |
最終ジャッジ日時 | 2025-06-12 14:34:52 |
合計ジャッジ時間 | 4,567 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 4 WA * 3 MLE * 1 -- * 83 |
ソースコード
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())) M = max(B) # Check if any initial A_i >= M for a in A: if a >= M: if N < K: print(A[N]) else: print(M) return # If N is less than K, output directly if N < K: print(A[N]) return current = deque(A) history = {} step = K while True: # Compute next value max_val = -float('inf') for j in range(K): p = current[j] b = B[j] current_min = min(p, b) if current_min > max_val: max_val = current_min X = max_val # Check if X >= M (though in this case, it's not possible) if X >= M: print(M) return # Update the current window current.popleft() current.append(X) # Check if all elements are the same first = current[0] all_same = True for x in current: if x != first: all_same = False break if all_same: print(first) return # Check for cycle current_tuple = tuple(current) if current_tuple in history: # Found a cycle prev_step = history[current_tuple] cycle_length = step - prev_step remaining = N - step if remaining <= 0: print(current[-1]) return remaining %= cycle_length # Simulate remaining steps for _ in range(remaining): max_val = -float('inf') for j in range(K): p = current[j] b = B[j] current_min = min(p, b) if current_min > max_val: max_val = current_min X = max_val current.popleft() current.append(X) print(X) return else: history[current_tuple] = step step += 1 if step > N: print(current[-1]) return if __name__ == "__main__": main()