結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | rlangevin |
提出日時 | 2023-01-16 20:23:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 413 ms / 5,000 ms |
コード長 | 579 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 87,136 KB |
実行使用メモリ | 84,224 KB |
最終ジャッジ日時 | 2023-08-30 03:05:18 |
合計ジャッジ時間 | 2,928 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 362 ms
82,100 KB |
testcase_01 | AC | 413 ms
84,224 KB |
testcase_02 | AC | 324 ms
81,588 KB |
testcase_03 | AC | 358 ms
83,368 KB |
ソースコード
from collections import * from heapq import * T = int(input()) for _ in range(T): N = int(input()) L = list(map(int, input().split())) D = defaultdict(int) for a in L: D[a] += 1 H = [] for k, v in D.items(): heappush(H, -v) ans = 0 while len(H) >= 3: a = heappop(H) b = heappop(H) c = heappop(H) a, b, c = -a - 1, -b - 1, -c - 1 ans += 1 if a: heappush(H, -a) if b: heappush(H, -b) if c: heappush(H, -c) print(ans)