답안 #395927

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395927 2021-04-29T08:15:50 Z ArshiaDadras 원형 문자열 (IZhO13_rowords) C++14
20 / 100
30 ms 32736 KB
/* In the name of Allah */
// Those were the days, my friend...
#include<bits/stdc++.h>
using namespace std;

string s, t;
const int N = 2e3 + 5;
int n, m, dp[N][2 * N], par[N][2 * N];

int calc(int i, int j, int st) {
	int lcs = 0;
	while (i && j > st)
		if (par[i][j])
			par[i][j] & 1? j--: i--;
		else {
			i--, j--;
			lcs++;
		}
	return lcs;
}

void read_input() {
	cin >> s >> t;
	n = s.size();
	m = t.size();
}

void solve() {
	t += t;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= 2 * m; j++)
			if (s[i - 1] == t[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else {
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
				par[i][j] = dp[i][j] > dp[i][j - 1]? 2: 1;
			}
}

void write_output() {
	int answer = 0;
	for (int i = 0; i < m; i++)
		answer = max(answer, calc(n, m + i, i));
	cout << answer;
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve(), write_output();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Correct 1 ms 716 KB Output is correct
5 Incorrect 1 ms 588 KB Output isn't correct
6 Correct 6 ms 9932 KB Output is correct
7 Correct 20 ms 24012 KB Output is correct
8 Incorrect 17 ms 24012 KB Output isn't correct
9 Incorrect 21 ms 24012 KB Output isn't correct
10 Incorrect 21 ms 24012 KB Output isn't correct
11 Incorrect 25 ms 26340 KB Output isn't correct
12 Correct 13 ms 15180 KB Output is correct
13 Incorrect 26 ms 30040 KB Output isn't correct
14 Incorrect 25 ms 27340 KB Output isn't correct
15 Incorrect 30 ms 31684 KB Output isn't correct
16 Incorrect 20 ms 26236 KB Output isn't correct
17 Incorrect 21 ms 24932 KB Output isn't correct
18 Incorrect 29 ms 32736 KB Output isn't correct
19 Incorrect 28 ms 24000 KB Output isn't correct
20 Incorrect 25 ms 29256 KB Output isn't correct
21 Incorrect 12 ms 17996 KB Output isn't correct
22 Incorrect 16 ms 21836 KB Output isn't correct
23 Incorrect 21 ms 24664 KB Output isn't correct
24 Incorrect 21 ms 25952 KB Output isn't correct
25 Incorrect 30 ms 30408 KB Output isn't correct