제출 #1243419

#제출 시각아이디문제언어결과실행 시간메모리
1243419chr34Round words (IZhO13_rowords)C++20
44 / 100
2097 ms484 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define dbg(x) cout << #x << " = " << (x) << endl; const int INF = 1e18; const int MAXN = 1e6 + 10; const int MOD = 1e9 + 7; int lcs(const string& a, const string& b) { unordered_map<char, vector<int>> pos; for (int i = 0; i < (int)b.size(); ++i) pos[b[i]].push_back(i); vector<int> seq; for (char c : a) { if (pos.count(c)) { const vector<int>& indices = pos[c]; for (int i = (int)indices.size() - 1; i >= 0; --i) { int idx = indices[i]; auto it = lower_bound(seq.begin(), seq.end(), idx); if (it == seq.end()) seq.push_back(idx); else *it = idx; } } } return (int)seq.size(); } int32_t main(){ ios::sync_with_stdio(false); cin.tie(nullptr); //freopen("input.in", "r", stdin); //freopen("input.out", "w", stdout); string s1, s2; cin >> s1 >> s2; int maxLCS = 0; string s1r = s1; reverse(s1r.begin(), s1r.end()); string s2r = s2; reverse(s2r.begin(), s2r.end()); string s2_doubled = s2 + s2; string s2r_doubled = s2r + s2r; int len = s2.size(); for (int i = 0; i < len; ++i) { string rot_s2 = s2_doubled.substr(i, len); string rot_s2r = s2r_doubled.substr(i, len); maxLCS = max(maxLCS, lcs(s1, rot_s2)); maxLCS = max(maxLCS, lcs(s1r, rot_s2)); maxLCS = max(maxLCS, lcs(s1, rot_s2r)); maxLCS = max(maxLCS, lcs(s1r, rot_s2r)); } cout << maxLCS << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...