結果
問題 | No.1739 Princess vs. Dragoness (& AoE) |
ユーザー | だれ |
提出日時 | 2021-11-13 01:14:22 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 391 ms / 3,000 ms |
コード長 | 8,647 bytes |
コンパイル時間 | 13,687 ms |
コンパイル使用メモリ | 167,184 KB |
実行使用メモリ | 193,200 KB |
最終ジャッジ日時 | 2024-11-26 04:01:54 |
合計ジャッジ時間 | 21,871 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
29,952 KB |
testcase_01 | AC | 50 ms
30,056 KB |
testcase_02 | AC | 49 ms
30,332 KB |
testcase_03 | AC | 53 ms
30,720 KB |
testcase_04 | AC | 353 ms
52,092 KB |
testcase_05 | AC | 390 ms
51,840 KB |
testcase_06 | AC | 260 ms
55,808 KB |
testcase_07 | AC | 59 ms
30,976 KB |
testcase_08 | AC | 159 ms
44,288 KB |
testcase_09 | AC | 211 ms
50,176 KB |
testcase_10 | AC | 244 ms
40,424 KB |
testcase_11 | AC | 136 ms
39,168 KB |
testcase_12 | AC | 71 ms
32,384 KB |
testcase_13 | AC | 209 ms
45,308 KB |
testcase_14 | AC | 285 ms
48,128 KB |
testcase_15 | AC | 297 ms
52,608 KB |
testcase_16 | AC | 224 ms
38,912 KB |
testcase_17 | AC | 172 ms
42,624 KB |
testcase_18 | AC | 254 ms
41,728 KB |
testcase_19 | AC | 153 ms
42,496 KB |
testcase_20 | AC | 104 ms
36,328 KB |
testcase_21 | AC | 227 ms
49,256 KB |
testcase_22 | AC | 279 ms
50,168 KB |
testcase_23 | AC | 297 ms
52,352 KB |
testcase_24 | AC | 383 ms
51,964 KB |
testcase_25 | AC | 369 ms
51,944 KB |
testcase_26 | AC | 298 ms
51,712 KB |
testcase_27 | AC | 381 ms
51,840 KB |
testcase_28 | AC | 314 ms
52,348 KB |
testcase_29 | AC | 391 ms
52,096 KB |
testcase_30 | AC | 366 ms
52,480 KB |
testcase_31 | AC | 326 ms
51,964 KB |
testcase_32 | AC | 387 ms
51,960 KB |
testcase_33 | AC | 56 ms
30,056 KB |
testcase_34 | AC | 54 ms
30,208 KB |
testcase_35 | AC | 52 ms
29,952 KB |
testcase_36 | AC | 50 ms
30,080 KB |
testcase_37 | AC | 51 ms
30,336 KB |
testcase_38 | AC | 54 ms
31,232 KB |
testcase_39 | AC | 55 ms
30,976 KB |
testcase_40 | AC | 54 ms
31,104 KB |
testcase_41 | AC | 54 ms
31,232 KB |
testcase_42 | AC | 53 ms
193,200 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (88 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) /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/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.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