結果

問題 No.1617 Palindrome Removal
ユーザー nebukuro09nebukuro09
提出日時 2021-07-22 21:26:49
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 907 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 94,160 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-04 13:24:58
合計ジャッジ時間 3,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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