제출 #1356916

#제출 시각아이디문제언어결과실행 시간메모리
1356916okok312원형 문자열 (IZhO13_rowords)C++20
44 / 100
2096 ms23356 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, rt;
deque<char> s;
int n, m;
int f[N][N], g[N][N], ans;

void solve(){
    cin >> t;

    n = sz(t);
    REP(i, sz(t)) s.pb(t[i]);

    cin >> t;
    m = sz(t);

    reverse(all(rt));
    rt = t;
    rt = " " + t;

    t = " " + t;

    s.push_front(' ');

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

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

        s.pop_front();
        s.push_front(s.back());
        s.push_front(' ');
        s.pop_back();
    }

    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...