Submission #444822

#TimeUsernameProblemLanguageResultExecution timeMemory
444822prvocisloNecklace (Subtask 4) (BOI19_necklace4)C++17
15 / 15
700 ms584 KiB
#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; }

Compilation message (stderr)

necklace.cpp: In function 'void pf_function(const string&, std::vector<int>&)':
necklace.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 1; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...