結果
問題 | No.186 中華風 (Easy) |
ユーザー |
👑 ![]() |
提出日時 | 2020-03-17 04:29:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,541 bytes |
コンパイル時間 | 3,032 ms |
コンパイル使用メモリ | 197,700 KB |
最終ジャッジ日時 | 2025-01-09 07:30:38 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 WA * 2 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); } } iosetup; template <typename T> pair<T, T> ext_gcd(T a, T b) { if (b == 0) return {1, 0}; T fst, snd; tie(fst, snd) = ext_gcd(b, a % b); return {snd, fst - a / b * snd}; } template <typename T> pair<T, T> crt(const vector<T> &b, const vector<T> &m) { T x = 0, md = 1; int n = b.size(); REP(i, n) { T g = __gcd(md, m[i]); if ((b[i] - x) % g != 0) return {0, -1}; x += md * ((b[i] - x) / g * ext_gcd(md, m[i]).first % (m[i] / g)); md *= m[i] / g; } return {x < 0 ? x + md : x, md}; } int main() { const int N = 3; vector<ll> x(N), y(N); REP(i, N) cin >> x[i] >> y[i]; pair<ll, ll> ans = crt(x, y); cout << (ans.second == -1 ? -1 : ans.first) << '\n'; return 0; }