結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー 👑 colognecologne
提出日時 2022-04-08 21:28:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 3,315 ms
コンパイル使用メモリ 254,672 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 07:03:07
合計ジャッジ時間 7,516 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 13 ms
5,376 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 9 ms
5,376 KB
testcase_07 AC 14 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 10 ms
5,376 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 9 ms
5,376 KB
testcase_24 AC 9 ms
5,376 KB
testcase_25 AC 9 ms
5,376 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 8 ms
5,376 KB
testcase_29 AC 8 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    int mx = 0;
    for (int &a : A)
        cin >> a, mx = max(mx, a);
    for (int &b : B)
        cin >> b, mx = max(mx, b);

    int mm = -1;
    for (int i = 29; i >= 0; --i)
        if (mx & (1 << i))
        {
            mm = i;
            break;
        }
    vector<tuple<int, int, int>> ans;
    int bv = -1, av = -1;
    for (int i = 0; i < N; i++)
    {
        if (B[i] & (1 << mm))
            bv = i;
        if (A[i] & (1 << mm))
            av = i;
    }

    if (bv == -1)
        ans.emplace_back(2, av, 0), bv = 0, B[bv] ^= A[av];
    else if (av == -1)
        ans.emplace_back(1, 0, bv), av = 0, A[av] ^= B[bv];

    for (int i = 0; i < N; i++)
        if (!(B[i] & (1 << mm)))
            ans.emplace_back(2, av, i);
    for (int i = 0; i < N; i++)
        if (A[i] & (1 << mm))
            ans.emplace_back(1, i, bv);

    cout << ans.size() << endl;

    for (auto [a, b, c] : ans)
        cout << a << " " << b + 1 << " " << c + 1 << endl;
}
0