結果

問題 No.1544 [Cherry 2nd Tune C] Synchroscope
ユーザー kotatsugamekotatsugame
提出日時 2021-06-11 21:32:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 67,528 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 11:40:41
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 13 ms
4,380 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 9 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 7 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 15 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 23 ms
4,380 KB
testcase_26 AC 23 ms
4,380 KB
testcase_27 AC 23 ms
4,380 KB
testcase_28 AC 23 ms
4,376 KB
testcase_29 AC 23 ms
4,376 KB
testcase_30 AC 23 ms
4,380 KB
testcase_31 AC 23 ms
4,380 KB
testcase_32 AC 23 ms
4,376 KB
testcase_33 AC 286 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 23 ms
4,376 KB
testcase_39 AC 22 ms
4,376 KB
testcase_40 AC 23 ms
4,376 KB
testcase_41 AC 23 ms
4,376 KB
testcase_42 AC 23 ms
4,380 KB
testcase_43 AC 21 ms
4,376 KB
testcase_44 AC 22 ms
4,376 KB
testcase_45 AC 23 ms
4,380 KB
testcase_46 AC 22 ms
4,376 KB
testcase_47 AC 22 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<algorithm>
using namespace std;
#line 1 "/home/kotatsugame/library/math/extgcd.cpp"
template<typename T>
T extgcd(T a,T b,T&x,T&y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	T q=a/b;
	T g=extgcd(b,a-q*b,y,x);
	y-=q*x;
	return g;
}
#line 5 "a.cpp"
int N,M;
int A[5000],B[5000];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<M;i++)cin>>B[i];
	long ans=9e18;
	for(int i=0;i<N;i++)for(int j=0;j<M;j++)if(A[i]==B[j])
	{
		long x,y;
		long g=extgcd<long>(N,M,x,y);
		if((j-i)%g!=0)continue;
		int n=N/g,m=M/g;
		int t=(j-i)/g;
		x*=t,y*=t;
		y=-y;
		{
			int l=min(x/m,-y/n);
			if(l>=0)x-=m*l,y+=n*l;
		}
		{
			int r=min(-x/m,y/n);
			if(r>=0)x+=m*r,y-=n*r;
		}
		while(x>=m)x-=m,y+=n;
		while(x<0)x+=m,y-=n;
		ans=min(ans,x*N+i);
	}
	if(ans==(long)9e18)ans=-2;
	cout<<ans+1<<endl;
}
0