結果

問題 No.1110 好きな歌
ユーザー semisagi
提出日時 2020-07-10 21:31:13
言語 Swift
(6.0.3)
結果
AC  
実行時間 402 ms / 5,000 ms
コード長 915 bytes
コンパイル時間 1,763 ms
コンパイル使用メモリ 130,944 KB
実行使用メモリ 17,200 KB
最終ジャッジ日時 2024-11-30 19:05:52
合計ジャッジ時間 12,901 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

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())!
    }
}

var scanner = Scanner()

let N = scanner.nextInt()
let D = scanner.nextInt()

let A = (0 ..< N).map { _ in scanner.nextInt() }
let I = A.indices.sorted(by: { i, j in A[i] < A[j] })

var answer = [Int](repeating: 0, count: N)
var j = 0
for i in I.indices {
    while A[I[j]] + D <= A[I[i]] {
        j += 1
    }
    answer[I[i]] = j
}

answer.forEach { print($0) }
0