結果
問題 |
No.2254 Reverse Only
|
ユーザー |
|
提出日時 | 2023-03-25 01:42:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 2,159 bytes |
コンパイル時間 | 3,056 ms |
コンパイル使用メモリ | 223,160 KB |
最終ジャッジ日時 | 2025-02-11 17:56:27 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } vector<int> Zalgo(vector<int> s){ int n=s.size(); vector<int> a(n,0); int from=-1,last=-1; for(int i=1;i<n;i++){ int &same=a[i]; if(from!=-1){ same=min(a[i-from],last-i); same=max(0,same); } while(i+same<n&&s[same]==s[i+same]){ same++; } if(last<i+same){ last=i+same; from=i; } } a[0]=n; return a; } bool slv(vector<int> a,vector<int> b,int n,int k) { if (a == b) { return true; } { auto v = a; auto vv = b; sort(v.begin(), v.end()); sort(vv.begin(), vv.end()); if (v != vv) return false; } if (k > n) { return false; } else if (k == n) { reverse(a.begin(), a.end()); return (a == b); } else if (k < n-1) { return true; } else { // k = n-1 vector<int> v; for (int i = 0; i < n; ++i) { v.push_back(b[i]); } v.push_back(-1); for (int i = 0; i < n; ++i) { v.push_back(a[i]); } for (int i = 0; i < n; ++i) { v.push_back(a[i]); } v.push_back(-1); for (int i = 0; i < n; ++i) { v.push_back(a[n-1-i]); } for (int i = 0; i < n; ++i) { v.push_back(a[n-1-i]); } auto Z = Zalgo(v); for (int i = n; i < v.size(); ++i) { if (Z[i] >= n) return true; } return false; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n,k; 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 (slv(a,b,n,k)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }