結果

問題 No.115 遠足のおやつ
ユーザー 明智重蔵明智重蔵
提出日時 2015-08-13 07:57:54
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,319 bytes
コンパイル時間 4,229 ms
コンパイル使用メモリ 108,928 KB
実行使用メモリ 30,512 KB
最終ジャッジ日時 2023-09-25 11:23:23
合計ジャッジ時間 11,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = "Input4";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10 9 3");
            //1 2 6
            //ルールを満たすおかしの組み合わせは
            //(1円,2円,6円)
            //(1円,3円,5円)
            //(2円,3円,4円)
            //の3つがありますが、
            //このうち辞書順が最小になる(1円,2円,6円)の組み合わせが答えになります。
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10 9 4");
            //-1
            //残念ながら直樹くんはおかしを買うことができませんでした・・・
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("30 40 4");
            //1 2 7 30
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct JyoutaiDef
    {
        internal int CurrN;
        internal List<int> SelectedList;
        internal int SumVal;
    }

    //メモ化探索用
    struct MemoDef
    {
        internal int CurrN;
        internal int SelectedCnt;
        internal int SumVal;
    }

    //No.115 遠足のおやつ
    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        int N = wkArr[0];
        int D = wkArr[1];
        int K = wkArr[2];

        var stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrN = 1;
        WillPush.SelectedList = new List<int>();
        WillPush.SumVal = 0;
        stk.Push(WillPush);

        var MemoList = new List<MemoDef>();

        while (stk.Count > 0) {
            JyoutaiDef Popped = stk.Pop();

            //クリア判定
            if (Popped.SelectedList.Count == K) {
                if (Popped.SumVal == D) {
                    Console.WriteLine(
                    string.Join(" ", Popped.SelectedList.Select(X => X.ToString()).ToArray()));
                    return;
                }
                continue;
            }

            for (int I = N; Popped.CurrN <= I; I--) {
                WillPush.CurrN = I + 1;
                WillPush.SelectedList = new List<int>(Popped.SelectedList) { I };
                WillPush.SumVal = Popped.SumVal + I;

                //解でないのに半分を超えたら枝切り
                if (WillPush.SumVal != D && WillPush.SumVal > D / 2) {
                    continue;
                }

                //メモ化探索
                MemoDef MemoInfo;
                MemoInfo.CurrN = WillPush.CurrN;
                MemoInfo.SelectedCnt = WillPush.SelectedList.Count;
                MemoInfo.SumVal = WillPush.SumVal;
                if (MemoList.Exists(X => X.CurrN == MemoInfo.CurrN
                    && X.SelectedCnt == MemoInfo.SelectedCnt
                    && X.SumVal == MemoInfo.SumVal)) continue;
                MemoList.Add(MemoInfo);

                stk.Push(WillPush);
            }
        }
    }
}
0