結果
問題 | No.3016 ハチマキおじさん |
ユーザー |
|
提出日時 | 2025-01-25 13:28:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 143,212 KB |
最終ジャッジ日時 | 2025-01-25 22:48:03 |
合計ジャッジ時間 | 6,638 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
import sys input = lambda: sys.stdin.readline().rstrip() def main(): # 入力 N = int(input()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) # 計算・出力 dp = [0, 10**16] ans = [] for i, b in enumerate(B): ndp = [10**16, 10**16] # i 番目を残すか? # まだ残さない ndp[0] = dp[0] + abs(A[i] - b) # もう残してる if i > 0: ndp[1] = dp[1] + abs(A[i+1] - b) # 今残す ndp1 = dp[0] + abs(A[i+1] - b) if ndp1 < ndp[1]: ans = [A[i]] ndp[1] = ndp1 elif ndp1 == ndp[1]: ans.append(A[i]) dp = ndp # print(dp) if dp[0] < dp[1]: ans = [A[-1]] elif dp[0] == dp[1]: ans.append(A[-1]) ans = sorted(list(set(ans))) print(len(ans)) print(*ans) if __name__ == "__main__": main()