# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
661012 | GusterGoose27 | Uplifting Excursion (BOI22_vault) | C++11 | 1 ms | 468 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>
using namespace std;
typedef pair<int, int> pii;
const int MAXN = 3000;
const int MAX_s = 4501502;
int n, m;
string s1;
string s2;
class Trie;
Trie *rt;
Trie *to_build[MAX_s];
int s = 0, e = 0;
class Trie {
public:
Trie *trans[26];
int len;
Trie *prv = nullptr;
Trie *par;
char pchar;
int s_pos;
Trie(Trie *par = nullptr, int l = 0, char pchar = 0, int s_pos = 0) : pchar(pchar), par(par), len(l), s_pos(s_pos) {
if (l == 0) rt = this;
fill(trans, trans+26, rt);
}
void build() {
s++;
for (int i = 0; i < 26; i++) {
if (trans[i] != rt) {
to_build[e++] = trans[i];
}
}
if (len == 0) {
return;
}
if (par->prv == nullptr) {
prv = rt;
}
else prv = par->prv->trans[pchar];
for (int i = 0; i < 26; i++) {
if (trans[i] == rt) trans[i] = prv->trans[i];
}
}
Trie* ins(char c, int p) {
if (trans[c] == rt) trans[c] = new Trie(this, len+1, c, p);
return trans[c];
}
};
char cur_match[2*MAXN];
int make_match(pii &p) {
int mn = 0;
int mx = m+1;
while (mn+1 < mx) {
int cur = (mn+mx)/2;
bool found = 0;
for (int i = 0; i <= m-cur; i++) {
Trie *pos = rt;
for (int j = i; j < i+cur; j++) {
pos = pos->trans[s2[j]-'a'];
if (pos->len == cur) {
p.first = pos->s_pos;
p.second = i;
found = 1;
break;
}
}
if (!found) {
for (int j = i; j < i+cur-1; j++) {
pos = pos->trans[s2[j]-'a'];
if (pos->len == cur) {
p.first = pos->s_pos;
p.second = i;
found = 1;
break;
}
}
}
if (found) break;
}
if (found) mn = cur;
else mx = cur;
}
return mn;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> s1 >> s2;
n = s1.size();
m = s2.size();
to_build[e++] = new Trie();
for (int i = 0; i < n; i++) {
Trie *cur = rt;
for (int j = i; j < n; j++) {
cur = cur->ins(s1[j]-'a', i);
}
}
while (s < e) to_build[s]->build();
pii p1, p2;
int b1 = make_match(p1);
for (int i = 0; i < m/2; i++) swap(s2[i], s2[m-1-i]);
int b2 = make_match(p2);
p2.second = m-b2-p2.second;
if (b1 < b2) {
b1 = b2;
p1 = p2;
}
cout << b1 << "\n" << p1.first << " " << p1.second << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |