結果

問題 No.1617 Palindrome Removal
ユーザー nebukuro09nebukuro09
提出日時 2021-07-22 21:29:31
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 94,164 KB
実行使用メモリ 6,392 KB
最終ジャッジ日時 2023-09-04 13:25:01
合計ジャッジ時間 1,950 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,500 KB
testcase_01 AC 5 ms
4,432 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 6 ms
4,476 KB
testcase_05 AC 5 ms
6,016 KB
testcase_06 AC 3 ms
4,428 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,408 KB
testcase_13 AC 6 ms
4,432 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,564 KB
権限があれば一括ダウンロードができます

ソースコード

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