結果

問題 No.52 よくある文字列の問題
ユーザー bluemeganebluemegane
提出日時 2018-10-08 09:12:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,123 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 110,092 KB
実行使用メモリ 25,164 KB
最終ジャッジ日時 2023-10-22 04:15:43
合計ジャッジ時間 1,872 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
25,088 KB
testcase_01 AC 28 ms
25,100 KB
testcase_02 AC 29 ms
25,164 KB
testcase_03 AC 28 ms
25,100 KB
testcase_04 AC 28 ms
25,088 KB
testcase_05 AC 28 ms
25,156 KB
testcase_06 AC 29 ms
25,156 KB
testcase_07 AC 29 ms
25,156 KB
testcase_08 AC 28 ms
25,164 KB
testcase_09 AC 25 ms
24,808 KB
testcase_10 AC 28 ms
25,088 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 ts = new List<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 == "") { ts.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  ts.Distinct().Count();
    }
}
0