結果

問題 No.1736 Princess vs. Dragoness
ユーザー O2MT
提出日時 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/

ソースコード

diff #
プレゼンテーションモードにする

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;
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0