結果
問題 | No.2771 Personal Space |
ユーザー |
![]() |
提出日時 | 2024-06-04 14:49:01 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 939 ms / 2,000 ms |
コード長 | 3,074 bytes |
コンパイル時間 | 3,549 ms |
コンパイル使用メモリ | 85,604 KB |
実行使用メモリ | 96,796 KB |
最終ジャッジ日時 | 2024-06-04 14:49:29 |
合計ジャッジ時間 | 22,837 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
38,156 KB |
testcase_01 | AC | 812 ms
91,908 KB |
testcase_02 | AC | 939 ms
91,992 KB |
testcase_03 | AC | 753 ms
92,048 KB |
testcase_04 | AC | 766 ms
91,960 KB |
testcase_05 | AC | 786 ms
91,900 KB |
testcase_06 | AC | 778 ms
91,956 KB |
testcase_07 | AC | 571 ms
51,116 KB |
testcase_08 | AC | 667 ms
67,756 KB |
testcase_09 | AC | 545 ms
51,364 KB |
testcase_10 | AC | 694 ms
60,984 KB |
testcase_11 | AC | 764 ms
92,792 KB |
testcase_12 | AC | 792 ms
86,280 KB |
testcase_13 | AC | 483 ms
57,448 KB |
testcase_14 | AC | 559 ms
51,068 KB |
testcase_15 | AC | 557 ms
53,200 KB |
testcase_16 | AC | 573 ms
53,072 KB |
testcase_17 | AC | 576 ms
58,652 KB |
testcase_18 | AC | 578 ms
51,204 KB |
testcase_19 | AC | 536 ms
51,404 KB |
testcase_20 | AC | 856 ms
96,796 KB |
testcase_21 | AC | 794 ms
93,152 KB |
testcase_22 | AC | 771 ms
92,880 KB |
testcase_23 | AC | 810 ms
92,260 KB |
testcase_24 | AC | 769 ms
89,356 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 t = sc.nextInt(); String result = IntStream.range(0, t).mapToObj(i -> { int n = sc.nextInt(); int m = sc.nextInt(); PriorityQueue<Space> queue = new PriorityQueue<>(); int[] ans = new int[n]; ans[m - 1] = 1; if (m > 1) { queue.add(new Space(1, m - 1)); } if (m < n) { queue.add(new Space(n, n - m)); } TreeSet<Integer> exists = new TreeSet<>(); exists.add(m); int current = 2; while (queue.size() > 0) { Space x = queue.poll(); ans[x.idx - 1] = current++; if (x.idx > 1) { int left = exists.lower(x.idx); if (left + 1 < x.idx) { queue.add(new Space((left + x.idx) / 2, (left + x.idx) / 2 - left)); } } if (x.idx < n) { int right = exists.higher(x.idx); if (right - 1 > x.idx) { queue.add(new Space((right + x.idx) / 2, (right + x.idx) / 2 - x.idx)); } } exists.add(x.idx); } return Arrays.stream(ans).mapToObj(String::valueOf).collect(Collectors.joining(" ")); }).collect(Collectors.joining("\n")); System.out.println(result); } static class Space implements Comparable<Space> { int idx; int value; public Space(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Space another) { if (value == another.value) { return idx - another.idx; } else { return another.value - value; } } public String toString() { return idx + ":" + value; } } } 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(); } } }