結果
問題 |
No.2104 Multiply-Add
|
ユーザー |
|
提出日時 | 2022-10-21 22:49:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,062 bytes |
コンパイル時間 | 3,890 ms |
コンパイル使用メモリ | 232,968 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 07:14:15 |
合計ジャッジ時間 | 5,325 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 RE * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:68:19: warning: 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: warning: 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'; | ^
ソースコード
// #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; }