#include <bits/stdc++.h>
using namespace std;
#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;}
short int n, m, k;
string a, b;
string B;
int ans;
int dp[2005][2005];
int iter = 0;
inline void do_it_now(){
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
iter++;
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){
short int i, j;
cin >> a >> B;
if(a.length() < B.length())swap(a,B);
n = a.length(), m = B.length();
vector<int> idx(m);
for(i=0;i<m;i++)idx[i] = i;
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
shuffle(all(idx), default_random_engine(seed));
for(i=0;i<m;i++){
short int now = idx[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();
if(iter > 4e8+1231231){
break;
}
}
cout << ans << '\n';
return;
}
signed main(){
FASTIO;
solve(1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
91 ms |
4716 KB |
Output is correct |
7 |
Correct |
1611 ms |
8252 KB |
Output is correct |
8 |
Execution timed out |
2043 ms |
8172 KB |
Time limit exceeded |
9 |
Incorrect |
1883 ms |
8300 KB |
Output isn't correct |
10 |
Incorrect |
1596 ms |
8300 KB |
Output isn't correct |
11 |
Incorrect |
1571 ms |
9068 KB |
Output isn't correct |
12 |
Correct |
1628 ms |
9836 KB |
Output is correct |
13 |
Incorrect |
1727 ms |
9836 KB |
Output isn't correct |
14 |
Correct |
1599 ms |
9452 KB |
Output is correct |
15 |
Correct |
1592 ms |
10112 KB |
Output is correct |
16 |
Execution timed out |
2044 ms |
8812 KB |
Time limit exceeded |
17 |
Correct |
1679 ms |
9580 KB |
Output is correct |
18 |
Incorrect |
1623 ms |
11524 KB |
Output isn't correct |
19 |
Correct |
1587 ms |
8252 KB |
Output is correct |
20 |
Correct |
1932 ms |
10220 KB |
Output is correct |
21 |
Correct |
328 ms |
8216 KB |
Output is correct |
22 |
Correct |
966 ms |
9388 KB |
Output is correct |
23 |
Correct |
1676 ms |
10084 KB |
Output is correct |
24 |
Correct |
1718 ms |
10732 KB |
Output is correct |
25 |
Correct |
1680 ms |
11944 KB |
Output is correct |