結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,144 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 16 ms
8,152 KB
testcase_05 WA -
testcase_06 AC 16 ms
8,404 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 AC 16 ms
8,172 KB
testcase_12 AC 16 ms
8,216 KB
testcase_13 AC 16 ms
8,188 KB
testcase_14 AC 27 ms
9,060 KB
testcase_15 AC 17 ms
8,508 KB
testcase_16 AC 32 ms
9,068 KB
testcase_17 AC 16 ms
8,504 KB
testcase_18 AC 16 ms
8,396 KB
testcase_19 AC 16 ms
8,372 KB
testcase_20 AC 16 ms
8,176 KB
testcase_21 AC 16 ms
8,236 KB
testcase_22 AC 16 ms
8,172 KB
testcase_23 AC 16 ms
8,148 KB
testcase_24 AC 16 ms
8,408 KB
testcase_25 AC 19 ms
8,392 KB
testcase_26 AC 30 ms
9,600 KB
testcase_27 AC 30 ms
9,692 KB
testcase_28 AC 30 ms
9,588 KB
testcase_29 AC 30 ms
9,580 KB
testcase_30 AC 16 ms
8,180 KB
testcase_31 AC 16 ms
8,148 KB
testcase_32 AC 16 ms
8,224 KB
testcase_33 AC 17 ms
8,332 KB
testcase_34 AC 17 ms
8,452 KB
testcase_35 AC 24 ms
9,120 KB
testcase_36 AC 17 ms
8,452 KB
testcase_37 AC 25 ms
9,016 KB
testcase_38 AC 20 ms
8,620 KB
testcase_39 AC 16 ms
8,400 KB
testcase_40 AC 15 ms
8,216 KB
testcase_41 AC 16 ms
8,308 KB
testcase_42 AC 16 ms
8,320 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 + ''.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 m != f[-1] and m != l[1]:
        if f == r:
            return f + m + m + l
        else:
            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