# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
744627 | rainboy | 원형 문자열 (IZhO13_rowords) | C11 | 127 ms | 46456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* https://codeforces.com/blog/entry/21372 */
/* https://arxiv.org/pdf/1208.0396.pdf */
/* https://oj.uz/submission/314177 (Benq) */
#include <stdio.h>
#include <string.h>
#define N 2000
#define M 2000
int max(int a, int b) { return a > b ? a : b; }
int solve(char *aa, int n, char *bb, int m) {
static int dp[N * 2 + 1][M + 1], dir[N * 2 + 1][M + 1];
int l, i, j, x, ans;
for (i = 0; i <= n * 2; i++)
for (j = 0; j <= m; j++)
if (i == 0 && j == 0)
dp[i][j] = 0, dir[i][j] = -1;
else {
dp[i][j] = dir[i][j] = -1;
if (j > 0 && dp[i][j] < (x = dp[i][j - 1]))
dp[i][j] = x, dir[i][j] = 0;
if (i > 0 && j > 0 && aa[(i - 1) % n] == bb[j - 1] && dp[i][j] < (x = dp[i - 1][j - 1] + 1))
dp[i][j] = x, dir[i][j] = 1;
if (i > 0 && dp[i][j] < (x = dp[i - 1][j]))
dp[i][j] = x, dir[i][j] = 2;
}
ans = 0;
for (l = 0; l < n; l++) {
i = n + l, j = m, x = 0;
while (dir[i][j] != -1)
if (dir[i][j] == 0)
j--;
else if (dir[i][j] == 1)
i--, j--, x++;
else
i--;
ans = max(ans, x);
i = l + 1, j = 0;
dir[i][j] = -1;
while (j < m)
if (dir[i][j + 1] == 0)
j++;
else {
dir[i][j + 1] = 0;
if (i++ == n * 2)
break;
if (dir[i][j + 1] == 1)
j++;
}
}
return ans;
}
int main() {
static char aa[N + 1], bb[M + 1];
int n, m, i, j, ans, tmp;
scanf("%s%s", aa, bb), n = strlen(aa), m = strlen(bb);
ans = solve(aa, n, bb, m);
for (i = 0, j = n - 1; i < j; i++, j--)
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
ans = max(ans, solve(aa, n, bb, m));
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |