結果

問題 No.95 Alice and Graph
ユーザー 14番14番
提出日時 2016-04-11 23:44:48
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 3,608 bytes
コンパイル時間 955 ms
コンパイル使用メモリ 112,492 KB
実行使用メモリ 36,876 KB
最終ジャッジ日時 2024-04-15 00:22:10
合計ジャッジ時間 2,403 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 35 ms
26,800 KB
testcase_09 AC 34 ms
26,528 KB
testcase_10 AC 34 ms
24,880 KB
testcase_11 AC 35 ms
24,620 KB
testcase_12 AC 35 ms
24,580 KB
testcase_13 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.GetInt();
        this.NodeCount = inpt[0];
        int connecterCount = inpt[1];
        int maxMove = inpt[2];

        for (int i = 0; i < connecterCount; i++)
        {
            inpt = Reader.GetInt();
            if (!roadDic.ContainsKey(inpt[0]))
            {
                roadDic.Add(inpt[0], new List<int>());
            }
            roadDic[inpt[0]].Add(inpt[1]);
            if (!roadDic.ContainsKey(inpt[1]))
            {
                roadDic.Add(inpt[1], new List<int>());
            }
            roadDic[inpt[1]].Add(inpt[0]);
        }

        ulong num = Convert.ToUInt64("1".PadLeft(61, '1'), 2);
        long ans = this.GetAns(1, maxMove, num);
        Console.WriteLine(ans);

    }

    private long GetAns(int nodeNum, int remain, ulong target)
    {
        ulong key = Convert.ToUInt64("1".PadRight(nodeNum, '0').PadLeft(61, '0'), 2);
        if (!dic.ContainsKey(nodeNum))
        {
            dic.Add(nodeNum, new Dictionary<int, Dictionary<ulong, long>>());
        }
        if (!dic[nodeNum].ContainsKey(remain))
        {
            dic[nodeNum].Add(remain, new Dictionary<ulong, long>());
        }
        if(dic[nodeNum][remain].ContainsKey(target)) {
            return dic[nodeNum][remain][target];
        }
        long ans = 0;
        if (remain == 0)
        {
            if ((target & key) == key)
            {
                ans = (long)Math.Pow(2, nodeNum - 1) - 1;
            }
        }
        else
        {
            long addNum = 0;
            if((target & key) == key) {
                addNum = (long)Math.Pow(2, nodeNum - 1) - 1;
                target -= key;
            }
            foreach (int num in roadDic[nodeNum])
            {
                long ret = this.GetAns(num, remain - 1, target);
                if(ret >= 0) {
                    ret += addNum;
                }
                ans = Math.Max(ans, ret);
            }
        }
        dic[nodeNum][remain].Add(target, ans);
        return ans;
    }

    private Dictionary<int, List<int>> roadDic = new Dictionary<int, List<int>>();

    private Dictionary<int, Dictionary<int, Dictionary<ulong, long>>> dic = new Dictionary<int,Dictionary<int,Dictionary<ulong,long>>>();
    private int NodeCount;

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



5 4 4
3 4
4 1
1 5
5 2



 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0