結果
| 問題 | No.186 中華風 (Easy) |
| コンテスト | |
| ユーザー |
shinohara_issp
|
| 提出日時 | 2022-04-16 20:14:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,781 bytes |
| コンパイル時間 | 2,524 ms |
| コンパイル使用メモリ | 228,484 KB |
| 最終ジャッジ日時 | 2025-01-28 18:54:34 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 17 |
ソースコード
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>;
template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>;
void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; }
template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}}
template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;}
template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;}
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(si, i,n) for(ll i=si;i<n;i++)
ll ex_eucrid(ll a,ll b,ll &x,ll &y){
// ax+by=gcd(a,b);
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = ex_eucrid(b, a%b, y,x);
y -= a/b * x;
return d;
}
bool crt_2(Vll am1,Vll bm2,Vll &cm3){
// Vll cm3(2);
ll a,b,m1,m2;
a=am1.at(0);
m1=am1.at(1);
b=bm2.at(0);
m2=bm2.at(1);
ll c,lcm,gcd;
gcd=__gcd(m1,m2);
lcm=m1*m2/gcd;
if( a%gcd != b%gcd) return false;
ll p,q;
ex_eucrid(m1,m2,p,q);
c=a+m1*(b-a)*p/gcd;
// cm3={(c+lcm)%lcm,lcm};
cm3={c,lcm};
return true;
}
bool crt(VVll ams,Vll &cm){
ll n=ams.size();
cm=ams.at(0);
for(ll i=1;i<n;i++) if(!crt_2(cm,ams.at(i),cm)) return false;
return true;
}
int main(){
// ll x,y;
// ex_eucrid(111,30,x,y);
// cout<<x<<' '<<y<<endl;
// Vll cm3;
// crt_2({5,6},{1,4},cm3);
// Vcout(cm3);
VVll ams(3);
rep(i,3){
ll a,b;
cin>>a>>b;
ams.at(i)={a,b};
}
Vll cm;
if(crt(ams,cm))cout<<cm.at(0);
else cout<<-1;
cout<<endl;
}
shinohara_issp