結果

問題 No.123 カードシャッフル
ユーザー fmhrfmhr
提出日時 2015-04-27 06:20:21
言語 Go
(1.22.1)
結果
AC  
実行時間 316 ms / 5,000 ms
コード長 754 bytes
コンパイル時間 9,495 ms
コンパイル使用メモリ 231,616 KB
実行使用メモリ 8,108 KB
最終ジャッジ日時 2024-04-18 10:44:48
合計ジャッジ時間 11,219 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 220 ms
7,840 KB
testcase_11 AC 316 ms
8,104 KB
testcase_12 AC 307 ms
8,108 KB
testcase_13 AC 302 ms
8,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
    "fmt"
)

//func pop(a []int, x int) ([]int, int){
//    x = a[x]
//    a = append(a[:x], a[x+1:]...)
//    return a, x
//}

func pop(a []int, x int) ([]int, int) {
    var r int
    r = a[x]
    if x == len(a)-1 {
        a = a[:x]
    } else {
        a = append(a[:x], a[x+1:]...)
    }
    return a, r
}

func main() {
    var N, M int
    fmt.Scan(&N, &M)
    s := make([]int, N)
    for i:=0; i<N; i++ {
        s[i] = i
    }
//    fmt.Println(s)
    var a int
    for i:=0; i<M; i++ {
        fmt.Scan(&a)
        a -= 1
        s, a = pop(s, a)
        tmp_slice :=[]int{a}
//        fmt.Println(s)
//        fmt.Println(a)
        s = append(tmp_slice, s[:]...)
//        fmt.Println(s)
    }
    fmt.Println(s[0]+1)
}
0