結果
問題 |
No.9 モンスターのレベル上げ
|
ユーザー |
![]() |
提出日時 | 2014-11-06 23:34:11 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,724 bytes |
コンパイル時間 | 2,850 ms |
コンパイル使用メモリ | 114,984 KB |
実行使用メモリ | 51,700 KB |
最終ジャッジ日時 | 2024-12-31 06:30:25 |
合計ジャッジ時間 | 33,049 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; internal class Program { internal class PriorityComparer : IComparer<Tuple<int, int>> { public int Compare(Tuple<int, int> x, Tuple<int, int> y) { int firstCompared = x.Item1.CompareTo(y.Item1); if (firstCompared == 0) { return x.Item2.CompareTo(y.Item2); } return firstCompared; } } private static readonly PriorityComparer _comparer = new PriorityComparer(); static void PushHeap(List<Tuple<int,int>> array, Tuple<int,int> elem) { int n = array.Count; array.Add(elem); while (n != 0) { int i = (n - 1) / 2; if (_comparer.Compare(array[n], array[i]) > 0) { var tmp = array[n]; array[n] = array[i]; array[i] = tmp; } n = i; } } static Tuple<int,int> PopHeap(List<Tuple<int,int>> array) { int n = array.Count - 1; var target = array[n/2]; array.RemoveAt(n/2); for (int i = 0, j; (j = 2 * i + 1) < n; ) { if ((j != n - 1) && (_comparer.Compare(array[j], array[j + 1]) < 0)) j++; if (_comparer.Compare(array[i], array[j]) < 0) { var tmp = array[j]; array[j] = array[i]; array[i] = tmp; } i = j; } return target; } public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var own = Console.ReadLine().Split(' ').Select(element=>new Tuple<int,int>(int.Parse(element), 0)).ToArray(); var opposites = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var list = new List<Tuple<int, int>>(); foreach (var element in own) { PushHeap(list, element); } var battleCounts = new int[n]; for (int i = 0; i < n; i++) { var maxBattleCount = 0; var source = new List<Tuple<int,int>>(list); for (int k = i; k < i + n; k++) { var first = PopHeap(source); var opposite = opposites[k%n]; int battleCount = first.Item2 + 1; PushHeap(source, new Tuple<int,int>(first.Item1 + opposite/2, battleCount)); maxBattleCount = Math.Max(maxBattleCount, battleCount); } battleCounts[i] = maxBattleCount; } Console.WriteLine(battleCounts.Min()); } }