結果
問題 |
No.408 五輪ピック
|
ユーザー |
![]() |
提出日時 | 2016-09-01 18:54:16 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,965 bytes |
コンパイル時間 | 929 ms |
コンパイル使用メモリ | 113,920 KB |
実行使用メモリ | 53,760 KB |
最終ジャッジ日時 | 2024-11-15 17:01:20 |
合計ジャッジ時間 | 28,593 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 TLE * 4 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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(); } }