結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,156 KB
testcase_01 WA -
testcase_02 AC 17 ms
8,144 KB
testcase_03 AC 16 ms
8,120 KB
testcase_04 AC 16 ms
8,084 KB
testcase_05 WA -
testcase_06 AC 17 ms
8,428 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 AC 16 ms
8,204 KB
testcase_12 AC 16 ms
8,228 KB
testcase_13 AC 16 ms
8,216 KB
testcase_14 AC 28 ms
8,996 KB
testcase_15 AC 18 ms
8,468 KB
testcase_16 AC 31 ms
9,156 KB
testcase_17 AC 16 ms
8,388 KB
testcase_18 AC 16 ms
8,352 KB
testcase_19 AC 17 ms
8,420 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 16 ms
8,204 KB
testcase_31 AC 18 ms
8,212 KB
testcase_32 AC 16 ms
8,172 KB
testcase_33 AC 17 ms
8,472 KB
testcase_34 AC 16 ms
8,440 KB
testcase_35 AC 26 ms
9,020 KB
testcase_36 AC 17 ms
8,500 KB
testcase_37 AC 26 ms
8,968 KB
testcase_38 AC 20 ms
8,524 KB
testcase_39 AC 16 ms
8,368 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 16 ms
8,248 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'

    if af == ar:
        return ''.join(af) + ''.join(ar[::-1])
    else:
        return 'NA'


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