結果
| 問題 | No.1617 Palindrome Removal | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-07-22 21:29:31 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,091 bytes | 
| コンパイル時間 | 890 ms | 
| コンパイル使用メモリ | 109,768 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-22 11:54:07 | 
| 合計ジャッジ時間 | 1,554 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 18 WA * 2 | 
ソースコード
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[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;
}
            
            
            
        