# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
339785 | tengiz05 | 원형 문자열 (IZhO13_rowords) | C++17 | 43 ms | 15468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2005;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int n, m, k;
string a, b;
int ans;
int dp[2005][4005];
void do_it_now(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m*2;j++){
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
//~ else dp[i][j] = max(dp[i-1][j]-dp[i-1][j-m-1], dp[i][j-1]-dp[i][j-m-1]);
if(a[i-1] == b[j-1]){
chmax(dp[i][j], dp[i-1][j-1]+1);
//~ else chmax(dp[i][j], dp[i-1][j-1]+1 - dp[i][j-m]);
}
//~ cout << dp[i][j] << ' ';
}
//~ cout << '\n';
}
//~ cout << '\n';
chmax(ans, dp[n][m]);
for(int j=m+1;j<=m*2;j++){
chmax(ans, dp[n][j]-dp[n][j-m-1]);
}
}
void solve(int test_case){
int i, j;
cin >> a >> b;
if(a.length() > b.length())swap(a,b);
b += b;
n = a.length(), m = b.length()/2;
do_it_now();
reverse(all(b));
do_it_now();
cout << ans << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int _T;
cin >> _T;
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |