結果

問題 No.186 中華風 (Easy)
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-12-20 15:18:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 2,920 ms
コンパイル使用メモリ 135,316 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 10:45:08
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//
// Created by zeronosu77108 on Dec 20, 2020.
//
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <complex>
#include <optional>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<(v)<<endl;}

using int64 = long long;

template<class T>
std::tuple<T, T, T> ext_gcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    const auto&& [x, y, d] = ext_gcd(b, a%b);
    return {y, x-a/b*y, d};
}

template<class T>
std::pair<std::optional<T>, std::optional<T>> crt(const std::vector<std::pair<T, T>>& am) {
    T r = 0, n = 1;
    for (const auto& [a, m] : am) {
        const auto&& [x, y, d] = ext_gcd(n, m); // x is inv of n/d (mod. m/d)
        if ((a - r) % d != 0) return {std::nullopt, std::nullopt};

        T tmp = (a - r) / d * x % (m/d);
        r += n * tmp;
        n *= m / d;
    }
    return {(r%n+n)%n, n};
}

int main() {
    vector<pair<long,long>> xy;
    for (int i=0; i<3; i++) {
        long x,y;
        cin >> x >> y;
        xy.emplace_back(x, y);
    }

    auto [ans, n] = crt(xy);
    if (ans) {
        if (ans.value() == 0) {
            cout << n.value() << endl;
        } else {
            cout << ans.value() << endl;
        }
    } else {
        cout << -1 << endl;
    }

}
0