結果
| 問題 |
No.273 回文分解
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-12 23:58:15 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,867 bytes |
| コンパイル時間 | 1,038 ms |
| コンパイル使用メモリ | 113,688 KB |
| 実行使用メモリ | 19,328 KB |
| 最終ジャッジ日時 | 2024-10-12 23:58:19 |
| 合計ジャッジ時間 | 3,542 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("ABACDDCEFGFE");
//5
//例えば「ABA」と「CDDC」と「EFGFE」の3つの回文に分解できる。
//最も長い回文は「EFGFE」で文字数は5である。
}
else if (InputPattern == "Input2") {
WillReturn.Add("ZZ");
//1
//「ZZ」はすでに回文であるが必ず2つ以上の回文に分解しなければならない。
//1文字の「Z」も回文とみなせるので「Z」と「Z」に分解でき文字数は1である。
}
else if (InputPattern == "Input3") {
WillReturn.Add("AABAAABBABBABBBAAABAA");
//8
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
string S = InputList[0];
//回文判定
Predicate<string> IsKaibun = (pStr) =>
pStr.SequenceEqual(pStr.Reverse());
var KaibunList = new List<string>();
for (int I = 0; I <= S.Length - 1; I++) {
for (int J = S.Length - 1; I <= J; J--) {
string wkStr = S.Substring(I, J - I + 1);
if (IsKaibun(wkStr) == false) continue;
KaibunList.Add(wkStr);
break;
}
}
//分解してない回文をRemove
KaibunList.RemoveAll(X => X == S);
Console.WriteLine(KaibunList.Max(X => X.Length));
}
}
aketijyuuzou