結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2017-04-03 03:00:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,329 bytes |
コンパイル時間 | 982 ms |
コンパイル使用メモリ | 115,440 KB |
実行使用メモリ | 26,336 KB |
最終ジャッジ日時 | 2024-07-08 00:29:01 |
合計ジャッジ時間 | 2,386 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class P { class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) { } public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) { } public PriorityQueue(Comparison<T> comparison) : this(16, comparison) { } public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } static void Solve() { while (2 < W.Count) { int l1 = W.Dequeue(); int l2 = W.Dequeue(); W.Enqueue(l1 + l2); } } static int N; static PriorityQueue<int> W = new PriorityQueue<int>(); static void Main(string[] _) { N = int.Parse(Console.ReadLine()); _ = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { W.Enqueue(int.Parse(_[i])); } Solve(); Console.WriteLine(W.Dequeue() == W.Dequeue() ? "possible" : "impossible"); } }