結果
問題 | No.1268 Fruit Rush 2 |
ユーザー | semisagi |
提出日時 | 2020-10-23 22:48:18 |
言語 | Swift (6.0.3) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,989 bytes |
コンパイル時間 | 8,843 ms |
コンパイル使用メモリ | 134,004 KB |
実行使用メモリ | 46,172 KB |
最終ジャッジ日時 | 2024-07-21 11:50:57 |
合計ジャッジ時間 | 15,012 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 9 ms
9,344 KB |
testcase_02 | AC | 9 ms
9,344 KB |
testcase_03 | AC | 9 ms
9,216 KB |
testcase_04 | AC | 9 ms
9,216 KB |
testcase_05 | AC | 9 ms
9,344 KB |
testcase_06 | AC | 9 ms
9,216 KB |
testcase_07 | AC | 9 ms
9,344 KB |
testcase_08 | AC | 9 ms
9,344 KB |
testcase_09 | AC | 9 ms
9,088 KB |
testcase_10 | WA | - |
testcase_11 | AC | 8 ms
9,344 KB |
testcase_12 | AC | 9 ms
9,344 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 9 ms
9,344 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 177 ms
30,676 KB |
testcase_35 | AC | 353 ms
46,172 KB |
ソースコード
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 A = (0 ..< N).map { _ in scanner.nextInt() }.sorted() var even = [Int: Int]() var answer = N for i in (0 ..< N).reversed() { answer += even[A[i] + 1] ?? 0 answer += even[A[i] + 2] ?? 0 even[A[i]] = even[A[i] + 2] ?? 1 } print(answer)