結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー tentententen
提出日時 2020-11-20 16:26:11
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,282 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 75,880 KB
実行使用メモリ 66,800 KB
最終ジャッジ日時 2023-09-30 18:32:06
合計ジャッジ時間 25,034 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
60,116 KB
testcase_01 AC 124 ms
56,224 KB
testcase_02 AC 132 ms
55,744 KB
testcase_03 AC 974 ms
64,528 KB
testcase_04 AC 1,062 ms
64,648 KB
testcase_05 AC 976 ms
64,500 KB
testcase_06 AC 882 ms
65,076 KB
testcase_07 AC 1,064 ms
62,788 KB
testcase_08 AC 271 ms
60,068 KB
testcase_09 AC 839 ms
64,820 KB
testcase_10 AC 1,282 ms
65,260 KB
testcase_11 AC 128 ms
55,500 KB
testcase_12 AC 1,059 ms
62,900 KB
testcase_13 AC 1,056 ms
64,852 KB
testcase_14 AC 1,111 ms
66,800 KB
testcase_15 AC 126 ms
55,984 KB
testcase_16 AC 127 ms
55,600 KB
testcase_17 AC 125 ms
55,516 KB
testcase_18 AC 136 ms
55,676 KB
testcase_19 AC 143 ms
55,668 KB
testcase_20 AC 132 ms
55,800 KB
testcase_21 AC 129 ms
55,392 KB
testcase_22 AC 131 ms
55,720 KB
testcase_23 AC 303 ms
60,376 KB
testcase_24 AC 601 ms
61,584 KB
testcase_25 AC 895 ms
64,720 KB
testcase_26 AC 400 ms
60,300 KB
testcase_27 AC 653 ms
63,868 KB
testcase_28 AC 808 ms
64,520 KB
testcase_29 AC 930 ms
63,436 KB
testcase_30 AC 1,051 ms
66,204 KB
testcase_31 AC 485 ms
60,432 KB
testcase_32 AC 382 ms
60,244 KB
testcase_33 AC 711 ms
63,932 KB
testcase_34 AC 130 ms
55,560 KB
testcase_35 AC 126 ms
55,880 KB
testcase_36 AC 127 ms
55,756 KB
testcase_37 AC 128 ms
55,752 KB
testcase_38 AC 127 ms
55,668 KB
testcase_39 AC 130 ms
56,056 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);
		long 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