結果

問題 No.186 中華風 (Easy)
ユーザー Nzt3Nzt3
提出日時 2023-11-08 18:40:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 205,488 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-08 18:40:24
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

namespace Lib{
  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=y-a/b*x;
    return d;
  }
}
namespace Lib{  
pair<ll,ll> crt(vector<ll> r,vector<ll>m){
  assert(r.size()==m.size());
  ll ret_r=r[0],ret_m=m[0];
  int n=r.size();
  for(int i=1;i<n;i++){
    ll x=0,y=0,d=extGCD(ret_m,m[i],x,y);
    if((ret_r-r[i])%d!=0){
      return make_pair(-1ll,-1ll);
    }
    ret_r+=x*(r[i]-ret_r)/d%(m[i]/d)*ret_m;
    ret_m*=m[i]/d;
    ret_r%=ret_m;
  }
  return make_pair(ret_r,ret_m);
}
} // namespace Lib


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector r(3,0ll),m(3,0ll);
  for(int i=0;i<3;i++){
    cin>>r[i]>>m[i];
  }
  auto [ans,l]=Lib::crt(r,m);
  if(ans==0)ans=l;
  cout<<ans<<'\n';
}
0