結果

問題 No.610 区間賞(Section Award)
ユーザー tentententen
提出日時 2023-01-31 10:50:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 2,259 bytes
コンパイル時間 2,958 ms
コンパイル使用メモリ 82,004 KB
実行使用メモリ 66,324 KB
最終ジャッジ日時 2023-09-13 05:01:38
合計ジャッジ時間 15,758 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,744 KB
testcase_01 AC 41 ms
49,788 KB
testcase_02 AC 42 ms
49,700 KB
testcase_03 AC 41 ms
49,764 KB
testcase_04 AC 42 ms
49,900 KB
testcase_05 AC 46 ms
49,708 KB
testcase_06 AC 56 ms
50,824 KB
testcase_07 AC 47 ms
50,728 KB
testcase_08 AC 57 ms
48,960 KB
testcase_09 AC 50 ms
49,880 KB
testcase_10 AC 57 ms
50,964 KB
testcase_11 AC 58 ms
51,036 KB
testcase_12 AC 44 ms
49,800 KB
testcase_13 AC 57 ms
51,412 KB
testcase_14 AC 57 ms
50,788 KB
testcase_15 AC 58 ms
50,972 KB
testcase_16 AC 56 ms
51,000 KB
testcase_17 AC 54 ms
49,992 KB
testcase_18 AC 47 ms
49,860 KB
testcase_19 AC 167 ms
57,260 KB
testcase_20 AC 347 ms
63,964 KB
testcase_21 AC 142 ms
56,008 KB
testcase_22 AC 282 ms
61,704 KB
testcase_23 AC 121 ms
54,620 KB
testcase_24 AC 187 ms
56,752 KB
testcase_25 AC 96 ms
52,692 KB
testcase_26 AC 228 ms
59,004 KB
testcase_27 AC 346 ms
63,892 KB
testcase_28 AC 343 ms
64,132 KB
testcase_29 AC 284 ms
61,632 KB
testcase_30 AC 324 ms
64,188 KB
testcase_31 AC 218 ms
58,860 KB
testcase_32 AC 331 ms
64,548 KB
testcase_33 AC 130 ms
54,940 KB
testcase_34 AC 325 ms
65,512 KB
testcase_35 AC 246 ms
59,084 KB
testcase_36 AC 333 ms
63,856 KB
testcase_37 AC 306 ms
63,780 KB
testcase_38 AC 165 ms
56,336 KB
testcase_39 AC 344 ms
65,696 KB
testcase_40 AC 347 ms
66,324 KB
testcase_41 AC 330 ms
65,480 KB
testcase_42 AC 339 ms
65,740 KB
testcase_43 AC 339 ms
65,340 KB
testcase_44 AC 434 ms
62,456 KB
testcase_45 AC 458 ms
65,472 KB
testcase_46 AC 468 ms
63,156 KB
testcase_47 AC 338 ms
63,672 KB
testcase_48 AC 301 ms
64,224 KB
testcase_49 AC 336 ms
63,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        ArrayDeque<Integer> prev = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            prev.add(sc.nextInt());
        }
        HashSet<Integer> used = new HashSet<>();
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (used.contains(x)) {
                continue;
            }
            while (prev.size() > 0) {
                int y = prev.poll();
                if (x == y) {
                    ans.add(x);
                    break;
                }
                used.add(y);
            }
        }
        Collections.sort(ans);
        StringBuilder sb = new StringBuilder();
        for (int x : ans) {
            sb.append(x).append("\n");
        }
        System.out.print(sb);
    }
    
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0