結果

問題 No.19 ステージの選択
ユーザー 14番14番
提出日時 2016-04-01 00:28:47
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,732 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 114,540 KB
実行使用メモリ 84,484 KB
最終ジャッジ日時 2024-04-10 07:00:51
合計ジャッジ時間 8,370 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
25,176 KB
testcase_01 AC 31 ms
25,136 KB
testcase_02 AC 31 ms
23,352 KB
testcase_03 AC 392 ms
34,824 KB
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;

public class Program
{
    public void Proc(){
        Reader.IsDebug = false;
        int stageCount = int.Parse(Reader.ReadLine());
        List<int> targetList = new List<int>();
        
        for(int i=0; i<stageCount; i++) {
            int[] inpt = Reader.GetInt();
            StageList.Add(new Nanido(i+1, inpt[1], inpt[0] * 10));
            targetList.Add(i+1);
        }
        int ans = this.GetAns(targetList);
        Console.WriteLine((ans / 10.0).ToString("0.0"));
    }
    
    private Dictionary<string, int> dic = new Dictionary<string, int>();
    
    private int GetAns(List<int> target) {
        if(target.Count == 0) {
            return 0;
        }
        string key = string.Join<int>("#", target);
        if(dic.ContainsKey(key)) {
            return dic[key];
        }
        int ans = int.MaxValue;
        for(int i=0; i<target.Count; i++) {
            int stage = target[i];
            int before = this.StageList[stage - 1].BeforeStage;
            int nanido = this.StageList[stage - 1].Value;
            if(!target.Contains(before)) {
                nanido = nanido / 2;
            }
            List<int> subList = new List<int>();
            subList.AddRange(target);
            subList.RemoveAt(i);
            ans = Math.Min(ans, GetAns(subList) + nanido);
        }
        this.dic[key] = ans;
        return ans;
    }
    
    private List<Nanido> StageList = new List<Nanido>();

    public class Nanido {
        public int Stage = 0;
        public int BeforeStage = 0;
        public int Value = 0;
        
        public Nanido(int stageNum, int beforeStage, int nan) {
            this.Stage = stageNum;
            this.BeforeStage = beforeStage;
            this.Value = nan;
        }
    }

    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

class Reader
{
    public static bool IsDebug = true;
    
    private static System.IO.StringReader sr;
    
    public static string ReadLine() {
        if(IsDebug) {
            if(sr == null) {
                sr = new System.IO.StringReader(initStr.Trim());
            }
            return sr.ReadLine();
        } else {
            return Console.ReadLine();
        }
    }
    
    public static int[] GetInt(char delimiter = ' ') {
        string[] inpt = ReadLine().Split(delimiter);
        int[] ret = new int[inpt.Length];
        for(int i=0; i<inpt.Length; i++) {
            ret[i] = int.Parse(inpt[i]);
        }
        return ret;
    }
    
    private static string initStr = @"


15
1 2
2 1
3 3
4 6
5 4
6 5
7 5
8 7
9 7
10 7
11 15
12 14
13 15
14 11
15 15


";
}

0