結果

問題 No.408 五輪ピック
ユーザー 14番14番
提出日時 2016-09-01 18:54:16
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,965 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 113,220 KB
実行使用メモリ 47,988 KB
最終ジャッジ日時 2024-04-27 14:26:40
合計ジャッジ時間 10,369 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
27,180 KB
testcase_01 AC 48 ms
29,172 KB
testcase_02 AC 46 ms
26,932 KB
testcase_03 AC 46 ms
27,312 KB
testcase_04 AC 46 ms
27,252 KB
testcase_05 AC 109 ms
39,116 KB
testcase_06 AC 89 ms
38,596 KB
testcase_07 AC 112 ms
36,156 KB
testcase_08 AC 95 ms
34,796 KB
testcase_09 AC 100 ms
35,312 KB
testcase_10 AC 93 ms
38,592 KB
testcase_11 AC 99 ms
36,536 KB
testcase_12 AC 132 ms
39,876 KB
testcase_13 AC 108 ms
35,460 KB
testcase_14 AC 66 ms
34,852 KB
testcase_15 AC 109 ms
39,624 KB
testcase_16 AC 117 ms
38,888 KB
testcase_17 AC 143 ms
38,752 KB
testcase_18 AC 126 ms
36,832 KB
testcase_19 AC 132 ms
39,996 KB
testcase_20 AC 66 ms
35,392 KB
testcase_21 AC 53 ms
31,244 KB
testcase_22 AC 82 ms
36,952 KB
testcase_23 AC 127 ms
42,184 KB
testcase_24 AC 285 ms
47,988 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int pointCount = inpt[0];
        int connectCount = inpt[1];

        for (int i = 0; i < connectCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            if (!con.ContainsKey(inpt[0]))
            {
                con.Add(inpt[0], new Dictionary<int, bool>());
            }
            con[inpt[0]][inpt[1]] = true;
            if (!con.ContainsKey(inpt[1]))
            {
                con.Add(inpt[1], new Dictionary<int, bool>());
            }
            con[inpt[1]][inpt[0]] = true;
        }
        bool ans = GetAns(1, 5, new SortedDictionary<int,bool>());
        Console.WriteLine(ans ? "YES" : "NO");
    }

    private bool GetAns(int pos, int remain, SortedDictionary<int, bool> flag)
    {
        string key = string.Join("#", flag.Keys);
        if (!dic.ContainsKey(pos))
        {
            dic.Add(pos, new Dictionary<string, bool>());
        }
        if (dic[pos].ContainsKey(key))
        {
            return dic[pos][key];
        }

        if (remain == 0)
        {
            return pos == 1;
        }

        if (remain != 5 && pos == 1)
        {
            return false;
        }

        bool ans = false;

        if (con.ContainsKey(pos))
        {
            foreach (int next in con[pos].Keys)
            {
                if (flag.ContainsKey(next))
                {
                    continue;
                }
                flag.Add(next, true);
                bool ret = this.GetAns(next, remain - 1, flag);
                flag.Remove(next);
                if (ret)
                {
                    ans = true;
                    break;
                }
            }
        }
        this.dic[pos].Add(key, ans);
        return ans;
    }

    private Dictionary<int, Dictionary<int, bool>> con = new Dictionary<int, Dictionary<int, bool>>();

    private Dictionary<int, Dictionary<string, bool>> dic = new Dictionary<int, Dictionary<string, bool>>();


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





7 10
1 2
1 3
1 4
1 5
2 3
2 4
2 6
3 4
3 7
4 5





";
        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();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0