結果

問題 No.1020 Reverse
ユーザー conf8oconf8o
提出日時 2020-04-16 15:29:07
言語 Swift
(5.8.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 171,336 KB
実行使用メモリ 13,968 KB
最終ジャッジ日時 2023-08-20 14:41:32
合計ジャッジ時間 3,747 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,228 KB
testcase_01 AC 5 ms
13,104 KB
testcase_02 AC 11 ms
13,468 KB
testcase_03 AC 6 ms
13,240 KB
testcase_04 AC 6 ms
13,668 KB
testcase_05 AC 6 ms
13,136 KB
testcase_06 AC 6 ms
13,276 KB
testcase_07 AC 13 ms
13,600 KB
testcase_08 AC 9 ms
13,588 KB
testcase_09 AC 9 ms
13,696 KB
testcase_10 AC 17 ms
13,396 KB
testcase_11 AC 22 ms
13,708 KB
testcase_12 AC 9 ms
13,956 KB
testcase_13 AC 9 ms
13,776 KB
testcase_14 AC 25 ms
13,968 KB
testcase_15 AC 33 ms
13,524 KB
testcase_16 AC 33 ms
13,864 KB
testcase_17 AC 9 ms
13,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import Foundation

func readInt() -> [Int] {
    return readLine()!.split(separator: " ").map { c in Int(c)! }
}

func main() {
    let line = readInt()
    let N = line[0]
    let K = line[1]

    let S = readLine()!

    let front = S.prefix(K-1)
    var back = S.suffix(N-K+1)

    if (N - K) % 2 == 0 {
        back += front.reversed()
    } else {
        back += front
    }

    print(back)
}

main()
0