結果
問題 | No.273 回文分解 |
ユーザー |
|
提出日時 | 2015-10-07 21:13:48 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 2,652 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 113,616 KB |
実行使用メモリ | 26,968 KB |
最終ジャッジ日時 | 2024-06-25 13:30:45 |
合計ジャッジ時間 | 2,893 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 LIB;using System;using System.Linq;using System.Text;using System.Collections.Generic;class Program{static bool loop(string s){int cnt = s.Count();bool ret = true;for (int i = 0; i < cnt / 2; i++){if (s[i] != s[cnt - 1 - i]){ret = false;break;}}return ret;}static void Main(string[] args){string s = io.r<string>();int len = s.Count();int output = 0;for (int i = 0; i < len; i++){for (int j = 0; j < i; j++){string ss = s.Substring(0, i - j);if (loop(ss)){if (output < ss.Count() && ss.Count() != len){output = ss.Count();}}}for (int j = i + 1; j <= len; j++){string ss = s.Substring(i, j - i);if (loop(ss)){if (output < ss.Count() && ss.Count() != len){output = ss.Count();}}}}io.w(output);io.wflush();}}namespace LIB{public class io{private const int WMAX = 1000;private static StringBuilder S = new StringBuilder();public static T r<T>() { return util.parse<T>(r()); }public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }private static string r() { return Console.ReadLine(); }public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) {wflush(); } }public static void wflush() { Console.Write(S.ToString()); S.Clear(); }}public class util{public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }}public class memo<Key, Result>{private Dictionary<Key, Result> R;public memo() { R = new Dictionary<Key, Result>(); }public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }}}