結果

問題 No.1617 Palindrome Removal
ユーザー nebukuro09nebukuro09
提出日時 2021-07-22 21:32:46
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 94,244 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-04 13:25:21
合計ジャッジ時間 1,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,492 KB
testcase_01 AC 6 ms
4,444 KB
testcase_02 AC 6 ms
4,412 KB
testcase_03 AC 6 ms
4,476 KB
testcase_04 AC 6 ms
4,496 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 3 ms
4,496 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 6 ms
4,480 KB
testcase_13 AC 6 ms
4,504 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 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.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;
}
0