結果

問題 No.9 モンスターのレベル上げ
ユーザー nanophoto12nanophoto12
提出日時 2014-11-06 23:34:11
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,724 bytes
コンパイル時間 2,833 ms
コンパイル使用メモリ 109,224 KB
実行使用メモリ 47,408 KB
最終ジャッジ日時 2023-08-30 01:44:00
合計ジャッジ時間 33,579 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,628 KB
testcase_01 AC 67 ms
21,816 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 64 ms
21,628 KB
testcase_11 WA -
testcase_12 AC 3,064 ms
43,792 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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());
    }
}

0