結果
問題 | No.186 中華風 (Easy) |
ユーザー | ミドリムシ |
提出日時 | 2022-04-05 18:31:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,905 bytes |
コンパイル時間 | 4,309 ms |
コンパイル使用メモリ | 172,500 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-05-05 04:33:58 |
合計ジャッジ時間 | 2,547 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | WA | - |
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 | 1 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function 'std::tuple<long long int, long long int, long long int> extgcd(lint, lint)': main.cpp:38:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 38 | auto [x, y, g] = extgcd(b, a % b); | ^ main.cpp: In function 'std::tuple<long long int, long long int, bool> IndeterminateEquation(lint, lint, lint)': main.cpp:43:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 43 | auto [x, y, g] = extgcd(a, b); | ^ main.cpp: In function 'std::pair<long long int, bool> CRT(lint, lint, lint, lint)': main.cpp:54:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 54 | auto [b, c, is_ok] = IndeterminateEquation(m1, -m2, a2 - a1); | ^ main.cpp: In function 'int main()': main.cpp:68:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 68 | auto [x12, is_ok] = CRT(y1, x1, y2, x2); | ^ main.cpp:76:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 76 | auto [x123, is_ok2] = CRT(y12, x12, y3, x3); | ^
ソースコード
//#include <atcoder/all> #include <bits/stdc++.h> using namespace std; using lint = long long; constexpr lint mod = 1e9 + 7; #define all(x) begin(x), end(x) #define bitcount(n) __builtin_popcountll((lint)(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzll(x)) #define rep(i, n) for(int i = 0; i < int(n); i++) #define rep2(i, l, r) for(int i = int(l); i < int(r); i++) #define repr(i, n) for(int i = int(n) - 1; i >= 0; i--) #define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--) #define accumulate you cannot use this word! constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18; inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; } template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } } template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; } template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; } template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; } inline int has(lint i, int j){ return (i >> j) & 1; } int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1}; bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); } struct io_init { io_init() { cin.tie(nullptr); cout.tie(nullptr); std::ios::sync_with_stdio(false); } } io_init; tuple<lint, lint, lint> extgcd(lint a, lint b){ if(b == 0){ return {1, 0, a}; } auto [x, y, g] = extgcd(b, a % b); return {y, x - (a / b) * y, g}; } tuple<lint, lint, bool> IndeterminateEquation(lint a, lint b, lint c){ auto [x, y, g] = extgcd(a, b); if(c % g != 0) return {0, 0, false}; x *= c / g; y *= c / g; assert(a * x + b * y == c); return {x, y, true}; } pair<lint, bool> CRT(lint m1, lint a1, lint m2, lint a2){ auto [b, c, is_ok] = IndeterminateEquation(m1, -m2, a2 - a1); if(!is_ok) return {0, false}; lint x = b * m1 + a1; lint L = lcm(m1, m2); if(x < 0) x += (-x + L - 1) / L * L; if(x >= L) x %= L; assert(0 <= x && x < L); return {x, true}; } int main(){ lint x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; auto [x12, is_ok] = CRT(y1, x1, y2, x2); if(!is_ok){ cout << -1 << endl; return 0; } lint y12 = lcm(y1, y2); auto [x123, is_ok2] = CRT(y12, x12, y3, x3); if(!is_ok2){ cout << -1 << endl; return 0; } lint y123 = lcm(y12, y3); if(x123 == 0) x123 += y123; assert(1 <= x123 && x123 <= y123); cout << x123 << endl; }