結果
問題 | No.2740 Old Maid |
ユーザー | tenten |
提出日時 | 2024-04-22 13:29:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,076 ms / 2,000 ms |
コード長 | 1,892 bytes |
コンパイル時間 | 4,813 ms |
コンパイル使用メモリ | 91,252 KB |
実行使用メモリ | 82,452 KB |
最終ジャッジ日時 | 2024-10-14 12:58:46 |
合計ジャッジ時間 | 38,230 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 787 ms
78,816 KB |
testcase_01 | AC | 784 ms
78,920 KB |
testcase_02 | AC | 789 ms
79,232 KB |
testcase_03 | AC | 792 ms
78,720 KB |
testcase_04 | AC | 793 ms
79,156 KB |
testcase_05 | AC | 816 ms
78,404 KB |
testcase_06 | AC | 789 ms
78,664 KB |
testcase_07 | AC | 796 ms
80,196 KB |
testcase_08 | AC | 777 ms
78,840 KB |
testcase_09 | AC | 810 ms
78,700 KB |
testcase_10 | AC | 790 ms
80,228 KB |
testcase_11 | AC | 746 ms
79,228 KB |
testcase_12 | AC | 758 ms
75,580 KB |
testcase_13 | AC | 807 ms
78,404 KB |
testcase_14 | AC | 385 ms
59,344 KB |
testcase_15 | AC | 412 ms
61,496 KB |
testcase_16 | AC | 647 ms
67,156 KB |
testcase_17 | AC | 358 ms
59,332 KB |
testcase_18 | AC | 785 ms
78,316 KB |
testcase_19 | AC | 463 ms
64,104 KB |
testcase_20 | AC | 925 ms
79,156 KB |
testcase_21 | AC | 372 ms
60,008 KB |
testcase_22 | AC | 664 ms
67,108 KB |
testcase_23 | AC | 293 ms
57,284 KB |
testcase_24 | AC | 466 ms
63,996 KB |
testcase_25 | AC | 1,076 ms
82,452 KB |
testcase_26 | AC | 135 ms
52,988 KB |
testcase_27 | AC | 245 ms
56,780 KB |
testcase_28 | AC | 692 ms
67,112 KB |
testcase_29 | AC | 650 ms
67,040 KB |
testcase_30 | AC | 183 ms
53,804 KB |
testcase_31 | AC | 1,000 ms
78,408 KB |
testcase_32 | AC | 498 ms
64,388 KB |
testcase_33 | AC | 878 ms
78,104 KB |
testcase_34 | AC | 658 ms
67,744 KB |
testcase_35 | AC | 434 ms
64,020 KB |
testcase_36 | AC | 480 ms
64,092 KB |
testcase_37 | AC | 553 ms
65,328 KB |
testcase_38 | AC | 447 ms
61,352 KB |
testcase_39 | AC | 342 ms
58,920 KB |
testcase_40 | AC | 736 ms
72,168 KB |
testcase_41 | AC | 918 ms
78,732 KB |
testcase_42 | AC | 74 ms
51,168 KB |
testcase_43 | AC | 76 ms
51,296 KB |
testcase_44 | AC | 72 ms
51,056 KB |
testcase_45 | AC | 72 ms
51,136 KB |
testcase_46 | AC | 74 ms
50,636 KB |
testcase_47 | AC | 70 ms
50,664 KB |
testcase_48 | AC | 73 ms
50,940 KB |
testcase_49 | AC | 72 ms
51,164 KB |
testcase_50 | AC | 72 ms
50,928 KB |
testcase_51 | AC | 73 ms
51,072 KB |
testcase_52 | AC | 72 ms
50,548 KB |
testcase_53 | AC | 74 ms
51,132 KB |
testcase_54 | AC | 71 ms
51,064 KB |
testcase_55 | AC | 73 ms
51,184 KB |
testcase_56 | AC | 71 ms
50,944 KB |
testcase_57 | AC | 71 ms
50,944 KB |
testcase_58 | AC | 73 ms
50,992 KB |
testcase_59 | AC | 74 ms
51,212 KB |
testcase_60 | AC | 74 ms
51,032 KB |
testcase_61 | AC | 72 ms
51,084 KB |
testcase_62 | AC | 72 ms
50,944 KB |
testcase_63 | AC | 73 ms
51,224 KB |
testcase_64 | AC | 73 ms
50,944 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[] values = new int[n]; int[] positions = new int[n]; TreeSet<Integer> remain = new TreeSet<>(); for (int i = 0; i < n; i++) { values[i] = sc.nextInt() - 1; positions[values[i]] = i; remain.add(i); } List<Integer> ans = new ArrayList<>(); for (int i = 0; i < n; i++) { if (!remain.contains(positions[i]) || remain.last() == positions[i]) { continue; } int next = remain.higher(positions[i]); ans.add(i + 1); ans.add(values[next] + 1); remain.remove(positions[i]); remain.remove(next); } System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining(" "))); } } 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(); } } }