結果

問題 No.2104 Multiply-Add
ユーザー hourenhouren
提出日時 2022-10-21 22:34:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,996 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 169,304 KB
実行使用メモリ 814,568 KB
最終ジャッジ日時 2023-09-13 22:50:55
合計ジャッジ時間 4,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:66:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   66 |     for(auto [p,q]:ans1){
      |              ^
main.cpp:71:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   71 |     for(auto [p,q]:ans2){
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
vector<P> f(int a, int b){
    vector<P> res;
    if(!a) res.push_back({1,1});
    if(!b) res.push_back({2,1});
    if(a<0){
        int x = (int)1e8 / b;
        res.push_back({1,x});
        a += b*x;
    }
    if(b<0){
        int x = (int)3e8 / a;
        res.push_back({2,x});
        b += a*x;
    }
    while(a!=b){
        if(a>b){
            if(a%b){
                int x = a/b;
                res.push_back({1,-x});
                a %= b;
            }else{
                int x = a/b-1;
                res.push_back({1,-x});
                a = b;
            }
        }else{
            if(b%a){
                int x = b/a;
                res.push_back({2,-x});
                b %= a;
            }else{
                int x = b/a-1;
                res.push_back({2,-x});
                b = a;
            }
        }
    }
    return res;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a==c && b==d){
        cout << "0\n";
        return 0;
    }else if((!a&&!b) || (abs(__gcd(c,d))!=abs(__gcd(a,b)))){
        cout << "-1\n";
        return 0;
    }
    auto ans1 = f(a,b);
    auto ans2 = f(c,d);
    cout << ans1.size()+ans2.size() << '\n';
    reverse(all(ans2));
    for(auto [p,q]:ans1){
        cout << p << " " << q << '\n';
        if(p==1) a += b * q;
        else b += a * q;
    }
    for(auto [p,q]:ans2){
        q *= -1;
        cout << p << " " << q << '\n';
        if(p==1) a += b * q;
        else b += a * q;
    }
    //cout << a << " " << b << '\n';
    return 0;
}
0