제출 #1356902

#제출 시각아이디문제언어결과실행 시간메모리
1356902okok312Round words (IZhO13_rowords)C++20
60 / 100
2095 ms11844 KiB
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define vt vector
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define sz(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define el '\n'

const ll N = 2000 + 7;
const ll MOD = 1e9 + 7;

string t, s, S;
int n, m;
int f[N][N], ans;

void solve(){
    cin >> S;
    n = sz(S);
    cin >> t;
    m = sz(t);
    t = " " + t;
    s = " " + S;

    REP(nvl, n){
        FOR(i, 1, n) FOR(j, 1, m){
            f[i][j] = max(f[i - 1][j], f[i][j - 1]);
            if(s[i] == t[j]) f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
        }

        ans = max(ans, f[n][m]);

        int j = 0;
        FOR(i, nvl + 1, n - 1) s[++j] = S[i];
        FOR(i, 0, nvl) s[++j] = S[i];
//        cerr << s << el;
    }

    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
        freopen("test.err","w",stderr);
    #endif
    int ts=1;
//    cin>>ts;
    while(ts--){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...