結果

問題 No.186 中華風 (Easy)
ユーザー uytvccuytvcc
提出日時 2021-03-10 17:16:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 885 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 167,284 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:46:08
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

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

// 
int main(){
  vector<ll> b(3),m(3);
  rep(i,3) cin>>b[i]>>m[i];
  ll r,mod;
  tie(r,mod) = crt(b,m);
  if(P(r,mod)==P(0,0)) cout<<-1<<endl;
  else cout<<r<<endl;
}
0