結果

問題 No.1243 約数加算
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-04-09 14:17:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 197,816 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 14:19:43
合計ジャッジ時間 3,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve(){

    // 010100110
    // 010101000
    // 010110000
    // 011000000
    // 100000000

    // 100101011
    ll A, B;
    cin >> A >> B;
    vector<ll> ans;

    //1,Bの最上位以外のbitを0にする(下から)
    for (int i=0; i<60; i++){
        if ((A>>i & 1) && A+(1LL<<i)<=B){
            A += (1LL<<i);
            ans.push_back((1LL<<i));
        }
    }

    //2,Bと立っているbitを揃える(上から)
    for (int i=59; i>=0; i--){
        if ((B>>i & 1) && !(A>>i & 1)){
            A += (1LL<<i);
            ans.push_back((1LL<<i));
        }
    }

    assert(A == B);
    cout << ans.size() << endl;
    for (auto x : ans) cout << x << " ";
    cout << endl;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int T;
    cin >>  T;
    while(T--) solve();

    return 0;
}
0