# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
444822 | prvocislo | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 700 ms | 584 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
void pf_function(const string &s, vector<int> &p)
{
p.resize(s.size());
p[0] = 0;
for (int i = 1; i < s.size(); i++)
{
int j = p[i-1];
while (j && s[i] != s[j]) j = p[j-1];
if (s[i] == s[j]) j++;
p[i] = j;
}
/*cout << "\n" << s << "\n";
for (int i = 0; i < p.size(); i++) cout << p[i] << " ";
cout << endl;*/
}
vector<int> best(const string &s, const string &t, bool rv)
{
int n = s.size(), m = t.size();
vector<int> ans = {0, 0, 0};
for (int i = 0; i < n; i++) // skusime kde rozrezat s
{
//cout << i << endl;
string s1 = s.substr(0, i), s2 = s.substr(i, n-i);
string t1 = t;
reverse(t1.begin(), t1.end()), reverse(s1.begin(), s1.end());
vector<int> v1, v2;
pf_function(s1 + "#" + t1, v1);
pf_function(s2 + "#" + t, v2);
for (int j = 0; j < m; j++)
{
int a = v1[v1.size() - j - 1], b = v2[s2.size() + j];
int si = i - a, ti = j - b;
if (rv) ti = m - (ti+a+b-1) - 1;
ans = max(ans, {a+b, si, ti});
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
vector<int> ans = best(s, t, false);
reverse(t.begin(), t.end());
ans = max(ans, best(s, t, true));
cout << ans[0] << "\n" << ans[1] << " " << ans[2] << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |