結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
homesentinel
|
| 提出日時 | 2018-11-24 01:04:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,732 bytes |
| コンパイル時間 | 1,238 ms |
| コンパイル使用メモリ | 118,040 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-24 18:59:55 |
| 合計ジャッジ時間 | 1,967 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 2 |
ソースコード
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (a % b == 0) return b;
return gcd(b, a % b);
}
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 = 1ll;
y = 0ll;
}
return d;
}
ll mod_inverse(ll a, ll m) {
ll x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
pair<ll, ll> chinese_youjo(const vector<ll> &B, const vector<ll> &M) {
ll x = 0ll, m = 1ll;
vector<ll> A(B.size(), 1ll);
for (int i = 0; i < A.size(); ++i) {
ll a = A[i] * m, b = B[i] - A[i] * x, d = gcd(M[i], a);
if (b % d != 0) return make_pair(0, -1); //解がない
ll t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
x = x + m * t;
m *= M[i] / d;
}
return make_pair(x % m, m);
}
class Solve {
public:
void input() {
}
void solve() {
input();
int n = 3;
vector<ll> B, M;
for (int i = 0; i < n; ++i) {
ll b, m;
cin >> b >> m;
B.push_back(b);
M.push_back(m);
}
auto tmp = chinese_youjo(B, M);
if(tmp.second == -1){
cout << -1 << endl;
return;
}
// cout << tmp.first << " " << tmp.second << endl;
// if(tmp.first < 0) tmp.first += tmp.second;
tmp.first = (tmp.first + tmp.second) % tmp.second;
cout << tmp.first << endl;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Solve().solve();
return 0;
}
homesentinel