結果

問題 No.4 おもりと天秤
ユーザー masaktmasakt
提出日時 2017-04-03 03:00:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,329 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 106,872 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-09-22 08:04:47
合計ジャッジ時間 5,258 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
20,804 KB
testcase_01 AC 61 ms
22,676 KB
testcase_02 AC 61 ms
20,688 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 62 ms
22,816 KB
testcase_07 WA -
testcase_08 AC 63 ms
20,584 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 60 ms
22,872 KB
testcase_12 AC 62 ms
20,804 KB
testcase_13 AC 61 ms
22,684 KB
testcase_14 AC 62 ms
18,652 KB
testcase_15 AC 61 ms
22,812 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 62 ms
18,604 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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");
    }
}
0