結果
問題 | No.1544 [Cherry 2nd Tune C] Synchroscope |
ユーザー |
![]() |
提出日時 | 2021-06-11 22:32:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,062 bytes |
コンパイル時間 | 993 ms |
コンパイル使用メモリ | 81,812 KB |
最終ジャッジ日時 | 2025-01-22 06:15:32 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 11 RE * 5 |
ソースコード
#include <atcoder/math> #include <iostream> #include <stdio.h> #include <vector> #include <utility> //#include <algorithm> using namespace std; using namespace atcoder; #define ull unsigned long long #define ll long long #define Pll pair<long,long> #define INF 1000000000000000000 ull min(ull x,ull y){ if(x>y)return y; return x; } ll gcd(ll x,ll y){ if(x%y)return y; return gcd(y,x%y); } ll lcm(ll x,ll y){ return x/gcd(x,y)*y; } signed main(){ ll N,M,K; ull ans=INF; cin>>N>>M; vector<ull> A(N); vector<ull> B(M); vector<ll>r(2); vector<ll>m={N,M}; K=lcm(N,M); for(ull i=0;i<N;i++)cin>>A.at(i); for(ull i=0;i<M;i++)cin>>B.at(i); for(ull i=0;i<N;i++)for(ull j=0;j<M;j++){ if(A.at(i)==B.at(j)){ if(i==j)ans=min(ans,i+1); else{ r.at(0)=i+1; r.at(1)=j+1; Pll a=crt(r,m); if(a.second==0){ ans=min(ans,K); continue; } ans=min(ans,(ull)a.first%a.second); } } } if(ans==INF)printf("-1\n"); else printf("%lld\n",ans); return 0; }