結果

問題 No.1238 選抜クラス
ユーザー semisagisemisagi
提出日時 2020-09-25 21:46:09
言語 Swift
(5.8.1)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 3,296 bytes
コンパイル時間 12,539 ms
コンパイル使用メモリ 133,192 KB
実行使用メモリ 8,340 KB
最終ジャッジ日時 2023-09-10 15:09:25
合計ジャッジ時間 14,651 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,092 KB
testcase_01 AC 4 ms
8,132 KB
testcase_02 AC 4 ms
8,228 KB
testcase_03 AC 4 ms
7,980 KB
testcase_04 AC 4 ms
8,152 KB
testcase_05 AC 4 ms
8,096 KB
testcase_06 AC 4 ms
8,088 KB
testcase_07 AC 5 ms
8,244 KB
testcase_08 AC 4 ms
8,176 KB
testcase_09 AC 4 ms
8,232 KB
testcase_10 AC 4 ms
8,188 KB
testcase_11 AC 5 ms
8,168 KB
testcase_12 AC 4 ms
8,200 KB
testcase_13 AC 4 ms
8,244 KB
testcase_14 AC 4 ms
8,232 KB
testcase_15 AC 4 ms
8,340 KB
testcase_16 AC 4 ms
8,228 KB
testcase_17 AC 6 ms
8,252 KB
testcase_18 AC 6 ms
8,172 KB
testcase_19 AC 7 ms
8,268 KB
testcase_20 AC 6 ms
8,276 KB
testcase_21 AC 6 ms
8,200 KB
testcase_22 AC 6 ms
8,196 KB
testcase_23 AC 6 ms
8,260 KB
testcase_24 AC 6 ms
8,304 KB
testcase_25 AC 6 ms
8,264 KB
testcase_26 AC 6 ms
8,256 KB
testcase_27 AC 6 ms
8,236 KB
testcase_28 AC 6 ms
8,204 KB
testcase_29 AC 6 ms
8,200 KB
testcase_30 AC 4 ms
8,272 KB
testcase_31 AC 5 ms
8,196 KB
testcase_32 AC 6 ms
8,096 KB
testcase_33 AC 4 ms
8,232 KB
testcase_34 AC 6 ms
8,136 KB
testcase_35 AC 4 ms
8,168 KB
testcase_36 AC 4 ms
8,236 KB
testcase_37 AC 5 ms
8,248 KB
testcase_38 AC 6 ms
8,304 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())!
    }
}

let MOD = 1000000007

struct Zn: CustomStringConvertible {
    let n: Int

    init(_ n: Int) {
        self.n = n
    }

    var description: String {
        String(self.n)
    }

    static var zero = Zn(0)
    static var one = Zn(1)

    static func + (lhs: Self, rhs: Self) -> Self {
        let n = lhs.n + rhs.n
        return Zn(n < MOD ? n : n - MOD)
    }

    static func + (lhs: Self, rhs: Int) -> Self {
        return lhs + Zn(rhs)
    }

    static func + (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) + rhs
    }

    static func - (lhs: Self, rhs: Self) -> Self {
        let n = lhs.n - rhs.n
        return Zn(n >= 0 ? n : n + MOD)
    }

    static func - (lhs: Self, rhs: Int) -> Self {
        return lhs - Zn(rhs)
    }

    static func - (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) - rhs
    }

    static func * (lhs: Self, rhs: Self) -> Self {
        Zn((lhs.n * rhs.n) % MOD)
    }

    static func * (lhs: Self, rhs: Int) -> Self {
        return lhs * Zn(rhs)
    }

    static func * (lhs: Int, rhs: Self) -> Self {
        return Zn(lhs) * rhs
    }

    static func += (lhs: inout Self, rhs: Self) {
        lhs = lhs + rhs
    }

    static func += (lhs: inout Self, rhs: Int) {
        lhs = lhs + Zn(rhs)
    }

    static func -= (lhs: inout Self, rhs: Self) {
        lhs = lhs - rhs
    }

    static func -= (lhs: inout Self, rhs: Int) {
        lhs = lhs - Zn(rhs)
    }

    static func *= (lhs: inout Self, rhs: Self) {
        lhs = lhs * rhs
    }

    static func *= (lhs: inout Self, rhs: Int) {
        lhs = lhs * Zn(rhs)
    }

    func pow(_ n: Int) -> Self {
        if n == 0 {
            return Zn(1)
        } else if n % 2 == 1 {
            return self * self.pow(n - 1)
        } else {
            return (self * self).pow(n / 2)
        }
    }

    var inverse: Self {
        self.pow(MOD - 2)
    }
}

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 K = scanner.nextInt()

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

var dp = [Zn](repeating: Zn(0), count: 20001)

dp[10000] = Zn(1)

for i in 0 ..< N {
    let from = dp
    for j in 0 ... 20000 where from[j].n != 0 {
        dp[j + A[i] - K] += from[j]
    }
}

let answer = dp[10000 ... 20000].reduce(Zn(0), +) - Zn(1)
print(answer)
0