結果

問題 No.1110 好きな歌
ユーザー semisagisemisagi
提出日時 2020-07-10 21:31:13
言語 Swift
(5.10.0)
結果
AC  
実行時間 432 ms / 5,000 ms
コード長 915 bytes
コンパイル時間 5,044 ms
コンパイル使用メモリ 133,564 KB
実行使用メモリ 16,060 KB
最終ジャッジ日時 2023-08-20 15:58:36
合計ジャッジ時間 14,960 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,688 KB
testcase_01 AC 3 ms
7,684 KB
testcase_02 AC 3 ms
7,700 KB
testcase_03 AC 3 ms
7,728 KB
testcase_04 AC 3 ms
7,660 KB
testcase_05 AC 3 ms
7,728 KB
testcase_06 AC 3 ms
7,680 KB
testcase_07 AC 3 ms
7,664 KB
testcase_08 AC 4 ms
7,724 KB
testcase_09 AC 4 ms
7,636 KB
testcase_10 AC 3 ms
7,636 KB
testcase_11 AC 4 ms
7,720 KB
testcase_12 AC 3 ms
7,768 KB
testcase_13 AC 3 ms
7,684 KB
testcase_14 AC 4 ms
7,664 KB
testcase_15 AC 4 ms
7,660 KB
testcase_16 AC 4 ms
7,620 KB
testcase_17 AC 5 ms
7,756 KB
testcase_18 AC 4 ms
7,728 KB
testcase_19 AC 5 ms
7,764 KB
testcase_20 AC 5 ms
7,716 KB
testcase_21 AC 4 ms
7,744 KB
testcase_22 AC 5 ms
7,748 KB
testcase_23 AC 4 ms
7,736 KB
testcase_24 AC 255 ms
12,336 KB
testcase_25 AC 304 ms
13,540 KB
testcase_26 AC 158 ms
10,496 KB
testcase_27 AC 303 ms
14,264 KB
testcase_28 AC 175 ms
10,968 KB
testcase_29 AC 355 ms
15,016 KB
testcase_30 AC 176 ms
10,960 KB
testcase_31 AC 108 ms
9,688 KB
testcase_32 AC 387 ms
15,404 KB
testcase_33 AC 202 ms
11,420 KB
testcase_34 AC 270 ms
12,816 KB
testcase_35 AC 418 ms
15,704 KB
testcase_36 AC 49 ms
8,576 KB
testcase_37 AC 119 ms
9,752 KB
testcase_38 AC 348 ms
14,112 KB
testcase_39 AC 258 ms
12,348 KB
testcase_40 AC 331 ms
14,208 KB
testcase_41 AC 28 ms
8,252 KB
testcase_42 AC 379 ms
15,028 KB
testcase_43 AC 350 ms
14,196 KB
testcase_44 AC 423 ms
15,572 KB
testcase_45 AC 423 ms
15,412 KB
testcase_46 AC 423 ms
15,536 KB
testcase_47 AC 429 ms
15,640 KB
testcase_48 AC 424 ms
16,060 KB
testcase_49 AC 416 ms
15,512 KB
testcase_50 AC 423 ms
15,520 KB
testcase_51 AC 432 ms
15,628 KB
testcase_52 AC 425 ms
15,924 KB
testcase_53 AC 429 ms
15,580 KB
権限があれば一括ダウンロードができます

ソースコード

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