結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
![]() |
提出日時 | 2015-10-02 09:38:47 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,941 bytes |
コンパイル時間 | 874 ms |
コンパイル使用メモリ | 114,148 KB |
実行使用メモリ | 27,888 KB |
最終ジャッジ日時 | 2024-11-06 19:43:58 |
合計ジャッジ時間 | 3,800 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 WA * 1 RE * 10 |
コンパイルメッセージ
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 = "Input5"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("1"); WillReturn.Add("3"); WillReturn.Add("3"); WillReturn.Add("4"); //1 //真ん中の竹に1度魔法を唱えることで。条件を満たすことができます } else if (InputPattern == "Input2") { WillReturn.Add("411"); WillReturn.Add("4"); WillReturn.Add("1"); WillReturn.Add("5"); //0 //魔法を使う必要がないこともあります } else if (InputPattern == "Input3") { WillReturn.Add("2"); WillReturn.Add("3"); WillReturn.Add("10"); WillReturn.Add("12"); //2 } else if (InputPattern == "Input4") { WillReturn.Add("1"); WillReturn.Add("0"); WillReturn.Add("0"); WillReturn.Add("0"); //-1 //魔法を使ってもどうしようもないこともあります } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static int D; static void Main() { List<string> InputList = GetInputList(); D = int.Parse(InputList[0]); int H1 = int.Parse(InputList[1]); int H2 = int.Parse(InputList[2]); int H3 = int.Parse(InputList[3]); Console.WriteLine(DeriveAnswer(H1, H2, H3)); } static int DeriveAnswer(int pH1, int pH2, int pH3) { int wkInt1 = DeriveMahouCnt1(pH1, pH2, pH3); int wkInt2 = DeriveMahouCnt2(pH1, pH2, pH3); if (wkInt1 == -1 && wkInt2 == -1) return -1; else if (wkInt1 == -1 && wkInt2 != -1) return wkInt2; else if (wkInt1 != -1 && wkInt2 == -1) return wkInt1; else return Math.Min(wkInt1, wkInt2); } //3本の竹全ての高さが互いに異なり、 //真ん中の竹の高さが一番高い状態にする static int DeriveMahouCnt1(int pH1, int pH2, int pH3) { int MahouCnt = 0; if (pH2 <= pH1) { int wkCnt = (pH1 - pH2) / D + 1; ExecMahou(ref pH1, wkCnt); MahouCnt += wkCnt; } if (pH2 <= pH3) { int wkCnt = (pH3 - pH2) / D + 1; ExecMahou(ref pH3, wkCnt); MahouCnt += wkCnt; } if (pH1 == pH3) { ExecMahou(ref pH1, 1); MahouCnt++; } if (pH1 == pH2) return -1; if (pH1 == pH3) return -1; if (pH2 == pH3) return -1; if (pH2 <= pH1) return -1; if (pH2 <= pH3) return -1; return MahouCnt; } //3本の竹全ての高さが互いに異なり、 //真ん中の竹の高さが一番低い状態にする static int DeriveMahouCnt2(int pH1, int pH2, int pH3) { int MahouCnt = 0; if (pH1 <= pH2) { int wkCnt = (pH2 - pH1) / D + 1; ExecMahou(ref pH2, wkCnt); MahouCnt += wkCnt; } if (pH3 <= pH2) { int wkCnt = (pH2 - pH3) / D + 1; ExecMahou(ref pH2, wkCnt); MahouCnt += wkCnt; } if (pH1 == pH3) { ExecMahou(ref pH1, 1); MahouCnt++; } if (pH1 == pH2) return -1; if (pH1 == pH3) return -1; if (pH2 == pH3) return -1; if (pH1 <= pH2) return -1; if (pH3 <= pH2) return -1; return MahouCnt; } //魔法をN回実行する static void ExecMahou(ref int pTarget, int pN) { pTarget = Math.Max(0, pTarget - pN * D); } }