結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-06-22 05:52:34 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 5,000 ms |
| コード長 | 2,209 bytes |
| コンパイル時間 | 2,297 ms |
| コンパイル使用メモリ | 116,468 KB |
| 実行使用メモリ | 29,124 KB |
| 最終ジャッジ日時 | 2024-10-02 12:07:37 |
| 合計ジャッジ時間 | 2,846 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番