結果
| 問題 |
No.1544 [Cherry 2nd Tune C] Synchroscope
|
| コンテスト | |
| ユーザー |
harurun
|
| 提出日時 | 2021-06-11 22:39:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 896 ms / 2,000 ms |
| コード長 | 1,116 bytes |
| コンパイル時間 | 974 ms |
| コンパイル使用メモリ | 81,860 KB |
| 最終ジャッジ日時 | 2025-01-22 06:21:25 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 |
ソースコード
#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 gcd(y,x%y);
return 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){
continue;
}
if(a.first==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;
}
harurun