結果

問題 No.52 よくある文字列の問題
ユーザー nanophoto12nanophoto12
提出日時 2014-10-29 00:24:56
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 876 bytes
コンパイル時間 2,481 ms
コンパイル使用メモリ 107,436 KB
実行使用メモリ 25,736 KB
最終ジャッジ日時 2023-10-22 03:55:38
合計ジャッジ時間 3,410 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
25,656 KB
testcase_01 AC 26 ms
25,640 KB
testcase_02 AC 26 ms
25,704 KB
testcase_03 AC 26 ms
25,640 KB
testcase_04 AC 27 ms
25,656 KB
testcase_05 AC 27 ms
25,728 KB
testcase_06 AC 27 ms
25,736 KB
testcase_07 AC 27 ms
25,736 KB
testcase_08 AC 27 ms
25,728 KB
testcase_09 AC 26 ms
25,640 KB
testcase_10 AC 26 ms
25,656 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.Globalization;

class Program
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var charactors = s.ToCharArray();
        var head = 0;
        var tail = s.Length - 1;
        var sets = new HashSet<string>();
        Dfs(sets, charactors, head, tail, "");
        Console.WriteLine(sets.Count);
    }

    private static void Dfs(HashSet<string> sets, char[] charactors, int head, int tail, string current)
    {
        if (head == tail)
        {
            if (!sets.Contains(current))
            {
                sets.Add(current);
            }
            return;
        }
        Dfs(sets, charactors, head+1, tail, current + charactors[head]);
        Dfs(sets, charactors, head, tail-1, current + charactors[tail]);
    }
}
0