結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-20 15:18:05 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,655 bytes |
| コンパイル時間 | 1,178 ms |
| コンパイル使用メモリ | 142,596 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 11:51:37 |
| 合計ジャッジ時間 | 1,989 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
//
// 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;
}
}