結果

問題 No.1617 Palindrome Removal
ユーザー irumo8202
提出日時 2022-02-13 12:23:44
言語 TypeScript
(5.7.2)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 8,487 ms
コンパイル使用メモリ 230,428 KB
実行使用メモリ 44,836 KB
最終ジャッジ日時 2024-12-31 16:45:33
合計ジャッジ時間 11,607 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import * as fs from "fs"

type Input = (args: string) => void

const main: Input = args => {
    const input = args.trim().split("\n");
    const S = input.shift()
    const n = S.length
    let isOdd = n % 2 == 1 ? true : false

    let flg = true
    let chars = new Set()
    for (let i = 0; i < n / 2; i++) {
        if (S[i] == S[n - i - 1]) {
            chars.add(S[i])
        } else {
            flg = false
        }
    }
    if (!flg) {
        console.log(n)
    } else if (chars.size === 1) {
        console.log(isOdd ? -1 : 0)
    } else if (isOdd && n >= 5 || !isOdd) {
        console.log(n - 2)
    } else {
        console.log(-1)
    }

}

main(fs.readFileSync('/dev/stdin', 'utf8'));
0