結果
問題 |
No.2254 Reverse Only
|
ユーザー |
![]() |
提出日時 | 2023-03-24 22:25:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 156 ms / 2,000 ms |
コード長 | 1,909 bytes |
コンパイル時間 | 1,851 ms |
コンパイル使用メモリ | 176,216 KB |
実行使用メモリ | 25,252 KB |
最終ジャッジ日時 | 2024-09-18 17:17:46 |
合計ジャッジ時間 | 7,619 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;}; template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; VI zalgo(VI s){ int n=s.size(); VI z(n); z[0]=n; int i=1, j=0; while(i<n){ while(i+j<n&&s[j]==s[i+j]) j++; z[i]=j; if(j==0){ i++; continue; } int k=1; while(k<j&&k+z[k]<j){ z[i+k]=z[k]; k++; } i+=k; j-=k; } return z; } int main(){ int n, k; cin >> n >> k; VI a(n), b(n); REP(i,n) cin >> a[i]; REP(i,n) cin >> b[i]; if(k<n-1){ sort(ALL(a)); sort(ALL(b)); if(a==b) cout << "Yes" << endl; else cout << "No" << endl; } else if(k==n-1){ VI c, z; c=a; REP(i,n*2) c.push_back(b[i%n]); z=zalgo(c); REP(i,n){ if(z[i+n]>=n){ cout << "Yes" << endl; return 0; } } reverse(ALL(a)); c=a; REP(i,n*2) c.push_back(b[i%n]); z=zalgo(c); REP(i,n){ if(z[i+n]>=n){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; } else{ if(a==b){ cout << "Yes" << endl; return 0; } if(k>n){ cout << "No" << endl; return 0; } reverse(ALL(a)); if(a==b) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }