結果

問題 No.77 レンガのピラミッド
ユーザー nanophoto12nanophoto12
提出日時 2014-11-27 23:47:26
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,592 bytes
コンパイル時間 2,982 ms
コンパイル使用メモリ 103,836 KB
実行使用メモリ 25,704 KB
最終ジャッジ日時 2023-09-01 22:27:43
合計ジャッジ時間 5,954 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
23,736 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 62 ms
21,736 KB
testcase_04 RE -
testcase_05 AC 60 ms
21,776 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 62 ms
21,836 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.Linq;

class Program77
{
    private static int PyramidCount(int row)
    {
        int sum = 0;
        for (int i = 1; i < (row+1)/2; i++)
        {
            sum += i*2;
        }
        sum += (row + 1) / 2;
        return sum;
    }

    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        var values = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var sum = values.Sum();
        int row = -1;
        while (true)
        {
            int count = PyramidCount(row+2);
            if (count > sum)
            {
                break;
            }
            row += 2;
        }
        int minValue = int.MaxValue;
        for (int currentRow = 1; currentRow <= row; currentRow+=2)
        {
            var upper = Math.Max(values.Length, currentRow+1);
            int diff = sum - PyramidCount(currentRow);
            int move = 0;
            for (int index = 0; index < upper; index++)
            {
                var center = (currentRow + 1) / 2;
                int height = center - Math.Abs(center - (index + 1));
                if (currentRow <= index)
                {
                    move += height;
                }
                else
                {
                    move += Math.Abs(values[index] - height);
                }
            }
            var count = (move - diff)/2;
            minValue = Math.Min(minValue, Math.Abs(count));
        }
        Console.WriteLine(minValue);
    }
}
0