結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー ShirotsumeShirotsume
提出日時 2022-03-20 01:56:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 581 ms / 2,000 ms
コード長 1,717 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 79,700 KB
実行使用メモリ 54,328 KB
最終ジャッジ日時 2024-04-16 12:54:02
合計ジャッジ時間 19,477 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,056 KB
testcase_01 AC 133 ms
41,388 KB
testcase_02 AC 130 ms
41,032 KB
testcase_03 AC 469 ms
48,892 KB
testcase_04 AC 566 ms
50,156 KB
testcase_05 AC 571 ms
50,000 KB
testcase_06 AC 473 ms
49,136 KB
testcase_07 AC 581 ms
49,392 KB
testcase_08 AC 535 ms
49,996 KB
testcase_09 AC 526 ms
49,808 KB
testcase_10 AC 529 ms
49,724 KB
testcase_11 AC 544 ms
54,328 KB
testcase_12 AC 511 ms
49,452 KB
testcase_13 AC 491 ms
53,096 KB
testcase_14 AC 499 ms
49,216 KB
testcase_15 AC 488 ms
48,768 KB
testcase_16 AC 484 ms
49,224 KB
testcase_17 AC 490 ms
49,524 KB
testcase_18 AC 390 ms
46,948 KB
testcase_19 AC 315 ms
45,628 KB
testcase_20 AC 413 ms
47,856 KB
testcase_21 AC 338 ms
45,552 KB
testcase_22 AC 458 ms
49,196 KB
testcase_23 AC 461 ms
48,944 KB
testcase_24 AC 464 ms
48,692 KB
testcase_25 AC 470 ms
49,380 KB
testcase_26 AC 452 ms
49,512 KB
testcase_27 AC 459 ms
49,160 KB
testcase_28 AC 450 ms
48,836 KB
testcase_29 AC 462 ms
48,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static int arrayMax(int[] a){
		int ret = 0;
		for(int i = 0; i < a.length; i++){
			ret = Math.max(a[i],ret);
		}
		return ret;
	}
	public static void query(ArrayList<ArrayList<Integer>> ans, int t, int p, int q, int[] a, int[] b){
		ArrayList<Integer> pro = new ArrayList<>();
		pro.add(t);
		pro.add(p + 1);
		pro.add(q + 1);
		ans.add(pro);
		int temp = a[p] ^ b[q];
		if(t == 1) a[p] = temp;
		else b[q] = temp;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i = 0; i < n; i++) a[i] = sc.nextInt();
		for(int i = 0;i < n; i++) b[i] = sc.nextInt();
		int MAX = Math.max(arrayMax(a), arrayMax(b));
		ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
		int ind = 0;
		int inbflag = -1;
		for(int i = 0; i < n; i++) if (b[i] == MAX) inbflag = i;
		if (inbflag == -1){
			for(int i = 0;i < n; i++){
				if (a[i] == MAX){
					ind = i;
					break;
				}
			}
		}
		else{
			ind = 0;
			query(ans, 1, ind, inbflag, a, b);
			query(ans, 2, ind, inbflag, a, b);
			query(ans, 1, ind, inbflag, a, b);
		}
		int now = 1;
		for(int i = 0; i < 30; i++){
			if (now <= MAX && 2 * now > MAX) break;
			now *= 2;
		}
		for(int i = 0; i < n; i++){
			if (b[i] < now) query(ans, 2, ind, i, a, b);
		}
		for(int i = 0; i < n; i++){
			if (a[i] >= now) query(ans, 1, i, 0, a, b);
		}

		System.out.println(ans.size());

		for(int i = 0; i < ans.size(); i++){
			ArrayList<Integer> foo = ans.get(i);
			int t = foo.get(0);
			int p = foo.get(1);
			int q = foo.get(2);
			System.out.printf("%d %d %d\n",t, p, q);

		}



	}
}
0