結果
| 問題 |
No.2104 Multiply-Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-21 22:39:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,953 bytes |
| コンパイル時間 | 1,801 ms |
| コンパイル使用メモリ | 177,408 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:06:18 |
| 合計ジャッジ時間 | 3,148 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#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';
}