結果
問題 | No.1111 コード進行 |
ユーザー | semisagi |
提出日時 | 2020-07-10 21:47:27 |
言語 | Swift (5.10.0) |
結果 |
AC
|
実行時間 | 401 ms / 2,000 ms |
コード長 | 1,973 bytes |
コンパイル時間 | 1,361 ms |
コンパイル使用メモリ | 130,620 KB |
実行使用メモリ | 220,928 KB |
最終ジャッジ日時 | 2024-05-07 22:21:40 |
合計ジャッジ時間 | 4,807 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
9,088 KB |
testcase_01 | AC | 9 ms
9,216 KB |
testcase_02 | AC | 9 ms
9,472 KB |
testcase_03 | AC | 9 ms
9,088 KB |
testcase_04 | AC | 8 ms
9,216 KB |
testcase_05 | AC | 10 ms
11,264 KB |
testcase_06 | AC | 13 ms
13,568 KB |
testcase_07 | AC | 13 ms
13,016 KB |
testcase_08 | AC | 11 ms
10,368 KB |
testcase_09 | AC | 10 ms
11,548 KB |
testcase_10 | AC | 12 ms
15,204 KB |
testcase_11 | AC | 10 ms
10,240 KB |
testcase_12 | AC | 13 ms
13,168 KB |
testcase_13 | AC | 11 ms
11,948 KB |
testcase_14 | AC | 15 ms
15,540 KB |
testcase_15 | AC | 9 ms
9,728 KB |
testcase_16 | AC | 15 ms
13,860 KB |
testcase_17 | AC | 12 ms
15,440 KB |
testcase_18 | AC | 9 ms
10,496 KB |
testcase_19 | AC | 9 ms
9,728 KB |
testcase_20 | AC | 10 ms
11,008 KB |
testcase_21 | AC | 8 ms
9,216 KB |
testcase_22 | AC | 14 ms
17,436 KB |
testcase_23 | AC | 12 ms
11,776 KB |
testcase_24 | AC | 11 ms
12,600 KB |
testcase_25 | AC | 17 ms
17,024 KB |
testcase_26 | AC | 13 ms
13,312 KB |
testcase_27 | AC | 9 ms
10,112 KB |
testcase_28 | AC | 104 ms
114,432 KB |
testcase_29 | AC | 35 ms
51,968 KB |
testcase_30 | AC | 62 ms
78,604 KB |
testcase_31 | AC | 13 ms
20,588 KB |
testcase_32 | AC | 70 ms
70,716 KB |
testcase_33 | AC | 66 ms
49,248 KB |
testcase_34 | AC | 50 ms
84,288 KB |
testcase_35 | AC | 72 ms
105,812 KB |
testcase_36 | AC | 276 ms
113,024 KB |
testcase_37 | AC | 72 ms
33,920 KB |
testcase_38 | AC | 47 ms
27,228 KB |
testcase_39 | AC | 114 ms
77,696 KB |
testcase_40 | AC | 183 ms
103,964 KB |
testcase_41 | AC | 109 ms
125,768 KB |
testcase_42 | AC | 119 ms
55,820 KB |
testcase_43 | AC | 96 ms
49,920 KB |
testcase_44 | AC | 36 ms
30,452 KB |
testcase_45 | AC | 93 ms
79,232 KB |
testcase_46 | AC | 10 ms
9,728 KB |
testcase_47 | AC | 401 ms
220,928 KB |
testcase_48 | AC | 13 ms
9,856 KB |
testcase_49 | AC | 12 ms
9,728 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)