結果

問題 No.52 よくある文字列の問題
ユーザー bluemeganebluemegane
提出日時 2018-10-08 09:20:18
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 2,828 ms
コンパイル使用メモリ 110,996 KB
実行使用メモリ 25,944 KB
最終ジャッジ日時 2023-10-22 04:16:06
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
25,880 KB
testcase_01 AC 28 ms
25,880 KB
testcase_02 AC 28 ms
25,944 KB
testcase_03 AC 28 ms
25,880 KB
testcase_04 AC 29 ms
25,880 KB
testcase_05 AC 28 ms
25,944 KB
testcase_06 AC 29 ms
25,944 KB
testcase_07 AC 29 ms
25,944 KB
testcase_08 AC 29 ms
25,944 KB
testcase_09 AC 25 ms
25,760 KB
testcase_10 AC 28 ms
25,880 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public string s { get; set; }
    public string t { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var ans = getAns(s);
        Console.WriteLine(ans);
    }
    public static int getAns(string s)
    {
        var sL = s.Length;
        if (sL == 1) return 1;
        var hs = new HashSet<string>();
        var q = new Queue<P>();
        q.Enqueue(new P { s = s.Substring(1), t = "" + s[0] });
        q.Enqueue(new P { s  = s.Substring(0,sL -1), t = "" + s[sL -1] });
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.s == "") { hs.Add(w.t); continue; }
            if (w.s.Length == 1) q.Enqueue(new P { s = "", t = w.t + w.s });
            else
            {
                q.Enqueue(new P { s = w.s.Substring(1), t = w.t + w.s[0] });
                q.Enqueue(new P { s = w.s.Substring(0, w.s.Length - 1), t = w.t + w.s[w.s.Length - 1] });
            }
        }
        return  hs.Count();
    }
}
0