結果

問題 No.1896 Arrays and XOR Procedure 2
コンテスト
ユーザー LyricalMaestro
提出日時 2026-11-26 02:20:38
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 54 ms / 2,000 ms
+ 984µs
コード長 1,335 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 93 ms
コンパイル使用メモリ 64,640 KB
実行使用メモリ 61,184 KB
最終ジャッジ日時 2026-11-26 02:20:46
合計ジャッジ時間 6,482 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/1896



def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a_list = [[A[i], i] for i in range(N)]
    b_list = [[B[i], i] for i in range(N)]

    a_list.sort(key=lambda x: x[0])
    b_list.sort(key=lambda x: x[0])
    for i in range(N):
        a = a_list[i][0]
        k = 0
        while a > 0:
            k += 1
            a //= 2
        a_list[i][0] = k
        a = b_list[i][0]
        k = 0
        while a > 0:
            k += 1
            a //= 2
        b_list[i][0] = k

    answer = []
    if a_list[-1][0] > b_list[-1][0]:
        answer.append((2, a_list[-1][1], b_list[-1][1]))
        b_list[-1][0] = a_list[-1][0]
    elif a_list[-1][0] < b_list[-1][0]:
        answer.append((1, a_list[-1][1], b_list[-1][1]))
        a_list[-1][0] = b_list[-1][0]


    for i in range(N - 1):
        if b_list[i][0] < a_list[-1][0]:
            answer.append((2, a_list[-1][1], b_list[i][1]))
            b_list[i][0] = a_list[-1][0]
    for i in range(N):
        if a_list[i][0] == b_list[-1][0]:
            answer.append((1, a_list[i][1], b_list[-1][1]))
            a_list[i][0] = b_list[-1][0]

    print(len(answer))
    for t, p, q in answer:
        print(t, p +1 , q + 1)






if __name__ == "__main__":
    main()
0