結果
| 問題 |
No.77 レンガのピラミッド
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-11-03 12:25:27 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 5,000 ms |
| コード長 | 2,662 bytes |
| コンパイル時間 | 1,068 ms |
| コンパイル使用メモリ | 112,492 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-09-13 12:04:27 |
| 合計ジャッジ時間 | 2,866 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.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);
}
}
明智重蔵