結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー tentententen
提出日時 2022-09-08 13:07:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 2,403 bytes
コンパイル時間 3,313 ms
コンパイル使用メモリ 74,672 KB
実行使用メモリ 52,452 KB
最終ジャッジ日時 2023-08-15 21:42:52
合計ジャッジ時間 11,568 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
49,360 KB
testcase_01 AC 40 ms
49,364 KB
testcase_02 AC 40 ms
50,000 KB
testcase_03 AC 76 ms
51,776 KB
testcase_04 AC 96 ms
52,280 KB
testcase_05 AC 94 ms
52,324 KB
testcase_06 AC 92 ms
52,452 KB
testcase_07 AC 95 ms
52,428 KB
testcase_08 AC 93 ms
51,888 KB
testcase_09 AC 91 ms
51,960 KB
testcase_10 AC 92 ms
52,168 KB
testcase_11 AC 91 ms
51,920 KB
testcase_12 AC 82 ms
52,292 KB
testcase_13 AC 90 ms
52,116 KB
testcase_14 AC 97 ms
51,156 KB
testcase_15 AC 78 ms
49,900 KB
testcase_16 AC 91 ms
51,188 KB
testcase_17 AC 91 ms
52,028 KB
testcase_18 AC 74 ms
52,380 KB
testcase_19 AC 70 ms
51,632 KB
testcase_20 AC 80 ms
52,180 KB
testcase_21 AC 60 ms
51,208 KB
testcase_22 AC 90 ms
52,424 KB
testcase_23 AC 93 ms
52,208 KB
testcase_24 AC 83 ms
52,040 KB
testcase_25 AC 91 ms
52,144 KB
testcase_26 AC 92 ms
51,820 KB
testcase_27 AC 106 ms
51,848 KB
testcase_28 AC 78 ms
51,816 KB
testcase_29 AC 82 ms
52,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] countsA = new int[n];
        int maxA = 0;
        int aIdx = 0;
        for (int i = 0; i < n; i++) {
            countsA[i] = getCount(sc.nextInt());
            if (maxA < countsA[i]) {
                maxA = countsA[i];
                aIdx = i;
            }
        }
        int[] countsB = new int[n];
        int maxB = 0;
        int bIdx = 0;
        for (int i = 0; i < n; i++) {
            countsB[i] = getCount(sc.nextInt());
            if (maxB < countsB[i]) {
                maxB = countsB[i];
                bIdx = i;
            }
        }
        int ans = 0;
        StringBuilder sb = new StringBuilder();
        if (maxA < maxB) {
            sb.append("1 1 ").append(bIdx + 1).append("\n");
            ans++;
            maxA = maxB;
            aIdx = 0;
            countsA[0] = maxB;
        }
        for (int i = 0; i < n; i++) {
            if (countsB[i] < maxA) {
                sb.append("2 ").append(aIdx + 1).append(" ").append(i + 1).append("\n");
                ans++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (countsA[i] == maxA) {
                sb.append("1 ").append(i + 1).append(" 1\n");
                ans++;
            }
        }
        System.out.println(ans);
        System.out.print(sb);
    }
    
    static int getCount(int x) {
        int count = 0;
        while (x > 0) {
            count++;
            x >>= 1;
        }
        return count;
    }
}
    
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0