結果

問題 No.186 中華風 (Easy)
ユーザー hokutohokuto
提出日時 2021-08-30 16:05:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,118 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 96,140 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 14:37:25
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
using namespace std;
using ll = long long int;
#define chmax(x,y)  x = (x > (y)) ? x : (x = (y));
#define chmin(x,y)  x = (x < (y)) ? x : (x = (y));

ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

ll extgcd(ll a, ll b,ll &x, ll &y)
{
  if(b == 0)
  {
    x = 1;
    y = 0;
    return a;
  }
  ll d = extgcd(b,a%b,y,x);
  y -= a/b * x;
  return d;
}

pair<ll,ll> crt(vector<ll> &b, vector<ll> &m)
{
  ll r = 0, M = 1;
  for(int i=0;i<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};
}

int main(int argc, char const *argv[])
{
  vector<ll> B,M;
  for(int i=0;i<3;++i)
  {
    ll a,b; cin >> a >> b;
    B.emplace_back(a);
    M.emplace_back(b);
  }
  auto answer = crt(B,M);
  if(answer.first == 0)answer.first = -1;
  std::cout << answer.first << std::endl;
}
0