結果
問題 | No.1110 好きな歌 |
ユーザー | tenten |
提出日時 | 2022-10-04 15:59:26 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 690 ms / 5,000 ms |
コード長 | 2,030 bytes |
コンパイル時間 | 2,391 ms |
コンパイル使用メモリ | 78,948 KB |
実行使用メモリ | 56,016 KB |
最終ジャッジ日時 | 2024-06-09 13:14:30 |
合計ジャッジ時間 | 20,166 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
36,992 KB |
testcase_01 | AC | 47 ms
37,016 KB |
testcase_02 | AC | 45 ms
37,144 KB |
testcase_03 | AC | 46 ms
36,704 KB |
testcase_04 | AC | 46 ms
37,068 KB |
testcase_05 | AC | 47 ms
37,180 KB |
testcase_06 | AC | 47 ms
36,684 KB |
testcase_07 | AC | 49 ms
36,552 KB |
testcase_08 | AC | 46 ms
36,984 KB |
testcase_09 | AC | 49 ms
37,032 KB |
testcase_10 | AC | 47 ms
36,972 KB |
testcase_11 | AC | 47 ms
37,060 KB |
testcase_12 | AC | 44 ms
36,704 KB |
testcase_13 | AC | 48 ms
36,844 KB |
testcase_14 | AC | 53 ms
36,940 KB |
testcase_15 | AC | 51 ms
37,084 KB |
testcase_16 | AC | 52 ms
37,188 KB |
testcase_17 | AC | 72 ms
37,724 KB |
testcase_18 | AC | 52 ms
36,948 KB |
testcase_19 | AC | 68 ms
37,992 KB |
testcase_20 | AC | 59 ms
37,088 KB |
testcase_21 | AC | 53 ms
37,056 KB |
testcase_22 | AC | 64 ms
37,544 KB |
testcase_23 | AC | 51 ms
37,132 KB |
testcase_24 | AC | 411 ms
49,372 KB |
testcase_25 | AC | 458 ms
52,076 KB |
testcase_26 | AC | 307 ms
49,184 KB |
testcase_27 | AC | 449 ms
51,800 KB |
testcase_28 | AC | 333 ms
48,376 KB |
testcase_29 | AC | 497 ms
52,800 KB |
testcase_30 | AC | 311 ms
48,420 KB |
testcase_31 | AC | 247 ms
47,184 KB |
testcase_32 | AC | 561 ms
53,344 KB |
testcase_33 | AC | 337 ms
48,804 KB |
testcase_34 | AC | 404 ms
50,984 KB |
testcase_35 | AC | 571 ms
52,404 KB |
testcase_36 | AC | 183 ms
44,448 KB |
testcase_37 | AC | 262 ms
47,920 KB |
testcase_38 | AC | 514 ms
53,508 KB |
testcase_39 | AC | 499 ms
51,328 KB |
testcase_40 | AC | 474 ms
51,392 KB |
testcase_41 | AC | 150 ms
41,304 KB |
testcase_42 | AC | 543 ms
53,184 KB |
testcase_43 | AC | 521 ms
54,224 KB |
testcase_44 | AC | 565 ms
54,124 KB |
testcase_45 | AC | 608 ms
53,872 KB |
testcase_46 | AC | 573 ms
54,284 KB |
testcase_47 | AC | 589 ms
56,016 KB |
testcase_48 | AC | 621 ms
54,304 KB |
testcase_49 | AC | 592 ms
51,956 KB |
testcase_50 | AC | 654 ms
54,336 KB |
testcase_51 | AC | 690 ms
53,768 KB |
testcase_52 | AC | 581 ms
54,408 KB |
testcase_53 | AC | 584 ms
55,840 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int d = sc.nextInt(); Tune[] tunes = new Tune[n]; for (int i = 0; i < n; i++) { tunes[i] = new Tune(i, sc.nextInt()); } Arrays.sort(tunes); int[] counts = new int[n + 2]; int right = 0; for (int i = 0; i < n; i++) { while (right < n && tunes[i].value + d > tunes[right].value) { right++; } counts[right + 1]++; } int[] ans = new int[n]; for (int i = 1; i <= n; i++) { counts[i] += counts[i - 1]; ans[tunes[i - 1].idx] = counts[i]; } StringBuilder sb = new StringBuilder(); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } static class Tune implements Comparable<Tune> { int idx; int value; public Tune(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Tune another) { return value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }