結果

問題 No.186 中華風 (Easy)
ユーザー Manuel1024Manuel1024
提出日時 2021-03-01 23:47:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,044 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 71,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 04:03:00
合計ジャッジ時間 1,733 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

ll myExtGCD(ll a, ll b, ll& x, ll& y){
    if(a % b == 0){
        x = 0;
        y = 1;
        return b;
    }
    
    ll d = myExtGCD(b, a % b, x, y);
    ll tmp = -y * (a / b) + x;
    x = y;
    y = tmp;
    return d;
}

P CRT(const vector<ll> &b, const vector<ll> &mo){
    ll r = 0, m = 1;
    for(int i = 0; i < b.size(); i++){
        ll p, q;
        ll d = myExtGCD(m, mo[i], p, q);
        if((b[i]-r)%d != 0) return make_pair(0, 0);
        else{
            ll tmp = (b[i]-r)/d * p % (mo[i]/d);
            r = r + tmp * m;
            m *= mo[i]/d;
            while(r < 0) r += m;
            r %= m;
        }
        // cerr << r << " " << m << endl;
    }
    return make_pair(r, m);
}

int main(){
    vector<ll> x(3), y(3);
    for(int i = 0; i < 3; i++) cin >> x[i] >> y[i];
    P ans = CRT(x, y);
    if(ans.first == 0 && ans.second == 0) cout << -1 << endl;
    else cout << ans.first << endl;
    return 0;
}
0