結果
問題 | No.2104 Multiply-Add |
ユーザー | milanis48663220 |
提出日時 | 2022-10-21 22:43:37 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,931 bytes |
コンパイル時間 | 1,489 ms |
コンパイル使用メモリ | 122,372 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 07:09:57 |
合計ジャッジ時間 | 2,599 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using P = pair<int, int>; vector<P> normalize_path(int a, int b){ vector<P> ans; while(true){ ans.push_back(P(a, b)); if(a == 0){ a = b; continue; } if(b == 0){ b = a; continue; } if(abs(a) == abs(b)) { if(a < 0){ a = -a; ans.push_back(P(a, b)); } if(b < 0){ b = -b; ans.push_back(P(a, b)); } break; } if(abs(a) < abs(b)){ int c = abs(b)/abs(a); if(b < 0) c *= -1; b -= abs(a)*c; }else{ int c = abs(a)/abs(b); if(a < 0) c *= -1; a -= abs(b)*c; } } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int a, b, c, d; cin >> a >> b >> c >> d; int g1 = gcd(abs(a), abs(b)); int g2 = gcd(abs(c), abs(d)); if(g1 != g2){ cout << -1 << endl; return 0; } if(a == 0 && b == 0){ cout << 0 << endl; return 0; } auto path = normalize_path(a, b); auto path1 = normalize_path(c, d); reverse(path1.begin(), path1.end()); for(int i = 1; i < path1.size(); i++){ path.push_back(path1[i]); } cout << path.size()-1 << endl; for(int i = 1; i < path.size(); i++){ auto [x0, y0] = path[i-1]; auto [x1, y1] = path[i]; if(x0 == x1){ int c = (y1-y0)/x0; cout << 2 << ' ' << c << endl; }else{ assert(y0 == y1); int c = (x1-x0)/y0; cout << 1 << ' ' << c << endl; } } }