結果
| 問題 |
No.2104 Multiply-Add
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2022-10-21 23:10:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,004 bytes |
| コンパイル時間 | 1,805 ms |
| コンパイル使用メモリ | 173,912 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:28:14 |
| 合計ジャッジ時間 | 3,047 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
75 | for(auto [p,q]:x){
| ^
main.cpp:82:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
82 | for(auto [p,q]:y){
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;
vector<P> f(ll a, ll b){
vector<P> x;
if(a==0){
a+=b;
x.push_back({1,1});
}
else if(b==0){
b+=a;
x.push_back({2,1});
}
while(abs(a)!=abs(b)){
if(abs(a)<abs(b)){
ll k=abs((b+(b<0?1:-1))/a);
if(b<0==a<0)
k*=-1;
b+=k*a;
x.push_back({2,k});
}
else{
ll k=abs((a+(a<0?1:-1))/b);
if(b<0==a<0)
k*=-1;
a+=k*b;
x.push_back({1,k});
}
}
if(a<0){
if(b<0){
a+=-2*b;
x.push_back({1,-2});
}
else{
a+=2*b;
x.push_back({1,2});
}
}
if(b<0){
b+=2*a;
x.push_back({2,2});
}
return x;
}
int main(){
ll a, b, c, d;
cin >> a >> b >> c >> d;
if(a==0&&b==0||c==0&&d==0){
if(a==0&&b==0&&c==0&&d==0)
cout << 0 << endl;
else
cout << -1 << endl;
return 0;
}
if(__gcd(abs(c),abs(d))!=__gcd(abs(a),abs(b))){
cout << -1 << endl;
return 0;
}
vector<P> x=f(a,b);
vector<P> y=f(c,d);
reverse(ALL(y));
cout << x.size()+y.size() << endl;
for(auto [p,q]:x){
cout << p << " " << q << endl;
if(p==1)
a+=b*q;
else
b+=a*q;
}
for(auto [p,q]:y){
cout << p << " " << -q << endl;
if(p==1)
a-=b*q;
else
b-=a*q;
}
//cout << a << " " << b << endl;
return 0;
}
Haa