結果

問題 No.2254 Reverse Only
ユーザー kotatsugamekotatsugame
提出日時 2023-03-24 22:07:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 93,992 KB
実行使用メモリ 12,092 KB
最終ジャッジ日時 2023-10-18 21:06:23
合計ジャッジ時間 7,107 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 152 ms
4,956 KB
testcase_09 AC 134 ms
12,092 KB
testcase_10 AC 126 ms
4,956 KB
testcase_11 AC 153 ms
4,956 KB
testcase_12 AC 151 ms
4,956 KB
testcase_13 AC 120 ms
4,956 KB
testcase_14 AC 120 ms
4,956 KB
testcase_15 AC 120 ms
4,956 KB
testcase_16 AC 134 ms
12,092 KB
testcase_17 AC 136 ms
12,092 KB
testcase_18 AC 152 ms
4,956 KB
testcase_19 AC 144 ms
4,956 KB
testcase_20 AC 142 ms
12,092 KB
testcase_21 AC 141 ms
12,092 KB
testcase_22 AC 79 ms
12,092 KB
testcase_23 AC 142 ms
12,092 KB
testcase_24 AC 131 ms
12,092 KB
testcase_25 AC 143 ms
12,092 KB
testcase_26 AC 143 ms
12,092 KB
testcase_27 AC 5 ms
4,348 KB
testcase_28 AC 32 ms
4,348 KB
testcase_29 AC 56 ms
4,348 KB
testcase_30 AC 61 ms
4,348 KB
testcase_31 AC 29 ms
4,348 KB
testcase_32 AC 32 ms
4,348 KB
testcase_33 AC 16 ms
4,348 KB
testcase_34 AC 72 ms
4,428 KB
testcase_35 AC 47 ms
4,348 KB
testcase_36 AC 128 ms
4,692 KB
testcase_37 AC 134 ms
4,692 KB
testcase_38 AC 23 ms
4,348 KB
testcase_39 AC 119 ms
4,692 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 42 ms
4,348 KB
testcase_42 AC 24 ms
4,348 KB
testcase_43 AC 76 ms
4,428 KB
testcase_44 AC 112 ms
4,956 KB
testcase_45 AC 87 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
#include<atcoder/string>
using namespace std;
int N,K;
int main()
{
	cin>>N>>K;
	vector<int>A(N),B(N);
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	if(A==B)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(K>N)
	{
		cout<<"No"<<endl;
		return 0;
	}
	if(K==2||K+2<=N)
	{
		sort(A.begin(),A.end());
		sort(B.begin(),B.end());
		if(A==B)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}
	if(K==N)
	{
		reverse(A.begin(),A.end());
		if(A==B)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}
	assert(K+1==N);
	vector<int>L=B,R=B;
	L.pop_back();
	R.pop_back();
	reverse(R.begin(),R.end());
	for(int t=0;t<2;t++)for(int a:A)
	{
		L.push_back(a);
		R.push_back(a);
	}
	L=atcoder::z_algorithm(L);
	R=atcoder::z_algorithm(R);
	for(int i=0;i<N;i++)if(A[i]==B[N-1])
	{
		if(max(L[N+i],R[N+i])>=N-1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}
0