結果

問題 No.1267 Stop and Coin Game
ユーザー semisagisemisagi
提出日時 2020-10-23 23:47:39
言語 Swift
(5.10.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 2,247 bytes
コンパイル時間 6,285 ms
コンパイル使用メモリ 134,060 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-09-28 19:07:27
合計ジャッジ時間 10,254 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,720 KB
testcase_01 AC 4 ms
7,660 KB
testcase_02 AC 3 ms
7,716 KB
testcase_03 AC 3 ms
7,704 KB
testcase_04 AC 3 ms
7,668 KB
testcase_05 AC 4 ms
7,764 KB
testcase_06 AC 3 ms
7,700 KB
testcase_07 AC 3 ms
7,648 KB
testcase_08 AC 25 ms
7,796 KB
testcase_09 AC 3 ms
7,768 KB
testcase_10 AC 202 ms
8,744 KB
testcase_11 AC 55 ms
7,964 KB
testcase_12 AC 9 ms
7,800 KB
testcase_13 AC 3 ms
7,664 KB
testcase_14 AC 3 ms
7,716 KB
testcase_15 AC 3 ms
7,604 KB
testcase_16 AC 221 ms
8,724 KB
testcase_17 AC 3 ms
7,664 KB
testcase_18 AC 4 ms
7,708 KB
testcase_19 AC 3 ms
7,736 KB
testcase_20 AC 4 ms
7,596 KB
testcase_21 AC 4 ms
7,700 KB
testcase_22 AC 4 ms
7,760 KB
testcase_23 AC 3 ms
7,696 KB
testcase_24 AC 96 ms
8,108 KB
testcase_25 AC 120 ms
8,132 KB
testcase_26 AC 4 ms
7,596 KB
testcase_27 AC 8 ms
7,664 KB
testcase_28 AC 6 ms
7,572 KB
testcase_29 AC 4 ms
7,620 KB
testcase_30 AC 189 ms
8,620 KB
testcase_31 AC 4 ms
7,664 KB
testcase_32 AC 25 ms
7,804 KB
testcase_33 AC 94 ms
8,068 KB
testcase_34 AC 113 ms
8,168 KB
testcase_35 AC 189 ms
8,660 KB
testcase_36 AC 5 ms
7,624 KB
testcase_37 AC 30 ms
7,784 KB
testcase_38 AC 227 ms
8,684 KB
testcase_39 AC 17 ms
7,672 KB
testcase_40 AC 6 ms
7,560 KB
testcase_41 AC 17 ms
7,652 KB
testcase_42 AC 4 ms
7,552 KB
testcase_43 AC 29 ms
7,676 KB
testcase_44 AC 226 ms
8,620 KB
testcase_45 AC 3 ms
7,692 KB
testcase_46 AC 3 ms
7,700 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