結果
問題 | No.1739 Princess vs. Dragoness (& AoE) |
ユーザー | だれ |
提出日時 | 2021-11-13 01:14:22 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 188 ms / 3,000 ms |
コード長 | 8,647 bytes |
コンパイル時間 | 8,608 ms |
コンパイル使用メモリ | 145,932 KB |
実行使用メモリ | 167,600 KB |
最終ジャッジ日時 | 2023-08-17 08:52:20 |
合計ジャッジ時間 | 15,083 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
33,292 KB |
testcase_01 | AC | 62 ms
31,212 KB |
testcase_02 | AC | 63 ms
31,316 KB |
testcase_03 | AC | 63 ms
31,516 KB |
testcase_04 | AC | 184 ms
47,916 KB |
testcase_05 | AC | 187 ms
49,996 KB |
testcase_06 | AC | 136 ms
51,024 KB |
testcase_07 | AC | 64 ms
31,356 KB |
testcase_08 | AC | 112 ms
44,248 KB |
testcase_09 | AC | 131 ms
45,852 KB |
testcase_10 | AC | 125 ms
40,648 KB |
testcase_11 | AC | 94 ms
36,480 KB |
testcase_12 | AC | 70 ms
32,656 KB |
testcase_13 | AC | 128 ms
45,140 KB |
testcase_14 | AC | 154 ms
47,292 KB |
testcase_15 | AC | 161 ms
49,856 KB |
testcase_16 | AC | 119 ms
36,396 KB |
testcase_17 | AC | 112 ms
41,824 KB |
testcase_18 | AC | 137 ms
41,572 KB |
testcase_19 | AC | 107 ms
41,388 KB |
testcase_20 | AC | 82 ms
37,376 KB |
testcase_21 | AC | 136 ms
47,624 KB |
testcase_22 | AC | 154 ms
50,284 KB |
testcase_23 | AC | 161 ms
49,880 KB |
testcase_24 | AC | 188 ms
49,916 KB |
testcase_25 | AC | 182 ms
47,908 KB |
testcase_26 | AC | 161 ms
51,864 KB |
testcase_27 | AC | 183 ms
49,788 KB |
testcase_28 | AC | 161 ms
47,980 KB |
testcase_29 | AC | 185 ms
51,920 KB |
testcase_30 | AC | 184 ms
51,904 KB |
testcase_31 | AC | 166 ms
49,948 KB |
testcase_32 | AC | 186 ms
49,888 KB |
testcase_33 | AC | 61 ms
31,360 KB |
testcase_34 | AC | 62 ms
33,272 KB |
testcase_35 | AC | 62 ms
31,356 KB |
testcase_36 | AC | 63 ms
31,324 KB |
testcase_37 | AC | 63 ms
31,536 KB |
testcase_38 | AC | 65 ms
31,416 KB |
testcase_39 | AC | 65 ms
33,776 KB |
testcase_40 | AC | 65 ms
33,688 KB |
testcase_41 | AC | 62 ms
31,660 KB |
testcase_42 | AC | 63 ms
167,600 KB |
コンパイルメッセージ
Determining projects to restore... Restored /home/judge/data/code/main.csproj (in 139 ms). .NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f Copyright (C) Microsoft Corporation.All rights reserved. プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください /home/judge/data/code/Main.cs(38,25): warning CS0078: l' と 数字の '1' との混同を避けるため、'L' を使用してください [/home/judge/data/code/main.csproj] /home/judge/data/code/Main.cs(39,16): warning CS0078: l' と 数字の '1' との混同を避けるため、'L' を使用してください [/home/judge/data/code/main.csproj] main -> /home/judge/data/code/bin/Release/net6.0/main.dll main -> /home/judge/data/code/bin/Release/net6.0/publish/
ソースコード
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Threading; using static System.Math; namespace CpLibrary.Contest { public class SolverC : SolverBase { Scanner sr; bool HasMultipleTestcases { get; } public override void Solve() { var (n, a, b, x, y) = sr.ReadValue<int, int, int, long, long>(); var h = sr.ReadLongArray(n); // PriorityQueue<long> que; Comparison<long> comp = Compare; var que = new PriorityQueue<long>(comp); for (int i = 0; i < n; i++) { que.Enqueue(h[i]); } for (int i = 0; i < a; i++) { var t = que.Dequeue(); t = Max(0, t - x); que.Enqueue(t); } var h2 = que.ToArray(); long ok = 10000000000l; long ng = -1l; while(ok - ng > 1) { var mid = (ok + ng) / 2; long sum = 0; for (int i = 0; i < n; i++) { sum += Max(0, h2[i] - mid); } if (sum <= b * y) ok = mid; else ng = mid; } Console.WriteLine(ok); } public int Compare(long x, long y) { if (x == y) return 0; else if (x > y) return -1; return 1; } public SolverC(Scanner sr) => this.sr = sr; public override void Run() { var _t = 1; if (HasMultipleTestcases) _t = sr.ReadInt(); while (_t-- > 0) Solve(); } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> heap; private readonly IComparer<T> comparer; public PriorityQueue(IComparer<T> comparer) { this.comparer = comparer; this.heap = new List<T>(); } public PriorityQueue(Comparison<T> comparison) : this(Comparer<T>.Create(comparison)) { } public PriorityQueue() : this(Comparer<T>.Default) { } public void Enqueue(T item) { this.heap.Add(item); int index = this.Count - 1; while (index > 0) { var par = Parent(index); if (comparer.Compare(heap[index], heap[par]) >= 0) break; Swap(index, par); index = par; } } public T Dequeue() { var ret = this.Peek; var last = this.Count - 1; heap[0] = heap[last]; heap.RemoveAt(last--); var index = 0; while (true) { var (r, l) = Child(index); int child; if (l <= last) { if (comparer.Compare(heap[l], heap[r]) < 0) child = l; else child = r; } else if (r <= last) child = r; else break; if (comparer.Compare(heap[index], heap[child]) <= 0) break; Swap(index, child); index = child; } return ret; } public T Peek => heap[0]; public int Count => heap.Count; private void Swap(int a, int b) { var t = heap[a]; heap[a] = heap[b]; heap[b] = t; } private int Parent(int index) => (index - 1) / 2; private (int l, int r) Child(int index) => (2 * index + 1, 2 * index + 2); public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count > 0) { ret.Add(this.Dequeue()); } for (int i = 0; i < ret.Count; i++) { this.Enqueue(ret[i]); } foreach (var e in ret) { yield return e; } } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); } public static class ProgramC { private static bool StartsOnThread = true; public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var sr = new Scanner(new StreamReader(Console.OpenStandardInput())); var solver = new SolverC(sr); if (StartsOnThread) { var thread = new Thread(new ThreadStart(() => solver.Run()), 1 << 27); thread.Start(); thread.Join(); } else solver.Run(); Console.Out.Flush(); } public static void Expand() => SourceExpander.Expander.Expand(); } } #region Expanded by https://github.com/naminodarie/SourceExpander namespace CpLibrary { public class Scanner { public StreamReader sr { get; private set; } string[] str; int index; char[] separators; public Scanner(StreamReader sr, char[] separators) { this.sr = sr; this.separators = separators; str = new string[0]; index = 0; } public Scanner(StreamReader sr): this(sr, new char[]{' '}) { } public Scanner(): this(new StreamReader(Console.OpenStandardInput()), new char[]{' '}) { } public string Read() { if (index < str.Length) return str[index++]; string s; do s = sr.ReadLine(); while (s == ""); str = s.Split(separators, StringSplitOptions.RemoveEmptyEntries); index = 0; return str[index++]; } public string ReadString() => Read(); public string[] ReadStringArray(int n) { var arr = new string[n]; for (int i = 0; i < n; i++) { arr[i] = ReadString(); } return arr; } public int ReadInt() => int.Parse(ReadString()); public int[] ReadIntArray(int n) => ReadValueArray<int>(n); public long ReadLong() => long.Parse(ReadString()); public long[] ReadLongArray(int n) => ReadValueArray<long>(n); public double ReadDouble() => double.Parse(ReadString()); public double[] ReadDoubleArray(int n) => ReadValueArray<double>(n); public BigInteger ReadBigInteger() => BigInteger.Parse(ReadString()); public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public T1[] ReadValueArray<T1>(int n) { var arr = new T1[n]; for (int i = 0; i < n; i++) { arr[i] = ReadValue<T1>(); } return arr; } public (T1, T2) ReadValue<T1, T2>() => (ReadValue<T1>(), ReadValue<T2>()); public (T1, T2, T3) ReadValue<T1, T2, T3>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>()); public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>()); public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>()); public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>(), ReadValue<T6>()); public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() => (ReadValue<T1>(), ReadValue<T2>(), ReadValue<T3>(), ReadValue<T4>(), ReadValue<T5>(), ReadValue<T6>(), ReadValue<T7>()); public (T1[], T2[]) ReadValueArray<T1, T2>(int n) { var(v1, v2) = (new T1[n], new T2[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i]) = ReadValue<T1, T2>(); } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int n) { var(v1, v2, v3) = (new T1[n], new T2[n], new T3[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i]) = ReadValue<T1, T2, T3>(); } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int n) { var(v1, v2, v3, v4) = (new T1[n], new T2[n], new T3[n], new T4[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i]) = ReadValue<T1, T2, T3, T4>(); } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int n) { var(v1, v2, v3, v4, v5) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i]) = ReadValue<T1, T2, T3, T4, T5>(); } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int n) { var(v1, v2, v3, v4, v5, v6) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i]) = ReadValue<T1, T2, T3, T4, T5, T6>(); } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int n) { var(v1, v2, v3, v4, v5, v6, v7) = (new T1[n], new T2[n], new T3[n], new T4[n], new T5[n], new T6[n], new T7[n]); for (int i = 0; i < n; i++) { (v1[i], v2[i], v3[i], v4[i], v5[i], v6[i], v7[i]) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); } return (v1, v2, v3, v4, v5, v6, v7); } } } namespace CpLibrary { public interface ISolver { public void Solve(); public void Run(); } public abstract class SolverBase : ISolver { public abstract void Solve(); public abstract void Run(); public bool YesNo(bool condition) { Console.WriteLine(condition ? "Yes" : "No"); return condition; } public bool YESNO(bool condition) { Console.WriteLine(condition ? "YES" : "NO"); return condition; } public bool yesno(bool condition) { Console.WriteLine(condition ? "yes" : "no"); return condition; } } } namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}} #endregion Expanded by https://github.com/naminodarie/SourceExpander