結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,172 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 18 ms
8,000 KB
testcase_05 WA -
testcase_06 AC 17 ms
8,420 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 AC 17 ms
8,096 KB
testcase_12 AC 17 ms
8,132 KB
testcase_13 AC 16 ms
8,164 KB
testcase_14 AC 29 ms
8,968 KB
testcase_15 AC 17 ms
8,540 KB
testcase_16 AC 32 ms
9,060 KB
testcase_17 AC 18 ms
8,452 KB
testcase_18 AC 18 ms
8,512 KB
testcase_19 AC 17 ms
8,548 KB
testcase_20 AC 17 ms
8,260 KB
testcase_21 AC 18 ms
8,184 KB
testcase_22 AC 17 ms
8,292 KB
testcase_23 AC 18 ms
8,172 KB
testcase_24 AC 18 ms
8,372 KB
testcase_25 AC 19 ms
8,404 KB
testcase_26 AC 32 ms
9,584 KB
testcase_27 AC 31 ms
9,716 KB
testcase_28 AC 31 ms
9,768 KB
testcase_29 AC 31 ms
9,600 KB
testcase_30 AC 17 ms
8,160 KB
testcase_31 AC 17 ms
8,172 KB
testcase_32 AC 17 ms
8,228 KB
testcase_33 AC 18 ms
8,420 KB
testcase_34 AC 17 ms
8,384 KB
testcase_35 AC 26 ms
8,996 KB
testcase_36 AC 18 ms
8,420 KB
testcase_37 AC 27 ms
8,960 KB
testcase_38 AC 22 ms
8,576 KB
testcase_39 AC 18 ms
8,356 KB
testcase_40 AC 17 ms
8,232 KB
testcase_41 AC 18 ms
8,136 KB
testcase_42 AC 17 ms
8,156 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 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