結果
| 問題 |
No.3020 ユークリッドの互除法・改
|
| コンテスト | |
| ユーザー |
ococonomy1
|
| 提出日時 | 2025-02-14 21:31:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,559 bytes |
| コンパイル時間 | 2,102 ms |
| コンパイル使用メモリ | 196,344 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-02-14 21:31:34 |
| 合計ジャッジ時間 | 3,038 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 4 |
ソースコード
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define VEC_UNIQ(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define REV_PRIORITY_QUEUE(tp) priority_queue<tp,vector<tp>,greater<tp>>
//ax + by == gcd(a,b)
//返り値は gcd で、x,yにこれを満たす x,y が入る。関数に渡すときの値はなんでもよい。
//ちなみに、max(absX,absY) <= max(absA,absB) を満たすらしい。すごい。
long long ococo_extgcd(long long a, long long b, long long &x,long long &y){
if(abs(a) < abs(b)) {
swap(a,b);
swap(x,y);
}
if(!b){
x = 1; y = 0;
return a;
}
ll ans = ococo_extgcd(b,a % b,x,y);
ll temp = x;
x = y;
y = temp - (a / b) * y;
return ans;
}
#define MULTI_TEST_CASE false
void solve(void){
//問題を見たらまず「この問題設定から言えること」をいっぱい言う
//一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる
//添え字回りで面倒になりそうなときは楽になる言い換えを実装の前にじっくり考える
//ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる
//よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
//g++ -D_GLIBCXX_DEBUG -O2 b.cpp -o o
vector<ll> a(4);
for(int i = 0; i < 4; i++)cin >> a[i];
int cnt = 0;
for(int i = 0; i < 4; i++){
if(a[i] < 0){
a[i] *= -1;
//cnt++;
}
}
ll ab = abs(a[0] * a[3] - a[1] * a[2]);
ll x,y;
ll g = ococo_extgcd(a[0],a[1],x,y);
for(int i = 2; i < 4; i++)g = ococo_extgcd(g,a[i],x,y);
if(g == 0LL){
cout << "0 0" << el; return;
}
ll d1 = g;
ll d2 = ab / d1;
if(cnt % 2)d2 *= -1;
cout << d1 << ' ' << d2 << el;
return;
}
void calc(void){
return;
}
signed main(void){
cin.tie(nullptr);
ios::sync_with_stdio(false);
calc();
int t = 1;
if(MULTI_TEST_CASE)cin >> t;
while(t--){
solve();
}
return 0;
}
ococonomy1