結果
| 問題 |
No.2104 Multiply-Add
|
| コンテスト | |
| ユーザー |
houren
|
| 提出日時 | 2022-10-21 22:37:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,056 bytes |
| コンパイル時間 | 2,596 ms |
| コンパイル使用メモリ | 173,088 KB |
| 実行使用メモリ | 814,592 KB |
| 最終ジャッジ日時 | 2024-07-01 07:05:52 |
| 合計ジャッジ時間 | 3,991 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | MLE * 1 -- * 31 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:72:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
72 | for(auto [p,q]:ans1){
| ^
main.cpp:77:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
77 | for(auto [p,q]:ans2){
| ^
ソースコード
#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});
a = b;
}
if(!b){
res.push_back({2,1});
b = a;
}
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;
}
houren