답안 #339774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339774 2020-12-26T07:47:24 Z tengiz05 원형 문자열 (IZhO13_rowords) C++17
20 / 100
2000 ms 63360 KB
#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;
string B;
int ans;
int dp[2005][4005];
void do_it_now(){
	memset(dp, 0, sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if(a[i-1] == b[j-1]){
				chmax(dp[i][j], dp[i-1][j-1]+1);
			}
		}
	}
	chmax(ans, dp[n][m]);
}
void solve(int test_case){
	int i, j;
	cin >> a >> B;
	if(a.length() > B.length())swap(a,B);
	n = a.length(), m = B.length();
	for(i=0;i<m;i++){
		int now = i;
		b.erase(all(b));
		for(j=0;j<m;j++){
			if(now == m)now=0;
			b.pb(B[now]);
			now++;
		}
		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;
}




# 결과 실행 시간 메모리 Grader output
1 Correct 181 ms 63212 KB Output is correct
2 Correct 209 ms 63212 KB Output is correct
3 Correct 377 ms 63340 KB Output is correct
4 Correct 938 ms 63340 KB Output is correct
5 Correct 708 ms 63340 KB Output is correct
6 Execution timed out 2094 ms 63212 KB Time limit exceeded
7 Execution timed out 2069 ms 63212 KB Time limit exceeded
8 Execution timed out 2092 ms 63212 KB Time limit exceeded
9 Execution timed out 2041 ms 63212 KB Time limit exceeded
10 Execution timed out 2099 ms 63212 KB Time limit exceeded
11 Execution timed out 2087 ms 63212 KB Time limit exceeded
12 Execution timed out 2095 ms 63212 KB Time limit exceeded
13 Execution timed out 2070 ms 63212 KB Time limit exceeded
14 Execution timed out 2090 ms 63212 KB Time limit exceeded
15 Execution timed out 2081 ms 63212 KB Time limit exceeded
16 Execution timed out 2097 ms 63212 KB Time limit exceeded
17 Execution timed out 2062 ms 63212 KB Time limit exceeded
18 Execution timed out 2080 ms 63212 KB Time limit exceeded
19 Execution timed out 2100 ms 63212 KB Time limit exceeded
20 Execution timed out 2061 ms 63360 KB Time limit exceeded
21 Execution timed out 2073 ms 63212 KB Time limit exceeded
22 Execution timed out 2072 ms 63212 KB Time limit exceeded
23 Execution timed out 2091 ms 63212 KB Time limit exceeded
24 Execution timed out 2090 ms 63212 KB Time limit exceeded
25 Execution timed out 2090 ms 63212 KB Time limit exceeded