結果

問題 No.281 門松と魔法(1)
ユーザー 明智重蔵明智重蔵
提出日時 2015-10-02 09:38:47
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 3,941 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 112,452 KB
実行使用メモリ 27,896 KB
最終ジャッジ日時 2024-04-24 11:55:54
合計ジャッジ時間 3,688 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,844 KB
testcase_01 AC 25 ms
23,664 KB
testcase_02 AC 25 ms
23,976 KB
testcase_03 AC 25 ms
23,464 KB
testcase_04 AC 25 ms
23,720 KB
testcase_05 AC 24 ms
21,684 KB
testcase_06 AC 25 ms
23,720 KB
testcase_07 AC 25 ms
25,972 KB
testcase_08 AC 24 ms
21,808 KB
testcase_09 AC 25 ms
23,848 KB
testcase_10 AC 25 ms
23,728 KB
testcase_11 AC 24 ms
23,792 KB
testcase_12 AC 25 ms
23,688 KB
testcase_13 AC 25 ms
25,984 KB
testcase_14 AC 25 ms
23,852 KB
testcase_15 AC 25 ms
23,540 KB
testcase_16 AC 25 ms
23,716 KB
testcase_17 AC 26 ms
23,720 KB
testcase_18 AC 26 ms
25,840 KB
testcase_19 AC 26 ms
23,852 KB
testcase_20 AC 25 ms
23,716 KB
testcase_21 AC 25 ms
27,888 KB
testcase_22 AC 25 ms
23,540 KB
testcase_23 AC 25 ms
26,016 KB
testcase_24 AC 25 ms
23,728 KB
testcase_25 AC 25 ms
23,728 KB
testcase_26 AC 24 ms
23,716 KB
testcase_27 AC 25 ms
25,728 KB
testcase_28 AC 24 ms
23,984 KB
testcase_29 AC 26 ms
23,672 KB
testcase_30 AC 25 ms
23,672 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 26 ms
23,976 KB
testcase_34 AC 25 ms
23,720 KB
testcase_35 AC 25 ms
25,756 KB
testcase_36 AC 25 ms
25,588 KB
testcase_37 AC 25 ms
21,684 KB
testcase_38 WA -
testcase_39 AC 25 ms
23,728 KB
testcase_40 AC 25 ms
23,716 KB
testcase_41 AC 24 ms
23,852 KB
testcase_42 AC 24 ms
24,112 KB
testcase_43 RE -
testcase_44 AC 25 ms
26,012 KB
testcase_45 AC 25 ms
23,972 KB
testcase_46 RE -
testcase_47 AC 25 ms
23,932 KB
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 25 ms
23,680 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 24 ms
23,596 KB
testcase_56 AC 25 ms
23,848 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.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);
    }
}
0