結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
keep_OC
|
| 提出日時 | 2021-03-23 20:30:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,280 bytes |
| コンパイル時間 | 1,809 ms |
| コンパイル使用メモリ | 193,708 KB |
| 最終ジャッジ日時 | 2025-01-19 21:18:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// // using mint = modint998244353;
typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;
template<class T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v) {
is >> e;
}
return is;
}
bool print_space_enable = false;
void print() {
std::cout << '\n';
print_space_enable = false;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
if (print_space_enable) std::cout << " ";
std::cout << fixed << setprecision(15) << head;
print_space_enable = true;
print(std::forward<Tail>(tail)...);
}
template<typename T>
void print(vector<T> v) {
for (size_t i = 0; i < v.size(); i++) {
if (i > 0) std::cout << " ";
std::cout << v[i];
}
std::cout << '\n';
}
template<class T>
vector<T> make_vec(size_t n, T val) {
return vector<T>(n, val);
}
template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
bool is_overflow(Int a, Int b) {
return a > INF / b;
}
Int f(Int a, Int m) {
return (a % m + m) % m;
}
int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int64_t g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
void solve() {
Int b[3], m[3];
for (Int i = 0; i < 3; i++) {
cin >> b[i] >> m[i];
}
Int x = b[0], md = m[0];
for (Int i = 1; i < 3; i++) {
Int p, q;
Int g = extgcd(md, m[i], p, q);
if (x % g != b[i] % g) {
print(-1);
return;
}
Int sp = (b[i] - x) / g * p % (m[i] / g);
x = f(sp * md + x, lcm(md, m[i]));
md = md * (m[i] / g);
//print(x % m[i]);
}
print(x);
// for (Int i = 0; i < 3; i++) {
// print(x % m[i]);
// }
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
//Int _t; cin >> _t; while (_t--) solve();
return 0;
}
keep_OC