結果
問題 | No.517 壊れたアクセサリー |
ユーザー |
![]() |
提出日時 | 2017-05-28 22:50:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,689 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 112,660 KB |
実行使用メモリ | 26,940 KB |
最終ジャッジ日時 | 2024-09-21 15:43:02 |
合計ジャッジ時間 | 3,169 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 |
コンパイルメッセージ
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.Linq;class Program{static void Main(){var dic = new Dictionary<char, char>();var len = 0;for (var k = 0; k < 2; k++){var n = int.Parse(Console.ReadLine());if (n == 1){Console.WriteLine(Console.ReadLine());return;}for (var i = 0; i < n; i++){var s = Console.ReadLine();if (k == 0) len += s.Length;for (var j = 0; j < s.Length - 1; j++){if (!dic.ContainsKey(s[j])){dic.Add(s[j], s[j + 1]);}}}}if (dic.Count < len - 1){Console.WriteLine(-1);return;}var flg = false;var tmp = new List<string>() { "" };var next = dic.First().Key;for (var i = 0; ; i++){if (!dic.ContainsKey(next)){if (!flg){tmp[tmp.Count - 1] += next;flg = true;}tmp.Add("");if (dic.Count == 0) break;next = dic.First().Key;continue;}tmp[tmp.Count - 1] += next;char c = dic[next];dic.Remove(next);next = c;}var ans = "";tmp.Reverse();tmp.ForEach((s) => { ans += s; });Console.WriteLine(ans);return;}}