답안 #525806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525806 2022-02-12T23:06:02 Z Yazan_Alattar Necklace (Subtask 1-3) (BOI19_necklace1) C++11
85 / 85
243 ms 106152 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 3005;
const ll inf = 1e18;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int dpS[M][M];
int dpPS[M][M];
int dpSP[M][M];

array <int, 3> solve (string s, string t){
	int n = s.size(), m = t.size();
	array <int, 3> ret = {0, 0, 0};
	
	for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) dpS[i][j] = dpSP[i][j] = dpPS[i][j] = 0;

	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j)
			if(s[i] == t[j])
				dpS[i][j] = (i && j ? dpS[i - 1][j - 1] + 1 : 1);
	
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j) if(dpS[i][j]){
			dpPS[i - dpS[i][j] + 1][j] = max(dpPS[i - dpS[i][j] + 1][j], dpS[i][j]);
			dpSP[i][j - dpS[i][j] + 1] = max(dpSP[i][j - dpS[i][j] + 1], dpS[i][j]);
	}
	
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			if(i) dpPS[i][j] = max(dpPS[i][j], dpPS[i - 1][j] - 1);
			if(j) dpSP[i][j] = max(dpSP[i][j], dpSP[i][j - 1] - 1);
	}
	
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			int len = dpSP[i][j];
			if(i + 1 < n && j) len += dpPS[i + 1][j - 1];
			if(len > ret[0]){
				ret[0] = len;
				ret[1] =  i - dpSP[i][j] + 1;
				ret[2] = j + dpSP[i][j] - len;
			}
		}
	}
	
	return ret;
}
 
int main()
{
	string s, t;
	cin >> s >> t;
	array <int, 3> ans = solve(s, t);
	
	reverse(all(t));
	array <int, 3> tmp = solve(s, t);
	tmp[2] = t.size() - tmp[2] - tmp[0];
	
	ans = max(ans, tmp);
	cout << ans[0] << endl << ans[1] << " " << ans[2] << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 6 ms 6988 KB Output is correct
7 Correct 5 ms 6972 KB Output is correct
8 Correct 6 ms 6476 KB Output is correct
9 Correct 6 ms 6696 KB Output is correct
10 Correct 5 ms 6808 KB Output is correct
11 Correct 6 ms 6852 KB Output is correct
12 Correct 6 ms 6660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1228 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 6 ms 6988 KB Output is correct
7 Correct 5 ms 6972 KB Output is correct
8 Correct 6 ms 6476 KB Output is correct
9 Correct 6 ms 6696 KB Output is correct
10 Correct 5 ms 6808 KB Output is correct
11 Correct 6 ms 6852 KB Output is correct
12 Correct 6 ms 6660 KB Output is correct
13 Correct 223 ms 106124 KB Output is correct
14 Correct 195 ms 106152 KB Output is correct
15 Correct 243 ms 102264 KB Output is correct
16 Correct 196 ms 105796 KB Output is correct
17 Correct 172 ms 104336 KB Output is correct
18 Correct 174 ms 105764 KB Output is correct
19 Correct 191 ms 105660 KB Output is correct
20 Correct 213 ms 104140 KB Output is correct
21 Correct 218 ms 104748 KB Output is correct