結果
問題 |
No.2248 max(C)-min(C)
|
ユーザー |
![]() |
提出日時 | 2025-03-26 15:46:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,088 ms / 3,000 ms |
コード長 | 1,573 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,564 KB |
実行使用メモリ | 180,816 KB |
最終ジャッジ日時 | 2025-03-26 15:48:25 |
合計ジャッジ時間 | 57,831 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx+N])) idx += N B = list(map(int, input[idx:idx+N])) idx += N possible_x = None for i in range(N): a = A[i] b = B[i] m = (a + b) // 2 current = {a, b, m} if possible_x is None: possible_x = current else: possible_x &= current if not possible_x: break if possible_x: print(0) return candidates = [] for i in range(N): a = A[i] b = B[i] m = (a + b) // 2 candidates.append((a, i)) candidates.append((b, i)) candidates.append((m, i)) candidates.sort() freq = [0] * N count = 0 min_length = float('inf') left = 0 for right in range(len(candidates)): val, group = candidates[right] if freq[group] == 0: count += 1 freq[group] += 1 while count == N and left <= right: current_min = candidates[left][0] current_max = val current_length = current_max - current_min if current_length < min_length: min_length = current_length left_val, left_group = candidates[left] freq[left_group] -= 1 if freq[left_group] == 0: count -= 1 left += 1 print(min_length) if __name__ == '__main__': main()