結果
問題 | No.273 回文分解 |
ユーザー |
![]() |
提出日時 | 2022-07-29 16:13:36 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 1,669 bytes |
コンパイル時間 | 2,265 ms |
コンパイル使用メモリ | 77,964 KB |
実行使用メモリ | 37,124 KB |
最終ジャッジ日時 | 2024-07-19 07:26:57 |
合計ジャッジ時間 | 5,405 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
import java.io.*; import java.util.*; public class Main { static HashMap<Character, Integer> change = new HashMap<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] values = sc.next().toCharArray(); int max = 0; for (int i = 0; i < values.length; i++) { int left = i; int right = i; while(left >= 0 && right < values.length && values[left] == values[right] && right - left + 1 < values.length) { max = Math.max(max, right - left + 1); left--; right++; } left = i; right = i + 1; while(left >= 0 && right < values.length && values[left] == values[right] && right - left + 1 < values.length) { max = Math.max(max, right - left + 1); left--; right++; } } System.out.println(max); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }