結果
問題 | No.483 マッチ並べ |
ユーザー | 14番 |
提出日時 | 2017-02-12 03:17:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 4,050 bytes |
コンパイル時間 | 915 ms |
コンパイル使用メモリ | 109,952 KB |
実行使用メモリ | 28,204 KB |
最終ジャッジ日時 | 2024-06-09 10:01:29 |
合計ジャッジ時間 | 5,328 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
25,648 KB |
testcase_01 | AC | 51 ms
27,936 KB |
testcase_02 | AC | 45 ms
25,572 KB |
testcase_03 | AC | 49 ms
26,028 KB |
testcase_04 | AC | 52 ms
25,904 KB |
testcase_05 | AC | 52 ms
25,896 KB |
testcase_06 | AC | 51 ms
23,984 KB |
testcase_07 | AC | 53 ms
26,040 KB |
testcase_08 | AC | 49 ms
25,904 KB |
testcase_09 | AC | 52 ms
27,740 KB |
testcase_10 | AC | 51 ms
27,944 KB |
testcase_11 | AC | 50 ms
25,900 KB |
testcase_12 | AC | 48 ms
28,204 KB |
testcase_13 | AC | 49 ms
28,072 KB |
testcase_14 | AC | 47 ms
25,764 KB |
testcase_15 | AC | 49 ms
26,036 KB |
testcase_16 | AC | 51 ms
26,028 KB |
testcase_17 | AC | 51 ms
24,244 KB |
testcase_18 | AC | 44 ms
23,476 KB |
testcase_19 | AC | 48 ms
25,916 KB |
testcase_20 | AC | 48 ms
27,928 KB |
testcase_21 | AC | 51 ms
27,940 KB |
testcase_22 | AC | 50 ms
27,956 KB |
testcase_23 | AC | 49 ms
26,028 KB |
testcase_24 | AC | 46 ms
26,032 KB |
testcase_25 | AC | 51 ms
26,288 KB |
testcase_26 | AC | 50 ms
25,800 KB |
testcase_27 | AC | 53 ms
25,900 KB |
testcase_28 | AC | 52 ms
25,908 KB |
testcase_29 | AC | 52 ms
26,044 KB |
testcase_30 | AC | 51 ms
28,076 KB |
testcase_31 | AC | 52 ms
25,900 KB |
testcase_32 | AC | 54 ms
25,900 KB |
testcase_33 | AC | 53 ms
25,768 KB |
testcase_34 | AC | 51 ms
26,024 KB |
testcase_35 | AC | 51 ms
25,896 KB |
testcase_36 | AC | 52 ms
27,964 KB |
testcase_37 | AC | 52 ms
24,120 KB |
testcase_38 | AC | 52 ms
27,972 KB |
testcase_39 | AC | 48 ms
25,900 KB |
testcase_40 | AC | 51 ms
27,964 KB |
testcase_41 | AC | 57 ms
25,912 KB |
testcase_42 | AC | 55 ms
26,032 KB |
testcase_43 | AC | 48 ms
26,036 KB |
testcase_44 | AC | 50 ms
25,772 KB |
testcase_45 | AC | 52 ms
25,904 KB |
testcase_46 | AC | 50 ms
28,072 KB |
testcase_47 | AC | 50 ms
25,900 KB |
testcase_48 | AC | 54 ms
27,964 KB |
testcase_49 | AC | 52 ms
25,772 KB |
testcase_50 | AC | 52 ms
23,984 KB |
testcase_51 | AC | 50 ms
25,908 KB |
testcase_52 | AC | 51 ms
27,940 KB |
testcase_53 | AC | 41 ms
25,780 KB |
testcase_54 | AC | 48 ms
28,080 KB |
testcase_55 | AC | 49 ms
25,904 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug =false; int itemCount = int.Parse(Reader.ReadLine()); Dictionary<Pos, bool> pList = new Dictionary<Pos, bool>(); for(int i=0; i<itemCount; i++) { Match m = new Match(Reader.ReadLine()); this.MatchList.Add(m); new Pos[] {m.P1, m.P2}.ToList().ForEach(a=>{ if(pList.ContainsKey(a)) { pList[a] = true; } else { pList.Add(a, false); } }); } pList.Where(a=>a.Value).Select(a=>a.Key).ToList().ForEach(a=>{ PosList.Add(PosList.Count, a); KeyList.Add(a, KeyList.Count); }); this.Target = this.MatchList.Where(a=>pList[a.P1] || pList[a.P2]).ToArray(); bool ans = this.GetAns(0, new bool[PosList.Count]); Console.WriteLine(ans?"YES":"NO"); } private Dictionary<int, Dictionary<string, bool>> dic = new Dictionary<int, Dictionary<string, bool>>(); private bool GetAns(int idx, bool[] flags) { string key = string.Join(string.Empty, flags.Select(a=>a?1:0)); if(!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary<string, bool>()); } if(dic[idx].ContainsKey(key)) { return dic[idx][key]; } if(idx >= Target.Count()) { return true; } Pos p1 = this.Target[idx].P1; Pos p2 = this.Target[idx].P2; if(KeyList.ContainsKey(p1)) { if(!flags[KeyList[p1]]) { bool[] sub = (bool[])flags.Clone(); sub[KeyList[p1]] = true; bool ret = this.GetAns(idx+1, sub); if(ret) { return true; } } } else { bool[] sub = (bool[])flags.Clone(); bool ret = this.GetAns(idx+1, sub); if(ret) { return true; } } if(KeyList.ContainsKey(p2)) { if(!flags[KeyList[p2]]) { bool[] sub = (bool[])flags.Clone(); sub[KeyList[p2]] = true; bool ret = this.GetAns(idx+1, sub); if(ret) { return true; } } } else { bool[] sub = (bool[])flags.Clone(); bool ret = this.GetAns(idx+1, sub); if(ret) { return true; } } dic[idx][key] = false; return false; } private Dictionary<Pos, int> KeyList = new Dictionary<Pos, int>(); private Dictionary<int, Pos> PosList = new Dictionary<int, Pos>(); private Match[] Target; private List<Match> MatchList = new List<Match>(); private class Match { public Pos P1; public Pos P2; public Match(string init) { int[] inpt = init.Split(' ').Select(a=>int.Parse(a)).ToArray(); this.P1 = new Pos(inpt[0], inpt[1]); this.P2 = new Pos(inpt[2], inpt[3]); } } private struct Pos { public int Row; public int Col; public Pos(int r, int c) { this.Row = r; this.Col = c; } } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 2 1 1 2 1 2 1 3 1 "; public static string ReadLine() { if(IsDebug) { if(SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }