結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー ShirotsumeShirotsume
提出日時 2022-03-20 01:55:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,717 bytes
コンパイル時間 2,925 ms
コンパイル使用メモリ 81,912 KB
実行使用メモリ 52,912 KB
最終ジャッジ日時 2024-04-15 16:24:49
合計ジャッジ時間 23,248 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 138 ms
41,652 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 577 ms
50,016 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 584 ms
49,812 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 552 ms
49,248 KB
testcase_17 AC 550 ms
49,184 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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, 0, i, 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