結果
問題 | No.1170 Never Want to Walk |
ユーザー | tenten |
提出日時 | 2024-08-05 17:09:32 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 516 ms / 2,000 ms |
コード長 | 2,754 bytes |
コンパイル時間 | 3,200 ms |
コンパイル使用メモリ | 90,172 KB |
実行使用メモリ | 83,068 KB |
最終ジャッジ日時 | 2024-08-05 17:09:49 |
合計ジャッジ時間 | 15,650 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
51,292 KB |
testcase_01 | AC | 71 ms
51,332 KB |
testcase_02 | AC | 73 ms
51,028 KB |
testcase_03 | AC | 70 ms
51,192 KB |
testcase_04 | AC | 75 ms
51,124 KB |
testcase_05 | AC | 74 ms
51,200 KB |
testcase_06 | AC | 74 ms
50,852 KB |
testcase_07 | AC | 72 ms
51,232 KB |
testcase_08 | AC | 73 ms
51,308 KB |
testcase_09 | AC | 73 ms
51,128 KB |
testcase_10 | AC | 71 ms
51,120 KB |
testcase_11 | AC | 68 ms
51,048 KB |
testcase_12 | AC | 86 ms
51,416 KB |
testcase_13 | AC | 89 ms
51,268 KB |
testcase_14 | AC | 88 ms
51,156 KB |
testcase_15 | AC | 94 ms
51,532 KB |
testcase_16 | AC | 89 ms
51,324 KB |
testcase_17 | AC | 92 ms
51,244 KB |
testcase_18 | AC | 88 ms
51,420 KB |
testcase_19 | AC | 91 ms
51,476 KB |
testcase_20 | AC | 91 ms
51,568 KB |
testcase_21 | AC | 89 ms
51,316 KB |
testcase_22 | AC | 90 ms
51,208 KB |
testcase_23 | AC | 88 ms
51,480 KB |
testcase_24 | AC | 89 ms
51,448 KB |
testcase_25 | AC | 91 ms
51,308 KB |
testcase_26 | AC | 90 ms
51,332 KB |
testcase_27 | AC | 511 ms
69,824 KB |
testcase_28 | AC | 500 ms
70,480 KB |
testcase_29 | AC | 509 ms
68,688 KB |
testcase_30 | AC | 502 ms
67,856 KB |
testcase_31 | AC | 503 ms
69,888 KB |
testcase_32 | AC | 512 ms
83,068 KB |
testcase_33 | AC | 516 ms
74,304 KB |
testcase_34 | AC | 516 ms
82,280 KB |
testcase_35 | AC | 513 ms
82,952 KB |
testcase_36 | AC | 504 ms
81,736 KB |
testcase_37 | AC | 514 ms
81,492 KB |
testcase_38 | AC | 502 ms
81,908 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); int[] points = new int[n]; for (int i = 0; i < n; i++) { points[i] = sc.nextInt(); } int left = 0; int right = 0; UnionFindTree uft = new UnionFindTree(n); for (int i = 0; i < n; i++) { while (left < n && points[left] - points[i] < a) { left++; } if (left >= n) { break; } while (right < n && points[right] - points[i] <= b) { right++; } for (int j = left; j < right; j++) { uft.unite(i, j); } left = right - 1; } String result = IntStream.range(0, n) .mapToObj(i -> String.valueOf(uft.getCount(i))) .collect(Collectors.joining("\n")); System.out.println(result); } static class UnionFindTree { int[] parents; int[] counts; public UnionFindTree(int size) { parents = IntStream.range(0, size).toArray(); counts = new int[size]; Arrays.fill(counts, 1); } public int find(int x) { return x== parents[x] ? x : (parents[x] = find(parents[x])); } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx != yy) { parents[xx] = yy; counts[yy] += counts[xx]; } } public int getCount(int x) { return counts[find(x)]; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }