結果

問題 No.187 中華風 (Hard)
ユーザー sirogamichan1sirogamichan1
提出日時 2020-09-26 22:49:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 4,005 ms
コンパイル使用メモリ 228,292 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-13 07:10:03
合計ジャッジ時間 5,142 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:17: 警告: "DEBUG" が再定義されました
   17 | #define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
      | 
main.cpp:16: 備考: ここが以前の宣言がある位置です
   16 | #define DEBUG(x) ;
      | 

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

////////////////////
// Chinese remainder theorem
inline ll mod(ll a, ll m)
{
	a %= m;
	if (a < 0) a += m;
	return a;
}

ll extGcd(ll a, ll b, ll &p, ll &q)
{
	if (b == 0) { p = 1; q = 0; return a;}
	ll d = extGcd(b, a%b, q, p);
	q -= a/b * p;
	return d;
}

pair<ll, ll> ChineseRem(const vector<ll> &b, const vector<ll> &m)
{
	ll r = 0, M = 1;
	for (ll i = 0; i < (int)b.size(); ++i)
	{
		ll p, q;
		ll d = extGcd(M, m[i], p, q);
		if ((b[i] - r) % d != 0) return {0, -1};
		ll tmp = (b[i] - r) / d * p %  (m[i]/d);
		r += M * tmp;
		M *= m[i]/d;
	}
	return {mod(r, M), M};
}

// Chinese remainder theorem
// x = b_0(mod, m_0)
// x = b_1(mod, m_1)
// ...
// x = b_N-1(mod, m_N-1)
// <=>
// x = r(mod, m)
//
// call :   ChineseRem(vector<ll>b, vector<ll>)
// return : pair<ll, ll>(x, m)
// return(no solution) : pair<ll, ll>(0, -1)

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N; N = 3;
	vector<ll> X(N), Y(N);
	REP(i, N) cin >> X[i] >> Y[i];

	auto res = ChineseRem(X, Y);
	if (res == P{0, -1})
	{
		std::cout << -1 << std::endl;
	}
	else
		std::cout << res.first << std::endl;
	
	return 0;
}
0