結果

問題 No.408 五輪ピック
ユーザー 14番14番
提出日時 2016-09-01 18:38:44
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,574 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 108,520 KB
実行使用メモリ 36,608 KB
最終ジャッジ日時 2024-04-27 14:26:28
合計ジャッジ時間 4,743 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
19,456 KB
testcase_01 AC 28 ms
19,584 KB
testcase_02 AC 28 ms
19,328 KB
testcase_03 AC 28 ms
19,456 KB
testcase_04 AC 28 ms
19,456 KB
testcase_05 AC 85 ms
28,800 KB
testcase_06 AC 72 ms
29,056 KB
testcase_07 AC 87 ms
29,184 KB
testcase_08 AC 72 ms
26,880 KB
testcase_09 AC 74 ms
27,904 KB
testcase_10 WA -
testcase_11 AC 65 ms
27,648 KB
testcase_12 AC 92 ms
30,976 KB
testcase_13 AC 88 ms
27,008 KB
testcase_14 WA -
testcase_15 AC 86 ms
27,776 KB
testcase_16 AC 89 ms
29,312 KB
testcase_17 AC 94 ms
29,312 KB
testcase_18 AC 95 ms
29,696 KB
testcase_19 AC 102 ms
32,384 KB
testcase_20 AC 48 ms
25,984 KB
testcase_21 AC 39 ms
22,584 KB
testcase_22 AC 60 ms
28,672 KB
testcase_23 AC 107 ms
36,608 KB
testcase_24 WA -
testcase_25 AC 91 ms
27,520 KB
testcase_26 AC 109 ms
33,920 KB
testcase_27 AC 103 ms
28,672 KB
testcase_28 AC 81 ms
28,672 KB
testcase_29 AC 79 ms
28,672 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
        Console.WriteLine(ans ? "YES" : "NO");
    }

    private bool GetAns(int pos, int remain)
    {
        if (!dic.ContainsKey(pos))
        {
            dic.Add(pos, new Dictionary<int, bool>());
        }
        if (dic[pos].ContainsKey(remain))
        {
            return dic[pos][remain];
        }

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

        bool ans = false;

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

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

    private Dictionary<int, Dictionary<int, bool>> dic = new Dictionary<int, Dictionary<int, 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