結果
問題 | No.517 壊れたアクセサリー |
ユーザー | 14番 |
提出日時 | 2017-05-28 21:49:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 3,682 bytes |
コンパイル時間 | 1,067 ms |
コンパイル使用メモリ | 112,552 KB |
実行使用メモリ | 25,192 KB |
最終ジャッジ日時 | 2023-10-21 14:08:25 |
合計ジャッジ時間 | 2,183 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
25,124 KB |
testcase_01 | AC | 29 ms
25,132 KB |
testcase_02 | AC | 25 ms
24,896 KB |
testcase_03 | AC | 29 ms
25,124 KB |
testcase_04 | AC | 25 ms
24,896 KB |
testcase_05 | AC | 24 ms
24,896 KB |
testcase_06 | AC | 28 ms
25,132 KB |
testcase_07 | AC | 29 ms
25,124 KB |
testcase_08 | AC | 29 ms
25,124 KB |
testcase_09 | AC | 30 ms
25,124 KB |
testcase_10 | AC | 29 ms
25,132 KB |
testcase_11 | AC | 29 ms
25,124 KB |
testcase_12 | AC | 29 ms
25,124 KB |
testcase_13 | AC | 25 ms
24,900 KB |
testcase_14 | AC | 29 ms
25,192 KB |
testcase_15 | AC | 28 ms
25,124 KB |
testcase_16 | AC | 29 ms
25,124 KB |
testcase_17 | AC | 29 ms
25,124 KB |
testcase_18 | AC | 29 ms
25,124 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.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { List<string> ac1 = new List<string>(); int cnt = int.Parse(Reader.ReadLine()); for (int i = 0; i < cnt; i++) { ac1.Add(Reader.ReadLine()); } List<string> ac2 = new List<string>(); cnt = int.Parse(Reader.ReadLine()); for (int i = 0; i < cnt; i++) { ac2.Add(Reader.ReadLine()); } string ans = this.GetAns(ac1, ac2); Console.WriteLine(ans); } private string GetAns(List<string> ac1, List<string> ac2) { if (ac1.Count == 1) { return ac1[0]; } if (ac2.Count == 1) { return ac2[0]; } if(ac1.Count <= 0 || ac2.Count <= 0) { return "-1"; } for (int i = 0; i < ac1.Count; i++) { char target = ac1[i].First(); string tmp = ac2.Where(a => a.Contains(target)).First(); int idx = tmp.IndexOf(target); if (idx > 0) { char prevChar = tmp[idx - 1]; int idxPrev = ac1.IndexOf(ac1.Find(a => a.Last() == prevChar)); return GetAns(Join(ac1, idxPrev, i), ac2); } target = ac1[i].Last(); tmp = ac2.Where(a => a.Contains(target)).First(); idx = tmp.IndexOf(target); if (tmp.Last() != target) { char nextChar = tmp[idx + 1]; int idxNext = ac1.IndexOf(ac1.Find(a => a.First() == nextChar)); return GetAns(Join(ac1, i, idxNext), ac2); } } for (int i = 0; i < ac2.Count; i++) { char target = ac2[i].First(); string tmp = ac1.Where(a => a.Contains(target)).First(); int idx = tmp.IndexOf(target); if (idx > 0) { char prevChar = tmp[idx - 1]; int idxPrev = ac2.IndexOf(ac2.Find(a => a.Last() == prevChar)); return GetAns(ac1, Join(ac2, idxPrev, i)); } target = ac2[i].Last(); tmp = ac1.Where(a => a.Contains(target)).First(); idx = tmp.IndexOf(target); if (tmp.Last() != target) { char nextChar = tmp[idx + 1]; int idxNext = ac2.IndexOf(ac2.Find(a => a.First() == nextChar)); return GetAns(ac1, Join(ac2, i, idxNext)); } } return "-1"; } private List<string> Join(List<string> list, int idx1, int idx2) { List<string> ret = new List<string>(); ret.AddRange(list); ret.RemoveAt(Math.Max(idx1, idx2)); ret.RemoveAt(Math.Min(idx1, idx2)); ret.Add(list[idx1] + list[idx2]); return ret; } public class Reader { public static bool IsDebug = false; private static String PlainInput = @" 2 EA T 2 T EA "; 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() { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }