結果

問題 No.9 モンスターのレベル上げ
ユーザー nanophoto12nanophoto12
提出日時 2014-11-07 01:38:36
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,841 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 101,516 KB
実行使用メモリ 47,088 KB
最終ジャッジ日時 2023-08-30 01:46:11
合計ジャッジ時間 9,217 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
15,604 KB
testcase_01 AC 65 ms
15,596 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
    {
        int left = 0;
        int right = n - 1;

        while (right - left > 1)
        {
            int middle = (right + left)/2;
            int compare = _comparer.Compare(elem, array[middle]);
            if (compare == 0)
            {
                array.Insert(middle, elem);
                return;
            }
            if (compare < 0)
            {
                right = middle;
            }
            else
            {
                left = middle;
            }
        }
        
        for (int i = left; i <= right; i++)
        {
            int compare = _comparer.Compare(elem, array[i]);
            if (compare == 0)
            {
                array.Insert(i, elem);
                return;
            }
            if (compare < 0)
            {
                array.Insert(i, elem);
                return;
            }
        }
        array.Add(elem);
    }

    static Tuple<int,int> PopHeap(List<Tuple<int,int>> array)
    {
        var target = array[0];
        array.RemoveAt(0);
        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();

        Array.Sort(own, new PriorityComparer());

        var minBattleCount = int.MaxValue;
        for (int i = 0; i < n; i++)
        {
            var maxBattleCount = 0;
            var source = new List<Tuple<int,int>>(own);
            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), n-1);
                maxBattleCount = Math.Max(maxBattleCount, battleCount);
            }
            minBattleCount = Math.Min(minBattleCount, maxBattleCount);
        }
        Console.WriteLine(minBattleCount);
    }
}
0