| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 386882 | two_sides | Round words (IZhO13_rowords) | C++17 | 70 ms | 64236 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;
#define fi first
#define se second
template <class X, class Y>
bool cmax(X &a, const Y &b) {
    return a < b ? a = b, 1 : 0;
}
const int N = 2005;
int dp[N][N], dir[N][N], m, n;
/// 0: up, 1: up-left, 2:left
void init_lcs(string s, string t) {
    memset(dp, 0, sizeof dp);
    memset(dir, 0, sizeof dp);
    m = s.size(), n = t.size(); t += t;
    dir[0][1] = 2;
    for (int i = 1; i <= m; i++)
        for (int j = 1; j <= 2 * n; j++) {
            dp[i][j] = dp[i - 1][j];
            if (s[i - 1] == t[j - 1] && cmax
            (dp[i][j], dp[i - 1][j - 1] + 1))
                dir[i][j] = 1;
            if (cmax(dp[i][j], dp[i][j - 1]))
                dir[i][j] = 2;
        }
}
int get_lcs(int i, int j) {
    int lcs = 0;
    while (i) {
        if (dir[i][j] == 2) j--;
        else if (dir[i][j] == 1) {
            i--; j--; lcs++;
        }
        else i--;
    }
    return lcs;
}
void remove_col(int j) {
    int i = 0;
    while (j < 2 * n) {
        if (dir[i][j + 1] == 2)
            dir[i][++j] = 0;
        else {
            if (i == m) break;
            if (dir[++i][j + 1] == 1)
                dir[i][++j] = 0;
        }
    }
}
int circular_lcs(string s, string t) {
    init_lcs(s, t); int lcs = 0;
    for (int j = 0; j < n; j++) {
        cmax(lcs, get_lcs(m, j + n));
        remove_col(j);
    }
    return lcs;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    string s, t; cin >> s >> t;
    cout << circular_lcs(s, t) << '\n';
}
	
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
