結果

問題 No.938 賢人を探せ
ユーザー htensaihtensai
提出日時 2019-12-09 11:43:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 3,468 ms
コンパイル使用メモリ 72,936 KB
実行使用メモリ 63,548 KB
最終ジャッジ日時 2023-08-21 03:36:48
合計ジャッジ時間 10,686 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
63,548 KB
testcase_01 AC 124 ms
55,928 KB
testcase_02 AC 123 ms
55,780 KB
testcase_03 AC 124 ms
55,844 KB
testcase_04 AC 128 ms
55,984 KB
testcase_05 AC 123 ms
56,116 KB
testcase_06 AC 123 ms
57,508 KB
testcase_07 AC 124 ms
56,016 KB
testcase_08 AC 295 ms
62,956 KB
testcase_09 AC 297 ms
62,540 KB
testcase_10 AC 122 ms
55,480 KB
testcase_11 AC 318 ms
62,512 KB
testcase_12 AC 306 ms
62,980 KB
testcase_13 AC 298 ms
63,200 KB
testcase_14 AC 302 ms
62,956 KB
testcase_15 AC 299 ms
62,768 KB
testcase_16 AC 300 ms
63,088 KB
testcase_17 AC 297 ms
62,556 KB
testcase_18 AC 304 ms
62,460 KB
testcase_19 AC 291 ms
62,904 KB
testcase_20 AC 298 ms
62,884 KB
testcase_21 AC 283 ms
62,500 KB
testcase_22 AC 327 ms
62,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<String> allList = new ArrayList<>();
        HashSet<String> outSet = new HashSet<>();
        for (int i = 0; i < n; i++) {
            String a = sc.next();
            String b = sc.next();
            allList.add(b);
            outSet.add(a);
        }
        StringBuilder sb = new StringBuilder();
        HashSet<String> putSet = new HashSet<>();
        for (String s : allList) {
            if (!outSet.contains(s) && !putSet.contains(s)) {
                sb.append(s).append("\n");
                putSet.add(s);
            }
        }
        System.out.print(sb);
    }
}
0