結果

問題 No.1617 Palindrome Removal
ユーザー nebukuro09
提出日時 2021-07-22 21:26:49
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 907 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 109,684 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 11:54:04
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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)) {
            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;
}
0