답안 #508807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508807 2022-01-13T19:54:51 Z dutch 원형 문자열 (IZhO13_rowords) C++17
0 / 100
2000 ms 110152 KB
#include <bits/stdc++.h>
using namespace std;
 
const int Z = 2000, INF = 1e8;
 
string S, T;
int N, M, ans, d[Z*2][Z], p[Z*2][Z];
array<int, 2> _q[4*Z*Z], *qL, *qR;
 
void dfs(int loR, int hiR, int *lo, int *hi) {
	if(loR > hiR) return;
 
	for(int j = 0; j < M; j++)
		for(int i = lo[j]; i <= hi[j]; i++) 
			d[i][j] = INF;
 
	int rt = (loR + hiR) / 2;

 	qR = qL = _q + 2*Z*Z;
	(*qR++) = {rt, d[rt][0] = 0};
 
	while(qL != qR) {
		auto [i, j] = (*qL++);
		for(int di : {0, 1}) for(int dj : {0, 1}) {
			int x = i + di, y = j + dj, w = di ^ dj;
			if(y == M || x > hi[y] || d[x][y] <= d[i][j] + w) continue;
			if(di && dj && S[i] != T[j]) continue;
 
			d[x][y] = d[i][j] + w;
			p[x][y] = di + 2 * dj;
 
			(w ? *qR++ : *--qL) = {x, y};
		}
	}
 
	int mMin[M], mMax[M] = {};
	fill(mMin, mMin+M, N+N);
 
	int i = rt+N-1, j = M-1;
 
	assert(lo[M-1] <= i && i <= hi[M-1]);
	ans = max(ans, N-1 + M-1 - d[i][j] + 2 * (S[i%N] == T[j]));
 
	while(1) {
		mMin[j] = min(mMin[j], i);
		mMax[j] = max(mMax[j], i);
		if(i == rt && !j) break;
		int k = p[i][j];
		if(k & 1) --i;
		if(k & 2) --j;
	}
 
	dfs(loR, rt - 1, lo, mMax);
	dfs(rt + 1, hiR, mMin, hi);
}
 
int main() {
	cin >> S >> T;
	S = string(Z, 'a');
	T = string(Z, 'a');
	N = size(S);
	M = size(T);
	S += S;
 
	for(int _ : {0, 1}) {
		if(_) reverse(begin(S), end(S));
		int lo[M] = {}, hi[M];
		fill(hi, hi + M, 2 * N - 1);
 
		dfs(0, N-1, lo, hi);
	}
	cout << ans / 2;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2092 ms 109980 KB Time limit exceeded
2 Execution timed out 2082 ms 110048 KB Time limit exceeded
3 Execution timed out 2084 ms 110092 KB Time limit exceeded
4 Execution timed out 2079 ms 109984 KB Time limit exceeded
5 Execution timed out 2083 ms 110024 KB Time limit exceeded
6 Execution timed out 2068 ms 110140 KB Time limit exceeded
7 Execution timed out 2090 ms 110036 KB Time limit exceeded
8 Execution timed out 2065 ms 109992 KB Time limit exceeded
9 Execution timed out 2068 ms 110080 KB Time limit exceeded
10 Execution timed out 2057 ms 110076 KB Time limit exceeded
11 Execution timed out 2089 ms 110024 KB Time limit exceeded
12 Execution timed out 2091 ms 110076 KB Time limit exceeded
13 Execution timed out 2104 ms 109992 KB Time limit exceeded
14 Execution timed out 2091 ms 110020 KB Time limit exceeded
15 Execution timed out 2092 ms 110012 KB Time limit exceeded
16 Execution timed out 2085 ms 110128 KB Time limit exceeded
17 Execution timed out 2079 ms 110152 KB Time limit exceeded
18 Execution timed out 2082 ms 109952 KB Time limit exceeded
19 Execution timed out 2077 ms 109956 KB Time limit exceeded
20 Execution timed out 2086 ms 110052 KB Time limit exceeded
21 Execution timed out 2073 ms 110008 KB Time limit exceeded
22 Execution timed out 2091 ms 110012 KB Time limit exceeded
23 Execution timed out 2092 ms 110008 KB Time limit exceeded
24 Execution timed out 2087 ms 110012 KB Time limit exceeded
25 Execution timed out 2096 ms 109980 KB Time limit exceeded