結果

問題 No.77 レンガのピラミッド
ユーザー 明智重蔵明智重蔵
提出日時 2015-11-03 12:25:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 2,662 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 105,764 KB
実行使用メモリ 23,996 KB
最終ジャッジ日時 2023-10-11 13:19:14
合計ジャッジ時間 5,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
23,880 KB
testcase_01 AC 63 ms
21,944 KB
testcase_02 AC 64 ms
21,760 KB
testcase_03 AC 63 ms
21,916 KB
testcase_04 AC 62 ms
21,904 KB
testcase_05 AC 63 ms
21,716 KB
testcase_06 AC 63 ms
23,996 KB
testcase_07 AC 63 ms
21,920 KB
testcase_08 AC 62 ms
23,904 KB
testcase_09 AC 63 ms
23,964 KB
testcase_10 AC 63 ms
21,908 KB
testcase_11 AC 63 ms
21,940 KB
testcase_12 AC 63 ms
19,816 KB
testcase_13 AC 63 ms
23,964 KB
testcase_14 AC 63 ms
21,920 KB
testcase_15 AC 63 ms
21,956 KB
testcase_16 AC 64 ms
21,760 KB
testcase_17 AC 64 ms
23,872 KB
testcase_18 AC 63 ms
21,788 KB
testcase_19 AC 62 ms
21,984 KB
testcase_20 AC 62 ms
19,912 KB
testcase_21 AC 63 ms
21,924 KB
testcase_22 AC 63 ms
21,956 KB
testcase_23 AC 63 ms
21,920 KB
testcase_24 AC 63 ms
23,976 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.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5");
            WillReturn.Add("2 2 2 1 2");
            //2
            //1列目のブロックを3列目に移動し、
            //5列目のブロックを4列目に移動すると、
            //ピラミッド配置になるので、2個のブロックを移動するとピラミッド配置になる
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("3 2 3");
            //4
            //4つのレンガを捨て置き場に移動すると、ピラミッド配置になる
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("9");
            WillReturn.Add("1 1 1 1 1 1 1 1 1");
            //4
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("3");
            WillReturn.Add("1 2 1");
            //0
            //すでにピラミッド配置になっている
        }
        else if (InputPattern == "Input5") {
            WillReturn.Add("1");
            WillReturn.Add("4");
            //3
            //最初が1列しかない場合でも3つ動かすことで3列のピラミッドができる
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        //レンガを捨てるのも、移動させるのも、同じコストなので
        //最大のピラミッドを作成するコストを求めればOK

        //最大のピラミッドの段数を求める
        int RengaCnt = AArr.Sum();
        int PyramidHeight = (int)Math.Sqrt(RengaCnt);

        int KasanVal = 1;
        int CurrHeight = 1;
        int Answer = 0;
        for (int I = 0; I <= AArr.GetUpperBound(0); I++) {
            //Console.WriteLine("現在のピラミッドの高さ={0}", CurrHeight);
            if (CurrHeight < AArr[I]) {
                Answer += AArr[I] - CurrHeight;
            }

            if (CurrHeight > 0) {
                if (CurrHeight == PyramidHeight) {
                    KasanVal = -1;
                }
                CurrHeight += KasanVal;
            }
        }
        Console.WriteLine(Answer);
    }
}
0