Submission #1186571

#TimeUsernameProblemLanguageResultExecution timeMemory
1186571kl0989eNecklace (Subtask 1-3) (BOI19_necklace1)C++20
17 / 85
116 ms70936 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll,ll>
#define all(x) (x).begin(),(x).end()

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	string a,b;
	cin >> a >> b;
	int n=a.size(),m=b.size();
	int ans=-1,aa=-1,bb=-1;
	for (int l=0; l<2; l++) {
		int dp[n+1][m+1];
		memset(dp,0,sizeof(dp));
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				if (i+dp[i][j]<n && a[i+dp[i][j]]==b[j]) {
					dp[i][j+1]=max(dp[i][j+1],dp[i][j]+1);
				}
			}
		}
		int dp2[n+1][m+1];
		memset(dp2,0,sizeof(dp2));
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				if (j+dp2[i][j]<m && a[i]==b[j+dp2[i][j]]) {
					dp2[i+1][j]=max(dp2[i+1][j],dp2[i][j]+1);
				}
			}
		}
		for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) {
				int t=dp[i][j+1]+dp2[i][j+1];
				if (t>ans) {
					ans=t;
					aa=i-dp2[i][j+1];
					bb=j-dp[i][j+1]+1;
					if (l) {
						bb=j+dp2[i][j+1];
						bb=m-1-bb;
					}
				}
			}
		}
		reverse(all(b));
	}
	cout << ans << '\n' << aa << ' ' << bb << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...