-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathF.cpp
More file actions
87 lines (78 loc) 路 2.08 KB
/
Copy pathF.cpp
File metadata and controls
87 lines (78 loc) 路 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pl pair<ll, ll>
#define vl vector<long long>
#define vp vector<pl>
#define vs vector<string>
#define vvl vector<vl>
#define sl set<ll>
#define ml map<ll, ll>
#define MAXHeap priority_queue<ll>
#define MINHeap priority_queue<ll, vector<ll>, greater<ll>>
ll mod = 1e9 + 7;
ll MAX = 1e9;
#define rep(i,a,b) for(ll i = a;i < b;i++)
#define rev(i,a,b) for(ll i = a;i >= b;i--)
#define pb push_back
#define po pop_back
#define mp make_pair
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define F first
#define S second
#define mset(m, v) memset(m, v, sizeof(m))
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define vin(v) rep(i, 0, v.size()) cin >> v[i]
#define vout(v) rep(i, 0, v.size()) cout << v[i] << " "; cout << endl;
#define all(o) (o).begin(), (o).end()
#define asort(o) sort((o).begin(), (o).end())
#define dsort(o) sort((o).rbegin(), (o).rend())
#define maxin(a) *max_element(a.begin(), a.end())
#define minin(a) *min_element(a.begin(), a.end())
#define ub_index(v, x) (ub(all(v), x) - v.begin())
#define lb_index(v, x) (lb(all(v), x) - v.begin())
void solve() {
ll n, m;
string X, Y;
cin >> X >> Y;
m = X.size();
n = Y.size();
ll DP[m + 1][n + 1];
for (int i = 0; i <= m; i++)
{
for (int j = 0; j <= n; j++)
{
if (i == 0 || j == 0) DP[i][j] = 0;
else if (X[i - 1] == Y[j - 1]) DP[i][j] = DP[i - 1][j - 1] + 1;
else DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
}
}
string ans = "";
int i = m, j = n;
while (i > 0 and j > 0)
{
if (X[i - 1] == Y[j - 1])
{
ans.pb(X[i - 1]);
i--;
j--;
}
else if (DP[i - 1][j] >= DP[i][j - 1]) i--;
else j--;
}
reverse(all(ans));
cout << ans << endl;
return;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll t = 1;
// cin >> t;
while (t--) solve();
return 0;
}