結果

問題 No.517 壊れたアクセサリー
ユーザー くれちーくれちー
提出日時 2017-05-28 22:50:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,689 bytes
コンパイル時間 1,093 ms
コンパイル使用メモリ 111,340 KB
実行使用メモリ 24,944 KB
最終ジャッジ日時 2023-10-21 14:27:58
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,944 KB
testcase_01 AC 25 ms
24,928 KB
testcase_02 AC 24 ms
24,732 KB
testcase_03 AC 28 ms
24,944 KB
testcase_04 AC 25 ms
24,732 KB
testcase_05 AC 24 ms
24,732 KB
testcase_06 AC 24 ms
24,736 KB
testcase_07 AC 24 ms
24,928 KB
testcase_08 AC 24 ms
24,928 KB
testcase_09 AC 26 ms
24,944 KB
testcase_10 AC 26 ms
24,932 KB
testcase_11 AC 27 ms
24,944 KB
testcase_12 AC 28 ms
24,944 KB
testcase_13 AC 26 ms
24,924 KB
testcase_14 AC 28 ms
24,944 KB
testcase_15 AC 28 ms
24,940 KB
testcase_16 AC 28 ms
24,932 KB
testcase_17 AC 26 ms
24,928 KB
testcase_18 AC 28 ms
24,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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;
    }
}
0