結果

問題 No.77 レンガのピラミッド
ユーザー 14番14番
提出日時 2017-06-22 05:52:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 2,209 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 114,192 KB
実行使用メモリ 27,440 KB
最終ジャッジ日時 2024-04-10 10:18:13
合計ジャッジ時間 2,689 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
27,316 KB
testcase_01 AC 30 ms
27,312 KB
testcase_02 AC 30 ms
25,404 KB
testcase_03 AC 30 ms
25,148 KB
testcase_04 AC 30 ms
25,140 KB
testcase_05 AC 30 ms
27,196 KB
testcase_06 AC 30 ms
25,140 KB
testcase_07 AC 29 ms
25,132 KB
testcase_08 AC 31 ms
27,440 KB
testcase_09 AC 31 ms
25,144 KB
testcase_10 AC 31 ms
27,312 KB
testcase_11 AC 31 ms
27,304 KB
testcase_12 AC 31 ms
27,300 KB
testcase_13 AC 30 ms
25,008 KB
testcase_14 AC 30 ms
25,400 KB
testcase_15 AC 31 ms
23,352 KB
testcase_16 AC 31 ms
27,188 KB
testcase_17 AC 30 ms
25,400 KB
testcase_18 AC 30 ms
25,136 KB
testcase_19 AC 30 ms
27,196 KB
testcase_20 AC 31 ms
25,140 KB
testcase_21 AC 31 ms
25,276 KB
testcase_22 AC 30 ms
25,272 KB
testcase_23 AC 30 ms
25,152 KB
testcase_24 AC 30 ms
25,284 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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());
        this.BlockList = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int maxYama = this.GetPiramidMax(this.BlockList.Sum());
        int ans = this.BlockList.Sum();
        for (int i = maxYama; i >= 1; i--) {
            ans = Math.Min(ans, GetMoveCount(i));
        }
        Console.WriteLine(ans);
    }


    private int[] BlockList;
    private int GetMoveCount(int num) {
        List<int> yama = new List<int>();
        for (int i = 1; i <= num; i++) {
            yama.Add(i);
        }
        for (int i = num - 1; i >= 1;i--) {
            yama.Add(i);
        }
        for (int i = 0; i < BlockList.Length; i++) {
            yama.Add(0);
        }

        int ans = 0;
        for (int i = 0; i < yama.Count; i++) {
            if(i>=BlockList.Length) {
                break;
            }
            if(BlockList[i]>yama[i]) {
                ans += BlockList[i] - yama[i];
            }
        }
        return ans;
    }

    private int GetPiramidMax(int num) {
        for (int i = num; i >= 1; i--) {
            int cnt = NeedCountBlock(i);
            if(cnt <= num) {
                return i;
            }
        }
        return 1;
    }

    private int NeedCountBlock(int maxColumnHeight) {
        if(maxColumnHeight == 1) {
            return 1;
        }
        int cnt = maxColumnHeight * (maxColumnHeight + 1) / 2;
        cnt += maxColumnHeight * (maxColumnHeight - 1) / 2;
        return cnt;
    }
    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


9
1 1 1 1 1 1 1 1 1


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
0