結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー ripityripity
提出日時 2022-04-15 20:29:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 2,229 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 84,708 KB
実行使用メモリ 48,780 KB
最終ジャッジ日時 2024-12-24 22:23:26
合計ジャッジ時間 15,406 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    
    public static Scanner sc = new Scanner(System.in);
    public static PrintWriter pw = new PrintWriter(System.out);
    
    public static void main(String[] args) {
        
        int N = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        int[] x = new int[N];
        int[] y = new int[N];
        int xmax = -1;
        int ymax = -1;
        int p = 0;
        int q = 0;
        LinkedList<Tuple> que = new LinkedList<>();
        
        for( int i = 0; i < N; i++ ) {
            a[i] = sc.nextInt();
            while( (a[i]>>x[i]) > 0 ) x[i]++;
            xmax = Math.max(xmax,x[i]);
        }
        
        for( int i = 0; i < N; i++ ) {
            b[i] = sc.nextInt();
            while( (b[i]>>y[i]) > 0 ) y[i]++;
            ymax = Math.max(ymax,y[i]);
        }
        
        if( xmax >= ymax ) {
            for( int i = 0; i < N; i++ ) {
                if( x[i] == xmax ) p = i;
            }
            for( q = 0; q < N; q++ ) {
                if( y[q] < x[p] ) {
                    b[q] = a[p]^b[q];
                    que.offer(new Tuple(2,p+1,q+1));
                }
            }
            for( p = 0; p < N; p++ ) {
                if( x[p] == xmax ) {
                    a[p] = a[p]^b[0];
                    que.offer(new Tuple(1,p+1,1));
                }
            }
        }else {
            for( int i = 0; i < N; i++ ) {
                if( y[i] == ymax ) q = i;
            }
            que.offer(new Tuple(1,1,q+1));
            a[0] = a[0]^b[q];
            for( q = 0; q < N; q++ ) {
                if( y[q] < ymax ) {
                    b[q] = a[0]^b[q];
                    que.offer(new Tuple(2,1,q+1));
                }
            }
            que.offer(new Tuple(1,1,1));
            a[0] = a[0]^b[0];
        }
        
        pw.println(que.size());
        for( Tuple t : que ) {
            pw.println(t.a+" "+t.b+" "+t.c);
        }
        
        pw.flush();
        
    }
    
}

class Tuple {
    
    int a, b, c;
    
    public Tuple(int a, int b, int c) {
        
        this.a = a;
        this.b = b;
        this.c = c;
        
    }
    
}
0