Submission #557663

# Submission time Handle Problem Language Result Execution time Memory
557663 2022-05-05T18:00:54 Z Soumya1 Necklace (Subtask 1-3) (BOI19_necklace1) C++17
85 / 85
671 ms 70852 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
vector<int> prefix_function(string &s) {
  int n = s.size();
  vector<int> pi(n);
  for (int i = 1; i < n; i++) {
    int j = pi[i - 1];
    while (j > 0 && s[j] != s[i]) j = pi[j - 1];
    if (s[j] == s[i]) j++;
    pi[i] = j;
  }
  return pi;
}
tuple<int, int, int> solve(string s, string t, bool f = false) {
  int n = s.size(), m = t.size();
  int a[n][m], b[n][m];
  memset(a, 0, sizeof a);
  memset(b, 0, sizeof b);
  auto _s = s;
  for (int i = 0; i < n; i++) {
    string ss = s + '#' + t;
    auto pi = prefix_function(ss);
    for (int j = 0; j < m; j++) {
      a[i][j] = pi[j + n - i + 1];
    }
    s.erase(s.begin());
  }
  s = _s;
  for (int j = 0; j < m; j++) {
    string ss = t + '#' + s;
    auto pi = prefix_function(ss);
    for (int i = 0; i < n; i++) {
      b[i][j] = pi[i + m - j + 1];
    }
    t.erase(t.begin());
  }
  tuple<int, int, int> ret = {0, 0, 0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ret = max(ret, {a[i][j], i, j - a[i][j] + 1});
      ret = max(ret, {b[i][j], i - b[i][j] + 1, j});
      if (i - 1 >= 0 && j + 1 < m) {
        ret = max(ret, {a[i][j] + b[i - 1][j + 1], i - 1 - b[i - 1][j + 1] + 1, j - a[i][j] + 1});
      }
    }
  }
  if (f) {
    auto &[l, i, j] = ret;
    i = n - i - l;
  }
  return ret;
}
void testCase() {
  string s, t;
  cin >> s >> t;
  auto a = solve(s, t);
  reverse(s.begin(), s.end());
  auto b = solve(s, t, true);
  a = max(a, b);
  auto [l, i, j] = a;
  cout << l << "\n";
  cout << i << " " << j << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 10 ms 1600 KB Output is correct
7 Correct 11 ms 1492 KB Output is correct
8 Correct 9 ms 1364 KB Output is correct
9 Correct 8 ms 1492 KB Output is correct
10 Correct 8 ms 1492 KB Output is correct
11 Correct 8 ms 1580 KB Output is correct
12 Correct 9 ms 1480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 10 ms 1600 KB Output is correct
7 Correct 11 ms 1492 KB Output is correct
8 Correct 9 ms 1364 KB Output is correct
9 Correct 8 ms 1492 KB Output is correct
10 Correct 8 ms 1492 KB Output is correct
11 Correct 8 ms 1580 KB Output is correct
12 Correct 9 ms 1480 KB Output is correct
13 Correct 586 ms 70852 KB Output is correct
14 Correct 587 ms 70840 KB Output is correct
15 Correct 670 ms 66624 KB Output is correct
16 Correct 611 ms 69816 KB Output is correct
17 Correct 540 ms 68332 KB Output is correct
18 Correct 564 ms 70328 KB Output is correct
19 Correct 627 ms 70192 KB Output is correct
20 Correct 671 ms 68244 KB Output is correct
21 Correct 642 ms 69064 KB Output is correct