Submission #556649

# Submission time Handle Problem Language Result Execution time Memory
556649 2022-05-03T13:09:00 Z stefantaga Necklace (Subtask 1-3) (BOI19_necklace1) C++14
85 / 85
348 ms 492 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int p1[6002], p2[6002];

void fill_p(string s, int *p) {
	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;
	}
}

tuple<int, int, int> solve(string s, string t, bool rev) {
	int n = s.size(), m = t.size();
	tuple<int, int, int> ans = {0, 0, 0};
	for (int i = 0; i < n; i++) {
		string s1 = s.substr(0, i), s2 = s.substr(i, n - i);
		reverse(s1.begin(), s1.end());
		string t1 = t, t2 = t;
		reverse(t2.begin(), t2.end());
		fill_p(s1 + "#" + t1, p1), fill_p(s2 + "#" + t2, p2);
		for (int j = 1; j <= m; j++)
			ans = max(ans, {
				p1[i + j] + p2[n + m - i - j],
				i - p1[i + j],
				rev ? m - j - p2[n + m - i - j] : j - p1[i + j]
			});
	}
	return ans;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	tuple<int, int, int> ans = solve(s, t, false);
	reverse(t.begin(), t.end());
	ans = max(ans, solve(s, t, true));
	cout << get<0>(ans) << '\n' << get<1>(ans) << ' ' << get<2>(ans);
	return 0;
}

Compilation message

necklace.cpp: In function 'void fill_p(std::string, int*)':
necklace.cpp:8:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for (int i = 1; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 6 ms 328 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 4 ms 328 KB Output is correct
12 Correct 7 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 6 ms 340 KB Output is correct
9 Correct 6 ms 328 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 4 ms 328 KB Output is correct
12 Correct 7 ms 340 KB Output is correct
13 Correct 292 ms 448 KB Output is correct
14 Correct 267 ms 468 KB Output is correct
15 Correct 348 ms 468 KB Output is correct
16 Correct 304 ms 492 KB Output is correct
17 Correct 183 ms 472 KB Output is correct
18 Correct 174 ms 416 KB Output is correct
19 Correct 256 ms 468 KB Output is correct
20 Correct 266 ms 464 KB Output is correct
21 Correct 254 ms 448 KB Output is correct