#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;
typedef tuple<int,int,int> tii;
typedef tuple<ll,ll,ll> tll;
typedef tuple<int,int,int,int> ti4;
typedef vector<vector<ll>> mat;
const ll mod=998244353,inf=1e18;
const int N=2005,M=1e6+5,K=1e5+5;
string s,t;
int n,m,k,V[N][2*N],H[N][2*N],res,ans;
void solve(){
memset(V,0,sizeof(V));
memset(H,0,sizeof(H));
for(int i=1;i<=m;i++) H[0][i]=i;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
if(s[i]==t[j]){
H[i][j]=V[i][j-1];
V[i][j]=H[i-1][j];
} else{
H[i][j]=max(V[i][j-1],H[i-1][j]);
V[i][j]=min(V[i][j-1],H[i-1][j]);
}
}
for(int i=1;i<=k;i++){
ans=0;
for(int j=i;j<=i+k-1;j++) if(H[n][j]<=i-1) ans++;
res=max(res,ans);
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>s>>t;
n=s.size(); k=t.size(); m=2*k; s=" "+s; t=" "+t+t;
solve();
reverse(t.begin()+1,t.begin()+1+m);
solve();
cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
63224 KB |
Output is correct |
2 |
Correct |
47 ms |
63224 KB |
Output is correct |
3 |
Correct |
45 ms |
63224 KB |
Output is correct |
4 |
Correct |
46 ms |
63228 KB |
Output is correct |
5 |
Correct |
46 ms |
63224 KB |
Output is correct |
6 |
Correct |
48 ms |
63224 KB |
Output is correct |
7 |
Correct |
66 ms |
63224 KB |
Output is correct |
8 |
Correct |
55 ms |
63224 KB |
Output is correct |
9 |
Correct |
59 ms |
63352 KB |
Output is correct |
10 |
Correct |
63 ms |
63224 KB |
Output is correct |
11 |
Correct |
66 ms |
63224 KB |
Output is correct |
12 |
Correct |
57 ms |
63224 KB |
Output is correct |
13 |
Correct |
68 ms |
63224 KB |
Output is correct |
14 |
Correct |
74 ms |
63480 KB |
Output is correct |
15 |
Correct |
69 ms |
63228 KB |
Output is correct |
16 |
Correct |
59 ms |
63224 KB |
Output is correct |
17 |
Correct |
62 ms |
63352 KB |
Output is correct |
18 |
Correct |
67 ms |
63224 KB |
Output is correct |
19 |
Correct |
69 ms |
63352 KB |
Output is correct |
20 |
Correct |
61 ms |
63224 KB |
Output is correct |
21 |
Correct |
50 ms |
63352 KB |
Output is correct |
22 |
Correct |
54 ms |
63352 KB |
Output is correct |
23 |
Correct |
57 ms |
63352 KB |
Output is correct |
24 |
Correct |
60 ms |
63352 KB |
Output is correct |
25 |
Correct |
62 ms |
63224 KB |
Output is correct |