結果

問題 No.238 Mr. K's Another Gift
ユーザー しらっ亭しらっ亭
提出日時 2015-07-05 23:47:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,233 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 9,736 KB
最終ジャッジ日時 2023-09-22 08:46:33
合計ジャッジ時間 3,613 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,304 KB
testcase_01 WA -
testcase_02 AC 16 ms
8,220 KB
testcase_03 AC 16 ms
8,092 KB
testcase_04 AC 15 ms
8,176 KB
testcase_05 WA -
testcase_06 AC 16 ms
8,440 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 AC 17 ms
8,200 KB
testcase_12 AC 18 ms
8,212 KB
testcase_13 AC 16 ms
8,224 KB
testcase_14 AC 27 ms
9,008 KB
testcase_15 AC 16 ms
8,412 KB
testcase_16 AC 30 ms
9,024 KB
testcase_17 AC 16 ms
8,580 KB
testcase_18 AC 16 ms
8,432 KB
testcase_19 AC 15 ms
8,388 KB
testcase_20 AC 15 ms
8,168 KB
testcase_21 AC 16 ms
8,304 KB
testcase_22 AC 16 ms
8,200 KB
testcase_23 AC 16 ms
8,308 KB
testcase_24 AC 17 ms
8,356 KB
testcase_25 AC 18 ms
8,352 KB
testcase_26 AC 30 ms
9,736 KB
testcase_27 AC 29 ms
9,616 KB
testcase_28 AC 29 ms
9,548 KB
testcase_29 AC 29 ms
9,652 KB
testcase_30 AC 16 ms
8,268 KB
testcase_31 AC 16 ms
8,284 KB
testcase_32 AC 16 ms
8,256 KB
testcase_33 AC 16 ms
8,324 KB
testcase_34 AC 16 ms
8,440 KB
testcase_35 AC 24 ms
9,024 KB
testcase_36 AC 16 ms
8,524 KB
testcase_37 AC 24 ms
8,968 KB
testcase_38 AC 20 ms
8,676 KB
testcase_39 AC 16 ms
8,448 KB
testcase_40 AC 16 ms
8,304 KB
testcase_41 AC 16 ms
8,308 KB
testcase_42 AC 16 ms
8,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def o2(f, r, m):
    flag = False
    i = 0
    j = 0
    af = []
    ar = []

    while i < len(f):
        if f[i] == r[j]:
            af.append(f[i])
            ar.append(r[j])
            i += 1
            j += 1
        else:
            if flag:
                return 'NA'
            flag = True
            af.append(r[j])
            ar.append(r[j])
            j += 1

    return ''.join(af) + m + m + ''.join(ar[::-1])


def odd(s):
    L = len(s) >> 1

    if L == 0:
        return s + s

    m = s[L]
    f = s[:L]
    l = s[L + 1:]
    r = l[::-1]

    if f == r:
        return f + m + m + l

    if m != f[-1] and m != l[1]:
        return 'NA'

    if m == f[-1]:
        return o2(f[:-1], r, m)
    elif m == r[-1]:
        return o2(r[:-1], f, m)


def even(s):
    L = len(s) >> 1
    f = s[:L]
    l = s[L:]
    r = l[::-1]

    af = []
    ar = []
    flag = False

    i = 0
    j = 0

    while True:
        if i == j == L:
            if not flag:
                af.append('x')
                break
        elif i == L:
            ar.append(r[j:])
            break
        elif j == L:
            af.append(f[i:])
            break

        if f[i] == r[j]:
            af.append(f[i])
            ar.append(r[j])
            i += 1
            j += 1
        else:
            if flag:
                return 'NA'
            flag = True
            if i == j == L - 1:
                af.append(r[j])
                af.append(f[i])
                ar.append(r[j])
                break
            elif f[i] == r[j + 1]:
                af.append(r[j])
                af.append(f[i])
                ar.append(r[j])
                ar.append(r[j + 1])
                i += 1
                j += 2
            elif f[i + 1] == r[j]:
                af.append(f[i])
                af.append(f[i + 1])
                ar.append(f[i])
                ar.append(r[j])
                i += 2
                j += 1
            else:
                return 'NA'

    return ''.join(af) + ''.join(ar[::-1])


def solve(s):
    if len(s) % 2 == 0:
        ans = even(s)
    else:
        ans = odd(s)

    print(ans)


def main():
    s = input()
    solve(s)


if __name__ == '__main__':
    main()
0