結果

問題 No.1268 Fruit Rush 2
ユーザー semisagisemisagi
提出日時 2020-10-23 22:48:18
言語 Swift
(5.10.0)
結果
WA  
実行時間 -
コード長 1,989 bytes
コンパイル時間 2,681 ms
コンパイル使用メモリ 138,152 KB
実行使用メモリ 44,836 KB
最終ジャッジ日時 2023-09-28 17:10:01
合計ジャッジ時間 8,213 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
7,960 KB
testcase_02 AC 4 ms
7,908 KB
testcase_03 AC 3 ms
7,900 KB
testcase_04 AC 4 ms
7,904 KB
testcase_05 AC 4 ms
7,932 KB
testcase_06 AC 3 ms
7,964 KB
testcase_07 AC 3 ms
7,968 KB
testcase_08 AC 3 ms
7,904 KB
testcase_09 AC 4 ms
7,908 KB
testcase_10 WA -
testcase_11 AC 4 ms
7,928 KB
testcase_12 AC 3 ms
7,884 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 4 ms
8,000 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 149 ms
29,188 KB
testcase_35 AC 285 ms
44,700 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())!
    }
}

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)

0