結果

問題 No.2104 Multiply-Add
ユーザー t98slidert98slider
提出日時 2022-10-21 22:39:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,953 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 174,964 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 22:54:13
合計ジャッジ時間 3,471 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, d, mn;
    cin >> a >> b >> c >> d;
    mn = min(a == 0 ? 1ll << 30 : abs(a), b == 0 ? 1ll << 30 : abs(b));
    vector<pair<int,int>> ope1, ope2, ope;
    function<pair<ll,ll>(ll,ll)> f = [&](ll x, ll y){
        if(abs(y) == 0){
            if(x < 0){
                ope.emplace_back(2, -1);
                ope.emplace_back(1, 1);
                return f(0, -x);
            }
            return make_pair(x, y);
        }
        if(abs(x) == 0){
            if(y > 0){
                ope.emplace_back(1, 1);
                ope.emplace_back(2, -1);
                return f(y, 0);
            }else{
                ope.emplace_back(1, -1);
                ope.emplace_back(2, 1);
                return f(-y, 0);
            }
        }
        if(abs(x) > abs(y)){
            ll d = x / y;
            ope.emplace_back(1, -d);
            return f(x - d * y, y);
        }
        ll d = y / x;
        ope.emplace_back(2, -d);
        return f(x, y - d * x);
    };
    auto p1 = f(a, b);
    ope1 = ope;
    ope.clear();
    auto p2 = f(c, d);
    ope2 = ope;
    //cerr << p1.first << " " << p1.second << '\n';
    //cerr << p2.first << " " << p2.second << '\n';
    if(p1 != p2){
        cout << -1 << '\n';
        return 0;
    }
    reverse(ope2.begin(), ope2.end());
    for(auto &&p:ope2)p.second *= -1;
    ope1.insert(ope1.end(), ope2.begin(), ope2.end());
    cout << ope1.size() << '\n';
    for(int i = 0; i < ope1.size(); i++){
        //cerr << a << " " << b << '\n';
        if(ope1[i].first == 1){
            a += ope1[i].second * b;
        }else{
            b += ope1[i].second * a;
        }
        cout << ope1[i].first << " " << ope1[i].second << '\n';
    }
    //cerr << a << " " << b << '\n';
    //cerr << a << " " << b << '\n';
    //cerr << c << " " << d << '\n';
}
0