結果
| 問題 |
No.52 よくある文字列の問題
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2018-10-08 09:20:18 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 5,000 ms |
| コード長 | 1,115 bytes |
| コンパイル時間 | 808 ms |
| コンパイル使用メモリ | 115,172 KB |
| 実行使用メモリ | 27,724 KB |
| 最終ジャッジ日時 | 2024-09-22 05:37:20 |
| 合計ジャッジ時間 | 1,681 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
bluemegane