結果

問題 No.2104 Multiply-Add
ユーザー baLoon8128baLoon8128
提出日時 2022-10-21 22:49:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,062 bytes
コンパイル時間 3,863 ms
コンパイル使用メモリ 231,172 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 23:03:00
合計ジャッジ時間 5,676 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

int gcd(int x, int y) {
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    return x == 0 ? y : gcd(y % x, x);
}
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (gcd(a, b) == gcd(c, d)) {
        vector<pii> fr, bk;
        while (1) {
            if (b == 0 && a < 0) {
                fr.emplace_back(2, -1);
                fr.emplace_back(1, 1);
                b = -a, a = 0;
            }
            if (a == 0) {
                a = abs(b);
                fr.emplace_back(1, a / b);
                fr.emplace_back(2, -b / a);
                b = 0;
            }
            if (b == 0) break;
            if (abs(a) > abs(b)) {
                fr.emplace_back(1, -a / b);
                a %= b;
            } else {
                fr.emplace_back(2, -b / a);
                b %= a;
            }
        }
        while (1) {
            if (d == 0 && c < 0) {
                bk.emplace_back(2, 1);
                bk.emplace_back(1, -1);
                d = -c, c = 0;
            }
            if (c == 0) {
                c = abs(d);
                bk.emplace_back(1, -c / d);
                bk.emplace_back(2, d / c);
                d = 0;
            }
            if (d == 0) break;
            if (abs(c) > abs(d)) {
                bk.emplace_back(1, c / d);
                c %= d;
            } else {
                bk.emplace_back(2, d / c);
                d %= c;
            }
        }
        reverse(bk.begin(), bk.end());

        cout << (int)(fr.size() + bk.size()) << endl;
        for (auto [x, y] : fr) cout << x << " " << y << '\n';
        for (auto [x, y] : bk) cout << x << " " << y << '\n';
    } else {
        cout << -1 << endl;
    }
    return 0;
}
0