# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
896887 | classic | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 132 ms | 572 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
namespace classic {
// Knuth-Morris-Pratt
std::vector<int> prefixFunction(std::string str) {
int lengthStr = (int)str.size();
std::vector<int> prefix(lengthStr);
for (int index = 1; index < lengthStr; index++) {
int previousIndex = prefix[index - 1];
while (previousIndex > 0 && str[index] != str[previousIndex]) {
previousIndex = prefix[previousIndex - 1];
}
if (str[index] == str[previousIndex]) {
previousIndex++;
}
prefix[index] = previousIndex;
}
return prefix;
}
} // namespace classic
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::string str1, str2;
std::cin >> str1 >> str2;
int lengthStr1 = str1.size(), lengthStr2 = str2.size();
int maxLength = 0;
std::pair<int, int> positionPrefix;
for (int index1 = 0; index1 < lengthStr1; index1++) {
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |