結果

問題 No.1111 コード進行
ユーザー semisagisemisagi
提出日時 2020-07-10 21:47:27
言語 Swift
(5.10.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 1,973 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 132,044 KB
実行使用メモリ 219,380 KB
最終ジャッジ日時 2023-08-20 15:59:31
合計ジャッジ時間 5,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,740 KB
testcase_01 AC 3 ms
7,684 KB
testcase_02 AC 3 ms
7,768 KB
testcase_03 AC 3 ms
7,660 KB
testcase_04 AC 3 ms
7,764 KB
testcase_05 AC 5 ms
9,896 KB
testcase_06 AC 7 ms
11,744 KB
testcase_07 AC 7 ms
11,400 KB
testcase_08 AC 5 ms
8,948 KB
testcase_09 AC 6 ms
10,092 KB
testcase_10 AC 8 ms
13,752 KB
testcase_11 AC 5 ms
8,852 KB
testcase_12 AC 8 ms
11,792 KB
testcase_13 AC 6 ms
10,588 KB
testcase_14 AC 10 ms
14,144 KB
testcase_15 AC 5 ms
8,376 KB
testcase_16 AC 9 ms
12,536 KB
testcase_17 AC 8 ms
14,104 KB
testcase_18 AC 4 ms
8,748 KB
testcase_19 AC 4 ms
8,488 KB
testcase_20 AC 5 ms
9,628 KB
testcase_21 AC 3 ms
7,748 KB
testcase_22 AC 10 ms
16,088 KB
testcase_23 AC 6 ms
10,312 KB
testcase_24 AC 6 ms
11,252 KB
testcase_25 AC 12 ms
15,536 KB
testcase_26 AC 9 ms
11,840 KB
testcase_27 AC 4 ms
8,744 KB
testcase_28 AC 84 ms
113,008 KB
testcase_29 AC 32 ms
50,648 KB
testcase_30 AC 60 ms
77,120 KB
testcase_31 AC 11 ms
19,092 KB
testcase_32 AC 61 ms
69,440 KB
testcase_33 AC 50 ms
47,872 KB
testcase_34 AC 50 ms
82,952 KB
testcase_35 AC 76 ms
104,308 KB
testcase_36 AC 264 ms
111,616 KB
testcase_37 AC 64 ms
32,408 KB
testcase_38 AC 40 ms
25,872 KB
testcase_39 AC 95 ms
76,204 KB
testcase_40 AC 176 ms
102,640 KB
testcase_41 AC 113 ms
124,484 KB
testcase_42 AC 113 ms
54,256 KB
testcase_43 AC 88 ms
48,408 KB
testcase_44 AC 34 ms
29,252 KB
testcase_45 AC 90 ms
77,908 KB
testcase_46 AC 5 ms
8,468 KB
testcase_47 AC 383 ms
219,380 KB
testcase_48 AC 7 ms
8,476 KB
testcase_49 AC 7 ms
8,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

struct Scanner {
    private var stack = [String]()
    private var index = 0
    
    mutating func peek() -> String {
        if stack.count == index {
            stack += readLine()!.split(separator: " ").map{ String($0) }
        }
        return stack[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 {
    let n: Int
    
    init(_ n: Int) {
        self.n = n
    }
    
    static func + (lhs: Self, rhs: Self) -> Self {
        Zn((lhs.n + rhs.n) % MOD)
    }
    
    static func - (lhs: Self, rhs: Self) -> Self {
        Zn((lhs.n - rhs.n + MOD) % MOD)
    }
    
    static func * (lhs: Self, rhs: Self) -> Self {
        Zn((lhs.n * rhs.n) % MOD)
    }
    
    static func += (lhs: inout Self, rhs: Self) {
        lhs = lhs + rhs
    }
}

var scanner = Scanner()
let N = scanner.nextInt()
let M = scanner.nextInt()
let K = scanner.nextInt()

struct Edge {
    let to: Int
    let cost: Int
}

var G = [[Edge]](repeating: [Edge](), count: 300)
for _ in 0 ..< M {
    let P = scanner.nextInt() - 1
    let Q = scanner.nextInt() - 1
    let C = scanner.nextInt()
    G[P].append(Edge(to: Q, cost: C))
}

var dp = [Zn](repeating: Zn(0), count: N * 300 * (K + 1))

func index(_ i: Int, _ j: Int, _ k: Int) -> Int {
    (i * 300 + j) * (K + 1) + k
}

for j in 0 ..< 300 {
    dp[index(0, j, 0)] = Zn(1)
}

for i in 1 ..< N {
    for from in 0 ..< 300 {
        for complexity in 0 ... K {
            for edge in G[from] where complexity + edge.cost <= K {
                dp[index(i, edge.to, complexity + edge.cost)] += dp[index(i - 1, from, complexity)]
            }
        }
    }
}

var answer = Zn(0)
for j in 0 ..< 300 {
    answer += dp[index(N - 1, j, K)]
}
print(answer.n)

0