結果
問題 |
No.1373 Directed Operations
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:47:24 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,106 bytes |
コンパイル時間 | 245 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 125,160 KB |
最終ジャッジ日時 | 2025-05-14 12:48:46 |
合計ジャッジ時間 | 4,165 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | TLE * 1 -- * 18 |
ソースコード
import heapq def main(): import sys input = sys.stdin.read data = input().split() n = int(data[0]) a_list = list(map(int, data[1:n])) connected = set([1]) heap = [1] heapq.heapify(heap) result = [] possible = True for ai in a_list: found = False temp = [] while heap: x = heapq.heappop(heap) new_node = x + ai if new_node > n: temp.append(x) continue if new_node not in connected: connected.add(new_node) heapq.heappush(heap, x) heapq.heappush(heap, new_node) result.append(x) found = True break else: temp.append(x) for x in temp: heapq.heappush(heap, x) if not found: possible = False break if possible and len(connected) == n: print("YES") print('\n'.join(map(str, result))) else: print("NO") if __name__ == "__main__": main()