結果
問題 | No.1111 コード進行 |
ユーザー | semisagi |
提出日時 | 2020-07-10 21:47:27 |
言語 | Swift (5.10.0) |
結果 |
AC
|
実行時間 | 386 ms / 2,000 ms |
コード長 | 1,973 bytes |
コンパイル時間 | 1,172 ms |
コンパイル使用メモリ | 130,808 KB |
実行使用メモリ | 220,940 KB |
最終ジャッジ日時 | 2024-11-30 19:06:39 |
合計ジャッジ時間 | 4,746 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
9,344 KB |
testcase_01 | AC | 8 ms
9,344 KB |
testcase_02 | AC | 8 ms
9,344 KB |
testcase_03 | AC | 8 ms
9,216 KB |
testcase_04 | AC | 8 ms
9,344 KB |
testcase_05 | AC | 10 ms
11,520 KB |
testcase_06 | AC | 13 ms
13,260 KB |
testcase_07 | AC | 12 ms
12,880 KB |
testcase_08 | AC | 11 ms
10,368 KB |
testcase_09 | AC | 12 ms
11,648 KB |
testcase_10 | AC | 12 ms
15,340 KB |
testcase_11 | AC | 10 ms
10,240 KB |
testcase_12 | AC | 13 ms
13,484 KB |
testcase_13 | AC | 12 ms
12,288 KB |
testcase_14 | AC | 15 ms
15,880 KB |
testcase_15 | AC | 10 ms
9,984 KB |
testcase_16 | AC | 15 ms
13,864 KB |
testcase_17 | AC | 12 ms
15,688 KB |
testcase_18 | AC | 10 ms
10,368 KB |
testcase_19 | AC | 9 ms
10,240 KB |
testcase_20 | AC | 9 ms
11,264 KB |
testcase_21 | AC | 9 ms
9,216 KB |
testcase_22 | AC | 15 ms
17,828 KB |
testcase_23 | AC | 13 ms
11,904 KB |
testcase_24 | AC | 12 ms
12,760 KB |
testcase_25 | AC | 18 ms
17,112 KB |
testcase_26 | AC | 14 ms
13,316 KB |
testcase_27 | AC | 10 ms
10,368 KB |
testcase_28 | AC | 72 ms
114,420 KB |
testcase_29 | AC | 34 ms
52,124 KB |
testcase_30 | AC | 60 ms
78,504 KB |
testcase_31 | AC | 14 ms
20,680 KB |
testcase_32 | AC | 79 ms
70,952 KB |
testcase_33 | AC | 66 ms
49,288 KB |
testcase_34 | AC | 43 ms
84,372 KB |
testcase_35 | AC | 60 ms
105,784 KB |
testcase_36 | AC | 251 ms
113,304 KB |
testcase_37 | AC | 69 ms
33,936 KB |
testcase_38 | AC | 47 ms
27,420 KB |
testcase_39 | AC | 105 ms
77,580 KB |
testcase_40 | AC | 165 ms
104,160 KB |
testcase_41 | AC | 100 ms
125,984 KB |
testcase_42 | AC | 115 ms
55,884 KB |
testcase_43 | AC | 93 ms
49,888 KB |
testcase_44 | AC | 36 ms
30,648 KB |
testcase_45 | AC | 84 ms
79,376 KB |
testcase_46 | AC | 10 ms
9,984 KB |
testcase_47 | AC | 386 ms
220,940 KB |
testcase_48 | AC | 13 ms
10,112 KB |
testcase_49 | AC | 12 ms
9,984 KB |
ソースコード
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)