結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー harurun
提出日時 2021-06-11 22:15:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 79,804 KB
最終ジャッジ日時 2025-01-22 06:04:13
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/math>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
using namespace atcoder;
#define ll long long
#define Pll pair<ll,ll>
#define INF 1000000000000000000

signed main(){
  ll N,M,K,ans=INF;
  cin>>N>>M;
  vector<ll> A(N);
  vector<ll> B(M);
  vector<ll>r(2);
  vector<ll>m={N,M};
  for(ll i=0;i<N;i++)cin>>A.at(i);
  for(ll i=0;i<M;i++)cin>>B.at(i);
  for(ll i=0;i<N;i++)for(ll j=0;j<M;j++){
    if(A.at(i)==B.at(j)){    
      r.at(0)=i+1;
      r.at(1)=j+1;
      Pll a=crt(r,m);
      if(a.second==0){
        continue;
      }
      ans=min(ans,a.first%a.second);
    }
  }
  if(ans==INF)printf("-1\n");
  else printf("%lld\n",ans);
  return 0;
}
0