結果

問題 No.2104 Multiply-Add
ユーザー HaaHaa
提出日時 2022-10-21 23:10:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,004 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 170,488 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 23:17:53
合計ジャッジ時間 4,292 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

vector<P> f(ll a, ll b){
    vector<P> x;
    if(a==0){
        a+=b;
        x.push_back({1,1});
    }
    else if(b==0){
        b+=a;
        x.push_back({2,1});
    }
    while(abs(a)!=abs(b)){
        if(abs(a)<abs(b)){
            ll k=abs((b+(b<0?1:-1))/a);
            if(b<0==a<0)
                k*=-1;
            b+=k*a;
            x.push_back({2,k});
        }
        else{
            ll k=abs((a+(a<0?1:-1))/b);
            if(b<0==a<0)
                k*=-1;
            a+=k*b;
            x.push_back({1,k});
        }
    }
    if(a<0){
        if(b<0){
            a+=-2*b;
            x.push_back({1,-2});
        }
        else{
            a+=2*b;
            x.push_back({1,2});
        }
    }
    if(b<0){
        b+=2*a;
        x.push_back({2,2});
    }
    return x;
}

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a==0&&b==0||c==0&&d==0){
        if(a==0&&b==0&&c==0&&d==0)
            cout << 0 << endl;
        else
            cout << -1 << endl;
        return 0;
    }
    if(__gcd(abs(c),abs(d))!=__gcd(abs(a),abs(b))){
        cout << -1 << endl;
        return 0;
    }
    vector<P> x=f(a,b);
    vector<P> y=f(c,d);
    reverse(ALL(y));
    cout << x.size()+y.size() << endl;
    for(auto [p,q]:x){
        cout << p << " " << q << endl;
        if(p==1)
            a+=b*q;
        else
            b+=a*q;
    }
    for(auto [p,q]:y){
        cout << p << " " << -q << endl;
        if(p==1)
            a-=b*q;
        else
            b-=a*q;
    }
    //cout << a << " " << b << endl;
    return 0;
}
0