답안 #343315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343315 2021-01-03T16:20:41 Z apostoldaniel854 원형 문자열 (IZhO13_rowords) C++14
100 / 100
50 ms 32876 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
using ll = long long;
const int MAX_N = 2000;
int mn[1 + MAX_N][1 + 2 * MAX_N], mx[1 + MAX_N][1 + 2 * MAX_N];
int solve (string a, string b) {
    int n = a.size ();
    int bound = b.size ();
    b = b + b;
    int m = b.size ();
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
            mn[i][j] = mx[i][j] = 0;
    for (int j = 0; j <= m; j++)
        mx[0][j] = j;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i - 1] == b[j - 1]) {
                mx[i][j] = mn[i][j - 1];
                mn[i][j] = mx[i - 1][j];
            }
            else {
                mn[i][j] = min (mx[i - 1][j], mn[i][j - 1]);
                mx[i][j] = max (mx[i - 1][j], mn[i][j - 1]);
            }
    int ans = 0;
    for (int i = 1; i <= bound; i++) {
        int cnt = 0;
        for (int j = i; j < i + bound; j++)
            if (mx[n][j] < i)
                cnt++;
        ans = max (ans, cnt);
    }
    return ans;
}
int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    string a, b;
    cin >> a >> b;
    int ans = solve (a, b);
    reverse (b.begin (), b.end ());
    ans = max (ans, solve (a, b));
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 8 ms 9964 KB Output is correct
7 Correct 35 ms 24044 KB Output is correct
8 Correct 33 ms 24044 KB Output is correct
9 Correct 36 ms 24044 KB Output is correct
10 Correct 39 ms 24172 KB Output is correct
11 Correct 40 ms 26476 KB Output is correct
12 Correct 31 ms 30060 KB Output is correct
13 Correct 44 ms 30060 KB Output is correct
14 Correct 40 ms 27500 KB Output is correct
15 Correct 50 ms 31724 KB Output is correct
16 Correct 40 ms 26496 KB Output is correct
17 Correct 31 ms 24940 KB Output is correct
18 Correct 46 ms 32876 KB Output is correct
19 Correct 37 ms 24044 KB Output is correct
20 Correct 41 ms 29420 KB Output is correct
21 Correct 15 ms 18028 KB Output is correct
22 Correct 21 ms 21868 KB Output is correct
23 Correct 28 ms 24684 KB Output is correct
24 Correct 28 ms 26092 KB Output is correct
25 Correct 35 ms 30572 KB Output is correct