結果
問題 | No.1617 Palindrome Removal |
ユーザー |
|
提出日時 | 2021-07-22 21:32:46 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,108 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 111,508 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 11:54:20 |
合計ジャッジ時間 | 1,730 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;import std.typecons, std.range, std.random, std.math, std.container;import std.numeric, std.bigint, core.bitop;void main() {auto S = readln.chomp;if (S.length % 2 == 1) {if (is_onaji(S)) {writeln(-1);} else if (is_kaibun(S)) {auto mid = S.length.to!int/2;if (S.length == 3 && S[mid] != S.front && is_onaji(S[0..mid] ~ S[mid+1..$])) {writeln(-1);} else {writeln(S.length.to!int - 2);}} else {writeln(S.length);}} else {if (is_onaji(S) ) {writeln(0);} else if (is_kaibun(S)) {writeln(S.length.to!int - 2);} else {writeln(S.length);}}}bool is_kaibun(string S) {foreach (i; 0..S.length.to!int/2) {if (S[i] != S[S.length.to!int-i-1]) return false;}return true;}bool is_onaji(string S) {foreach (i; 1..S.length) if (S[i] != S.front) return false;return true;}