結果

問題 No.187 中華風 (Hard)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-11-19 00:26:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 948 bytes
コンパイル時間 11,599 ms
コンパイル使用メモリ 458,424 KB
実行使用メモリ 4,332 KB
最終ジャッジ日時 2023-09-30 15:20:14
合計ジャッジ時間 17,774 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define Cint boost::multiprecision::cpp_int
using namespace std;
const int mod = 1e9 + 7;

//ax + by = gcd(a,b)
Cint extgcd(Cint a, Cint b, Cint& x, Cint& y) {
    if (b) {
        Cint d = extgcd(b, a % b, y, x);
        y -= a / b * x;
        return d;
    } else {
        x = 1;
        y = 0;
        return a;
    }
}

int main() {
    int N;
    cin >> N;
    vector<Cint> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }
    Cint ans = X[0];
    if (ans == 0)
        ans = Y[0];
    Cint y = Y[0];
    for (int i = 1; i < N; i++) {
        Cint a, b;
        extgcd(y, Y[i], a, b);
        if (abs(ans - X[i]) % gcd(y, Y[i]) != 0) {
            cout << -1 << endl;
            return 0;
        }
        a *= (X[i] - ans) / gcd(y, Y[i]);
        ans += a * y;
        y = lcm(y, Y[i]);
    }

    ans %= mod;
    cout << ans << endl;
}
0