結果

問題 No.186 中華風 (Easy)
ユーザー とばりとばり
提出日時 2018-09-21 06:29:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,160 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 175,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 10:38:51
合計ジャッジ時間 2,918 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using int64 = long long;
using uint64 = unsigned long long;

inline int64 mod(int64 a, int64 m) { return (a % m + m) % m; }

std::tuple<int64, int64, int64> extGCD(int64 a, int64 b) {
    if (b == 0) return std::make_tuple(1LL, 0LL, a);

    int64 s, t, g;
    std::tie(s, t, g) = extGCD(b, a % b);
    return std::make_tuple(t, s - (a / b) * t, g);
}

std::tuple<int64, bool> CRT(std::vector<int64> b, std::vector<int64> m) {
    int n = b.size();

    int64 B = 0, M = 1;
    for (int i = 0; i < n; i++) {
        int64 p, q, d;
        std::tie(p, q, d) = extGCD(M, m[i]);

        if ((b[i] - B) % d != 0) return std::make_tuple(0, false);

        int64 tmp = mod((b[i] - B) / d * p, m[i] / d);
        B += M * tmp;
        M *= m[i] / d;
        B = mod(B, M);
    }
    return std::make_tuple(B, true);
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    std::vector<int64> X(3), Y(3);
    for (int i = 0; i < 3; i++) {
        std::cin >> X[i] >> Y[i];
    }

    int64 x;
    bool ok;
    std::tie(x, ok) = CRT(X, Y);

    if (!ok) x = -1;
    std::cout << x << std::endl;

    return 0;
}
0