結果

問題 No.9 モンスターのレベル上げ
ユーザー 14番14番
提出日時 2016-05-28 13:01:41
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 5,468 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 109,056 KB
実行使用メモリ 32,000 KB
最終ジャッジ日時 2024-04-16 18:07:28
合計ジャッジ時間 8,300 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
19,200 KB
testcase_01 AC 34 ms
19,328 KB
testcase_02 AC 671 ms
32,000 KB
testcase_03 WA -
testcase_04 AC 295 ms
25,600 KB
testcase_05 AC 204 ms
24,576 KB
testcase_06 AC 93 ms
23,892 KB
testcase_07 AC 35 ms
19,584 KB
testcase_08 AC 115 ms
23,908 KB
testcase_09 AC 646 ms
31,360 KB
testcase_10 AC 31 ms
19,072 KB
testcase_11 AC 683 ms
31,872 KB
testcase_12 WA -
testcase_13 AC 616 ms
31,616 KB
testcase_14 AC 647 ms
31,232 KB
testcase_15 AC 600 ms
30,592 KB
testcase_16 WA -
testcase_17 AC 395 ms
27,136 KB
testcase_18 AC 333 ms
26,240 KB
testcase_19 AC 43 ms
21,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int monsterCount = int.Parse(Reader.ReadLine());
        List<int> mikata = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).OrderBy(a=>a).ToList();
        
        TreeNode root = this.CreateTree(mikata);
        
        List<int> teki = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToList();
        
        long ans = long.MaxValue;
        for(int i=0; i<teki.Count; i++) {
            TreeNode sub = root.Duplicate();
            for(int j=0; j<teki.Count; j++) {
                int idx = (i+j) % teki.Count;
                sub.Item.Count++;
                sub.Item.Level += (teki[idx] / 2);
                sub.Swap();
            }
            ans = Math.Min(ans, sub.MaxCount());
        }
        Console.WriteLine(ans);
    }
    
    public class Mikata {
        public int Level;
        public int Count;
        
        public Mikata Duplicate() {
            Mikata newM = new Mikata(this.Level);
            newM.Count = this.Count;
            return newM;
        }
        
        public Mikata(int level) {
            this.Level = level;
        }
        
    }
    
    public TreeNode CreateTree(List<int> src) {
        Queue<TreeNode> task = new Queue<TreeNode>();
        TreeNode root = new TreeNode();
        root.Item = new Mikata(src[0]);
        task.Enqueue(root);
        for(int i=0; i<src.Count; i+=2) {
            TreeNode tr = task.Dequeue();
            tr.Left = new TreeNode();
            tr.Left.Parent = tr;
            tr.Left.Item = new Mikata(src[i]);
            task.Enqueue(tr.Left);
            if(i+1 >= src.Count) {
                break;
            }
            tr.Right = new TreeNode();
            tr.Right.Parent = tr;
            tr.Right.Item = new Mikata(src[i+1]);
            task.Enqueue(tr.Right);
        }
        return root;
    }
    
    public class TreeNode {
        public TreeNode Parent;
        public TreeNode Left;
        public TreeNode Right;
        
        public Mikata Item;
        
        public int MaxCount() {
            int ans = this.Item.Count;
            if(this.Left != null) {
                ans = Math.Max(ans, this.Left.MaxCount());
            }
            if(this.Right != null) {
                ans = Math.Max(ans, this.Right.MaxCount());
            }
            return ans;
        }
        public TreeNode Duplicate() {
            TreeNode tn = new TreeNode();
            if(this.Left != null) {
                tn.Left = this.Left.Duplicate();
                tn.Left.Parent = tn;
            }
            if(this.Right != null) {
                tn.Right = this.Right.Duplicate();
                tn.Right.Parent = tn;
            }
            tn.Item = this.Item.Duplicate();
            return tn;
        }
        private bool IsSmaller(TreeNode target) {
            if(this.Item.Level < target.Item.Level) {
                return true;
            } else if(this.Item.Level > target.Item.Level) {
                return false;
            } else if(this.Item.Count < target.Item.Count) {
                return true;
            }
            return false;
        }
        public void Swap() {
            // 小さいものが上にくる
            if(this.Left == null && this.Right == null) {
                return;
            }
            bool isLeft = true;
            bool mustSwap = false;
            
            if(this.Left != null & this.Right != null) {
                if(this.Right.IsSmaller(this.Left)) {
                    if(this.Right.IsSmaller(this)) {
                        isLeft = false;
                        mustSwap = true;
                    }
                } else {
                    if(this.Left.IsSmaller(this)) {
                        isLeft = true;
                        mustSwap = true;
                    }
                }
            } else if(this.Left != null && this.Left.IsSmaller(this)) {
                isLeft = true;
                mustSwap = true;
            } else if(this.Right != null && this.Right.IsSmaller(this)) {
                isLeft = false;
                mustSwap = true;
            }
            if(mustSwap) {
                if(isLeft) {
                    Mikata tmp = this.Item;
                    this.Item = this.Left.Item;
                    this.Left.Item = tmp;
                    this.Left.Swap();
                    
                } else {
                    Mikata tmp = this.Item;
                    this.Item = this.Right.Item;
                    this.Right.Item = tmp;
                    this.Right.Swap();
                }
            }
        }
        
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"








";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0