結果
| 問題 | No.77 レンガのピラミッド |
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2014-11-27 23:47:26 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,592 bytes |
| 記録 | |
| コンパイル時間 | 4,407 ms |
| コンパイル使用メモリ | 104,832 KB |
| 実行使用メモリ | 19,968 KB |
| 最終ジャッジ日時 | 2026-06-06 14:12:13 |
| 合計ジャッジ時間 | 6,027 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 RE * 1 |
| other | AC * 2 WA * 1 RE * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}
nanophoto12