結果

問題 No.1267 Stop and Coin Game
ユーザー semisagisemisagi
提出日時 2020-10-23 23:47:39
言語 Swift
(5.10.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 2,247 bytes
コンパイル時間 11,339 ms
コンパイル使用メモリ 132,616 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-07-21 13:49:29
合計ジャッジ時間 13,322 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
9,088 KB
testcase_01 AC 9 ms
8,960 KB
testcase_02 AC 8 ms
9,088 KB
testcase_03 AC 9 ms
9,088 KB
testcase_04 AC 9 ms
8,960 KB
testcase_05 AC 9 ms
9,088 KB
testcase_06 AC 9 ms
9,088 KB
testcase_07 AC 8 ms
8,960 KB
testcase_08 AC 26 ms
9,216 KB
testcase_09 AC 9 ms
9,088 KB
testcase_10 AC 164 ms
10,112 KB
testcase_11 AC 51 ms
9,216 KB
testcase_12 AC 14 ms
8,960 KB
testcase_13 AC 8 ms
9,088 KB
testcase_14 AC 9 ms
8,960 KB
testcase_15 AC 9 ms
8,960 KB
testcase_16 AC 184 ms
10,112 KB
testcase_17 AC 9 ms
9,088 KB
testcase_18 AC 9 ms
9,088 KB
testcase_19 AC 9 ms
8,960 KB
testcase_20 AC 8 ms
9,088 KB
testcase_21 AC 9 ms
8,960 KB
testcase_22 AC 9 ms
9,088 KB
testcase_23 AC 9 ms
8,960 KB
testcase_24 AC 79 ms
9,600 KB
testcase_25 AC 104 ms
9,600 KB
testcase_26 AC 9 ms
8,960 KB
testcase_27 AC 13 ms
8,960 KB
testcase_28 AC 11 ms
8,960 KB
testcase_29 AC 9 ms
8,960 KB
testcase_30 AC 150 ms
10,112 KB
testcase_31 AC 10 ms
9,088 KB
testcase_32 AC 25 ms
9,216 KB
testcase_33 AC 75 ms
9,472 KB
testcase_34 AC 97 ms
9,600 KB
testcase_35 AC 147 ms
10,240 KB
testcase_36 AC 10 ms
9,088 KB
testcase_37 AC 32 ms
9,216 KB
testcase_38 AC 192 ms
10,112 KB
testcase_39 AC 20 ms
8,960 KB
testcase_40 AC 11 ms
9,088 KB
testcase_41 AC 20 ms
9,088 KB
testcase_42 AC 9 ms
8,960 KB
testcase_43 AC 29 ms
9,088 KB
testcase_44 AC 183 ms
10,112 KB
testcase_45 AC 8 ms
9,088 KB
testcase_46 AC 9 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

struct Scanner {
    private var elements = [String]()
    private var index = 0

    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }

    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }

    mutating func nextInt() -> Int {
        return Int(next())!
    }

    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

struct UnionFind {
    var parent: [Int]
    var count: [Int]

    init(_ n: Int) {
        parent = Array(0 ..< n)
        count = [Int](repeating: 1, count: n)
    }

    mutating func find(_ v: Int) -> Int {
        if v == parent[v] {
            return v
        }
        parent[v] = find(parent[v])
        return parent[v]
    }

    mutating func union(_ u: Int, _ v: Int) {
        var u = find(u)
        var v = find(v)
        guard u != v else { return }
        if count[u] < count[v] {
            swap(&u, &v)
        }
        count[u] += count[v]
        parent[v] = u
    }

    mutating func count(_ u: Int) -> Int {
        count[find(u)]
    }
}

struct Array2D<Element> {
    let n1: Int
    let n2: Int
    private var elements: [Element]

    init(repeating: Element, _ n1: Int, _ n2: Int) {
        self.n1 = n1
        self.n2 = n2
        self.elements = [Element](repeating: repeating, count: n1 * n2)
    }

    subscript(i: Int, j: Int) -> Element {
        get {
            elements[i * n2 + j]
        }
        set {
            elements[i * n2 + j] = newValue
        }
    }
}

var scanner = Scanner()
let N = scanner.nextInt()
let V = scanner.nextInt()
let A = (0 ..< N).map { _ in scanner.nextInt() }

var win = [Bool](repeating: false, count: 1 << N)

for i in (0 ..< 1 << N).reversed() {
    var total = 0
    for j in 0 ..< N where (i >> j) & 1 == 1 {
        total += A[j]
    }
    for j in 0 ..< N where (i >> j) & 1 == 0 && total + A[j] <= V {
        if !win[i | 1 << j] {
            win[i] = true
        }
    }
}

if A.reduce(0, +) <= V {
    print("Draw")
} else if win[0] {
    print("First")
} else {
    print("Second")
}
0