結果

問題 No.9 モンスターのレベル上げ
ユーザー mbanmban
提出日時 2017-01-14 18:35:01
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,023 bytes
コンパイル時間 2,622 ms
コンパイル使用メモリ 109,328 KB
実行使用メモリ 46,624 KB
最終ジャッジ日時 2023-08-23 10:37:18
合計ジャッジ時間 33,760 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
27,820 KB
testcase_01 AC 60 ms
22,812 KB
testcase_02 TLE -
testcase_03 AC 4,032 ms
46,496 KB
testcase_04 AC 1,835 ms
38,352 KB
testcase_05 AC 1,124 ms
38,308 KB
testcase_06 AC 356 ms
24,984 KB
testcase_07 AC 64 ms
20,820 KB
testcase_08 AC 488 ms
33,336 KB
testcase_09 TLE -
testcase_10 AC 59 ms
20,636 KB
testcase_11 AC 4,858 ms
44,452 KB
testcase_12 TLE -
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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{ 
    static void Main(string[]args)
    {
        Magatro m = new Magatro();
        m.Scan();
        m.Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;
    private string[] S;
    private int Index;

    private const char Separator=' ';

    public Scanner()
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(Console.OpenStandardInput());
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public bool ScanToEnd(ref string s)
    {
        if (Sr.EndOfStream)
        {
            return false;
        }
        else
        {
            s = Sr.ReadLine();
            return true;
        }
    }
}

public class Magatro
{
    private int N;
    private int[] A, B;

    public void Scan()
    {
        Scanner sc = new Scanner();
        N = sc.NextInt();
        A = new int[N];
        B = new int[N];
        for(int i = 0; i < N; i++)
        {
            A[i] = sc.NextInt();
        }
        for(int i = 0; i < N; i++)
        {
            B[i] = sc.NextInt();
        }
    }

    public void Solve()
    {
        int ans = int.MaxValue;
        for(int i = 0; i < N; i++)
        {
            ans = Math.Min(Ans(i), ans);
        }
        Console.WriteLine(ans);
    }
    private int Ans(int n)
    {
        var Q = new PriorityQueue<My>(Compare);
        for(int i = 0; i < N; i++)
        {
            Q.Enqueue(new My(A[i]));
        }
        for(int i = n; i < N; i++)
        {
            My t = Q.Dequeue();
            t.Cnt++;
            t.Level += B[i] / 2;
            Q.Enqueue(t);
        }
        for(int i = 0; i < n; i++)
        {
            My t = Q.Dequeue();
            t.Cnt++;
            t.Level += B[i] / 2;
            Q.Enqueue(t);
        }
        
        var L = Q.list;
        int max = 0;
        for(int i = 0; i < L.Count; i++)
        {
            max = Math.Max(max, L[i].Cnt);
        }
        return max;
    }

    private int Compare(My a,My b)
    {
        if (a.Level < b.Level) return -1;
        else if (b.Level < a.Level) return 1;
        else
        {
            if (a.Cnt < b.Cnt)
            {
                return -1;
            }
            else if(a.Cnt>b.Cnt)
            {
                return 1;
            }
            else
            {
                return 0;
            }
            
        }
    }
}

struct My
{
    public int Cnt, Level;
    public My(int level)
    {
        Level = level;
        Cnt = 0;
    }
}

public class PriorityQueue<T>
{
    public List<T> list = new List<T>();
    public IComparer<T> comp = Comparer<T>.Default;
    class Comparer : IComparer<T>
    {
        Comparison<T> comparison;
        public Comparer(Comparison<T> comparison) { this.comparison = comparison; }
        public int Compare(T x, T y) { return comparison(x, y); }
    }
    public PriorityQueue() { }
    public PriorityQueue(Comparison<T> comp) { this.comp = new Comparer(comp); }
    public void Enqueue(T item) { int i = list.BinarySearch(item, comp); list.Insert(i < 0 ? ~i : i, item); }
    public T Dequeue() { T r = list[0]; list.RemoveAt(0); return r; }
    public T Peek() { return list[0]; }
    public int Count { get { return list.Count; } }
    public T this[int i] { get { return list[i]; } set { list[i] = value; } }
}
0