結果

問題 No.186 中華風 (Easy)
ユーザー nikutto_nikutto_
提出日時 2019-10-27 20:44:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 147,036 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 00:57:43
合計ジャッジ時間 2,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

ll extGcd(ll a,ll b,ll& p,ll &q){
    if(b==0) {p=1; q=0; return a;}
    ll d = extGcd(b,a%b,q,p);
    q -= a/b * p;
    return d;
}
// return minimum x s.t. x>=0 and x=b0 (mod m0) and x=b1 (mod m1)
// if such x don't exist, return (0,-1)
// O(log(m0)+log(m1))
// Note that the risk of overflow
pair<ll,ll> CRT(ll b0,ll m0,ll b1,ll m1){
    ll p,q;
    ll d = extGcd(m0,m1,p,q);
    if((b1-b0)%d!=0) return make_pair(ll(0),ll(-1));
    ll m = m0/d * m1;
    ll tmp = (b1-b0)/d * p % (m1/d);
    ll r = (b0 + m0 * tmp) % m;
    if(r<0) r = (r+m)%m;
    return make_pair(r,m);
}
// modify ll -> __int128
int main(){
    vector<ll> x(3),y(3);
    for(int i=0;i<3;i++) cin>>x[i]>>y[i];
    auto ret = CRT(x[0],y[0],x[1],y[1]);
    if(ret.second==-1){
        cout<<-1<<endl;
        return 0;
    }    
    ret = CRT(ret.first,ret.second,x[2],y[2]);
    if(ret.second==-1){
        cout<<-1<<endl;
        return 0;
    }
    cout<<(ret.first==0 ? ret.second : ret.first)<<endl;
    return 0;
}
0