結果
問題 | No.1736 Princess vs. Dragoness |
ユーザー |
|
提出日時 | 2021-11-24 18:48:23 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 4,333 bytes |
コンパイル時間 | 11,449 ms |
コンパイル使用メモリ | 169,044 KB |
実行使用メモリ | 185,652 KB |
最終ジャッジ日時 | 2024-06-27 04:38:29 |
合計ジャッジ時間 | 14,558 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (100 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;using System.Collections;using System.Collections.Generic;using System.Linq;namespace Sample{class Program{static void Main(string[] args){var arr = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();var (N, A, B, X, Y) = (arr[0], arr[1], arr[2], arr[3], arr[4]);var H = Console.ReadLine().Split(' ').Select(long.Parse).ToList();var PQ = new PriorityQueue<long>((int)N);H.ForEach(PQ.Push);for (int i = 0; i < A && PQ.Count > 0; i++){var num = PQ.Pop();if (num - X > 0){PQ.Push(num - X);}}for (int i = 0; i < B; i++){var YY = Y;var list = new List<long>();while (YY > 0 && PQ.Count > 0){var num = PQ.Pop();if (num > YY){list.Add(num - YY);}YY -= num;}list.ForEach(PQ.Push);}if (PQ.Count > 0){Console.WriteLine("No");}else{Console.WriteLine("Yes");}}}class PriorityQueue<T> where T : IComparable<T>{private readonly T[] _array;private readonly IComparer _comparer;public int Count { get; private set; } = 0;public T Root => _array[0];public PriorityQueue(int capacity, IComparer comparer = null){_array = new T[capacity];_comparer = comparer;}/// <summary>/// 要素を挿入する/// </summary>///public void Push(T item){_array[this.Count] = item;Count += 1;var n = Count - 1; // 末尾(追加した)のノードの番号while (n != 0){var parent = (n - 1) / 2; // 親ノードの番号if (Compare(_array[n], _array[parent]) > 0){Swap(n, parent);n = parent;}else{break;}}}/// <summary>/// 優先度の一番高いものを取り出す/// </summary>public T Pop(){Swap(0, this.Count - 1); // 先頭要素を末尾にするCount -= 1;var parent = 0; // 親ノードの番号while (true){var child = 2 * parent + 1; // 子ノードの番号if (child > Count - 1) break;// 値の大きい方の子を選ぶif (child < Count - 1 && Compare(_array[child], _array[child + 1]) < 0) child += 1;// 子の方が親より大きければ入れ替えるif (Compare(_array[parent], _array[child]) < 0){Swap(parent, child);parent = child;}else{break;}}return _array[Count];}/// <summary>/// 大きいものから列挙していく/// withPop = falseのときは順番関係なく取り出しもしないが素早く全要素を取得できる/// </summary>public IEnumerable<T> GetAllElements(bool withPop = true){int count = Count;for (int i = 0; i < count; i++){if (withPop) yield return Pop();else yield return _array[count - i - 1];}}private int Compare(T a, T b){if (_comparer == null) return a.CompareTo(b);return _comparer.Compare(a, b);}private void Swap(int a, int b){var tmp = _array[a];_array[a] = _array[b];_array[b] = tmp;}}}