結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー ShirotsumeShirotsume
提出日時 2022-03-28 13:39:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 2,445 ms
コンパイル使用メモリ 201,428 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 19:57:36
合計ジャッジ時間 5,071 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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 WA -
testcase_17 WA -
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:50:23: warning: 'now' may be used uninitialized [-Wmaybe-uninitialized]
   50 |         if (1 & (a[now] >> i)) k = i;
      |                       ^
main.cpp:33:9: note: 'now' was declared here
   33 |     int now;
      |         ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void query(int t, int p, int q, vector<int>& a, vector<int>& b, vector<vector<int>>& ans){
    vector<int> temp;
    temp.push_back(t);
    temp.push_back(p + 1);
    temp.push_back(q + 1);
    if(t == 1) a[p] = a[p] ^ b[q];
    if(t == 2) b[q] = a[p] ^ b[q];
    ans.push_back(temp);
}

void swap(int i, int j, vector<int>& a, vector<int>& b, vector<vector<int>>& ans){
    //a[i] と b[j] を交換
    query(1, i, j, a, b, ans);
    query(2, i, j, a, b, ans);
    query(1, i, j, a, b, ans);
}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    vector<vector<int>> ans;
    int maxa = 0, maxb = 0;
    rep(i, n){
        if(a[i] > maxa) maxa = a[i];
        if(b[i] > maxb) maxb = b[i];
    }
    int now;
    if (maxa > maxb){
        rep(i, n) if (a[i] == maxa){
         now = i;
         break;
        }
    }

    else{
        rep(i, n) if (b[i] == maxb){
            swap(0, i, a, b, ans);
            now = 0;
            break;
        }
    }
    int k = 0;
    rep(i, 30){
        if (1 & (a[now] >> i)) k = i;
    }
    cout << k << endl;
    rep(i,n){
        if (b[i] < 1 << k){
            query(2, now, i, a, b, ans);
        }
    }
    rep(i, n){
        if (1 & (a[i] >> k)){
            query(1, i, 0, a, b, ans);
        }
    }
    int ans1 = ans.size();
    cout << ans1 << endl;
    rep(i, ans1){
        printf("%d %d %d\n" ,ans[i][0], ans[i][1], ans[i][2]);
    }
    
    return 0;
}
0