結果
| 問題 |
No.2104 Multiply-Add
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-10-21 22:06:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,240 bytes |
| コンパイル時間 | 4,070 ms |
| コンパイル使用メモリ | 255,084 KB |
| 最終ジャッジ日時 | 2025-02-08 10:07:51 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 3000000000000000
vector<pair<int,int>> get(long long a,long long b){
vector<pair<int,int>> ret;
while(true){
if(abs(a)>abs(b)){
ret.emplace_back(2,1);
b += a;
ret.emplace_back(1,-1);
a -= b;
continue;
}
if(a==0){
if(b<0){
ret.emplace_back(1,-1);
a -= b;
ret.emplace_back(2,1);
b += a;
continue;
}
else{
return ret;
}
}
long long d = abs(b) / abs(a);
if(abs(b) < abs(b+a*d)){
d *= -1;
}
ret.emplace_back(2,d);
b += a * d;
}
}
int main(){
long long a,b,c,d;
cin>>a>>b>>c>>d;
if(gcd(abs(a),abs(b))!=gcd(abs(c),abs(d))){
cout<<-1<<endl;
return 0;
}
auto ans = get(a,b);
auto t = get(c,d);
reverse(t.begin(),t.end());
rep(i,t.size()){
ans.emplace_back(t[i].first,t[i].second*-1);
}
cout<<ans.size()<<endl;
rep(i,ans.size()){
cout<<ans[i].first<<' '<<ans[i].second<<endl;
if(ans[i].first==1){
a += b * ans[i].second;
}
else{
b += a * ans[i].second;
}
}
//cout<<a<<','<<b<<endl;
return 0;
}
沙耶花