結果

問題 No.2104 Multiply-Add
ユーザー 沙耶花沙耶花
提出日時 2022-10-21 22:06:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 4,163 ms
コンパイル使用メモリ 264,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 22:23:28
合計ジャッジ時間 6,027 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 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 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 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 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0