結果
問題 | No.186 中華風 (Easy) |
ユーザー | Linaria2002 |
提出日時 | 2022-07-04 18:49:54 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,890 bytes |
コンパイル時間 | 2,243 ms |
コンパイル使用メモリ | 204,236 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-08 08:14:55 |
合計ジャッジ時間 | 3,127 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
ソースコード
#include<bits/stdc++.h> #define int ll #define rep(i, N) for(int i = 0; i < (int)(N); ++i) #define rep1(i, N) for(int i = 1; i <= (int)(N); ++i) #define per(i, N) for(int i = (N)-1; i >= 0; --i) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define bit(n, k) ((n) >> (k)) #define pcnt(n) (__builtin_popcount(n)) #define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n" #define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n" #define endl '\n' #define fi first #define se second #define mkpr make_pair #define mktpl make_tuple #define eb emplace_back using namespace std; using ll = int64_t; using ull = uint64_t; using ld = long double; using point = struct{ ll x, y; }; using pointld = struct{ ld x, y; }; template<class T> using max_heap = priority_queue<T>; template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<class T> using vec = vector<T>; template<class T> using vvec = vec<vec<T>>; template<class T> using vvvec = vec<vvec<T>>; template<class T> using vvvvec = vvec<vvec<T>>; constexpr ld EPS = 1e-10; constexpr int INF = 1001001001; constexpr ll LINF = 1001001001001001001ll; constexpr ll MOD = (1) ? 998244353 : 1e9+7; constexpr int NIL = -1; constexpr int pm[2] = {1, -1}; constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ll cel(ll a, ll b){ return (a + b - 1) / b;} ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : abs(a);} template<class T> T powi(T x, ll exp){ return exp > 0 ? (exp & 1 ? x : 1) * powi(x * x, exp >> 1) : x / x; } ll modpow(ll x, ll exp, ll mod){ x %= mod; return exp > 0 ? (exp & 1 ? x : 1) * modpow(x * x, exp >> 1, mod) % mod : 1; } template<class T> bool chmin(T &a, T b){ return a > b ? (a = b, true) : 0;} template<class T> bool chmax(T &a, T b){ return a < b ? (a = b, true) : 0;} using Pair = pair<ll, ll>; using Tpl = tuple<char, int, int>; ll ExtGcd(ll a, ll b, ll &x, ll &y){ ll d = a; if(b != 0){ d = ExtGcd(b, a % b, y, x); y -= (a / b) * x; } else{ x = 1, y = 0; } return d; } pair<ll, ll> ChineseRem(vec<ll> &b, vec<ll> &m) { ll r = 0, M = 1; for (int i = 0; i < (int)b.size(); ++i) { ll p, q; ll d = ExtGcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return make_pair(0, -1); ll tmp = (b[i] - r) / d * p % (m[i]/d); r += M * tmp; M *= m[i]/d; } return mkpr((r % M + M) % M, M); } void Main(){ vec<ll> B(3), M(3); rep(i, 3) cin >> B[i] >> M[i]; auto ans = ChineseRem(B, M); if(ans.se == -1) cout << -1 << endl; else if(ans.fi != 0) cout << ans.fi << endl; else cout << ans.se << endl; } signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); Main(); return 0; }