結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tentententen
提出日時 2020-11-20 16:24:13
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 76,060 KB
実行使用メモリ 67,036 KB
最終ジャッジ日時 2023-09-30 18:31:39
合計ジャッジ時間 24,768 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
60,288 KB
testcase_01 AC 128 ms
56,136 KB
testcase_02 AC 134 ms
58,040 KB
testcase_03 AC 964 ms
64,560 KB
testcase_04 WA -
testcase_05 AC 972 ms
64,752 KB
testcase_06 AC 901 ms
64,708 KB
testcase_07 WA -
testcase_08 AC 274 ms
60,284 KB
testcase_09 AC 871 ms
63,312 KB
testcase_10 WA -
testcase_11 AC 126 ms
56,372 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 127 ms
55,716 KB
testcase_16 AC 127 ms
55,984 KB
testcase_17 AC 126 ms
55,964 KB
testcase_18 AC 136 ms
55,744 KB
testcase_19 AC 145 ms
55,744 KB
testcase_20 AC 134 ms
55,908 KB
testcase_21 AC 127 ms
55,932 KB
testcase_22 AC 131 ms
55,940 KB
testcase_23 AC 293 ms
60,416 KB
testcase_24 AC 607 ms
60,516 KB
testcase_25 AC 910 ms
65,016 KB
testcase_26 AC 398 ms
60,152 KB
testcase_27 AC 659 ms
63,924 KB
testcase_28 AC 845 ms
64,664 KB
testcase_29 AC 945 ms
64,640 KB
testcase_30 WA -
testcase_31 AC 466 ms
60,424 KB
testcase_32 AC 391 ms
60,496 KB
testcase_33 AC 735 ms
66,344 KB
testcase_34 AC 132 ms
55,820 KB
testcase_35 AC 130 ms
55,536 KB
testcase_36 AC 130 ms
56,052 KB
testcase_37 AC 129 ms
56,136 KB
testcase_38 AC 128 ms
55,496 KB
testcase_39 AC 132 ms
55,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int[] order = new int[n + 1];
		for (int i = 0; i < n; i++) {
		    order[sc.nextInt()] = i;
		}
		ArrayList<Integer> list = new ArrayList<>();
		list.add(-1);
		list.add(Integer.MAX_VALUE);
		int count = 0;
		for (int i = 0; i < n; i++) {
		    int x = order[arr[i]];
		    int left = 0;
		    int right = list.size();
		    while (right - left > 1) {
		        int m = (left + right) / 2;
		        if (list.get(m) < x) {
		            left = m;
		        } else {
		            right = m;
		        }
		    }
		    count += list.size() - right - 1;
		    list.add(right, x);
		}
		System.out.println(count);
   }
}

0