# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1010989 | bornag | 원형 문자열 (IZhO13_rowords) | C++14 | 61 ms | 126132 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4007;
int dp[maxn][maxn], ty[maxn][maxn];
int n, m;
void dplcs(string s, string t){
memset(dp, 0, sizeof dp);
memset(ty, 0, sizeof ty);
t += t;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= 2*m; j++){
dp[i][j] = dp[i-1][j];
if(s[i-1] == t[j-1] and dp[i-1][j-1]+1 > dp[i][j]) dp[i][j] = dp[i-1][j-1]+1, ty[i][j] = 1;
if(dp[i][j-1] > dp[i][j]) dp[i][j] = dp[i][j-1], ty[i][j] = 2;
}
}
}
int lcs(int a, int b){
int ret = 0;
while(a){
if(ty[a][b] == 1){
ret++;
a--;
b--;
} else if(ty[a][b] == 2) b--;
else a--;
}
return ret;
}
void res(int b){
int a = 0;
while(b < 2 * m){
if(ty[a][b+1] == 2){
ty[a][b+1] = 0;
b++;
} else {
if(a == n) break;
a++;
if(ty[a][b+1] == 1){
ty[a][b+1] = 0;
b++;
}
}
}
}
int solve(string s, string t){
dplcs(s, t);
int ret = 0;
for(int j = 0; j < m; j++){
ret = max(ret, lcs(n, m+j));
//res(j);
}
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
string s, t; cin >> s >> t;
n = s.size(); m = t.size();
int sol = solve(s, t);
reverse(t.begin(), t.end());
sol = max(sol, solve(s, t));
cout << sol << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |