Submission #933639

# Submission time Handle Problem Language Result Execution time Memory
933639 2024-02-26T03:37:42 Z mgch Round words (IZhO13_rowords) C++14
16 / 100
2000 ms 14752 KB
#include <bits/stdc++.h>

using namespace std;

/** so there is complicated algo based on some research let's get it later
 * 
 * 
 *  you have to get that |lcs(a, b) - lcs(a, b[1..n-1] + b[0])| <= 2
 *  so if you have ans >= lcs(a, b) + 2 then ... push it
 * */

const int N = 2024;

int dp[N][N], n, m;

int lcs(const string &a, const string &b) {
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            if (a[i] == b[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            }
        }
    }
    return dp[n][m];
}


int main() {
//  freopen("rowords.in", "r", stdin); freopen("rowords.out", "w", stdout);
    string a, b;
    getline(cin, a);
    getline(cin, b);
    n = a.length();
    m = b.length();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ans = max(ans, lcs(a.substr(i) + a.substr(0, i), b.substr(j) + b.substr(0, j)));
        }
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 18 ms 604 KB Output is correct
5 Correct 8 ms 604 KB Output is correct
6 Execution timed out 2091 ms 4848 KB Time limit exceeded
7 Execution timed out 2039 ms 8832 KB Time limit exceeded
8 Execution timed out 2067 ms 9044 KB Time limit exceeded
9 Execution timed out 2055 ms 8840 KB Time limit exceeded
10 Execution timed out 2016 ms 9064 KB Time limit exceeded
11 Execution timed out 2020 ms 11096 KB Time limit exceeded
12 Execution timed out 2061 ms 11092 KB Time limit exceeded
13 Execution timed out 2077 ms 11120 KB Time limit exceeded
14 Execution timed out 2069 ms 11112 KB Time limit exceeded
15 Execution timed out 2100 ms 10868 KB Time limit exceeded
16 Execution timed out 2098 ms 10880 KB Time limit exceeded
17 Execution timed out 2045 ms 13120 KB Time limit exceeded
18 Execution timed out 2025 ms 13136 KB Time limit exceeded
19 Execution timed out 2035 ms 9308 KB Time limit exceeded
20 Execution timed out 2056 ms 13164 KB Time limit exceeded
21 Execution timed out 2064 ms 8028 KB Time limit exceeded
22 Execution timed out 2024 ms 10844 KB Time limit exceeded
23 Execution timed out 2065 ms 12040 KB Time limit exceeded
24 Execution timed out 2057 ms 12592 KB Time limit exceeded
25 Execution timed out 2049 ms 14752 KB Time limit exceeded