結果

問題 No.186 中華風 (Easy)
ユーザー shinohara_isspshinohara_issp
提出日時 2022-04-16 20:14:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,781 bytes
コンパイル時間 3,790 ms
コンパイル使用メモリ 235,436 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-26 20:44:47
合計ジャッジ時間 3,831 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    


    
}
0