problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define PII pair<ll, ll>
#define N 100007
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;
int dp[3001][3001];
int main() {
string s, t, r = "";
cin >> s >> t;
for (int i = 0; i <= s.size(); i++) {
for (int j = 0; j <= t.size(); j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (s[i - 1] == t[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = s.size(), j = t.size();
while (i >= 0 && j >= 0) {
if (s[i - 1] == t[j - 1] && dp[i][j] == 1 + dp[i - 1][j - 1]) {
r += s[i - 1];
i -= 1;
j -= 1;
} else if (dp[i][j] == dp[i - 1][j]) {
i -= 1;
} else {
j -= 1;
}
}
reverse(all(r));
cout << r;
return 0;
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define PII pair<ll, ll>
#define N 100007
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;
int dp[3001][3001];
int main() {
string s, t, r = "";
cin >> s >> t;
for (int i = 0; i <= s.size(); i++) {
for (int j = 0; j <= t.size(); j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (s[i - 1] == t[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1] && dp[i][j] == 1 + dp[i - 1][j - 1]) {
r += s[i - 1];
i -= 1;
j -= 1;
} else if (dp[i][j] == dp[i - 1][j]) {
i -= 1;
} else {
j -= 1;
}
}
reverse(all(r));
cout << r;
return 0;
}
|
replace
| 50 | 51 | 50 | 51 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
ll memo[33][33];
int main() {
string a, b;
cin >> a >> b;
for (int i = 0; i <= a.size(); i++)
memo[i][0] = 0;
for (int j = 0; j <= b.size(); j++)
memo[0][j] = 0;
for (int i = 1; i <= a.size(); i++) {
for (int j = 1; j <= b.size(); j++) {
if (a[i - 1] == b[j - 1])
memo[i][j] = memo[i - 1][j - 1] + 1;
else
memo[i][j] = max(memo[i - 1][j], memo[i][j - 1]);
}
}
string res;
int i = a.size(), j = b.size();
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
res += a[i - 1];
i--;
j--;
} else if (memo[i - 1][j] > memo[i][j - 1])
i--;
else
j--;
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
ll memo[3003][3003];
int main() {
string a, b;
cin >> a >> b;
for (int i = 0; i <= a.size(); i++)
memo[i][0] = 0;
for (int j = 0; j <= b.size(); j++)
memo[0][j] = 0;
for (int i = 1; i <= a.size(); i++) {
for (int j = 1; j <= b.size(); j++) {
if (a[i - 1] == b[j - 1])
memo[i][j] = memo[i - 1][j - 1] + 1;
else
memo[i][j] = max(memo[i - 1][j], memo[i][j - 1]);
}
}
string res;
int i = a.size(), j = b.size();
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
res += a[i - 1];
i--;
j--;
} else if (memo[i - 1][j] > memo[i][j - 1])
i--;
else
j--;
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FF first
#define SS second
#define pii pair<int, int>
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define sz(x) (int)x.size()
#define mp make_pair
#define Mod 1000000007
typedef long long int ll;
vector<int> dp(100001, 0);
vector<int> ans(100001, 0);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
// dp[i][j] -> i for string s and j for string t
string s, t;
string ans = "";
cin >> s >> t;
int n = s.length(), m = t.length();
int i, j;
vector<vector<pii>> dp(n + 1, vector<pii>(m + 1));
for (i = 0; i <= n; i++)
dp[i][0] = {0, 0};
for (i = 0; i <= m; i++)
dp[0][i] = {0, 0};
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = {1, dp[i - 1][j - 1].se + 1};
else
dp[i][j] = mp(0, max(dp[i][j - 1].se, dp[i - 1][j].se));
// cout<<dp[i][j].se<<" ";
}
// cout<<"\n";
}
// cout<<dp[n][m]<<"\n";
i = n, j = m;
while (i > 0 && j > 0) {
if (dp[i][j].se == dp[i - 1][j - 1].se + 1 && dp[i][j].fi == 1) {
// cout<<j<<"\n";
ans += t[j - 1];
i -= 1;
j -= 1;
} else if (dp[i][j].se == dp[i - 1][j].se && dp[i][j].fi == 0)
i -= 1;
else if (dp[i][j].se == dp[i][j - 1].se && dp[i][j].fi == 0)
j -= 1;
}
// cout<<reverse(ans.begin(), ans.end());
// cout<<reverse(ans.begin(), ans.end())<<"\n";
for (i = ans.length() - 1; i >= 0; i--)
cout << ans[i];
cout << "\n";
}
|
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FF first
#define SS second
#define pii pair<int, int>
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define sz(x) (int)x.size()
#define mp make_pair
#define Mod 1000000007
typedef long long int ll;
vector<int> dp(100001, 0);
vector<int> ans(100001, 0);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// #endif
// dp[i][j] -> i for string s and j for string t
string s, t;
string ans = "";
cin >> s >> t;
int n = s.length(), m = t.length();
int i, j;
vector<vector<pii>> dp(n + 1, vector<pii>(m + 1));
for (i = 0; i <= n; i++)
dp[i][0] = {0, 0};
for (i = 0; i <= m; i++)
dp[0][i] = {0, 0};
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = {1, dp[i - 1][j - 1].se + 1};
else
dp[i][j] = mp(0, max(dp[i][j - 1].se, dp[i - 1][j].se));
// cout<<dp[i][j].se<<" ";
}
// cout<<"\n";
}
// cout<<dp[n][m]<<"\n";
i = n, j = m;
while (i > 0 && j > 0) {
if (dp[i][j].se == dp[i - 1][j - 1].se + 1 && dp[i][j].fi == 1) {
// cout<<j<<"\n";
ans += t[j - 1];
i -= 1;
j -= 1;
} else if (dp[i][j].se == dp[i - 1][j].se && dp[i][j].fi == 0)
i -= 1;
else if (dp[i][j].se == dp[i][j - 1].se && dp[i][j].fi == 0)
j -= 1;
}
// cout<<reverse(ans.begin(), ans.end());
// cout<<reverse(ans.begin(), ans.end())<<"\n";
for (i = ans.length() - 1; i >= 0; i--)
cout << ans[i];
cout << "\n";
}
|
replace
| 24 | 27 | 24 | 27 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s, t, ans;
int dp[3001][3001];
int main() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
}
}
for (int i = s.size(); i > 0;) {
for (int j = t.size(); j > 0;) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans = s[i - 1] + ans;
i--;
j--;
}
}
}
cout << ans;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string s, t, ans;
int dp[3001][3001];
int main() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
}
}
for (int i = s.size(), j = t.size(); i > 0 && j > 0;) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans = s[i - 1] + ans;
i--;
j--;
}
}
cout << ans;
}
|
replace
| 16 | 27 | 16 | 25 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
#define chmax(a, b) a = max(a, b)
#define N 310
ll f[N][N];
string s, t;
int main() {
cin >> s >> t;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
f[i][j] = 0;
for (int i = 1; i <= s.size(); i++)
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
chmax(f[i][j], f[i - 1][j - 1] + 1);
chmax(f[i][j], f[i - 1][j]);
chmax(f[i][j], f[i][j - 1]);
}
string ans;
ll x = s.size(), y = t.size();
// cout<<"#"<<f[x][y]<<endl;
while (x > 0 && y > 0) {
if (f[x - 1][y - 1] == f[x][y] - 1 && s[x - 1] == t[y - 1]) {
ans += s[x - 1];
x--, y--;
continue;
}
if (f[x - 1][y] == f[x][y]) {
x--;
} else
y--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
#define chmax(a, b) a = max(a, b)
#define N 3010
ll f[N][N];
string s, t;
int main() {
cin >> s >> t;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
f[i][j] = 0;
for (int i = 1; i <= s.size(); i++)
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
chmax(f[i][j], f[i - 1][j - 1] + 1);
chmax(f[i][j], f[i - 1][j]);
chmax(f[i][j], f[i][j - 1]);
}
string ans;
ll x = s.size(), y = t.size();
// cout<<"#"<<f[x][y]<<endl;
while (x > 0 && y > 0) {
if (f[x - 1][y - 1] == f[x][y] - 1 && s[x - 1] == t[y - 1]) {
ans += s[x - 1];
x--, y--;
continue;
}
if (f[x - 1][y] == f[x][y]) {
x--;
} else
y--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define dbg(n) cout << '\n' << #n << " is " << n << '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define cs(i) cout << "Case " << i + 1 << ": "
const int sz = 1e3 + 5;
const int INF = 1e9 + 5;
string a, b, ans;
int dp[sz][sz];
void printLCS(int i, int j) {
if (i == 0 || j == 0)
return;
else if (a[i - 1] == b[j - 1]) {
ans.pb(a[i - 1]);
printLCS(i - 1, j - 1);
} else if (dp[i - 1][j] > dp[i][j - 1]) {
printLCS(i - 1, j);
} else if (dp[i - 1][j] < dp[i][j - 1]) {
printLCS(i, j - 1);
} else {
printLCS(i, j - 1);
}
}
int main() {
cin >> a >> b;
for (int i = 1; i <= a.size(); i++) {
for (int j = 1; j <= b.size(); j++) {
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
printLCS(a.size(), b.size());
reverse(all(ans));
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define dbg(n) cout << '\n' << #n << " is " << n << '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
#define cs(i) cout << "Case " << i + 1 << ": "
const int sz = 3e3 + 5;
const int INF = 1e9 + 5;
string a, b, ans;
int dp[sz][sz];
void printLCS(int i, int j) {
if (i == 0 || j == 0)
return;
else if (a[i - 1] == b[j - 1]) {
ans.pb(a[i - 1]);
printLCS(i - 1, j - 1);
} else if (dp[i - 1][j] > dp[i][j - 1]) {
printLCS(i - 1, j);
} else if (dp[i - 1][j] < dp[i][j - 1]) {
printLCS(i, j - 1);
} else {
printLCS(i, j - 1);
}
}
int main() {
cin >> a >> b;
for (int i = 1; i <= a.size(); i++) {
for (int j = 1; j <= b.size(); j++) {
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
printLCS(a.size(), b.size());
reverse(all(ans));
cout << ans << endl;
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p03165
|
C++
|
Runtime Error
|
/*----------------by syr----------------*/
/*
----- ----- -----
| | |---| _/
| | | \_ /
----- | \ -----
|---\ \ / |\ /|
| | \_/ | \/ |
| | / \ | |
|---/ / \ | |
*/
#include <bits/stdc++.h>
using namespace std;
#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 1e3 + 5;
int n, m;
int dp[maxn][maxn];
char s[maxn], t[maxn];
pii f[maxn][maxn];
vector<char> ans;
int main() {
scanf("%s%s", s + 1, t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
dp[0][0] = 0;
REP(i, 1, n) {
REP(j, 1, m) {
if (s[i] == t[j]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
if (dp[i][j] == dp[i - 1][j - 1] + 1)
f[i][j] = MP(i - 1, j - 1);
}
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (dp[i][j] == dp[i - 1][j])
f[i][j] = MP(i - 1, j);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
if (dp[i][j] == dp[i][j - 1])
f[i][j] = MP(i, j - 1);
}
}
int x = n, y = m;
while (x || y) {
if (f[x][y] == MP(x - 1, y - 1))
ans.PB(s[x]);
int nx = f[x][y].fst, ny = f[x][y].snd;
x = nx, y = ny;
}
for (int i = ans.size() - 1; i >= 0; --i)
printf("%c", ans[i]);
return 0;
}
|
/*----------------by syr----------------*/
/*
----- ----- -----
| | |---| _/
| | | \_ /
----- | \ -----
|---\ \ / |\ /|
| | \_/ | \/ |
| | / \ | |
|---/ / \ | |
*/
#include <bits/stdc++.h>
using namespace std;
#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 3e3 + 5;
int n, m;
int dp[maxn][maxn];
char s[maxn], t[maxn];
pii f[maxn][maxn];
vector<char> ans;
int main() {
scanf("%s%s", s + 1, t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
dp[0][0] = 0;
REP(i, 1, n) {
REP(j, 1, m) {
if (s[i] == t[j]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
if (dp[i][j] == dp[i - 1][j - 1] + 1)
f[i][j] = MP(i - 1, j - 1);
}
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (dp[i][j] == dp[i - 1][j])
f[i][j] = MP(i - 1, j);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
if (dp[i][j] == dp[i][j - 1])
f[i][j] = MP(i, j - 1);
}
}
int x = n, y = m;
while (x || y) {
if (f[x][y] == MP(x - 1, y - 1))
ans.PB(s[x]);
int nx = f[x][y].fst, ny = f[x][y].snd;
x = nx, y = ny;
}
for (int i = ans.size() - 1; i >= 0; --i)
printf("%c", ans[i]);
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e4 + 5;
typedef long long ll;
string a, b, c;
int len1, len2;
int dp[inf][inf];
bool vis[inf][inf];
void str(int i, int j) {
if (a[i] == '\0' || b[i] == '\0') {
cout << c << endl;
return;
}
if (a[i] == b[j]) {
c += a[i];
str(i + 1, j + 1);
} else {
if (dp[i + 1][j] > dp[i][j + 1]) {
str(i + 1, j);
} else {
str(i, j + 1);
}
}
}
int solve(int i, int j) {
if (a[i] == '\0' || b[j] == '\0') {
return 0;
}
if (vis[i][j])
return dp[i][j];
int ans = 0;
if (a[i] == b[j]) {
ans = 1 + solve(i + 1, j + 1);
} else {
int val1 = solve(i + 1, j);
int val2 = solve(i, j + 1);
ans = max(val1, val2);
}
vis[i][j] = 1;
dp[i][j] = ans;
return dp[i][j];
// return c;
}
int main() {
cin >> a >> b;
int k = solve(0, 0);
str(0, 0);
// cout<<c<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e4 + 5;
typedef long long ll;
string a, b, c;
int len1, len2;
int dp[inf][inf];
bool vis[inf][inf];
void str(int i, int j) {
if (a[i] == '\0' || b[j] == '\0') {
cout << c << endl;
return;
}
if (a[i] == b[j]) {
c += a[i];
str(i + 1, j + 1);
} else {
if (dp[i + 1][j] > dp[i][j + 1]) {
str(i + 1, j);
} else {
str(i, j + 1);
}
}
}
int solve(int i, int j) {
if (a[i] == '\0' || b[j] == '\0') {
return 0;
}
if (vis[i][j])
return dp[i][j];
int ans = 0;
if (a[i] == b[j]) {
ans = 1 + solve(i + 1, j + 1);
} else {
int val1 = solve(i + 1, j);
int val2 = solve(i, j + 1);
ans = max(val1, val2);
}
vis[i][j] = 1;
dp[i][j] = ans;
return dp[i][j];
// return c;
}
int main() {
cin >> a >> b;
int k = solve(0, 0);
str(0, 0);
// cout<<c<<endl;
}
|
replace
| 9 | 10 | 9 | 10 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1e6 + 3;
#define Hello \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ld long double
#define X real()
#define Y imag()
#define cross(a, b) (conj(a) * (b)).imag()
#define dot(a, b) (conj(a) * (b)).real()
#define dist(a, b) (pow(a.X - b.X, 2) + pow(a.Y - b.Y, 2))
typedef tuple<int, int, int> line;
typedef complex<double> point;
typedef vector<point> polygon;
string s, t;
ll dp[1000][1000], ans = 0;
ll solve(int si, int ti) {
if (si >= s.size() || ti >= t.size())
return 0;
if (dp[si][ti] != -1)
return dp[si][ti];
if (s[si] == t[ti])
ans = 1 + solve(si + 1, ti + 1);
else
ans = max(solve(si, ti + 1), solve(si + 1, ti));
dp[si][ti] = ans;
return ans;
}
void print(int si, int ti) {
if (si >= s.size() || ti >= t.size())
return;
if (s[si] == t[ti]) {
cout << s[si];
print(si + 1, ti + 1);
} else {
if (solve(si, ti + 1) >= solve(si + 1, ti))
print(si, ti + 1);
else
print(si + 1, ti);
}
return;
}
int main() {
Hello memset(dp, -1, sizeof dp);
cin >> s >> t;
solve(0, 0);
print(0, 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1e6 + 3;
#define Hello \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ld long double
#define X real()
#define Y imag()
#define cross(a, b) (conj(a) * (b)).imag()
#define dot(a, b) (conj(a) * (b)).real()
#define dist(a, b) (pow(a.X - b.X, 2) + pow(a.Y - b.Y, 2))
typedef tuple<int, int, int> line;
typedef complex<double> point;
typedef vector<point> polygon;
string s, t;
ll dp[3005][3005], ans = 0;
ll solve(int si, int ti) {
if (si >= s.size() || ti >= t.size())
return 0;
if (dp[si][ti] != -1)
return dp[si][ti];
if (s[si] == t[ti])
ans = 1 + solve(si + 1, ti + 1);
else
ans = max(solve(si, ti + 1), solve(si + 1, ti));
dp[si][ti] = ans;
return ans;
}
void print(int si, int ti) {
if (si >= s.size() || ti >= t.size())
return;
if (s[si] == t[ti]) {
cout << s[si];
print(si + 1, ti + 1);
} else {
if (solve(si, ti + 1) >= solve(si + 1, ti))
print(si, ti + 1);
else
print(si + 1, ti);
}
return;
}
int main() {
Hello memset(dp, -1, sizeof dp);
cin >> s >> t;
solve(0, 0);
print(0, 0);
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p03165
|
Python
|
Runtime Error
|
s = input()
t = input()
dp = [0]
lcs = [""]
for b in t:
search_idx = 0
ncs = lcs.copy()
for i, curr_idx in enumerate(dp):
char_idx = s.find(b, search_idx)
if char_idx == -1:
break
next_idx = char_idx + 1
if next_idx < curr_idx:
dp[i] = next_idx
ncs[i] = lcs[i - 1] + b
search_idx = curr_idx
else:
char_idx = s.find(b, search_idx)
if char_idx > -1:
dp.append(char_idx + 1)
ncs.append(lcs[-1] + b)
lcs = ncs
print(lcs[-1])
|
s = input()
t = input()
dp = [0]
lcs = [""]
for b in t:
search_idx = 0
ncs = lcs[:]
for i, curr_idx in enumerate(dp):
char_idx = s.find(b, search_idx)
if char_idx == -1:
break
next_idx = char_idx + 1
if next_idx < curr_idx:
dp[i] = next_idx
ncs[i] = lcs[i - 1] + b
search_idx = curr_idx
else:
char_idx = s.find(b, search_idx)
if char_idx > -1:
dp.append(char_idx + 1)
ncs.append(lcs[-1] + b)
lcs = ncs
print(lcs[-1])
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <unordered_map>
#include <vector>
using namespace std;
void solve() {
string s, t;
cin >> s >> t;
int m = s.size();
int n = t.size();
vector<vector<int>> dp(m, vector<int>(n, 0));
vector<vector<vector<int>>> sdp(m, vector<vector<int>>(n, vector<int>(0)));
for (int i = 1; i < m + 1; ++i) {
for (int j = 1; j < n + 1; ++j) {
if (s[i - 1] == t[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;
int j = n;
while (i && j) {
if (s[i - 1] == t[j - 1]) {
ans = s[i - 1] + ans;
i--;
j--;
} else {
if (dp[i][j - 1] > dp[i - 1][j]) {
j--;
} else {
i--;
}
}
}
cout << ans;
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <unordered_map>
#include <vector>
using namespace std;
void solve() {
string s, t;
cin >> s >> t;
int m = s.size();
int n = t.size();
vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
// vector<vector<vector<int>>> sdp(m, vector<vector<int>>(n, vector<int>(0)));
for (int i = 1; i < m + 1; ++i) {
for (int j = 1; j < n + 1; ++j) {
if (s[i - 1] == t[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;
int j = n;
while (i && j) {
if (s[i - 1] == t[j - 1]) {
ans = s[i - 1] + ans;
i--;
j--;
} else {
if (dp[i][j - 1] > dp[i - 1][j]) {
j--;
} else {
i--;
}
}
}
cout << ans;
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
|
replace
| 21 | 23 | 21 | 23 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define nd second
#define st first
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using mii = map<int, int>;
using si = set<int, int>;
using vpi = vector<pii>;
using vpl = vector<pll>;
const int N = (int)1e3 + 5;
int n, m, a, b, c, q, dp[N][N];
vi V;
string A, B, wyn;
int R(int l, int p) { return rand() % (p - l + 1) + l; }
void wczytaj() {
cin >> A >> B;
A = '#' + A;
B = '#' + B;
}
void solve() {
for (int i = 1; i < A.size(); ++i) {
for (int j = 1; j < B.size(); j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (A[i] == B[j]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
int i = A.size() - 1, j = B.size() - 1;
while (i and j) {
if (A[i] == B[j]) {
wyn += A[i];
i--;
j--;
} else if (dp[i - 1][j] == dp[i][j]) {
i--;
} else
j--;
}
reverse(wyn.begin(), wyn.end());
if (wyn.size() == 0) {
cout << ' ';
return;
}
cout << wyn << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ilosc_przypadkow_testowych = 1;
// cin>>ilosc_przypadkow_testowych
for (int i = 1; i <= ilosc_przypadkow_testowych; ++i) {
wczytaj();
solve();
}
}
|
#include <bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define nd second
#define st first
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using mii = map<int, int>;
using si = set<int, int>;
using vpi = vector<pii>;
using vpl = vector<pll>;
const int N = (int)3e3 + 5;
int n, m, a, b, c, q, dp[N][N];
vi V;
string A, B, wyn;
int R(int l, int p) { return rand() % (p - l + 1) + l; }
void wczytaj() {
cin >> A >> B;
A = '#' + A;
B = '#' + B;
}
void solve() {
for (int i = 1; i < A.size(); ++i) {
for (int j = 1; j < B.size(); j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (A[i] == B[j]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
int i = A.size() - 1, j = B.size() - 1;
while (i and j) {
if (A[i] == B[j]) {
wyn += A[i];
i--;
j--;
} else if (dp[i - 1][j] == dp[i][j]) {
i--;
} else
j--;
}
reverse(wyn.begin(), wyn.end());
if (wyn.size() == 0) {
cout << ' ';
return;
}
cout << wyn << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ilosc_przypadkow_testowych = 1;
// cin>>ilosc_przypadkow_testowych
for (int i = 1; i <= ilosc_przypadkow_testowych; ++i) {
wczytaj();
solve();
}
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string lcs(string a, string b) {
int n = a.size(), m = b.size();
vector<vector<int>> X(3000, vector<int>(3000));
vector<vector<int>> Y(3000, vector<int>(3000));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a.at(i) == b.at(j)) {
X.at(i + 1).at(j + 1) = X.at(i).at(j) + 1;
Y.at(i + 1).at(j + 1) = 0;
} else if (X.at(i + 1).at(j) < X.at(i).at(j + 1)) {
X.at(i + 1).at(j + 1) = X.at(i).at(j + 1);
Y.at(i + 1).at(j + 1) = 1;
} else {
X.at(i + 1).at(j + 1) = X.at(i + 1).at(j);
Y.at(i + 1).at(j + 1) = -1;
}
}
}
string c;
for (int i = n, j = m; i > 0 && j > 0;) {
if (Y.at(i).at(j) > 0) {
i--;
} else if (Y.at(i).at(j) < 0) {
j--;
} else {
c.push_back(a.at(i - 1));
i--;
j--;
}
}
reverse(c.begin(), c.end());
return c;
}
int main() {
string S, T;
cin >> S >> T;
cout << lcs(S, T) << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
string lcs(string a, string b) {
int n = a.size(), m = b.size();
vector<vector<int>> X(3001, vector<int>(3001));
vector<vector<int>> Y(3001, vector<int>(3001));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a.at(i) == b.at(j)) {
X.at(i + 1).at(j + 1) = X.at(i).at(j) + 1;
Y.at(i + 1).at(j + 1) = 0;
} else if (X.at(i + 1).at(j) < X.at(i).at(j + 1)) {
X.at(i + 1).at(j + 1) = X.at(i).at(j + 1);
Y.at(i + 1).at(j + 1) = 1;
} else {
X.at(i + 1).at(j + 1) = X.at(i + 1).at(j);
Y.at(i + 1).at(j + 1) = -1;
}
}
}
string c;
for (int i = n, j = m; i > 0 && j > 0;) {
if (Y.at(i).at(j) > 0) {
i--;
} else if (Y.at(i).at(j) < 0) {
j--;
} else {
c.push_back(a.at(i - 1));
i--;
j--;
}
}
reverse(c.begin(), c.end());
return c;
}
int main() {
string S, T;
cin >> S >> T;
cout << lcs(S, T) << "\n";
}
|
replace
| 5 | 7 | 5 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s, t;
cin >> s >> t;
int lens = s.length();
int lent = t.length();
int dp[lens][lent];
for (int i = 0; i <= lens; i++) {
for (int j = 0; j <= lent; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = lens;
int j = lent;
string res = "";
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
res = res + s[i - 1];
i--;
j--;
} else {
if (dp[i - 1][j] == dp[i][j])
i--;
else
j--;
}
}
reverse(res.begin(), res.end());
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s, t;
cin >> s >> t;
int lens = s.length();
int lent = t.length();
int dp[lens + 1][lent + 1];
for (int i = 0; i <= lens; i++) {
for (int j = 0; j <= lent; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = lens;
int j = lent;
string res = "";
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
res = res + s[i - 1];
i--;
j--;
} else {
if (dp[i - 1][j] == dp[i][j])
i--;
else
j--;
}
}
reverse(res.begin(), res.end());
cout << res << endl;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define ppb pop_back
using namespace std;
int dp[3005][3005];
string ans = "";
int main() {
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
for (int i = 0; i < 3005; i++)
dp[i][0] = dp[0][i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = n, j = m;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--;
j--;
} else {
}
if (dp[i][j] == dp[i - 1][j])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define ppb pop_back
using namespace std;
int dp[3005][3005];
string ans = "";
int main() {
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
for (int i = 0; i < 3005; i++)
dp[i][0] = dp[0][i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = n, j = m;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--;
j--;
} else if (dp[i][j] == dp[i - 1][j])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
replace
| 29 | 32 | 29 | 30 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define fl(i, a, b) for (int i = a; i < b; i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 200005
#define inf 2e9
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
ll dp[3001][3001] = {0};
int main() {
fast;
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
// cout<<dp[n][m];
ll index = dp[n][m];
ll i = n, j = m;
char lcs[index + 1];
lcs[index] = '\0';
while (i >= 0 && j >= 0) {
if (s[i - 1] == t[j - 1]) {
lcs[index - 1] = s[i - 1];
index--;
i--, j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
cout << lcs;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fl(i, a, b) for (int i = a; i < b; i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 200005
#define inf 2e9
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
ll dp[3001][3001] = {0};
int main() {
fast;
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
// cout<<dp[n][m];
ll index = dp[n][m];
ll i = n, j = m;
char lcs[index + 1];
lcs[index] = '\0';
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
lcs[index - 1] = s[i - 1];
index--;
i--, j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
cout << lcs;
}
|
replace
| 36 | 37 | 36 | 37 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define int long long int
#define mp make_pair
using namespace std;
string s, t;
int dp[3002][3002];
int l1, l2;
int fun(int pos1, int pos2) {
if (pos1 == l1) {
return 0;
}
if (pos2 == l2) {
return 0;
}
if (s[pos1] == t[pos2]) {
dp[pos1][pos2] = 1 + fun(pos1 + 1, pos2 + 1);
} else {
dp[pos1][pos2] = max(fun(pos1 + 1, pos2), fun(pos1, pos2 + 1));
}
return dp[pos1][pos2];
}
void path(int i, int j) {
if (i == l1) {
return;
}
if (j == l2) {
return;
}
if (s[i] == t[j]) {
cout << s[i];
path(i + 1, j + 1);
} else {
if (dp[i + 1][j] > dp[i][j + 1]) {
path(i + 1, j);
} else {
path(i, j + 1);
}
}
return;
}
int32_t main() {
cin >> s >> t;
l1 = s.length();
l2 = t.length();
for (int i = 0; i < 3002; ++i) {
for (int j = 0; j < 3002; ++j) {
dp[i][j] = -1;
}
}
int ans1 = fun(0, 0);
path(0, 0);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long int
#define mp make_pair
using namespace std;
string s, t;
int dp[3002][3002];
int l1, l2;
int fun(int pos1, int pos2) {
if (pos1 == l1) {
return 0;
}
if (pos2 == l2) {
return 0;
}
if (dp[pos1][pos2] != -1) {
return dp[pos1][pos2];
}
if (s[pos1] == t[pos2]) {
dp[pos1][pos2] = 1 + fun(pos1 + 1, pos2 + 1);
} else {
dp[pos1][pos2] = max(fun(pos1 + 1, pos2), fun(pos1, pos2 + 1));
}
return dp[pos1][pos2];
}
void path(int i, int j) {
if (i == l1) {
return;
}
if (j == l2) {
return;
}
if (s[i] == t[j]) {
cout << s[i];
path(i + 1, j + 1);
} else {
if (dp[i + 1][j] > dp[i][j + 1]) {
path(i + 1, j);
} else {
path(i, j + 1);
}
}
return;
}
int32_t main() {
cin >> s >> t;
l1 = s.length();
l2 = t.length();
for (int i = 0; i < 3002; ++i) {
for (int j = 0; j < 3002; ++j) {
dp[i][j] = -1;
}
}
int ans1 = fun(0, 0);
path(0, 0);
return 0;
}
|
insert
| 15 | 15 | 15 | 18 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
# 1 "f.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "f.cpp"
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 1
# 12 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/bits/stdc++.h" 1
#include <bits/stdc++.h>
# 13 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/assoc_container.hpp" 1
#include <ext/pb_ds/assoc_container.hpp>
# 14 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/tree_policy.hpp" 1
#include <ext/pb_ds/tree_policy.hpp>
# 15 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
using namespace std;
using namespace __gnu_pbds;
using ii = pair<long long, long long>;
using vi = vector<long long>;
using vd = vector<long double>;
using vb = vector<bool>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvd = vector<vd>;
using vvb = vector<vb>;
using vvii = vector<vii>;
# 50 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
inline long long mod(const long long n,
const long long m = ((long long)1e9 + 7)) {
return (n % m + m) % m;
}
/**
* Euclidean GCD.
*
* Time Complexity: O(log(min(a, b))).
* Space Complexity: O(log(min(a, b))).
*/
long long gcd(const long long a, const long long b) {
if (a < 0 or b < 0)
return gcd(abs(a), abs(b));
if (a == 0)
return b;
return gcd(b % a, a);
}
/**
* Euclidean derivated LCM.
*
* Time Complexity: O(log(min(a, b))).
* Space Complexity: O(log(min(a, b))).
*/
long long lcm(const long long a, const long long b) {
// same as a*b/gcd(a, b) but avoiding overflow.
return a / gcd(a, b) * b;
}
# 2 "f.cpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/string/longest-commom-subsequence.hpp" 1
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/array/longest-commom-subsequence.hpp" 1
vi lcs(const vi &a, const vi &b) {
long long n = a.size(), m = b.size();
vvi dis(n + 1, vi(m + 1));
for (long long i = 0; i <= n; ++i) {
for (long long j = 0; j <= m; ++j) {
if (!i or !j)
dis[i][j] = max(i, j);
else {
dis[i][j] = min(
{(a[i - 1] == b[j - 1] ? dis[i - 1][j - 1] : ((long long)1e9 + 1)),
dis[i][j - 1] + 1, dis[i - 1][j] + 1});
}
}
}
vi res;
long long i = n, j = m;
while (i or j) {
if (a[i - 1] == b[j - 1]) {
res.push_back(a[i - 1]);
i--;
j--;
} else if (dis[i - 1][j] <= dis[i][j - 1])
i--;
else
j--;
}
reverse(res.begin(), res.end());
return res;
}
# 4 "/home/tysm/dev/cpplib/bin/../include/cpplib/string/longest-commom-subsequence.hpp" 2
string lcs(const string &a, const string &b) {
vi arr_a, arr_b;
for (char c : a)
arr_a.push_back(c);
for (char c : b)
arr_b.push_back(c);
string res;
for (char i : lcs(arr_a, arr_b))
res += i;
return res;
}
# 3 "f.cpp" 2
int32_t main() {
(ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL));
string a, b;
cin >> a >> b;
cout << lcs(a, b) << "\n";
return 0;
}
|
# 1 "f.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "f.cpp"
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 1
# 12 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/bits/stdc++.h" 1
#include <bits/stdc++.h>
# 13 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/assoc_container.hpp" 1
#include <ext/pb_ds/assoc_container.hpp>
# 14 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/tree_policy.hpp" 1
#include <ext/pb_ds/tree_policy.hpp>
# 15 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
using namespace std;
using namespace __gnu_pbds;
using ii = pair<long long, long long>;
using vi = vector<long long>;
using vd = vector<long double>;
using vb = vector<bool>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvd = vector<vd>;
using vvb = vector<vb>;
using vvii = vector<vii>;
# 50 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
inline long long mod(const long long n,
const long long m = ((long long)1e9 + 7)) {
return (n % m + m) % m;
}
/**
* Euclidean GCD.
*
* Time Complexity: O(log(min(a, b))).
* Space Complexity: O(log(min(a, b))).
*/
long long gcd(const long long a, const long long b) {
if (a < 0 or b < 0)
return gcd(abs(a), abs(b));
if (a == 0)
return b;
return gcd(b % a, a);
}
/**
* Euclidean derivated LCM.
*
* Time Complexity: O(log(min(a, b))).
* Space Complexity: O(log(min(a, b))).
*/
long long lcm(const long long a, const long long b) {
// same as a*b/gcd(a, b) but avoiding overflow.
return a / gcd(a, b) * b;
}
# 2 "f.cpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/string/longest-commom-subsequence.hpp" 1
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/array/longest-commom-subsequence.hpp" 1
vi lcs(const vi &a, const vi &b) {
long long n = a.size(), m = b.size();
vvi dis(n + 1, vi(m + 1));
for (long long i = 0; i <= n; ++i) {
for (long long j = 0; j <= m; ++j) {
if (!i or !j)
dis[i][j] = max(i, j);
else {
dis[i][j] = min(
{(a[i - 1] == b[j - 1] ? dis[i - 1][j - 1] : ((long long)1e9 + 1)),
dis[i][j - 1] + 1, dis[i - 1][j] + 1});
}
}
}
vi res;
long long i = n, j = m;
while (i and j) {
if (a[i - 1] == b[j - 1]) {
res.push_back(a[i - 1]);
i--;
j--;
} else if (dis[i - 1][j] <= dis[i][j - 1])
i--;
else
j--;
}
reverse(res.begin(), res.end());
return res;
}
# 4 "/home/tysm/dev/cpplib/bin/../include/cpplib/string/longest-commom-subsequence.hpp" 2
string lcs(const string &a, const string &b) {
vi arr_a, arr_b;
for (char c : a)
arr_a.push_back(c);
for (char c : b)
arr_b.push_back(c);
string res;
for (char i : lcs(arr_a, arr_b))
res += i;
return res;
}
# 3 "f.cpp" 2
int32_t main() {
(ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL));
string a, b;
cin >> a >> b;
cout << lcs(a, b) << "\n";
return 0;
}
|
replace
| 80 | 81 | 80 | 81 |
0
| |
p03165
|
C++
|
Runtime Error
|
// shan61916
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl "\n"
typedef long long ll;
typedef unsigned long long ull;
typedef double dll;
ll dp[1010][1010];
string s1, s2, an = "";
ll len;
ll recurse(ll id1, ll id2) {
if (id1 < 0 or id2 < 0)
return 0;
if (dp[id1][id2] != -1)
return dp[id1][id2];
if (s1[id1] == s2[id2]) {
return dp[id1][id2] = 1 + recurse(id1 - 1, id2 - 1);
}
return dp[id1][id2] = max(recurse(id1 - 1, id2), recurse(id1, id2 - 1));
}
void print(ll id1, ll id2) {
if (id1 < 0 or id2 < 0)
return;
ll x = recurse(id1, id2);
if (s1[id1] == s2[id2]) {
an += s1[id1];
print(id1 - 1, id2 - 1);
} else {
if (recurse(id1 - 1, id2) == x)
print(id1 - 1, id2);
else {
print(id1, id2 - 1);
}
}
}
int main() {
IOS
#ifdef SHAN
freopen("input.txt", "r", stdin);
#endif
memset(dp, -1, sizeof(dp));
cin >> s1 >> s2;
len = recurse((ll)s1.length() - 1, (ll)s2.length() - 1);
print((ll)s1.length() - 1, (ll)s2.length() - 1);
reverse(an.begin(), an.end());
cout << an;
return 0;
} // good night.
|
// shan61916
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl "\n"
typedef long long ll;
typedef unsigned long long ull;
typedef double dll;
ll dp[3010][3010];
string s1, s2, an = "";
ll len;
ll recurse(ll id1, ll id2) {
if (id1 < 0 or id2 < 0)
return 0;
if (dp[id1][id2] != -1)
return dp[id1][id2];
if (s1[id1] == s2[id2]) {
return dp[id1][id2] = 1 + recurse(id1 - 1, id2 - 1);
}
return dp[id1][id2] = max(recurse(id1 - 1, id2), recurse(id1, id2 - 1));
}
void print(ll id1, ll id2) {
if (id1 < 0 or id2 < 0)
return;
ll x = recurse(id1, id2);
if (s1[id1] == s2[id2]) {
an += s1[id1];
print(id1 - 1, id2 - 1);
} else {
if (recurse(id1 - 1, id2) == x)
print(id1 - 1, id2);
else {
print(id1, id2 - 1);
}
}
}
int main() {
IOS
#ifdef SHAN
freopen("input.txt", "r", stdin);
#endif
memset(dp, -1, sizeof(dp));
cin >> s1 >> s2;
len = recurse((ll)s1.length() - 1, (ll)s2.length() - 1);
print((ll)s1.length() - 1, (ll)s2.length() - 1);
reverse(an.begin(), an.end());
cout << an;
return 0;
} // good night.
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1));
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s.at(i) == t.at(j)) {
dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
} else {
if (dp.at(i + 1).at(j) > dp.at(i).at(j + 1)) {
dp.at(i + 1).at(j + 1) = dp.at(i + 1).at(j);
} else {
dp.at(i + 1).at(j + 1) = dp.at(i).at(j + 1);
}
}
}
}
string ans = "";
int i = s.size(), j = t.size();
while (i != 0 || j != 0) {
if (i - 1 >= 0 && j - 1 >= 0 &&
dp.at(i).at(j) == dp.at(i - 1).at(j - 1) + 1 && s.at(i) == t.at(j)) {
i--;
j--;
ans += s.at(i);
} else if (i - 1 >= 0 && dp.at(i).at(j) == dp.at(i - 1).at(j)) {
i--;
} else if (j - 1 >= 0 && dp.at(i).at(j) == dp.at(i).at(j - 1)) {
j--;
}
}
reverse(ALL(ans));
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1));
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s.at(i) == t.at(j)) {
dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
} else {
if (dp.at(i + 1).at(j) > dp.at(i).at(j + 1)) {
dp.at(i + 1).at(j + 1) = dp.at(i + 1).at(j);
} else {
dp.at(i + 1).at(j + 1) = dp.at(i).at(j + 1);
}
}
}
}
string ans = "";
int i = s.size(), j = t.size();
while (i != 0 || j != 0) {
if (i - 1 >= 0 && j - 1 >= 0 &&
dp.at(i).at(j) == dp.at(i - 1).at(j - 1) + 1 &&
s.at(i - 1) == t.at(j - 1)) {
i--;
j--;
ans += s.at(i);
} else if (i - 1 >= 0 && dp.at(i).at(j) == dp.at(i - 1).at(j)) {
i--;
} else if (j - 1 >= 0 && dp.at(i).at(j) == dp.at(i).at(j - 1)) {
j--;
}
}
reverse(ALL(ans));
cout << ans << endl;
}
|
replace
| 28 | 29 | 28 | 30 |
-6
|
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
string s, t;
ll n, m;
ll dp[4000][4000], vis[4000][4000];
string ans;
ll lcs(ll i, ll j) {
if (i >= n or j >= m)
return 0;
if (vis[i][j])
return dp[i][j];
if (s[i] == t[j]) {
dp[i][j] = 1 + lcs(i + 1, j + 1);
} else {
ll on = lcs(i + 1, j);
ll to = lcs(i, j + 1);
dp[i][j] = max(on, to);
}
return dp[i][j];
}
void print(ll i, ll j) {
if (i >= n or j >= m) {
cout << ans << endl;
return;
}
if (s[i] == t[j]) {
ans.pb(s[i]);
print(i + 1, j + 1);
} else {
if (dp[i + 1][j] > dp[i][j + 1])
print(i + 1, j);
else
print(i, j + 1);
}
}
int main() {
cin >> s >> t;
n = s.size(), m = t.size();
lcs(0, 0);
print(0, 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
string s, t;
ll n, m;
ll dp[4000][4000], vis[4000][4000];
string ans;
ll lcs(ll i, ll j) {
if (i >= n or j >= m)
return 0;
if (vis[i][j])
return dp[i][j];
if (s[i] == t[j]) {
dp[i][j] = 1 + lcs(i + 1, j + 1);
} else {
ll on = lcs(i + 1, j);
ll to = lcs(i, j + 1);
dp[i][j] = max(on, to);
}
vis[i][j] = 1;
return dp[i][j];
}
void print(ll i, ll j) {
if (i >= n or j >= m) {
cout << ans << endl;
return;
}
if (s[i] == t[j]) {
ans.pb(s[i]);
print(i + 1, j + 1);
} else {
if (dp[i + 1][j] > dp[i][j + 1])
print(i + 1, j);
else
print(i, j + 1);
}
}
int main() {
cin >> s >> t;
n = s.size(), m = t.size();
lcs(0, 0);
print(0, 0);
return 0;
}
|
insert
| 25 | 25 | 25 | 26 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define endl "\n"
#define si set<int>
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define mii map<int, int>
#define que_max priority_queue<int>
#define que_min priority_queue<int, vi, greater<int>>
#define loop(i, s, e) for (int i = s; i < e; i++)
#define rloop(i, e, s) for (int i = e; i >= s; i--)
#define mset(a, f) memset(a, f, sizeof(a))
#define M 1000000007
#define sz(x) ((int)x.size())
#define all(p) p.begin(), p.end()
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define print(a) \
for (auto x : a) \
cout << x << " "; \
cout << endl
#define Print(a, x, y) \
for (int i = x; i < y; i++) \
cout << a[i] << " "; \
cout << endl
inline int power(int a, int b) {
int x = 1;
while (b) {
if (b & 1)
x *= a;
a *= a;
b >>= 1;
}
return x;
}
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const int N = 3e5 + 7;
int dp[3005][3005];
void solve() {
string s, t;
cin >> s >> t;
int n1 = s.length();
int n2 = t.length();
s = " " + s;
t = " " + t;
mset(dp, 0);
loop(i, 1, n1 + 1) {
loop(j, 1, n2 + 1) {
if (s[i] == t[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
vector<char> v;
int x = n1, y = n2;
while (x > 0 and y > 0) {
if (s[x] == t[y]) {
v.pb(s[x]);
x--;
y--;
} else {
if (dp[x][y - 1] > dp[x - 1][y])
y = y - 1;
else
x = x - 1;
}
}
int cnt = v.size();
rloop(i, cnt - 1, 0) cout << v[i];
return;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cout << setprecision(9) << fixed;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define endl "\n"
#define si set<int>
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector<pii>
#define mii map<int, int>
#define que_max priority_queue<int>
#define que_min priority_queue<int, vi, greater<int>>
#define loop(i, s, e) for (int i = s; i < e; i++)
#define rloop(i, e, s) for (int i = e; i >= s; i--)
#define mset(a, f) memset(a, f, sizeof(a))
#define M 1000000007
#define sz(x) ((int)x.size())
#define all(p) p.begin(), p.end()
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define print(a) \
for (auto x : a) \
cout << x << " "; \
cout << endl
#define Print(a, x, y) \
for (int i = x; i < y; i++) \
cout << a[i] << " "; \
cout << endl
inline int power(int a, int b) {
int x = 1;
while (b) {
if (b & 1)
x *= a;
a *= a;
b >>= 1;
}
return x;
}
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const int N = 3e5 + 7;
int dp[3005][3005];
void solve() {
string s, t;
cin >> s >> t;
int n1 = s.length();
int n2 = t.length();
s = " " + s;
t = " " + t;
mset(dp, 0);
loop(i, 1, n1 + 1) {
loop(j, 1, n2 + 1) {
if (s[i] == t[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
vector<char> v;
int x = n1, y = n2;
while (x > 0 and y > 0) {
if (s[x] == t[y]) {
v.pb(s[x]);
x--;
y--;
} else {
if (dp[x][y - 1] > dp[x - 1][y])
y = y - 1;
else
x = x - 1;
}
}
int cnt = v.size();
rloop(i, cnt - 1, 0) cout << v[i];
return;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(9) << fixed;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
delete
| 104 | 109 | 104 | 104 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define mem(x) memset(x, 0, sizeof(x));
#define what_is(x) cerr << #x << " is " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;
void solve() {
string s, t;
cin >> s >> t;
int n = sz(s);
int m = sz(t);
int dp[n + 1][m + 1];
rep(i, 0, n + 1) {
rep(j, 0, m + 1) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else
dp[i][j] = max(dp[i - 1][j - 1] + (int)(s[i - 1] == t[j - 1]),
max(dp[i - 1][j], dp[i][j - 1]));
}
}
string ans = "";
int i = n, j = m;
while (j > 0 && i > 0) {
if (dp[i][j] == dp[i][j - 1]) {
j--;
} else if (s[i - 1] == t[j - 1]) {
ans += t[j - 1];
i--;
j--;
} else
i--;
}
reverse(all(ans));
cout << ans << endl;
}
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1, i = 1;
// cin>>t;
while (t--) {
// cout<<"Case #"<<i++<<": ";
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define mem(x) memset(x, 0, sizeof(x));
#define what_is(x) cerr << #x << " is " << x << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;
void solve() {
string s, t;
cin >> s >> t;
int n = sz(s);
int m = sz(t);
int dp[n + 1][m + 1];
rep(i, 0, n + 1) {
rep(j, 0, m + 1) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else
dp[i][j] = max(dp[i - 1][j - 1] + (int)(s[i - 1] == t[j - 1]),
max(dp[i - 1][j], dp[i][j - 1]));
}
}
string ans = "";
int i = n, j = m;
while (j > 0 && i > 0) {
if (dp[i][j] == dp[i][j - 1]) {
j--;
} else if (s[i - 1] == t[j - 1]) {
ans += t[j - 1];
i--;
j--;
} else
i--;
}
reverse(all(ans));
cout << ans << endl;
}
int main() {
// #ifndef ONLINE_JUDGE
// // for getting input from input.txt
// freopen("input.txt", "r", stdin);
// // for writing output to output.txt
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1, i = 1;
// cin>>t;
while (t--) {
// cout<<"Case #"<<i++<<": ";
solve();
}
return 0;
}
|
replace
| 62 | 68 | 62 | 68 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(), (a).end()
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _fromto2(i, n) for (int i = 0; i <= (n); ++i)
#define _fromto3(i, a, b) for (int i = (a); i <= (b); ++i)
#define fromto(...) _overload3(__VA_ARGS__, _fromto3, _fromto2, )(__VA_ARGS__)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++it)
const int MOD = 1e9 + 7;
const int INF = 1e9;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
// debug
template <class T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); ++i)
os << (i ? ", " : "") << vec[i];
os << "}";
return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &rhs) {
out << "(" << rhs.first << ", " << rhs.second << ")";
return out;
}
#include <type_traits>
template <
typename T, size_t SIZE,
enable_if_t<!is_same<remove_cv_t<T>, char>::value, nullptr_t> = nullptr>
ostream &operator<<(ostream &os, T (&arr)[SIZE]) {
os << "{";
for (size_t i = 0; i < SIZE; ++i)
os << (i ? ", " : "") << arr[i];
os << "}";
return os;
}
#ifdef LOCAL
#define debug(v) cerr << v << "\n"
#else
#define debug(...) 42
#endif
int main() {
string s, t;
cin >> s >> t;
int N = s.size(), M = t.size();
int dp[N + 1][M + 1];
rep(i, N + 1) rep(j, M + 1) dp[i][j] = 0;
rep(i, N) rep(j, M) {
if (s[i] == t[j])
dp[i + 1][j + 1] = 1 + dp[i][j];
else
dp[i + 1][j + 1] = max(dp[i][j + 1], max(dp[i + 1][j], dp[i][j]));
}
stack<char> st;
int lcs = dp[N][M];
int m = M;
rrep(i, N) {
if (dp[i][m] == lcs - 1) {
st.push(s[i]);
while (dp[i][m] == lcs - 1)
--m;
++m;
--lcs;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
cout << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(), (a).end()
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _fromto2(i, n) for (int i = 0; i <= (n); ++i)
#define _fromto3(i, a, b) for (int i = (a); i <= (b); ++i)
#define fromto(...) _overload3(__VA_ARGS__, _fromto3, _fromto2, )(__VA_ARGS__)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++it)
const int MOD = 1e9 + 7;
const int INF = 1e9;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
// debug
template <class T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); ++i)
os << (i ? ", " : "") << vec[i];
os << "}";
return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &rhs) {
out << "(" << rhs.first << ", " << rhs.second << ")";
return out;
}
#include <type_traits>
template <
typename T, size_t SIZE,
enable_if_t<!is_same<remove_cv_t<T>, char>::value, nullptr_t> = nullptr>
ostream &operator<<(ostream &os, T (&arr)[SIZE]) {
os << "{";
for (size_t i = 0; i < SIZE; ++i)
os << (i ? ", " : "") << arr[i];
os << "}";
return os;
}
#ifdef LOCAL
#define debug(v) cerr << v << "\n"
#else
#define debug(...) 42
#endif
int main() {
string s, t;
cin >> s >> t;
int N = s.size(), M = t.size();
int dp[N + 1][M + 1];
rep(i, N + 1) rep(j, M + 1) dp[i][j] = 0;
rep(i, N) rep(j, M) {
if (s[i] == t[j])
dp[i + 1][j + 1] = 1 + dp[i][j];
else
dp[i + 1][j + 1] = max(dp[i][j + 1], max(dp[i + 1][j], dp[i][j]));
}
stack<char> st;
int lcs = dp[N][M];
int m = M;
rrep(i, N) {
if (dp[i][m] == lcs - 1) {
st.push(s[i]);
while (m >= 0 && dp[i][m] == lcs - 1)
--m;
++m;
--lcs;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
cout << endl;
return 0;
}
|
replace
| 92 | 93 | 92 | 93 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) \
ll inp; \
cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
string s, t, ans = "";
ll dp[3010][3010], vis[3001][3001];
ll check(ll pos1, ll pos2) {
if (vis[pos1][pos2])
return dp[pos1][pos2];
vis[pos1][pos2] = 1;
if (pos1 == s.length() or pos2 == t.length())
return 0;
if (s[pos1] == t[pos2]) {
dp[pos1][pos2] += 1 + check(pos1 + 1, pos2 + 1);
} else
dp[pos1][pos2] +=
max(check(pos1 + 1, pos2),
max(check(pos1, pos2 + 1), check(pos1 + 1, pos2 + 1)));
return dp[pos1][pos2];
}
void solve() {
cin >> s >> t;
check(0, 0);
ll i = 1, j = 1;
while (i <= s.length() and j <= t.length()) {
// what(i)
if (dp[i][j] + 1 == dp[i - 1][j - 1] and s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i++, j++;
} else if (dp[i - 1][j] == dp[i][j])
i++;
else if ((dp[i][j - 1] == dp[i][j]))
j++;
}
// reverse(all(ans));
cout << ans;
}
int main() {
fastio
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
ll test = 1;
// cin >> test;
while (test--) {
solve();
}
}
|
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) \
ll inp; \
cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
string s, t, ans = "";
ll dp[3010][3010], vis[3001][3001];
ll check(ll pos1, ll pos2) {
if (vis[pos1][pos2])
return dp[pos1][pos2];
vis[pos1][pos2] = 1;
if (pos1 == s.length() or pos2 == t.length())
return 0;
if (s[pos1] == t[pos2]) {
dp[pos1][pos2] += 1 + check(pos1 + 1, pos2 + 1);
} else
dp[pos1][pos2] +=
max(check(pos1 + 1, pos2),
max(check(pos1, pos2 + 1), check(pos1 + 1, pos2 + 1)));
return dp[pos1][pos2];
}
void solve() {
cin >> s >> t;
check(0, 0);
ll i = 1, j = 1;
while (i <= s.length() and j <= t.length()) {
// what(i)
if (dp[i][j] + 1 == dp[i - 1][j - 1] and s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i++, j++;
} else if (dp[i - 1][j] == dp[i][j])
i++;
else
j++;
}
// reverse(all(ans));
cout << ans;
}
int main() {
fastio
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
ll test = 1;
// cin >> test;
while (test--) {
solve();
}
}
|
replace
| 48 | 49 | 48 | 49 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout << #a << ":" << a << endl;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
int maxn, minn;
int T, n;
string s1, s2;
int len1, len2;
int dp[4010][4010];
int main() {
cin >> s1 >> s2;
len1 = s1.size();
len2 = s2.size();
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (s1[i - 1] == s2[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 s = "";
int i = len1, j = len2;
while (i + j > 2) {
if (dp[i][j] == dp[i - 1][j - 1] + 1) {
s += s1[i - 1];
i--, j--;
} else {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
}
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout << #a << ":" << a << endl;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
int maxn, minn;
int T, n;
string s1, s2;
int len1, len2;
int dp[4010][4010];
int main() {
cin >> s1 >> s2;
len1 = s1.size();
len2 = s2.size();
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (s1[i - 1] == s2[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 s = "";
int i = len1, j = len2;
while (i != 0 && j != 0) {
if (s1[i - 1] == s2[j - 1]) {
s += s1[i - 1];
i--, j--;
} else {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
}
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
}
|
replace
| 28 | 30 | 28 | 30 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <cstring>
#include <iostream>
using namespace std;
char s[3001], t[3001];
int n, m, i, j, a[3001][3001];
int main() {
cin >> s >> t;
n = strlen(s);
m = strlen(t);
for (i = n; i > 0; i--) {
for (j = m; j > 0; j--) {
if (s[i - 1] == t[j - 1]) {
a[i][j] = a[i + 1][j + 1] + 1;
} else
a[i][j] = max(a[i][j + 1], a[i + 1][j]);
}
}
i = 1, j = 1;
while (i <= n && j <= m) {
if (s[i - 1] == t[j - 1]) {
cout << s[i - 1];
i++, j++;
} else {
if (a[i + 1][j] > a[i][j + 1]) {
i++;
} else
j++;
}
}
return 0;
}
|
#include <cstring>
#include <iostream>
using namespace std;
char s[3003], t[3003];
int n, m, i, j, a[3003][3003];
int main() {
cin >> s >> t;
n = strlen(s);
m = strlen(t);
for (i = n; i > 0; i--) {
for (j = m; j > 0; j--) {
if (s[i - 1] == t[j - 1]) {
a[i][j] = a[i + 1][j + 1] + 1;
} else
a[i][j] = max(a[i][j + 1], a[i + 1][j]);
}
}
i = 1, j = 1;
while (i <= n && j <= m) {
if (s[i - 1] == t[j - 1]) {
cout << s[i - 1];
i++, j++;
} else {
if (a[i + 1][j] > a[i][j + 1]) {
i++;
} else
j++;
}
}
return 0;
}
|
replace
| 3 | 5 | 3 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
// https://atcoder.jp/contests/dp/tasks/dp_f
// shauryakr
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[3005][3005];
void solve() {
for (int i = 1; i <= a.length(); i++) {
for (int j = 1; j <= b.length(); j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
}
// for(int i=0; i<=b.length(); i++)
// {
// for(int j=0; j<=a.length(); j++)
// {
// cout << dp[j][i] << " ";
// }
// cout << endl;
// }
int i = a.length(), j = b.length();
string subseq = "";
while (i != 0 || j != 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
subseq = subseq + a[i - 1];
i--;
j--;
}
}
reverse(subseq.begin(), subseq.end());
cout << subseq << endl;
}
int main() {
cin >> a >> b;
solve();
return 0;
}
|
// https://atcoder.jp/contests/dp/tasks/dp_f
// shauryakr
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[3005][3005];
void solve() {
for (int i = 1; i <= a.length(); i++) {
for (int j = 1; j <= b.length(); j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
}
// for(int i=0; i<=b.length(); i++)
// {
// for(int j=0; j<=a.length(); j++)
// {
// cout << dp[j][i] << " ";
// }
// cout << endl;
// }
int i = a.length(), j = b.length();
string subseq = "";
while (i != 0 && j != 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
subseq = subseq + a[i - 1];
i--;
j--;
}
}
reverse(subseq.begin(), subseq.end());
cout << subseq << endl;
}
int main() {
cin >> a >> b;
solve();
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, n, m, dp[10000][10000];
string s, t, str;
cin >> s;
cin >> t;
n = s.size();
m = t.size();
for (i = 0; i <= n; i++) {
for (j = 0; j <= m; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
i = s.size();
j = t.size();
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
str.push_back(s[i - 1]);
i--;
j--;
} else {
if (dp[i][j - 1] > dp[i - 1][j])
j--;
else
i--;
}
}
n = str.size();
for (i = n - 1; i >= 0; i--)
cout << str[i];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, n, m, dp[3003][3003];
string s, t, str;
cin >> s;
cin >> t;
n = s.size();
m = t.size();
for (i = 0; i <= n; i++) {
for (j = 0; j <= m; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
i = s.size();
j = t.size();
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
str.push_back(s[i - 1]);
i--;
j--;
} else {
if (dp[i][j - 1] > dp[i - 1][j])
j--;
else
i--;
}
}
n = str.size();
for (i = n - 1; i >= 0; i--)
cout << str[i];
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <functional>
#include <stdio.h>
using namespace std;
#define ll int
#define dd long double
#define pb push_back
#define pf push_front
#define pi pair<ll, ll>
#define vi vector<ll>
#define vpi vector<pi>
#define mi map<ll, ll>
#define vvi vector<vector<ll>>
#define mpi map<pi, ll>
#define pipi pair<ll, pair<ll, ll>>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define g endl
#define PI 3.141592653589
#define bs(v, n) binary_search(all((v)), (n))
#define lb(v, n) lower_bound(all((v)), (n))
#define ub(v, n) upper_bound(all((v)), (n))
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define rf(s) for (auto &c : s)
#define allfo(s) \
for (auto it = (s).begin(); it != (s).end(); it++) // use Iterator
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define M 998244353
#define ef else if
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define C continue;
#define wa(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
#define debug(vec) \
cout << (#vec) << ": "; \
for (auto &i : vec) \
cout << i << " "; \
cout << endl
#define debugp(vec) \
cout << (#vec) << ": "; \
for (auto &i : vec) \
cout << i.x << "," << i.y << " | "; \
cout << endl
const ll N = 1e5 + 5;
#include <ext/pb_ds/assoc_container.hpp> //common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<pi, null_type, less<pi>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define fbo find_by_order
#define ook order_of_key
// const ll inf=1e17+7;
/*
template<class T>
T big(T a, T b) { return a>b ? a : b; }*/
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
/*
ll lcm(ll a, ll b) { return (a*b)/gcd(a,b); }
bool M(double a,double b) {return a/b - floor(a/b);}
ll occurs(vi v,ll n) { auto it=lb(v,n);auto it1=ub(v,n);ll x=it1-it;return x;}
ll logb(ll base, ll x) {return (log(x) / log(base));}*/
ll power(ll x, ll y) {
ll res = 1; // Initialize result
x %= M;
if (x == 0)
return 0;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % M;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % M; // Change x to x^2
}
return res;
} /*
ll factors(ll ans){
ll count=0;
for (ll i=1; i<=sqrt(ans); i++) {
if (ans%i == 0)
{if (ans/i == i) count++;
else count+=2;}
}
return count;
}
bool isSubSequence(string str1, string str2, ll m, ll n) // str1<str2
{
if (m == 0) return true;
if (n == 0) return false;
if (str1[m-1] == str2[n-1])
return isSubSequence(str1, str2, m-1, n-1);
return isSubSequence(str1, str2, m, n-1);
}
bool search(int x[], int n, int k) {
int p = 0;
for (int a = n; a >= 1; a /= 2) {
while (p+a < n && x[p+a] <= k) p += a;
}
return x[p] == k;
}
*/
string s, t2;
ll t1[3001][3001];
ll solve(ll n, ll m) {
if (n == -1 || m == -1)
return 0;
if (t1[n][m] != -1)
return t1[n][m];
if (s[n] == t2[m])
return t1[n][m] = 1 + solve(n - 1, m - 1);
return t1[n][m] = max(solve(n - 1, m), solve(n, m - 1));
}
signed main() {
tezz ll t = 1;
// cin>>t;
while (t--) {
ll i, j;
cin >> s >> t2;
ll n = s.length();
ll m = t2.length();
fo(i, 0, 3001) {
fo(j, 0, 3001) { t1[i][j] = -1; }
}
string s1 = "";
ll ans = solve(n - 1, m - 1);
i = n - 1, j = m - 1;
while (1) {
if (s[i] == t2[j]) {
s1 += s[i];
i--;
j--;
} else {
if (t1[i - 1][j] > t1[i][j - 1]) {
if (i > 0)
i--;
else
j--;
} else {
if (j > 0)
j--;
else
i--;
}
}
if (i < 0 || j < 0)
break;
}
rfo(i, s1.length() - 1, 0) { cout << s1[i]; }
cout << g;
}
return 0;
}
|
#include <bits/stdc++.h>
#include <functional>
#include <stdio.h>
using namespace std;
#define ll int
#define dd long double
#define pb push_back
#define pf push_front
#define pi pair<ll, ll>
#define vi vector<ll>
#define vpi vector<pi>
#define mi map<ll, ll>
#define vvi vector<vector<ll>>
#define mpi map<pi, ll>
#define pipi pair<ll, pair<ll, ll>>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define g endl
#define PI 3.141592653589
#define bs(v, n) binary_search(all((v)), (n))
#define lb(v, n) lower_bound(all((v)), (n))
#define ub(v, n) upper_bound(all((v)), (n))
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define rf(s) for (auto &c : s)
#define allfo(s) \
for (auto it = (s).begin(); it != (s).end(); it++) // use Iterator
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define M 998244353
#define ef else if
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define C continue;
#define wa(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
#define debug(vec) \
cout << (#vec) << ": "; \
for (auto &i : vec) \
cout << i << " "; \
cout << endl
#define debugp(vec) \
cout << (#vec) << ": "; \
for (auto &i : vec) \
cout << i.x << "," << i.y << " | "; \
cout << endl
const ll N = 1e5 + 5;
#include <ext/pb_ds/assoc_container.hpp> //common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<pi, null_type, less<pi>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define fbo find_by_order
#define ook order_of_key
// const ll inf=1e17+7;
/*
template<class T>
T big(T a, T b) { return a>b ? a : b; }*/
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
/*
ll lcm(ll a, ll b) { return (a*b)/gcd(a,b); }
bool M(double a,double b) {return a/b - floor(a/b);}
ll occurs(vi v,ll n) { auto it=lb(v,n);auto it1=ub(v,n);ll x=it1-it;return x;}
ll logb(ll base, ll x) {return (log(x) / log(base));}*/
ll power(ll x, ll y) {
ll res = 1; // Initialize result
x %= M;
if (x == 0)
return 0;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % M;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % M; // Change x to x^2
}
return res;
} /*
ll factors(ll ans){
ll count=0;
for (ll i=1; i<=sqrt(ans); i++) {
if (ans%i == 0)
{if (ans/i == i) count++;
else count+=2;}
}
return count;
}
bool isSubSequence(string str1, string str2, ll m, ll n) // str1<str2
{
if (m == 0) return true;
if (n == 0) return false;
if (str1[m-1] == str2[n-1])
return isSubSequence(str1, str2, m-1, n-1);
return isSubSequence(str1, str2, m, n-1);
}
bool search(int x[], int n, int k) {
int p = 0;
for (int a = n; a >= 1; a /= 2) {
while (p+a < n && x[p+a] <= k) p += a;
}
return x[p] == k;
}
*/
string s, t2;
ll t1[3001][3001];
ll solve(ll n, ll m) {
if (n == -1 || m == -1)
return 0;
if (t1[n][m] != -1)
return t1[n][m];
if (s[n] == t2[m])
return t1[n][m] = 1 + solve(n - 1, m - 1);
return t1[n][m] = max(solve(n - 1, m), solve(n, m - 1));
}
signed main() {
tezz ll t = 1;
// cin>>t;
while (t--) {
ll i, j;
cin >> s >> t2;
ll n = s.length();
ll m = t2.length();
fo(i, 0, 3001) {
fo(j, 0, 3001) { t1[i][j] = -1; }
}
string s1 = "";
ll ans = solve(n - 1, m - 1);
i = n - 1, j = m - 1;
while (1) {
if (s[i] == t2[j]) {
s1 += s[i];
i--;
j--;
} else {
if (i == 0)
j--;
else if (j == 0)
i--;
else if (t1[i - 1][j] > t1[i][j - 1]) {
if (i > 0)
i--;
else
j--;
} else {
if (j > 0)
j--;
else
i--;
}
}
if (i < 0 || j < 0)
break;
}
rfo(i, s1.length() - 1, 0) { cout << s1[i]; }
cout << g;
}
return 0;
}
|
replace
| 164 | 165 | 164 | 169 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int len(string &s, string &t, int i, int j, vector<vector<int>> &dp) {
if (i >= s.length() || j >= t.length()) {
return 0;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
if (s[i] == t[j]) {
return dp[i][j] = 1 + len(s, t, i + 1, j + 1, dp);
} else {
int option1 = len(s, t, i + 1, j, dp);
int option2 = len(s, t, i, j + 1, dp);
return dp[i][j] = max(option1, option2);
}
}
string get_lcs(string &s, string &t, int l, vector<vector<int>> &dp) {
string str;
str.reserve(l);
int i = 0, j = 0;
while (l > 0) {
if (s[i] == t[j]) {
str.push_back(s[i]);
++i;
++j;
--l;
} else {
if (dp[i + 1][j] > dp[i][j + 1]) {
++i;
} else {
++j;
}
}
}
return str;
}
int main() {
string s, t;
cin >> s >> t;
int n = s.length();
int m = t.length();
vector<vector<int>> dp(n, vector<int>(m, -1));
int l = len(s, t, 0, 0, dp);
cout << get_lcs(s, t, l, dp);
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int len(string &s, string &t, int i, int j, vector<vector<int>> &dp) {
if (i >= s.length() || j >= t.length()) {
return 0;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
if (s[i] == t[j]) {
return dp[i][j] = 1 + len(s, t, i + 1, j + 1, dp);
} else {
int option1 = len(s, t, i + 1, j, dp);
int option2 = len(s, t, i, j + 1, dp);
return dp[i][j] = max(option1, option2);
}
}
string get_lcs(string &s, string &t, int l, vector<vector<int>> &dp) {
string str;
str.reserve(l);
int i = 0, j = 0;
while (l > 0) {
if (s[i] == t[j]) {
str.push_back(s[i]);
++i;
++j;
--l;
} else {
if (dp[i + 1][j] > dp[i][j + 1]) {
++i;
} else {
++j;
}
}
}
return str;
}
int main() {
string s, t;
cin >> s >> t;
int n = s.length();
int m = t.length();
vector<vector<int>> dp(n + 1, vector<int>(m + 1, -1));
int l = len(s, t, 0, 0, dp);
cout << get_lcs(s, t, l, dp);
return 0;
}
|
replace
| 47 | 48 | 47 | 48 |
0
| |
p03165
|
C++
|
Runtime Error
|
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** ******* *** ************* **
*** ******** ** *************** *
**********_**********************
* | / / \ \ / /\ *
* | / | | \ / / \ *
* | / | | \ / / \ *
* |+\ | | | /______\ *
* | \ | | | | | *
* | \ \_/ | | | *
********************************/
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout << '\n'
#define TEST cout << "TEST", nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a < b) ? b : a))
#define remin(a, b) (a = ((a < b) ? a : b))
#define pr pair<lli, lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout << fixed << setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr>
#define P pair<lli, pr>
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define NA(i, s, n) for (lli i = s; i < n; i++)
using namespace std;
lli power(lli x, lli y, lli p) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
const lli N = 3e3 + 2;
lli dp[N][N], n, m;
string s, t;
void solve() {
cin >> s >> t;
n = s.size(), m = t.size();
memset(dp, 0, sizeof dp);
NA(i, 1, n + 1) {
NA(j, 1, m + 1) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i - 1] == t[j - 1]) {
remax(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
string res = "";
if (!dp[n][m]) {
cout << res;
return;
}
lli i = n, j = m;
while (i > 0 || j > 0) {
if (dp[i][j] == dp[i - 1][j - 1] + 1 && s[i - 1] == t[j - 1])
res += s[i - 1], --i, --j;
else if (dp[i][j - 1] == dp[i][j])
--j;
else
--i;
}
reverse(all(res));
cout << res;
return;
}
int main() {
fastIO;
lli t = 1;
// cin>>t;
NA(i, 0, t) { solve(); }
return 0;
}
|
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** ******* *** ************* **
*** ******** ** *************** *
**********_**********************
* | / / \ \ / /\ *
* | / | | \ / / \ *
* | / | | \ / / \ *
* |+\ | | | /______\ *
* | \ | | | | | *
* | \ \_/ | | | *
********************************/
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout << '\n'
#define TEST cout << "TEST", nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a < b) ? b : a))
#define remin(a, b) (a = ((a < b) ? a : b))
#define pr pair<lli, lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout << fixed << setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr>
#define P pair<lli, pr>
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define NA(i, s, n) for (lli i = s; i < n; i++)
using namespace std;
lli power(lli x, lli y, lli p) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
const lli N = 3e3 + 2;
lli dp[N][N], n, m;
string s, t;
void solve() {
cin >> s >> t;
n = s.size(), m = t.size();
memset(dp, 0, sizeof dp);
NA(i, 1, n + 1) {
NA(j, 1, m + 1) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i - 1] == t[j - 1]) {
remax(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
string res = "";
if (!dp[n][m]) {
cout << res;
return;
}
lli i = n, j = m;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j - 1] + 1 && s[i - 1] == t[j - 1])
res += s[i - 1], --i, --j;
else if (dp[i][j - 1] == dp[i][j])
--j;
else
--i;
}
reverse(all(res));
cout << res;
return;
}
int main() {
fastIO;
lli t = 1;
// cin>>t;
NA(i, 0, t) { solve(); }
return 0;
}
|
replace
| 81 | 82 | 81 | 82 |
0
| |
p03165
|
C++
|
Runtime Error
|
/**
* author: bholuakku
**/
#include <bits/stdc++.h>
#define For(i, a, b) for (i = (a); i < (b); i++)
#define rep(i, n) for (i = 0; i < (n); i++)
#define Nfor(i, a, b) for (i = (a)-1; i >= (b); i--)
#define dep(i, n) for (i = (n - 1); i >= 0; i--)
#define mp make_pair
#define pb push_back
#define Auto(a) for (auto &val : a)
#define X first
#define Y second
#define MOD 1000000007
#define MOD1 998244353
#define iterate(A, i) for (auto i = A.begin(); i != A.end(); i++)
#define mset(A, val, n) memset(A, val, n * sizeof(int))
#define Endl cout << "\n"
#define Test cout << "Hello\n"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> pii;
typedef vector<vector<pair<int, int>>> vvp;
int power(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int modInverse(ll n) {
ll p = MOD;
return power(n, p - 2, p);
}
int min(int a, int b, int c) { return min(a, min(b, c)); }
int max(int a, int b, int c) { return max(a, max(b, c)); }
inline void swap(int &a, int &b) {
int t = a;
a = b;
b = t;
}
bool cmp(int a, int b) { return a > b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\ACER\\Desktop\\Codes\\input.txt", "r", stdin);
#endif
string s1, s2;
int i, j;
cin >> s1 >> s2;
s1 = " " + s1;
s2 = " " + s2;
int l1 = s1.size(), l2 = s2.size();
int dp[l1][l2];
rep(i, l1) {
rep(j, l2) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
if (s1[i] == s2[j])
dp[i][j] = dp[i - 1][j - 1] + 1;
else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
}
string ans = "";
i = l1 - 1;
j = l2 - 1;
while (i && j) {
if (s1[i] == s2[j]) {
ans.pb(s1[i]);
i--, j--;
} else if (dp[i][j] == dp[i - 1][j])
i--;
else
j--;
}
l1 = ans.size();
rep(i, l1) cout << ans[l1 - 1 - i];
return 0;
}
|
/**
* author: bholuakku
**/
#include <bits/stdc++.h>
#define For(i, a, b) for (i = (a); i < (b); i++)
#define rep(i, n) for (i = 0; i < (n); i++)
#define Nfor(i, a, b) for (i = (a)-1; i >= (b); i--)
#define dep(i, n) for (i = (n - 1); i >= 0; i--)
#define mp make_pair
#define pb push_back
#define Auto(a) for (auto &val : a)
#define X first
#define Y second
#define MOD 1000000007
#define MOD1 998244353
#define iterate(A, i) for (auto i = A.begin(); i != A.end(); i++)
#define mset(A, val, n) memset(A, val, n * sizeof(int))
#define Endl cout << "\n"
#define Test cout << "Hello\n"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> pii;
typedef vector<vector<pair<int, int>>> vvp;
int power(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int modInverse(ll n) {
ll p = MOD;
return power(n, p - 2, p);
}
int min(int a, int b, int c) { return min(a, min(b, c)); }
int max(int a, int b, int c) { return max(a, max(b, c)); }
inline void swap(int &a, int &b) {
int t = a;
a = b;
b = t;
}
bool cmp(int a, int b) { return a > b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, s2;
int i, j;
cin >> s1 >> s2;
s1 = " " + s1;
s2 = " " + s2;
int l1 = s1.size(), l2 = s2.size();
int dp[l1][l2];
rep(i, l1) {
rep(j, l2) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
if (s1[i] == s2[j])
dp[i][j] = dp[i - 1][j - 1] + 1;
else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
}
string ans = "";
i = l1 - 1;
j = l2 - 1;
while (i && j) {
if (s1[i] == s2[j]) {
ans.pb(s1[i]);
i--, j--;
} else if (dp[i][j] == dp[i - 1][j])
i--;
else
j--;
}
l1 = ans.size();
rep(i, l1) cout << ans[l1 - 1 - i];
return 0;
}
|
delete
| 61 | 64 | 61 | 61 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(), v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl
const int N = 3000;
ll dp[100][N];
int n, m;
string s, w;
ll calc(int i, int j) {
if (i == n || j == m)
return 0;
ll &ret = dp[i][j];
if (~ret)
return ret;
if (s[i] == w[j])
ret = calc(i + 1, j + 1) + 1;
else
ret = max(calc(i + 1, j), calc(i, j + 1));
return ret;
}
void display(int i, int j) {
if (i == n || j == m)
return;
if (s[i] == w[j]) {
cout << s[i];
display(i + 1, j + 1);
return;
}
if (calc(i, j) == calc(i + 1, j))
display(i + 1, j);
else
display(i, j + 1);
}
void Suhaib_Sawalha() {
cin >> s >> w;
n = s.size();
m = w.size();
memset(dp, -1, sizeof dp);
calc(0, 0);
display(0, 0);
}
int main() {
In_The_Name_Of_Allah_The_Merciful /* بسم الله الرحمن الرحيم */
#ifndef ONLINE_JUDGE
freopen("SuhaibSawalha1.txt", "r", stdin);
#endif
// int _;for(cin>>_;_;--_,cout<<'\n')
Suhaib_Sawalha();
Alhamdulillah /* الحمد لله */
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(), v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl
const int N = 3000;
ll dp[N][N];
int n, m;
string s, w;
ll calc(int i, int j) {
if (i == n || j == m)
return 0;
ll &ret = dp[i][j];
if (~ret)
return ret;
if (s[i] == w[j])
ret = calc(i + 1, j + 1) + 1;
else
ret = max(calc(i + 1, j), calc(i, j + 1));
return ret;
}
void display(int i, int j) {
if (i == n || j == m)
return;
if (s[i] == w[j]) {
cout << s[i];
display(i + 1, j + 1);
return;
}
if (calc(i, j) == calc(i + 1, j))
display(i + 1, j);
else
display(i, j + 1);
}
void Suhaib_Sawalha() {
cin >> s >> w;
n = s.size();
m = w.size();
memset(dp, -1, sizeof dp);
calc(0, 0);
display(0, 0);
}
int main() {
In_The_Name_Of_Allah_The_Merciful /* بسم الله الرحمن الرحيم */
#ifndef ONLINE_JUDGE
freopen("SuhaibSawalha1.txt", "r", stdin);
#endif
// int _;for(cin>>_;_;--_,cout<<'\n')
Suhaib_Sawalha();
Alhamdulillah /* الحمد لله */
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define in(v) \
v; \
cin >> v;
#define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i)
#define rrep(i, n) for (long long i = (n); i >= 0; --i)
int main() {
string in(s);
string in(t);
int N = s.size(), M = t.size();
int dp[N + 1][M + 1];
rep(i, N + 1) rep(j, M + 1) dp[i][j] = 0;
rep(i, N) rep(j, M) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i][j], max(dp[i + 1][j], dp[i][j + 1]));
}
string ans;
int m = M;
int lcs = dp[N][M];
rrep(i, N) {
if (dp[i][m] != lcs) {
ans += s[i];
--lcs;
while (dp[i][m - 1] == lcs)
--m;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define in(v) \
v; \
cin >> v;
#define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i)
#define rrep(i, n) for (long long i = (n); i >= 0; --i)
int main() {
string in(s);
string in(t);
int N = s.size(), M = t.size();
int dp[N + 1][M + 1];
rep(i, N + 1) rep(j, M + 1) dp[i][j] = 0;
rep(i, N) rep(j, M) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i][j], max(dp[i + 1][j], dp[i][j + 1]));
}
string ans;
int m = M;
int lcs = dp[N][M];
rrep(i, N) {
if (dp[i][m] != lcs) {
ans += s[i];
--lcs;
while (m - 1 >= 0 && dp[i][m - 1] == lcs)
--m;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
#define pvec(vec) \
{ \
for (auto v : vec) \
cout << v << ' '; \
cout << endl; \
}
#define pivec(vec) \
{ \
rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; \
cout << endl; \
}
using namespace std;
using ll = long long;
int main() {
string s, t;
cin >> s >> t;
s += '$';
t += '$';
vector<vector<int>> dp(3010, vector<int>(3010, -1));
vector<vector<pair<int, int>>> par(3000,
vector<pair<int, int>>(3000, {-1, -1}));
dp[0][0] = 0;
rep(spos, 0, s.size() + 1) rep(tpos, 0, t.size() + 1) {
if (s[spos] == t[tpos] and dp[spos + 1][tpos + 1] < dp[spos][tpos] + 1) {
dp[spos + 1][tpos + 1] = dp[spos][tpos] + 1;
par[spos + 1][tpos + 1] = make_pair(spos, tpos);
}
if (dp[spos + 1][tpos] < dp[spos][tpos]) {
dp[spos + 1][tpos] = dp[spos][tpos];
par[spos + 1][tpos] = make_pair(spos, tpos);
}
if (dp[spos][tpos + 1] < dp[spos][tpos]) {
dp[spos][tpos + 1] = dp[spos][tpos];
par[spos][tpos + 1] = make_pair(spos, tpos);
}
}
// cout << dp[s.size()][t.size()] << endl;
string res = "";
pair<int, int> now = {s.size(), t.size()};
while (now.first > 0 and now.second > 0) {
pair<int, int> prev = par[now.first][now.second];
// cout << now.first << ' ' << now.second << ' ' << prev.first << ' ' <<
// prev.second << endl;
if (now.first - prev.first + now.second - prev.second == 2)
res += s[prev.first];
swap(prev, now);
}
reverse(res.begin(), res.end());
res.pop_back();
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
#define pvec(vec) \
{ \
for (auto v : vec) \
cout << v << ' '; \
cout << endl; \
}
#define pivec(vec) \
{ \
rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; \
cout << endl; \
}
using namespace std;
using ll = long long;
int main() {
string s, t;
cin >> s >> t;
s += '$';
t += '$';
vector<vector<int>> dp(3010, vector<int>(3010, -1));
vector<vector<pair<int, int>>> par(3100,
vector<pair<int, int>>(3100, {-1, -1}));
dp[0][0] = 0;
rep(spos, 0, s.size() + 1) rep(tpos, 0, t.size() + 1) {
if (s[spos] == t[tpos] and dp[spos + 1][tpos + 1] < dp[spos][tpos] + 1) {
dp[spos + 1][tpos + 1] = dp[spos][tpos] + 1;
par[spos + 1][tpos + 1] = make_pair(spos, tpos);
}
if (dp[spos + 1][tpos] < dp[spos][tpos]) {
dp[spos + 1][tpos] = dp[spos][tpos];
par[spos + 1][tpos] = make_pair(spos, tpos);
}
if (dp[spos][tpos + 1] < dp[spos][tpos]) {
dp[spos][tpos + 1] = dp[spos][tpos];
par[spos][tpos + 1] = make_pair(spos, tpos);
}
}
// cout << dp[s.size()][t.size()] << endl;
string res = "";
pair<int, int> now = {s.size(), t.size()};
while (now.first > 0 and now.second > 0) {
pair<int, int> prev = par[now.first][now.second];
// cout << now.first << ' ' << now.second << ' ' << prev.first << ' ' <<
// prev.second << endl;
if (now.first - prev.first + now.second - prev.second == 2)
res += s[prev.first];
swap(prev, now);
}
reverse(res.begin(), res.end());
res.pop_back();
cout << res << endl;
return 0;
}
|
replace
| 26 | 28 | 26 | 28 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define in insert
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n]
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
int32_t main() {
FIO;
string a, b;
cin >> a >> b;
int dp[a.length() + 1][b.length() + 1];
for (int i = 0; i <= (int)a.length(); i++) {
for (int j = 0; j <= (int)b.length(); j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
string ans;
int n = a.length(), m = b.length();
while (n > 0 || m > 0) {
if (dp[n][m] == dp[n - 1][m])
n--;
else if (dp[n][m] == dp[n][m - 1])
m--;
else
ans += a[n - 1], n--, m--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define in insert
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n]
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
int32_t main() {
FIO;
string a, b;
cin >> a >> b;
int dp[a.length() + 1][b.length() + 1];
for (int i = 0; i <= (int)a.length(); i++) {
for (int j = 0; j <= (int)b.length(); j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
string ans;
int n = a.length(), m = b.length();
while (n > 0 && m > 0) {
if (dp[n][m] == dp[n - 1][m])
n--;
else if (dp[n][m] == dp[n][m - 1])
m--;
else
ans += a[n - 1], n--, m--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 61 | 62 | 61 | 62 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
string x;
int dp[3001][3001], ans = 0;
// vector<vector<string> >dp;
int fn(int i, int j, string s, string t) {
if (i == 0 || j == 0)
return 0;
if (dp[i][j] != -1) {
return dp[i][j];
}
if (s[i - 1] == t[j - 1]) {
x += s[i - 1];
ans = fn(i - 1, j - 1, s, t) + 1;
dp[i][j] = ans;
return ans;
}
ans = max(fn(i - 1, j, s, t), fn(i, j - 1, s, t));
dp[i][j] = ans;
return ans;
}
int main() {
string s, t, a;
cin >> s >> t;
for (int i = 0; i <= s.size(); i++)
for (int j = 0; j <= t.size(); j++)
dp[i][j] = -1;
int i = s.size(), j = t.size();
int y = fn(i, j, s, t);
// cout<<dp[i][j];
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
a += s[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
reverse(a.begin(), a.end());
cout << a;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
string x;
int dp[3001][3001], ans = 0;
// vector<vector<string> >dp;
int fn(int i, int j, string &s, string &t) {
if (i == 0 || j == 0)
return 0;
if (dp[i][j] != -1) {
return dp[i][j];
}
if (s[i - 1] == t[j - 1]) {
x += s[i - 1];
ans = fn(i - 1, j - 1, s, t) + 1;
dp[i][j] = ans;
return ans;
}
ans = max(fn(i - 1, j, s, t), fn(i, j - 1, s, t));
dp[i][j] = ans;
return ans;
}
int main() {
string s, t, a;
cin >> s >> t;
for (int i = 0; i <= s.size(); i++)
for (int j = 0; j <= t.size(); j++)
dp[i][j] = -1;
int i = s.size(), j = t.size();
int y = fn(i, j, s, t);
// cout<<dp[i][j];
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
a += s[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
reverse(a.begin(), a.end());
cout << a;
}
|
replace
| 7 | 8 | 7 | 8 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e3 + 2;
string s, t;
int n, m, dp[mxN][mxN];
pair<int, int> parent[mxN][mxN];
int calc(int i, int j) {
if (i < 0 || j < 0)
return 0;
return dp[i][j];
}
int main() {
cin >> s >> t;
n = s.length();
m = t.length();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = 0;
if (calc(i - 1, j) >= dp[i][j]) {
parent[i][j] = {i - 1, j};
dp[i][j] = calc(i - 1, j);
}
if (calc(i, j - 1) >= dp[i][j]) {
parent[i][j] = {i, j - 1};
dp[i][j] = calc(i, j - 1);
}
if (s[i] == t[j] && calc(i - 1, j - 1) + 1 >= dp[i][j]) {
parent[i][j] = {i - 1, j - 1};
dp[i][j] = calc(i - 1, j - 1) + 1;
}
}
}
string ret = "";
pair<int, int> cur = {n - 1, m - 1};
while (cur.first >= 0 && cur.second >= 0) {
if (s[cur.first] == t[cur.second])
ret.push_back(s[cur.first]);
cur = parent[cur.first][cur.second];
}
reverse(ret.begin(), ret.end());
cout << ret << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e3 + 2;
string s, t;
int n, m, dp[mxN][mxN];
pair<int, int> parent[mxN][mxN];
int calc(int i, int j) {
if (i < 0 || j < 0)
return 0;
return dp[i][j];
}
int main() {
cin >> s >> t;
n = s.length();
m = t.length();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = 0;
if (calc(i - 1, j) >= dp[i][j]) {
parent[i][j] = {i - 1, j};
dp[i][j] = calc(i - 1, j);
}
if (calc(i, j - 1) >= dp[i][j]) {
parent[i][j] = {i, j - 1};
dp[i][j] = calc(i, j - 1);
}
if (s[i] == t[j] && calc(i - 1, j - 1) + 1 >= dp[i][j]) {
parent[i][j] = {i - 1, j - 1};
dp[i][j] = calc(i - 1, j - 1) + 1;
}
}
}
string ret = "";
pair<int, int> cur = {n - 1, m - 1};
while (cur.first >= 0 && cur.second >= 0) {
if (s[cur.first] == t[cur.second])
ret.push_back(s[cur.first]);
cur = parent[cur.first][cur.second];
}
reverse(ret.begin(), ret.end());
cout << ret << endl;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FasterIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define bug(a, b) cout << a << "\t" << b << "\n";
#define Case(a, b) cout << "Case " << a << ": " << b << "\n";
#define watch(a) cout << fixed << setprecision(a)
#define lp(i, a, b) for (int i = a; i < b; i++)
#define Endl "\n";
#define tab "\t"
#define reset(a, b) memset(a, b, sizeof(a));
#define sf(a) scanf(" %d", &a);
#define srt(a) sort(a.begin(), a.end());
#define pi 2 * acos(0.0)
#define inf INT_MAX
#define infn INT_MIN
const int sz = 1e5 + 9;
string s, t;
int dp[3009][3009];
void lcs(int i, int j) {
if (i >= s.size() || j >= t.size())
return;
if (dp[i][j] != -1)
return;
if (s[i] == t[j]) {
lcs(i + 1, j + 1);
dp[i][j] = 1 + max(0, dp[i + 1][j + 1]);
} else {
lcs(i + 1, j);
lcs(i, j + 1);
dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
dp[i][j] = max(0, dp[i][j]);
}
return;
}
void solve() {
reset(dp, -1);
getline(cin, s);
getline(cin, t);
lcs(0, 0);
// cout<<dp[0][0];
/* for(int i=0;i<=s.size();i++){
for(int j=0;j<=t.size();j++){
cout<<dp[i][j]<<tab;
}
cout<<endl;
}*/
int i = 0, j = 0, temp = dp[i][j];
if (temp == 0) {
cout << "\n\n";
return;
}
while (true) {
if (dp[i][j + 1] == temp) {
j++;
continue;
}
if (dp[i + 1][j] == temp) {
i++;
continue;
}
if (temp == 1) {
cout << s[i];
break;
}
if (dp[i + 1][j + 1] == temp - 1) {
cout << s[i];
temp--, i++, j++;
continue;
}
}
cout << "\n";
}
int main() {
FasterIO;
#ifndef ONLINE_JUDGE
freopen("1.txt", "r", stdin);
#endif
// int t;
// cin>>t;
// while(t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FasterIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define bug(a, b) cout << a << "\t" << b << "\n";
#define Case(a, b) cout << "Case " << a << ": " << b << "\n";
#define watch(a) cout << fixed << setprecision(a)
#define lp(i, a, b) for (int i = a; i < b; i++)
#define Endl "\n";
#define tab "\t"
#define reset(a, b) memset(a, b, sizeof(a));
#define sf(a) scanf(" %d", &a);
#define srt(a) sort(a.begin(), a.end());
#define pi 2 * acos(0.0)
#define inf INT_MAX
#define infn INT_MIN
const int sz = 1e5 + 9;
string s, t;
int dp[3009][3009];
void lcs(int i, int j) {
if (i >= s.size() || j >= t.size())
return;
if (dp[i][j] != -1)
return;
if (s[i] == t[j]) {
lcs(i + 1, j + 1);
dp[i][j] = 1 + max(0, dp[i + 1][j + 1]);
} else {
lcs(i + 1, j);
lcs(i, j + 1);
dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
dp[i][j] = max(0, dp[i][j]);
}
return;
}
void solve() {
reset(dp, -1);
getline(cin, s);
getline(cin, t);
lcs(0, 0);
// cout<<dp[0][0];
/* for(int i=0;i<=s.size();i++){
for(int j=0;j<=t.size();j++){
cout<<dp[i][j]<<tab;
}
cout<<endl;
}*/
int i = 0, j = 0, temp = dp[i][j];
if (temp == 0) {
cout << "\n\n";
return;
}
while (true) {
if (dp[i][j + 1] == temp) {
j++;
continue;
}
if (dp[i + 1][j] == temp) {
i++;
continue;
}
if (temp == 1) {
cout << s[i];
break;
}
if (dp[i + 1][j + 1] == temp - 1) {
cout << s[i];
temp--, i++, j++;
continue;
}
}
cout << "\n";
}
int main() {
/* FasterIO;
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
*/
// int t;
// cin>>t;
// while(t--)
solve();
}
|
replace
| 83 | 87 | 83 | 88 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define mx 5e12
using namespace std;
ll dp[3010][3010];
int main() {
string s, t, ans;
cin >> s;
cin >> t;
int n = s.size(), m = t.size();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout<<dp[n][m];
for (int i = n, j = m; i > 0, j > 0;) {
if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
ans = s[i - 1] + ans;
i--;
j--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else
i--;
}
cout << ans;
}
|
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define mx 5e12
using namespace std;
ll dp[3010][3010];
int main() {
string s, t, ans;
cin >> s;
cin >> t;
int n = s.size(), m = t.size();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout<<dp[n][m];
for (int i = n, j = m; i > 0 & j > 0;) {
if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
ans = s[i - 1] + ans;
i--;
j--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else
i--;
}
cout << ans;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long
int dp[3001][3001];
int main() {
IOS;
memset(dp, 0, sizeof(dp));
string s, t;
cin >> s >> t;
s = "$" + s;
t = "#" + t;
int n = s.size();
int m = t.size();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i] == t[j]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string ans = "";
int i = n;
int j = m;
while (i > 0 && j > 0) {
if (s[i] == t[j]) {
// cout << s[i] << endl;
ans += s[i];
i--;
j--;
} else {
if (dp[i - 1][j] >= dp[i][j - 1]) {
i--;
} else
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans.substr(0, ans.size() - 1) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long
int dp[3005][3005];
int main() {
IOS;
memset(dp, 0, sizeof(dp));
string s, t;
cin >> s >> t;
s = "$" + s;
t = "#" + t;
int n = s.size();
int m = t.size();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i] == t[j]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string ans = "";
int i = n;
int j = m;
while (i > 0 && j > 0) {
if (s[i] == t[j]) {
// cout << s[i] << endl;
ans += s[i];
i--;
j--;
} else {
if (dp[i - 1][j] >= dp[i][j - 1]) {
i--;
} else
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans.substr(0, ans.size() - 1) << endl;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03165
|
C++
|
Runtime Error
|
/*coderanant*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
const int mod = 1000000007;
int i, j;
ll temp;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/home/akmittal/Desktop/Competitive Programming/in.txt", "r", stdin);
freopen("/home/akmittal/Desktop/Competitive Programming/out.txt", "w",
stdout);
#endif
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
vector<vector<tuple<int, int, int>>> dp(n + 1,
vector<tuple<int, int, int>>(m + 1));
f1(i, 0, n + 1) {
f1(j, 0, m + 1) { dp[i][j] = make_tuple(0ll, 0ll, 0ll); }
}
f1(i, 1, n + 1) {
f1(j, 1, m + 1) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = make_tuple(get<0>(dp[i - 1][j - 1]) + 1, i - 1, j - 1);
} else if (get<0>(dp[i][j - 1]) > get<0>(dp[i - 1][j]))
dp[i][j] = make_tuple(get<0>(dp[i][j - 1]), i, j - 1);
else
dp[i][j] = make_tuple(get<0>(dp[i - 1][j]), i - 1, j);
}
}
int ans = get<0>(dp[n][m]);
int x = n, y = m;
string final;
/// cout<<ans<<endl;
// ans=99;
// f1(i,0,n+1)
// {
// f1(j,0,m+1)
// cout<<get<0>(dp[i][j])<<gp<<get<1>(dp[i][j])<<gp<<get<2>(dp[i][j])<<gp<<gp<<gp;
// cout<<endl;
// }
while (1) {
// cout<<x<<gp<<y<<endl;
if (get<1>(dp[x][y]) < x && get<2>(dp[x][y]) < y) {
final.pb(s[x - 1]);
x--;
y--;
ans--;
} else {
// cout<<gp<<get<1>(dp[x][y])<<gp<<get<2>(dp[x][y])<<endl;
temp = get<1>(dp[x][y]);
y = get<2>(dp[x][y]);
x = temp;
// cout<<gp<<get<1>(dp[x][y])<<gp<<get<2>(dp[x][y])<<endl;
}
if (x == 0 || y == 0)
break;
}
reverse(final.begin(), final.end());
cout << final;
return 0;
}
|
/*coderanant*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define f1(i, a, b) for (i = a; i < b; i++)
#define f2(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
const int mod = 1000000007;
int i, j;
ll temp;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("/home/akmittal/Desktop/Competitive
// Programming/in.txt","r",stdin); freopen("/home/akmittal/Desktop/Competitive
// Programming/out.txt","w",stdout); #endif
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
vector<vector<tuple<int, int, int>>> dp(n + 1,
vector<tuple<int, int, int>>(m + 1));
f1(i, 0, n + 1) {
f1(j, 0, m + 1) { dp[i][j] = make_tuple(0ll, 0ll, 0ll); }
}
f1(i, 1, n + 1) {
f1(j, 1, m + 1) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = make_tuple(get<0>(dp[i - 1][j - 1]) + 1, i - 1, j - 1);
} else if (get<0>(dp[i][j - 1]) > get<0>(dp[i - 1][j]))
dp[i][j] = make_tuple(get<0>(dp[i][j - 1]), i, j - 1);
else
dp[i][j] = make_tuple(get<0>(dp[i - 1][j]), i - 1, j);
}
}
int ans = get<0>(dp[n][m]);
int x = n, y = m;
string final;
/// cout<<ans<<endl;
// ans=99;
// f1(i,0,n+1)
// {
// f1(j,0,m+1)
// cout<<get<0>(dp[i][j])<<gp<<get<1>(dp[i][j])<<gp<<get<2>(dp[i][j])<<gp<<gp<<gp;
// cout<<endl;
// }
while (1) {
// cout<<x<<gp<<y<<endl;
if (get<1>(dp[x][y]) < x && get<2>(dp[x][y]) < y) {
final.pb(s[x - 1]);
x--;
y--;
ans--;
} else {
// cout<<gp<<get<1>(dp[x][y])<<gp<<get<2>(dp[x][y])<<endl;
temp = get<1>(dp[x][y]);
y = get<2>(dp[x][y]);
x = temp;
// cout<<gp<<get<1>(dp[x][y])<<gp<<get<2>(dp[x][y])<<endl;
}
if (x == 0 || y == 0)
break;
}
reverse(final.begin(), final.end());
cout << final;
return 0;
}
|
replace
| 22 | 27 | 22 | 26 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
ll const maxn = 1e3 + 5;
ll const inf = 1e18;
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll powm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
bool prime(ll x) {
if (x < 2)
return false;
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0)
return false;
}
return true;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
ll n = s.size();
ll m = t.size();
ll dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
string x = "";
ll a = n, b = m;
while (a > 0 and b > 0) {
if (s[a - 1] == t[b - 1]) {
x += s[a - 1];
a--;
b--;
} else if (dp[a - 1][b] > dp[a][b - 1])
a--;
else
b--;
}
reverse(x.begin(), x.end());
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
ll const maxn = 1e3 + 5;
ll const inf = 1e18;
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll powm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
bool prime(ll x) {
if (x < 2)
return false;
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0)
return false;
}
return true;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
ll n = s.size();
ll m = t.size();
ll dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
string x = "";
ll a = n, b = m;
while (a > 0 and b > 0) {
if (s[a - 1] == t[b - 1]) {
x += s[a - 1];
a--;
b--;
} else if (dp[a - 1][b] > dp[a][b - 1])
a--;
else
b--;
}
reverse(x.begin(), x.end());
cout << x;
return 0;
}
|
replace
| 28 | 32 | 28 | 32 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) fo(i, 0, n)
#define pln(n) printf("%lld\n", n)
#define sll(n) scanf("%lld", &n)
#define ss(n) scanf("%s", n)
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) \
{ cout << #x << ": " << (x) << endl; }
#define dbg2(x, y) \
{ cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x, y, z) \
{ \
cout << #x << ": " << (x) << " , " << #y << ": " << (y) << " , " << #z \
<< ": " << (z) << endl; \
}
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) for (decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define pis pair<int, string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int m = a.size();
int n = b.size();
int L[m + 1][n + 1];
for (int i = 0; i <= m; i++) {
L[i][0] = 0;
}
for (int i = 0; i <= n; i++) {
L[0][i] = 0;
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (a[i - 1] == b[j - 1]) {
L[i][j] = L[i - 1][j - 1] + 1;
} else {
L[i][j] = max(L[i - 1][j], L[i][j - 1]);
}
}
}
int i = m;
int j = n;
string ans = "";
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
ans += a[i - 1];
continue;
}
if (L[i][j] == L[i - 1][j]) {
i--;
} else if (L[i][j] == L[i][j - 1]) {
j--;
} else {
i--;
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) fo(i, 0, n)
#define pln(n) printf("%lld\n", n)
#define sll(n) scanf("%lld", &n)
#define ss(n) scanf("%s", n)
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) \
{ cout << #x << ": " << (x) << endl; }
#define dbg2(x, y) \
{ cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x, y, z) \
{ \
cout << #x << ": " << (x) << " , " << #y << ": " << (y) << " , " << #z \
<< ": " << (z) << endl; \
}
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) for (decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define pis pair<int, string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int m = a.size();
int n = b.size();
int L[m + 1][n + 1];
for (int i = 0; i <= m; i++) {
L[i][0] = 0;
}
for (int i = 0; i <= n; i++) {
L[0][i] = 0;
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (a[i - 1] == b[j - 1]) {
L[i][j] = L[i - 1][j - 1] + 1;
} else {
L[i][j] = max(L[i - 1][j], L[i][j - 1]);
}
}
}
int i = m;
int j = n;
string ans = "";
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
ans += a[i - 1];
i--;
j--;
continue;
}
if (L[i][j] == L[i - 1][j]) {
i--;
} else if (L[i][j] == L[i][j - 1]) {
j--;
} else {
i--;
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
|
insert
| 59 | 59 | 59 | 61 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N = 1e3 + 5;
string s, t;
int n, m;
int mem[N][N];
int oo = 0x3f3f3f3f;
int DP(int i = 0, int j = 0) {
if (i == n || j == m)
return 0;
int &ret = mem[i][j];
if (~ret)
return ret;
return ret =
max(DP(i + 1, j),
max(DP(i, j + 1), (s[i] == t[j] ? DP(i + 1, j + 1) + 1 : 0)));
}
string res;
void print(int i = 0, int j = 0) {
if (i == n || j == m)
return;
if (DP(i, j) == DP(i + 1, j))
return print(i + 1, j);
else if (DP(i, j) == DP(i, j + 1))
return print(i, j + 1);
else {
res.push_back(s[i]);
print(i + 1, j + 1);
}
}
int main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
memset(mem, -1, sizeof(mem));
cin >> s >> t;
n = s.size(), m = t.size();
DP(0, 0);
print();
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N = 3e3 + 5;
string s, t;
int n, m;
int mem[N][N];
int oo = 0x3f3f3f3f;
int DP(int i = 0, int j = 0) {
if (i == n || j == m)
return 0;
int &ret = mem[i][j];
if (~ret)
return ret;
return ret =
max(DP(i + 1, j),
max(DP(i, j + 1), (s[i] == t[j] ? DP(i + 1, j + 1) + 1 : 0)));
}
string res;
void print(int i = 0, int j = 0) {
if (i == n || j == m)
return;
if (DP(i, j) == DP(i + 1, j))
return print(i + 1, j);
else if (DP(i, j) == DP(i, j + 1))
return print(i, j + 1);
else {
res.push_back(s[i]);
print(i + 1, j + 1);
}
}
int main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
memset(mem, -1, sizeof(mem));
cin >> s >> t;
n = s.size(), m = t.size();
DP(0, 0);
print();
cout << res << endl;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 1007;
long long dp[N][N];
string s, t;
int abs(int val) { return max(val, -val); }
int main() {
int n, tw, val, cst;
cin >> s >> t;
for (int i = 1; i <= s.size(); ++i)
for (int j = 1; j <= t.size(); ++j)
dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]),
dp[i - 1][j - 1] + (s[i - 1] == t[j - 1]));
int ci(s.size()), cj(t.size());
string ans;
while (ci && cj) {
if (dp[ci][cj] == dp[ci - 1][cj]) {
--ci;
} else if (dp[ci][cj] == dp[ci][cj - 1]) {
--cj;
} else {
--ci;
--cj;
ans = ans + s[ci];
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 3007;
long long dp[N][N];
string s, t;
int abs(int val) { return max(val, -val); }
int main() {
int n, tw, val, cst;
cin >> s >> t;
for (int i = 1; i <= s.size(); ++i)
for (int j = 1; j <= t.size(); ++j)
dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]),
dp[i - 1][j - 1] + (s[i - 1] == t[j - 1]));
int ci(s.size()), cj(t.size());
string ans;
while (ci && cj) {
if (dp[ci][cj] == dp[ci - 1][cj]) {
--ci;
} else if (dp[ci][cj] == dp[ci][cj - 1]) {
--cj;
} else {
--ci;
--cj;
ans = ans + s[ci];
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a, int b) {
if (a < b || b < 0)
return 0;
return fact[a] * finv[b] % mod * finv[a - b] % mod;
}
void init_C(int n) {
fact[0] = finv[0] = inv[1] = 1;
for (int i = 2; i < n; i++) {
inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
}
for (int i = 1; i < n; i++) {
fact[i] = fact[i - 1] * i % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long pw(long long a, long long b) {
if (a < 0LL)
return 0;
if (b < 0LL)
return 0;
long long ret = 1;
while (b) {
if (b % 2)
ret = ret * a % mod;
a = a * a % mod;
b /= 2;
}
return ret;
}
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
double ABS(double a) { return max(a, -a); }
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
int rev[3100][3100];
int dp[3100][3100];
char s[3100];
char t[3100];
char ans[3100];
int main() {
scanf("%s%s", s, t);
int N = strlen(s);
int M = strlen(t);
for (int i = 0; i < 3100; i++)
for (int j = 0; j < 3100; j++)
dp[i][j] = 0;
dp[0][0] = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
if (i + 1 <= N) {
if (dp[i + 1][j] < dp[i][j]) {
dp[i + 1][j] = dp[i][j];
rev[i + 1][j] = 0;
}
}
if (j + 1 <= M) {
if (dp[i][j + 1] < dp[i][j]) {
dp[i][j + 1] = dp[i][j];
rev[i][j + 1] = 1;
}
}
if (i + 1 <= N && j + 1 <= M && s[i] == t[j]) {
if (dp[i + 1][j + 1] < dp[i][j] + 1) {
dp[i + 1][j + 1] = dp[i][j] + 1;
rev[i + 1][j + 1] = 2;
}
}
}
}
int ns = N;
int nt = M;
int at = dp[N][M] - 1;
while (ns || nt) {
if (rev[ns][nt] == 0)
ns--;
else if (rev[ns][nt] == 1)
nt--;
else {
ns--;
nt--;
ans[at] = s[ns];
at--;
}
}
printf("%s\n", ans);
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a, int b) {
if (a < b || b < 0)
return 0;
return fact[a] * finv[b] % mod * finv[a - b] % mod;
}
void init_C(int n) {
fact[0] = finv[0] = inv[1] = 1;
for (int i = 2; i < n; i++) {
inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
}
for (int i = 1; i < n; i++) {
fact[i] = fact[i - 1] * i % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long pw(long long a, long long b) {
if (a < 0LL)
return 0;
if (b < 0LL)
return 0;
long long ret = 1;
while (b) {
if (b % 2)
ret = ret * a % mod;
a = a * a % mod;
b /= 2;
}
return ret;
}
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
double ABS(double a) { return max(a, -a); }
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
int rev[3100][3100];
int dp[3100][3100];
char s[3100];
char t[3100];
char ans[3100];
int main() {
scanf("%s%s", s, t);
int N = strlen(s);
int M = strlen(t);
for (int i = 0; i < 3100; i++)
for (int j = 0; j < 3100; j++)
dp[i][j] = -3100;
dp[0][0] = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
if (i + 1 <= N) {
if (dp[i + 1][j] < dp[i][j]) {
dp[i + 1][j] = dp[i][j];
rev[i + 1][j] = 0;
}
}
if (j + 1 <= M) {
if (dp[i][j + 1] < dp[i][j]) {
dp[i][j + 1] = dp[i][j];
rev[i][j + 1] = 1;
}
}
if (i + 1 <= N && j + 1 <= M && s[i] == t[j]) {
if (dp[i + 1][j + 1] < dp[i][j] + 1) {
dp[i + 1][j + 1] = dp[i][j] + 1;
rev[i + 1][j + 1] = 2;
}
}
}
}
int ns = N;
int nt = M;
int at = dp[N][M] - 1;
while (ns || nt) {
if (rev[ns][nt] == 0)
ns--;
else if (rev[ns][nt] == 1)
nt--;
else {
ns--;
nt--;
ans[at] = s[ns];
at--;
}
}
printf("%s\n", ans);
}
|
replace
| 71 | 72 | 71 | 72 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
/*
*/
int lcsMemo(int i, int j, string &s, string &t, vector<vector<int>> &dp) {
if (i >= (int)s.size() || j >= (int)t.size() || i < 0 || j < 0)
return 0;
if (dp[i][j] != -1) {
return dp[i][j];
} else if (s[i] == t[j]) {
dp[i][j] = 1 + lcsMemo(i + 1, j + 1, s, t, dp);
return dp[i][j];
} else {
int firstRemoval = lcsMemo(i + 1, j, s, t, dp);
int secondRemoval = lcsMemo(i, j + 1, s, t, dp);
dp[i][j] = max(firstRemoval, secondRemoval);
return dp[i][j];
}
}
string lcsWord(vector<vector<int>> &dp, string s, string t) {
int i = 0, j = 0;
string res = "";
while (i < dp.size() && j < dp[0].size()) {
// cout<<i<<" "<<j<<" ";
if (s[i] == t[j]) {
// cout<<"1"<<endl;
res += s[i];
i++;
j++;
} else if (dp[i + 1][j] > dp[i][j + 1]) {
// cout<<2<<endl;
i++;
} else {
// cout<<3<<endl;
j++;
}
}
// reverse(res.begin(), res.end());
return res;
}
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp((int)s.size(), vector<int>((int)t.size(), -1));
int lcsLength = lcsMemo(0, 0, s, t, dp);
// for(int i=0; i< (int)s.size(); i++){
// for(int j=0; j< (int)t.size(); j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
string answer = lcsWord(dp, s, t);
cout << answer << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
/*
*/
int lcsMemo(int i, int j, string &s, string &t, vector<vector<int>> &dp) {
if (i >= (int)s.size() || j >= (int)t.size() || i < 0 || j < 0)
return 0;
if (dp[i][j] != -1) {
return dp[i][j];
} else if (s[i] == t[j]) {
dp[i][j] = 1 + lcsMemo(i + 1, j + 1, s, t, dp);
return dp[i][j];
} else {
int firstRemoval = lcsMemo(i + 1, j, s, t, dp);
int secondRemoval = lcsMemo(i, j + 1, s, t, dp);
dp[i][j] = max(firstRemoval, secondRemoval);
return dp[i][j];
}
}
string lcsWord(vector<vector<int>> &dp, string s, string t) {
int i = 0, j = 0;
string res = "";
while (i < dp.size() && j < dp[0].size()) {
// cout<<i<<" "<<j<<" ";
if (s[i] == t[j]) {
// cout<<"1"<<endl;
res += s[i];
i++;
j++;
} else if (i + 1 == dp.size()) {
j++;
} else if (j + 1 == dp[0].size()) {
i++;
} else if (dp[i + 1][j] > dp[i][j + 1]) {
// cout<<2<<endl;
i++;
} else {
// cout<<3<<endl;
j++;
}
}
// reverse(res.begin(), res.end());
return res;
}
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp((int)s.size(), vector<int>((int)t.size(), -1));
int lcsLength = lcsMemo(0, 0, s, t, dp);
// for(int i=0; i< (int)s.size(); i++){
// for(int j=0; j< (int)t.size(); j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
string answer = lcsWord(dp, s, t);
cout << answer << endl;
return 0;
}
|
insert
| 30 | 30 | 30 | 34 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(NULL);
string a = "", b = "";
cin >> a >> b;
int i, j;
int al = a.length();
int bl = b.length();
int dp[al + 1][bl + 1];
for (i = 0; i <= al; i++) {
dp[0][i] = 0;
}
for (i = 1; i <= bl; i++) {
dp[i][0] = 0;
for (j = 1; j <= al; j++) {
if (b[i - 1] == a[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
/* for(i=0;i<=bl;i++){
for(j=0;j<=al;j++){
cout << dp[i][j] << " ";
}
cout << "\n";
}*/
string s = "";
i = bl;
j = al;
while (dp[i][j] > 0) {
if (a[j - 1] == b[i - 1]) {
s = s + b[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
reverse(s.begin(), s.end());
cout << s;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(NULL);
string a = "", b = "";
cin >> a >> b;
int i, j;
int al = a.length();
int bl = b.length();
int dp[bl + 1][al + 1];
for (i = 0; i <= al; i++) {
dp[0][i] = 0;
}
for (i = 1; i <= bl; i++) {
dp[i][0] = 0;
for (j = 1; j <= al; j++) {
if (b[i - 1] == a[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
/* for(i=0;i<=bl;i++){
for(j=0;j<=al;j++){
cout << dp[i][j] << " ";
}
cout << "\n";
}*/
string s = "";
i = bl;
j = al;
while (dp[i][j] > 0) {
if (a[j - 1] == b[i - 1]) {
s = s + b[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
reverse(s.begin(), s.end());
cout << s;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define calctime \
std::cout << setprecision(5) << fixed << "Time to completed program: " \
<< (double)(clock() - start) / (CLOCKS_PER_SEC) << "s.\n";
#define FOR(i, j, k, in) for (int i = (j); i < (k); i += (in))
#define FORW(i, j, k, in) for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in) for (int i = (j); i >= (k); i -= (in))
#define RFORW(i, j, k, in) for (int i = (j); i > (k); i -= (in))
#define aint64(cont) cont.begin(), cont.end()
#define raint64(cont) cont.end(), cont.begin()
#define sz(cont) int((cont).size())
#define PB push_back
#define MP make_pair
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define Ff first
#define Ss second
#define FastIO \
ios_base::sync_with_stdio(false); \
std::cin.tie(NULL); \
std::cout.tie(NULL);
#define fileIO(name) \
ifstream iFs(name ".inp"); \
ofstream oFs(name ".out");
#define fileio(name) \
ifstream cin(name ".inp"); \
ofstream cout(name ".out");
#define endl '\n'
// int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
int dp[3005][3005] = {};
int main() {
FastIO;
#ifndef ONLINE_JUDGE
fileio("input"); // Remember to change this
#endif
string s, t;
cin >> s >> t;
int n = sz(s), m = sz(t);
FORW(i, 0, n, 1)
FORW(j, 0, m, 1) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
int len = dp[n][m];
string ans(len, '?');
int i = n, j = m;
while (i && m) {
if (s[i - 1] == t[j - 1]) {
ans[--len] = s[i - 1];
i--, j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
cout << ans << endl;
// calctime
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define calctime \
std::cout << setprecision(5) << fixed << "Time to completed program: " \
<< (double)(clock() - start) / (CLOCKS_PER_SEC) << "s.\n";
#define FOR(i, j, k, in) for (int i = (j); i < (k); i += (in))
#define FORW(i, j, k, in) for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in) for (int i = (j); i >= (k); i -= (in))
#define RFORW(i, j, k, in) for (int i = (j); i > (k); i -= (in))
#define aint64(cont) cont.begin(), cont.end()
#define raint64(cont) cont.end(), cont.begin()
#define sz(cont) int((cont).size())
#define PB push_back
#define MP make_pair
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define Ff first
#define Ss second
#define FastIO \
ios_base::sync_with_stdio(false); \
std::cin.tie(NULL); \
std::cout.tie(NULL);
#define fileIO(name) \
ifstream iFs(name ".inp"); \
ofstream oFs(name ".out");
#define fileio(name) \
ifstream cin(name ".inp"); \
ofstream cout(name ".out");
#define endl '\n'
// int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
int dp[3005][3005] = {};
int main() {
FastIO;
#ifndef ONLINE_JUDGE
fileio("input"); // Remember to change this
#endif
string s, t;
cin >> s >> t;
int n = sz(s), m = sz(t);
FORW(i, 0, n, 1)
FORW(j, 0, m, 1) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
int len = dp[n][m];
string ans(len, '?');
int i = n, j = m;
while (i && j) {
if (s[i - 1] == t[j - 1]) {
ans[--len] = s[i - 1];
i--, j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
cout << ans << endl;
// calctime
return 0;
}
|
replace
| 95 | 96 | 95 | 96 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
EACH(it, P) { s << "<" << *it << "> "; }
return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
return s << endl;
}
template <class T> void show(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << " ";
}
cerr << "\n";
}
typedef long long ll;
int dp[3010][3010];
signed main() {
string s, t;
cin >> s >> t;
dp[0][0] = 0;
string ans = "";
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans += s[i - 1] + ans;
i--, j--;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
EACH(it, P) { s << "<" << *it << "> "; }
return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
return s << endl;
}
template <class T> void show(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << " ";
}
cerr << "\n";
}
typedef long long ll;
int dp[3010][3010];
signed main() {
string s, t;
cin >> s >> t;
dp[0][0] = 0;
string ans = "";
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans = s[i - 1] + ans;
i--, j--;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 81 | 82 | 81 | 82 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int dp[s.size() + 1][t.size() + 1];
dp[0][0] = 1;
for (int i1 = 1; i1 <= t.size(); i1++)
dp[0][i1] = 0;
for (int i2 = 1; i2 <= s.size(); i2++)
dp[i2][0] = 0;
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1]; // popoff from both
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); // try both, choose max
}
}
stack<char> lcs;
int i, j;
i = s.size();
j = t.size();
while (i != 0 || j != 0) {
if (dp[i][j] != max(dp[i - 1][j], dp[i][j - 1])) {
lcs.push(s[i - 1]);
i--;
j--;
} else {
if (dp[i][j - 1] <= dp[i - 1][j])
i--; // dont push, just reach there and in next iteration it will be
// pushed
else
j--;
}
}
while (!lcs.empty())
cout << lcs.top(), lcs.pop();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int dp[s.size() + 1][t.size() + 1];
dp[0][0] = 1;
for (int i1 = 1; i1 <= t.size(); i1++)
dp[0][i1] = 0;
for (int i2 = 1; i2 <= s.size(); i2++)
dp[i2][0] = 0;
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1]; // popoff from both
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); // try both, choose max
}
}
stack<char> lcs;
int i, j;
i = s.size();
j = t.size();
while (i != 0 && j != 0) {
if (dp[i][j] > max(dp[i - 1][j], dp[i][j - 1])) {
lcs.push(s[i - 1]);
i--;
j--;
} else {
if (dp[i][j - 1] <= dp[i - 1][j])
i--; // dont push, just reach there and in next iteration it will be
// pushed
else
j--;
}
}
while (!lcs.empty())
cout << lcs.top(), lcs.pop();
return 0;
}
|
replace
| 27 | 29 | 27 | 29 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define flb(i, a, b) for (int i = a; i < b; i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18 + 1e15)
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
int calculated[100][100];
string s, t;
int n, m;
int solve(int i, int j) {
if (i == n || j == m)
return 0;
if (calculated[i][j] != -1)
return calculated[i][j];
if (s[i] == t[j]) {
calculated[i][j] = 1 + solve(i + 1, j + 1);
} else {
calculated[i][j] = max(solve(i + 1, j), solve(i, j + 1));
}
return calculated[i][j];
}
int main() {
cin >> s >> t;
n = s.size();
m = t.size();
int ans = 0;
memset(calculated, -1, sizeof(calculated));
solve(0, 0);
string temp;
int i = 0, j = 0;
while (i < n && j < m) {
if (s[i] == t[j]) {
temp.push_back(s[i]);
i++;
j++;
} else if (calculated[i + 1][j] > calculated[i][j + 1]) {
i++;
} else
j++;
}
cout << temp;
}
|
#include <bits/stdc++.h>
using namespace std;
#define flb(i, a, b) for (int i = a; i < b; i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18 + 1e15)
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
int calculated[3001][3001];
string s, t;
int n, m;
int solve(int i, int j) {
if (i == n || j == m)
return 0;
if (calculated[i][j] != -1)
return calculated[i][j];
if (s[i] == t[j]) {
calculated[i][j] = 1 + solve(i + 1, j + 1);
} else {
calculated[i][j] = max(solve(i + 1, j), solve(i, j + 1));
}
return calculated[i][j];
}
int main() {
cin >> s >> t;
n = s.size();
m = t.size();
int ans = 0;
memset(calculated, -1, sizeof(calculated));
solve(0, 0);
string temp;
int i = 0, j = 0;
while (i < n && j < m) {
if (s[i] == t[j]) {
temp.push_back(s[i]);
i++;
j++;
} else if (calculated[i + 1][j] > calculated[i][j + 1]) {
i++;
} else
j++;
}
cout << temp;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
string s1, s2;
cin >> s1 >> s2;
int n = s1.size();
int m = s2.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
string ans = "";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s1[i - 1] == s2[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = n, j = m;
if (dp[n][m] == 0) {
cout << ans << endl;
return 0;
}
while (i != 0 || j != 0) {
if (s1[i - 1] == s2[j - 1]) {
ans = s1[i - 1] + ans;
i--;
j--;
} else {
if (dp[i][j - 1] >= dp[i - 1][j])
j--;
else
i--;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
string s1, s2;
cin >> s1 >> s2;
int n = s1.size();
int m = s2.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
string ans = "";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s1[i - 1] == s2[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = n, j = m;
if (dp[n][m] == 0) {
cout << ans << endl;
return 0;
}
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
ans = s1[i - 1] + ans;
i--;
j--;
} else {
if (dp[i][j - 1] >= dp[i - 1][j])
j--;
else
i--;
}
}
cout << ans << endl;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
string a, b;
cin >> a;
cin >> b;
int dp[1001][1001];
for (int i = 0; i <= (int)a.length(); i++)
dp[i][0] = 0;
for (int i = 0; i <= (int)b.length(); i++)
dp[0][i] = 0;
for (int i = 1; i <= (int)a.length(); i++) {
for (int j = 1; j <= (int)b.length(); j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[(int)a.length()][(int)b.length()];
int i = (int)a.length(), j = (int)b.length();
stack<char> st;
while (dp[i][j] != 0) {
if (dp[i][j] > max(dp[i - 1][j], dp[i][j - 1])) {
st.push(a[i - 1]);
i--;
j--;
} else {
if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
string a, b;
cin >> a;
cin >> b;
int dp[3001][3001];
for (int i = 0; i <= (int)a.length(); i++)
dp[i][0] = 0;
for (int i = 0; i <= (int)b.length(); i++)
dp[0][i] = 0;
for (int i = 1; i <= (int)a.length(); i++) {
for (int j = 1; j <= (int)b.length(); j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[(int)a.length()][(int)b.length()];
int i = (int)a.length(), j = (int)b.length();
stack<char> st;
while (dp[i][j] != 0) {
if (dp[i][j] > max(dp[i - 1][j], dp[i][j - 1])) {
st.push(a[i - 1]);
i--;
j--;
} else {
if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03165
|
C++
|
Runtime Error
|
// define DEBUG for debug
#define DEBUG
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define MAX 3000
#define MOD 1000000007
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int dp[MAX + 10][MAX + 10];
string cevap;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef DEBUG
freopen("i.txt", "r", stdin);
freopen("o.txt", "w", stdout);
#endif
string a, b;
cin >> a >> b;
int x = a.size(), y = b.size();
for (int i = 1; i <= x; i++)
for (int j = 1; j <= y; j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
int index = dp[x][y];
while (x > 0 || y > 0) {
if (x > 0 && dp[x - 1][y] == dp[x][y]) {
x--;
} else if (y > 0 && dp[x][y - 1] == dp[x][y]) {
y--;
} else {
cevap += a[x - 1];
x--;
y--;
}
}
for (int i = index - 1; i >= 0; i--)
cout << cevap[i];
return 0;
}
|
// define DEBUG for debug
// #define DEBUG
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define MAX 3000
#define MOD 1000000007
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int dp[MAX + 10][MAX + 10];
string cevap;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef DEBUG
freopen("i.txt", "r", stdin);
freopen("o.txt", "w", stdout);
#endif
string a, b;
cin >> a >> b;
int x = a.size(), y = b.size();
for (int i = 1; i <= x; i++)
for (int j = 1; j <= y; j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
int index = dp[x][y];
while (x > 0 || y > 0) {
if (x > 0 && dp[x - 1][y] == dp[x][y]) {
x--;
} else if (y > 0 && dp[x][y - 1] == dp[x][y]) {
y--;
} else {
cevap += a[x - 1];
x--;
y--;
}
}
for (int i = index - 1; i >= 0; i--)
cout << cevap[i];
return 0;
}
|
replace
| 1 | 2 | 1 | 2 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T, n;
const int maxl = 3000 + 5;
int dp[maxl][maxl];
int path[maxl][maxl];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
dp[0][0] = 0;
dp[1][0] = 0;
dp[0][1] = 0;
path[0][0] = path[0][1] = path[1][0] = -1;
for (int i = 1; i <= s.size(); i++)
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1, path[i][j] = 0;
else if (dp[i - 1][j] > dp[i][j - 1])
dp[i][j] = dp[i - 1][j], path[i][j] = 1;
else
dp[i][j] = dp[i][j - 1], path[i][j] = 2;
}
// cout << dp[s.size()][t.size()];
char ans[maxl];
int x = s.size(), y = t.size();
int cur = dp[x][y];
ans[cur--] = '\0';
while (path[x][y] != -1) {
if (path[x][y] == 0)
x--, y--, ans[cur--] = s[x];
else if (path[x][y] == 1)
x--;
else
y--;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T, n;
const int maxl = 3000 + 5;
int dp[maxl][maxl];
int path[maxl][maxl];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
for (int i = 0; i <= max(s.size(), t.size()); i++)
dp[0][i] = dp[i][0] = 0, path[0][i] = path[i][0] = -1;
for (int i = 1; i <= s.size(); i++)
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1, path[i][j] = 0;
else if (dp[i - 1][j] > dp[i][j - 1])
dp[i][j] = dp[i - 1][j], path[i][j] = 1;
else
dp[i][j] = dp[i][j - 1], path[i][j] = 2;
}
// cout << dp[s.size()][t.size()];
char ans[maxl];
int x = s.size(), y = t.size();
int cur = dp[x][y];
ans[cur--] = '\0';
while (path[x][y] != -1) {
if (path[x][y] == 0)
x--, y--, ans[cur--] = s[x];
else if (path[x][y] == 1)
x--;
else
y--;
}
cout << ans;
return 0;
}
|
replace
| 17 | 21 | 17 | 19 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 5;
int dp[N][N];
string a, b, ans;
int dpf(int i, int j) {
if (dp[i][j] != -INF)
return dp[i][j];
if (!i or !j)
return dp[i][j] = 0;
if (a[i - 1] == b[j - 1])
return dp[i][j] = 1 + dpf(i - 1, j - 1);
return dp[i][j] = max(dpf(i - 1, j), dpf(i, j - 1));
}
void rec(int i, int j) {
if (!i or !j)
return;
if (a[i - 1] == b[j - 1])
ans += a[i - 1], rec(i - 1, j - 1);
else if (dp[i][j] == dp[i - 1][j])
rec(i - 1, j);
else
rec(i, j - 1);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> a >> b;
int n = a.size(), m = b.size();
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i][j] = -INF;
dpf(n, m);
rec(n, m);
reverse(ans.begin(), ans.end());
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 3e3 + 5;
int dp[N][N];
string a, b, ans;
int dpf(int i, int j) {
if (dp[i][j] != -INF)
return dp[i][j];
if (!i or !j)
return dp[i][j] = 0;
if (a[i - 1] == b[j - 1])
return dp[i][j] = 1 + dpf(i - 1, j - 1);
return dp[i][j] = max(dpf(i - 1, j), dpf(i, j - 1));
}
void rec(int i, int j) {
if (!i or !j)
return;
if (a[i - 1] == b[j - 1])
ans += a[i - 1], rec(i - 1, j - 1);
else if (dp[i][j] == dp[i - 1][j])
rec(i - 1, j);
else
rec(i, j - 1);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> a >> b;
int n = a.size(), m = b.size();
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i][j] = -INF;
dpf(n, m);
rec(n, m);
reverse(ans.begin(), ans.end());
cout << ans << "\n";
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
#define debug(var) std::cout << #var " = " << var << std::endl
#else
#define debug(var)
#endif
#define p(var) std::cout << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0, i##_length = (n); i < i##_length; ++i)
#define repeq(i, n) for (int i = 1, i##_length = (n); i <= i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a >= 0 && ceil(a) == floor(a); }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
for (int i = 0, len = v.size(); i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
for (int i = 0, len = vv.size(); i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
/*-----8<-----8<-----*/
// sとtの最長共通部分列を求める
// 戻り値:最長共通部分列の長さ
// dp配列を格納して返す
ll lcs(string s, string t, vector<vector<ll>> &dp) {
dp.assign(s.size() + 1, vector<ll>(t.size() + 1, 0));
for (ll i = 0, slen = s.size(); i < slen; i++) {
for (ll j = 0, tlen = t.size(); j < tlen; j++) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
return dp[s.size()][t.size()];
}
// sとtの最長共通部分列を求める
// 戻り値:最長共通部分列の文字列
string buildlcs(string s, string t, vector<vector<ll>> &dp) {
string lcsstr = "";
ll i = s.size();
ll j = t.size();
if (dp[i][j] == 0)
return 0;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
i--;
j--;
lcsstr = s[i] + lcsstr;
}
}
return lcsstr;
}
signed main() {
// Longest Common Subsequence
string s, t;
cin >> s >> t;
vector<vector<ll>> dp;
ll lcsnum = lcs(s, t, dp);
debug(lcsnum);
string lcsstr = buildlcs(s, t, dp);
p(lcsstr);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
#define debug(var) std::cout << #var " = " << var << std::endl
#else
#define debug(var)
#endif
#define p(var) std::cout << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0, i##_length = (n); i < i##_length; ++i)
#define repeq(i, n) for (int i = 1, i##_length = (n); i <= i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a >= 0 && ceil(a) == floor(a); }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
for (int i = 0, len = v.size(); i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
for (int i = 0, len = vv.size(); i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
/*-----8<-----8<-----*/
// sとtの最長共通部分列を求める
// 戻り値:最長共通部分列の長さ
// dp配列を格納して返す
ll lcs(string s, string t, vector<vector<ll>> &dp) {
dp.assign(s.size() + 1, vector<ll>(t.size() + 1, 0));
for (ll i = 0, slen = s.size(); i < slen; i++) {
for (ll j = 0, tlen = t.size(); j < tlen; j++) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
return dp[s.size()][t.size()];
}
// sとtの最長共通部分列を求める
// 戻り値:最長共通部分列の文字列
string buildlcs(string s, string t, vector<vector<ll>> &dp) {
string lcsstr = "";
ll i = s.size();
ll j = t.size();
if (dp[i][j] == 0)
return "";
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
i--;
j--;
lcsstr = s[i] + lcsstr;
}
}
return lcsstr;
}
signed main() {
// Longest Common Subsequence
string s, t;
cin >> s >> t;
vector<vector<ll>> dp;
ll lcsnum = lcs(s, t, dp);
debug(lcsnum);
string lcsstr = buildlcs(s, t, dp);
p(lcsstr);
return 0;
}
|
replace
| 81 | 82 | 81 | 82 |
0
| |
p03165
|
C++
|
Runtime Error
|
#define NDEBUG
NDEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T> using vec2d = std::vector<std::vector<T>>;
template <class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
return vec2d<T>(n1, vec<T>(n2, initValue));
}
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define all(c) c.begin(), c.end()
// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END
// Section with adoption of array and vector algorithms.
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//
// template <class T> using StdTree = tree<T, null_type, less<T>,
// rb_tree_tag,tree_order_statistics_node_update>;
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N> struct bytetype {};
/// caide keep
template <uint64_t N> struct minimal_uint : bytetype<bytecount(N)> {};
} // namespace template_util
template <class T> T next(istream &in) {
T ret;
in >> ret;
return ret;
}
void solve(istream &in, ostream &out) {
auto s = next<string>(in);
auto t = next<string>(in);
vec2d<int> f = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
vec2d<int> p = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
f[0][0] = 0;
FOR(i, s.length()) {
FOR(j, t.length()) {
if (f[i][j] != -1) {
if (f[i + 1][j] < f[i][j]) {
f[i + 1][j] = f[i][j];
p[i + 1][j] = 0;
}
if (f[i][j + 1] < f[i][j]) {
f[i][j + 1] = f[i][j];
p[i][j + 1] = 1;
}
if (s[i] == t[j]) {
if (f[i + 1][j + 1] < f[i][j] + 1) {
f[i + 1][j + 1] = f[i][j] + 1;
p[i + 1][j + 1] = 2;
}
}
}
}
}
int res = 0;
int bi = -1, bj = -1;
FOR(i, s.length() + 1) {
FOR(j, t.length() + 1) {
if (res < f[i][j]) {
res = f[i][j];
bi = i;
bj = j;
}
}
}
string r;
while (bi != 0 || bj != 0) {
if (p[bi][bj] == 2) {
r.push_back(s[bi - 1]);
--bi;
--bj;
} else if (p[bi][bj] == 0) {
--bi;
} else {
--bj;
}
}
reverse(all(r));
out << r << "\n";
}
// #include <fstream>
int main() {
// ifstream fin("bridges.in");
// ofstream fout("bridges.out");
solve(cin, cout);
// solve(fin, fout);
return 0;
}
|
#define NDEBUG
NDEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T> using vec2d = std::vector<std::vector<T>>;
template <class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
return vec2d<T>(n1, vec<T>(n2, initValue));
}
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define all(c) c.begin(), c.end()
// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END
// Section with adoption of array and vector algorithms.
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//
// template <class T> using StdTree = tree<T, null_type, less<T>,
// rb_tree_tag,tree_order_statistics_node_update>;
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N> struct bytetype {};
/// caide keep
template <uint64_t N> struct minimal_uint : bytetype<bytecount(N)> {};
} // namespace template_util
template <class T> T next(istream &in) {
T ret;
in >> ret;
return ret;
}
void solve(istream &in, ostream &out) {
auto s = next<string>(in);
auto t = next<string>(in);
vec2d<int> f = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
vec2d<int> p = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
f[0][0] = 0;
FOR(i, s.length()) {
FOR(j, t.length()) {
if (f[i][j] != -1) {
if (f[i + 1][j] < f[i][j]) {
f[i + 1][j] = f[i][j];
p[i + 1][j] = 0;
}
if (f[i][j + 1] < f[i][j]) {
f[i][j + 1] = f[i][j];
p[i][j + 1] = 1;
}
if (s[i] == t[j]) {
if (f[i + 1][j + 1] < f[i][j] + 1) {
f[i + 1][j + 1] = f[i][j] + 1;
p[i + 1][j + 1] = 2;
}
}
}
}
}
int res = 0;
int bi = 0, bj = 0;
FOR(i, s.length() + 1) {
FOR(j, t.length() + 1) {
if (res < f[i][j]) {
res = f[i][j];
bi = i;
bj = j;
}
}
}
string r;
while (bi != 0 || bj != 0) {
if (p[bi][bj] == 2) {
r.push_back(s[bi - 1]);
--bi;
--bj;
} else if (p[bi][bj] == 0) {
--bi;
} else {
--bj;
}
}
reverse(all(r));
out << r << "\n";
}
// #include <fstream>
int main() {
// ifstream fin("bridges.in");
// ofstream fout("bridges.out");
solve(cin, cout);
// solve(fin, fout);
return 0;
}
|
replace
| 98 | 99 | 98 | 99 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc \
int t; \
cin >> t; \
while (t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep = "";
for (const auto &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << "\n"; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cerr << ' ' << H;
dbg_out(T...);
}
const int N = 3e3 + 5;
int dp[N][N];
int dir[N][N];
void solve() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
memset(dp, 0, sizeof dp);
memset(dir, 0, sizeof dir);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
dir[i][j] = 1;
} else {
if (dp[i - 1][j] > dp[i][j - 1]) {
dir[i][j] = 2;
dp[i][j] = dp[i - 1][j];
} else {
dir[i][j] = 3;
dp[i][j] = dp[i][j - 1];
}
}
string res = "";
int i = n, j = m;
while (i > 0 || j > 0) {
if (dir[i][j] == 1) {
res += s[i - 1];
i--;
j--;
} else if (dir[i][j] == 2)
i--;
else
j--;
}
reverse(All(res));
cout << res << "\n";
}
int main() {
Fast;
// louisfghbvc{
solve();
//}
return 0;
}
|
#include <bits/stdc++.h>
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc \
int t; \
cin >> t; \
while (t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep = "";
for (const auto &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << "\n"; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cerr << ' ' << H;
dbg_out(T...);
}
const int N = 3e3 + 5;
int dp[N][N];
int dir[N][N];
void solve() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
memset(dp, 0, sizeof dp);
memset(dir, 0, sizeof dir);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
dir[i][j] = 1;
} else {
if (dp[i - 1][j] > dp[i][j - 1]) {
dir[i][j] = 2;
dp[i][j] = dp[i - 1][j];
} else {
dir[i][j] = 3;
dp[i][j] = dp[i][j - 1];
}
}
string res = "";
int i = n, j = m;
while (i > 0 && j > 0) {
if (dir[i][j] == 1) {
res += s[i - 1];
i--;
j--;
} else if (dir[i][j] == 2)
i--;
else
j--;
}
reverse(All(res));
cout << res << "\n";
}
int main() {
Fast;
// louisfghbvc{
solve();
//}
return 0;
}
|
replace
| 62 | 63 | 62 | 63 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
int main() {
FAST_IO;
string s, t;
cin >> s >> t;
int n1 = s.length();
int n2 = t.length();
int dp[n1 + 1][n2 + 1];
for (int i = 0; i < n1 + 1; i++) {
dp[i][n2] = 0;
}
for (int i = 0; i < n2 + 1; i++) {
dp[n1][i] = 0;
}
for (int i = n1 - 1; i >= 0; i--) {
for (int j = n2 - 1; j >= 0; j--) {
if (s[i] == t[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
} else {
dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
}
}
}
/* for(int i=0; i <= n1; i++){
for(int j= 0; j <=n2; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
string ans;
int i = 0;
int j = 0;
while (i < n1 || j < n2) {
if (s[i] == t[j]) {
ans.push_back(s[i]);
i++;
j++;
} else {
if (dp[i + 1][j] == dp[i][j]) {
i++;
} else {
j++;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
int main() {
FAST_IO;
string s, t;
cin >> s >> t;
int n1 = s.length();
int n2 = t.length();
int dp[n1 + 1][n2 + 1];
for (int i = 0; i < n1 + 1; i++) {
dp[i][n2] = 0;
}
for (int i = 0; i < n2 + 1; i++) {
dp[n1][i] = 0;
}
for (int i = n1 - 1; i >= 0; i--) {
for (int j = n2 - 1; j >= 0; j--) {
if (s[i] == t[j]) {
dp[i][j] = dp[i + 1][j + 1] + 1;
} else {
dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
}
}
}
/* for(int i=0; i <= n1; i++){
for(int j= 0; j <=n2; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
string ans;
int i = 0;
int j = 0;
while (i < n1 && j < n2) {
if (s[i] == t[j]) {
ans.push_back(s[i]);
i++;
j++;
} else {
if (dp[i + 1][j] == dp[i][j]) {
i++;
} else {
j++;
}
}
}
cout << ans << endl;
return 0;
}
|
replace
| 56 | 57 | 56 | 57 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll w[100], v[100], ar[100][100000], sum;
int main() {
string a, b;
cin >> a >> b;
ll n = a.length(), m = b.length(), i, j, dp[m + 1][n + 1];
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (b[i - 1] == a[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string s = "";
i = m, j = n;
while (i > 0 || j > 0) {
if (b[i - 1] == a[j - 1]) {
s = a[j - 1] + s;
i--, j--;
} else if (dp[i][j - 1] > dp[i - 1][j])
j--;
else
i--;
}
cout << s;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll w[100], v[100], ar[100][100000], sum;
int main() {
string a, b;
cin >> a >> b;
ll n = a.length(), m = b.length(), i, j, dp[m + 1][n + 1];
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (b[i - 1] == a[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string s = "";
i = m, j = n;
while (i > 0 && j > 0) {
if (b[i - 1] == a[j - 1]) {
s = a[j - 1] + s;
i--, j--;
} else if (dp[i][j - 1] > dp[i - 1][j])
j--;
else
i--;
}
cout << s;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <stdio.h>
#define lldi unsigned long long int
using namespace std;
string cadena;
int dp[400][400] = {0};
int lcs(string s1, string s2) {
int tam1 = s1.length();
int tam2 = s2.length();
for (int i = 1; i <= tam1; i++) {
for (int j = 1; j <= tam2; j++) {
if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = tam1;
int j = tam2;
int band = 0;
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
cadena.push_back(s1[i - 1]);
i--;
j--;
}
else if (dp[i][j - 1] > dp[i - 1][j])
j--;
else
i--;
}
if (cadena.size() == 0)
printf("\n");
else {
for (int i = cadena.size() - 1; i >= 0; i--)
cout << cadena[i];
cout << endl;
}
}
int main() {
string s1, s2;
cin >> s1;
cin >> s2;
lcs(s1, s2);
return 0;
}
|
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <stdio.h>
#define lldi unsigned long long int
using namespace std;
string cadena;
int dp[4000][4000] = {0};
int lcs(string s1, string s2) {
int tam1 = s1.length();
int tam2 = s2.length();
for (int i = 1; i <= tam1; i++) {
for (int j = 1; j <= tam2; j++) {
if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = tam1;
int j = tam2;
int band = 0;
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
cadena.push_back(s1[i - 1]);
i--;
j--;
}
else if (dp[i][j - 1] > dp[i - 1][j])
j--;
else
i--;
}
if (cadena.size() == 0)
printf("\n");
else {
for (int i = cadena.size() - 1; i >= 0; i--)
cout << cadena[i];
cout << endl;
}
}
int main() {
string s1, s2;
cin >> s1;
cin >> s2;
lcs(s1, s2);
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl '\n'
const int mod = 1e9 + 7, u = 1e5 + 5;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int dp[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 0; i <= m; i++) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int x = n, y = m;
string ans;
while (n > 0 and y > 0) {
if (s[x - 1] == t[y - 1]) {
ans += s[x - 1];
x--;
y--;
} else if (dp[x][y] == dp[x - 1][y]) {
x--;
} else {
y--;
}
}
reverse(all(ans));
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl '\n'
const int mod = 1e9 + 7, u = 1e5 + 5;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int dp[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 0; i <= m; i++) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int x = n, y = m;
string ans;
while (x > 0 and y > 0) {
if (s[x - 1] == t[y - 1]) {
ans += s[x - 1];
x--;
y--;
} else if (dp[x][y] == dp[x - 1][y]) {
x--;
} else {
y--;
}
}
reverse(all(ans));
cout << ans;
return 0;
}
|
replace
| 37 | 38 | 37 | 38 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[1005][1005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a, b, t = "";
cin >> a >> b;
for (int i = 1; i <= a.size(); i++)
for (int j = 1; j <= b.size(); j++)
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
int i = a.size(), j = b.size();
while (dp[i][j]) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else if (dp[i][j] > dp[i - 1][j - 1])
i--, j--, t += a[i];
}
reverse(t.begin(), t.end());
cout << t;
}
/*#include <stack>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close
std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define
FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y)
for (LL i = (x), _##i = (y); i > _##i; --i) #define SORT_UNIQUE(c)
(sort(c.begin(),c.end()),
c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define CASET int ___T;
scanf("%d", &___T); for(int __CS=1;__CS<=___T;__CS++) typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x *
x % MOD)if (n & 1) ret = ret * x % MOD;return ret;} inline LL get_inv(LL x, LL
p) { return bin(x, p - 2, p); } const double PI = acos(-1.0); constexpr int maxn
= 1e6+10; constexpr int INF = 0x3f3f3f3f; constexpr ll linf =
0x3f3f3f3f3f3f3f3f; constexpr int mod = 1e9+7; int dp[1005][1005]; int main()
{
string s, t;
cin >> s >> t;
int len1 = s.size(), len2= t.size();
for(int i = 0; i < len1 ; i++){
for(int j = 0; j < len2; j++){
if(s[i] == t[i]){
dp[i+1][j+1] = dp[i][j] + 1;
}else {
dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
}
}
}cout << dp[len1 ] [len2] ;
}*/
|
#include <bits/stdc++.h>
using namespace std;
int dp[3005][3005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a, b, t = "";
cin >> a >> b;
for (int i = 1; i <= a.size(); i++)
for (int j = 1; j <= b.size(); j++)
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
int i = a.size(), j = b.size();
while (dp[i][j]) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else if (dp[i][j] > dp[i - 1][j - 1])
i--, j--, t += a[i];
}
reverse(t.begin(), t.end());
cout << t;
}
/*#include <stack>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close
std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) #define
FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y)
for (LL i = (x), _##i = (y); i > _##i; --i) #define SORT_UNIQUE(c)
(sort(c.begin(),c.end()),
c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define CASET int ___T;
scanf("%d", &___T); for(int __CS=1;__CS<=___T;__CS++) typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x *
x % MOD)if (n & 1) ret = ret * x % MOD;return ret;} inline LL get_inv(LL x, LL
p) { return bin(x, p - 2, p); } const double PI = acos(-1.0); constexpr int maxn
= 1e6+10; constexpr int INF = 0x3f3f3f3f; constexpr ll linf =
0x3f3f3f3f3f3f3f3f; constexpr int mod = 1e9+7; int dp[1005][1005]; int main()
{
string s, t;
cin >> s >> t;
int len1 = s.size(), len2= t.size();
for(int i = 0; i < len1 ; i++){
for(int j = 0; j < len2; j++){
if(s[i] == t[i]){
dp[i+1][j+1] = dp[i][j] + 1;
}else {
dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
}
}
}cout << dp[len1 ] [len2] ;
}*/
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f(i, n) for (int i = 0; i < n; i++)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
const int N = 3005;
int dp[N][N], n, m;
string s, t;
void solve() {
cin >> s >> t;
n = s.length();
m = t.length();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
int nn = n;
int mm = m;
vector<char> v;
while (nn >= 0 && mm >= 0) {
if (s[nn - 1] == t[mm - 1]) {
v.pb(s[nn - 1]);
nn--;
mm--;
} else if (dp[nn][mm - 1] > dp[nn - 1][mm])
mm--;
else
nn--;
}
reverse(v.begin(), v.end());
for (auto z : v)
cout << z;
}
signed main() {
fast;
int t = 1;
// cin >> t;
while (t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f(i, n) for (int i = 0; i < n; i++)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
const int N = 3005;
int dp[N][N], n, m;
string s, t;
void solve() {
cin >> s >> t;
n = s.length();
m = t.length();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
int nn = n;
int mm = m;
vector<char> v;
while (nn >= 1 && mm >= 1) {
if (s[nn - 1] == t[mm - 1]) {
v.pb(s[nn - 1]);
nn--;
mm--;
} else if (dp[nn][mm - 1] > dp[nn - 1][mm])
mm--;
else
nn--;
}
reverse(v.begin(), v.end());
for (auto z : v)
cout << z;
}
signed main() {
fast;
int t = 1;
// cin >> t;
while (t--)
solve();
}
|
replace
| 33 | 34 | 33 | 34 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
#include <utility>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int main() {
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
PP dp[100][100];
fill(dp[0], dp[0] + 100, PP(0, P(-1, -1)));
for (int i = 0; i < 100; i++) {
dp[i][0] = PP(0, P(-1, -1));
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = PP(dp[i - 1][j - 1].first + 1, P(i - 1, j - 1));
else {
if (dp[i - 1][j].first >= dp[i][j - 1].first)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = dp[i][j - 1];
}
}
}
P p = dp[n][m].second;
char c[3002];
while (p.first >= 0 && p.second >= 0) {
c[dp[p.first][p.second].first] = s[p.first];
p = dp[p.first][p.second].second;
}
for (int i = 0; i < dp[n][m].first; i++)
cout << c[i];
cout << endl;
}
|
#include <iostream>
#include <string>
#include <utility>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int main() {
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
PP dp[3002][3002];
fill(dp[0], dp[0] + 3002, PP(0, P(-1, -1)));
for (int i = 0; i < 3002; i++) {
dp[i][0] = PP(0, P(-1, -1));
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = PP(dp[i - 1][j - 1].first + 1, P(i - 1, j - 1));
else {
if (dp[i - 1][j].first >= dp[i][j - 1].first)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = dp[i][j - 1];
}
}
}
P p = dp[n][m].second;
char c[3002];
while (p.first >= 0 && p.second >= 0) {
c[dp[p.first][p.second].first] = s[p.first];
p = dp[p.first][p.second].second;
}
for (int i = 0; i < dp[n][m].first; i++)
cout << c[i];
cout << endl;
}
|
replace
| 11 | 14 | 11 | 14 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string str1, str2;
int dp[1000][1000], n, m;
int solve(int id1, int id2) {
if (id1 == n || id2 == m)
return 0;
if (dp[id1][id2] != -1)
return dp[id1][id2];
int ans = 0;
if (str1[id1] == str2[id2])
ans = max(ans, 1 + solve(id1 + 1, id2 + 1));
else
ans = max(solve(id1 + 1, id2), solve(id1, id2 + 1));
return dp[id1][id2] = ans;
}
string printLCS() {
int id1 = 0, id2 = 0;
string str = "";
while (id1 < n && id2 < m) {
if (str1[id1] == str2[id2]) {
str += str1[id1];
id1++;
id2++;
} else if (dp[id1 + 1][id2] > dp[id1][id2 + 1])
id1++;
else
id2++;
}
return str;
}
int main() {
cin >> str1 >> str2;
n = str1.size();
m = str2.size();
memset(dp, -1, sizeof dp);
solve(0, 0);
cout << printLCS() << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string str1, str2;
int dp[5000][5000], n, m;
int solve(int id1, int id2) {
if (id1 == n || id2 == m)
return 0;
if (dp[id1][id2] != -1)
return dp[id1][id2];
int ans = 0;
if (str1[id1] == str2[id2])
ans = max(ans, 1 + solve(id1 + 1, id2 + 1));
else
ans = max(solve(id1 + 1, id2), solve(id1, id2 + 1));
return dp[id1][id2] = ans;
}
string printLCS() {
int id1 = 0, id2 = 0;
string str = "";
while (id1 < n && id2 < m) {
if (str1[id1] == str2[id2]) {
str += str1[id1];
id1++;
id2++;
} else if (dp[id1 + 1][id2] > dp[id1][id2 + 1])
id1++;
else
id2++;
}
return str;
}
int main() {
cin >> str1 >> str2;
n = str1.size();
m = str2.size();
memset(dp, -1, sizeof dp);
solve(0, 0);
cout << printLCS() << endl;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define INF 10000000000000000
#define pll pair<ll, ll>
#define ff first
#define ss second
using namespace std;
const ll N = 200005;
const ll MOD = 998244353;
ll dp[305][305];
pll p[305][305];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
ll n = s.size();
ll m = t.size();
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (s[i] == t[j]) {
if (dp[i + 1][j + 1] < dp[i][j] + 1) {
dp[i + 1][j + 1] = dp[i][j] + 1;
p[i + 1][j + 1] = {i, j};
}
}
if (dp[i][j + 1] < dp[i][j]) {
dp[i][j + 1] = dp[i][j];
p[i][j + 1] = {i, j};
}
if (dp[i + 1][j] < dp[i][j]) {
dp[i + 1][j] = dp[i][j];
p[i + 1][j] = {i, j};
}
}
}
ll i1 = 0;
ll j1 = 0;
for (ll i = 0; i < n + 1; i++) {
for (ll j = 0; j < m + 1; j++) {
if (dp[i][j] > dp[i1][j1]) {
i1 = i;
j1 = j;
}
}
}
string an = "";
while (i1 != 0 && j1 != 0) {
pll k = p[i1][j1];
if (dp[i1][j1] > dp[k.ff][k.ss])
an += s[k.ff];
i1 = k.ff;
j1 = k.ss;
}
reverse(an.begin(), an.end());
cout << an;
}
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define INF 10000000000000000
#define pll pair<ll, ll>
#define ff first
#define ss second
using namespace std;
const ll N = 200005;
const ll MOD = 998244353;
ll dp[3005][3005];
pll p[3005][3005];
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
ll n = s.size();
ll m = t.size();
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (s[i] == t[j]) {
if (dp[i + 1][j + 1] < dp[i][j] + 1) {
dp[i + 1][j + 1] = dp[i][j] + 1;
p[i + 1][j + 1] = {i, j};
}
}
if (dp[i][j + 1] < dp[i][j]) {
dp[i][j + 1] = dp[i][j];
p[i][j + 1] = {i, j};
}
if (dp[i + 1][j] < dp[i][j]) {
dp[i + 1][j] = dp[i][j];
p[i + 1][j] = {i, j};
}
}
}
ll i1 = 0;
ll j1 = 0;
for (ll i = 0; i < n + 1; i++) {
for (ll j = 0; j < m + 1; j++) {
if (dp[i][j] > dp[i1][j1]) {
i1 = i;
j1 = j;
}
}
}
string an = "";
while (i1 != 0 && j1 != 0) {
pll k = p[i1][j1];
if (dp[i1][j1] > dp[k.ff][k.ss])
an += s[k.ff];
i1 = k.ff;
j1 = k.ss;
}
reverse(an.begin(), an.end());
cout << an;
}
|
replace
| 13 | 15 | 13 | 15 |
0
| |
p03165
|
C++
|
Runtime Error
|
/*==========================================================================================*\
** _ _ _ _ _ _ _ **
** | |__ _ _/ | |_| |__ | || | _ __ | |__ **
** | '_ \| | | | | __| '_ \| || |_| '_ \| '_ \ **
** | |_) | |_| | | |_| | | |__ _| | | | | | | **
** |_.__/ \__,_|_|\__|_| |_| |_| |_| |_|_| |_| **
\*==========================================================================================*/
//=====================================
// Solution Briefing - Foreword
//=====================================
// Libraries and namespaces
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#if __cplusplus >= 201103L
#include <chrono>
#include <random>
#include <unordered_map>
#include <unordered_set>
#endif // __cplusplus
using namespace std;
// #define DEBUG
#define OPTIONAL_FEATURE
//=====================================
// Macroes
#define sp ' '
#define el '\n'
#define task ""
#define maxinp ()
#define fi first
#define se second
#define pb push_back
#define whole(x) x.begin(), x.end()
#define whole_1(x) x.begin() + 1, x.end()
#define r_whole(x) x.rbegin(), x.rend()
#define FOR(i, x, y) for (auto i = x; i <= y; ++i)
#define FORl(i, x, y) for (auto i = x; i < y; ++i)
#define FORb(i, x, y) for (auto i = x; i >= y; --i)
#define FORlb(i, x, y) for (auto i = x; i > y; --i)
#define MEMS(x, val) memset(x, val, sizeof(x))
#define what_is(x) cerr << #x << " is " << x << endl;
#define FILEOP() \
{ \
freopen(task ".inp", "r", stdin); \
freopen(task ".out", "w", stdout); \
}
#define FILEOP_DEBUG() \
{ \
freopen(task ".inp", "r", stdin); \
freopen(task ".out", "w", stdout); \
freopen(task ".err", "w", stderr); \
}
// Macroes - Optional
#ifdef OPTIONAL_FEATURE
#define pc(x) putchar(x)
#define gc() getchar()
#endif
//=====================================
// Auxilary Functions and Fast I/O
#ifdef OPTIONAL_FEATURE
template <class T, class R> T max(const T &__X, const R &__Y) {
return __X > __Y ? __X : __Y;
}
template <class T, class R> T min(const T &__X, const R &__Y) {
return __X < __Y ? __X : __Y;
}
template <class T, class R> void maximize(T &__X, R __Y) {
__X = __X > __Y ? __X : __Y;
}
template <class T, class R> void minimize(T &__X, R __Y) {
__X = __X < __Y ? __X : __Y;
}
template <class T> int getBit(T &__X, int __i) {
return ((__X >> __i) & 1) == 1;
}
template <class T> bool inRange(T __L, T __R, T __X) {
return __L <= __X && __X <= __R;
}
template <class T> T __abs(T __X) { return (__X < 0) ? -__X : __X; }
#endif
// Fast I/O
template <class T> inline void scan(T &__ret) {
__ret = T();
char c = 0;
bool neg = 0;
while (isdigit(c) == 0 && c != '-')
c = getchar();
if (c == '-') {
neg = 1;
c = getchar();
}
for (; isdigit(c) != 0; c = getchar())
__ret = __ret * 10 + c - '0';
__ret = (neg) ? -__ret : __ret;
}
template <class T> void print(T __X) {
if (__X < 0) {
putchar('-');
__X *= -1;
}
if (__X > 9)
print(__X / 10);
putchar(__X % 10 + '0');
}
//=====================================
// Constants
//=====================================
// Typedefs
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vii> vvii;
string s, t, res;
int m, n;
vvi dp;
//=====================================
// Functions and procedures
// File I/O and utilities
void FileInit() { FILEOP() }
void FileDebug() {
#ifdef DEBUG
FILEOP_DEBUG()
#else
FILEOP()
#endif
}
void FileClose() {
fclose(stdin);
fclose(stdout);
}
// Enter
void Enter() {
cin >> s >> t;
s = '$' + s;
t = '#' + t;
n = s.size() - 1;
m = t.size() - 1;
dp = vvi(n + 2, vi(n + 2, 0));
}
// Check
void Solve() {
FOR(i, 1, n) {
FOR(j, 1, m) {
maximize(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
if (s[i] == t[j])
maximize(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
int i = n, j = m;
while (i > 0 && j > 0) {
if (s[i] == t[j])
res = s[i] + res, --j, --i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else
--i;
}
cout << res << el;
}
// Main Procedure
int main() {
Enter();
Solve();
return 0;
}
//=============================================================================//
/** CTB, you are always in my heart and in my code <3 #30yearsCTB **/
//=============================================================================//
|
/*==========================================================================================*\
** _ _ _ _ _ _ _ **
** | |__ _ _/ | |_| |__ | || | _ __ | |__ **
** | '_ \| | | | | __| '_ \| || |_| '_ \| '_ \ **
** | |_) | |_| | | |_| | | |__ _| | | | | | | **
** |_.__/ \__,_|_|\__|_| |_| |_| |_| |_|_| |_| **
\*==========================================================================================*/
//=====================================
// Solution Briefing - Foreword
//=====================================
// Libraries and namespaces
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#if __cplusplus >= 201103L
#include <chrono>
#include <random>
#include <unordered_map>
#include <unordered_set>
#endif // __cplusplus
using namespace std;
// #define DEBUG
#define OPTIONAL_FEATURE
//=====================================
// Macroes
#define sp ' '
#define el '\n'
#define task ""
#define maxinp ()
#define fi first
#define se second
#define pb push_back
#define whole(x) x.begin(), x.end()
#define whole_1(x) x.begin() + 1, x.end()
#define r_whole(x) x.rbegin(), x.rend()
#define FOR(i, x, y) for (auto i = x; i <= y; ++i)
#define FORl(i, x, y) for (auto i = x; i < y; ++i)
#define FORb(i, x, y) for (auto i = x; i >= y; --i)
#define FORlb(i, x, y) for (auto i = x; i > y; --i)
#define MEMS(x, val) memset(x, val, sizeof(x))
#define what_is(x) cerr << #x << " is " << x << endl;
#define FILEOP() \
{ \
freopen(task ".inp", "r", stdin); \
freopen(task ".out", "w", stdout); \
}
#define FILEOP_DEBUG() \
{ \
freopen(task ".inp", "r", stdin); \
freopen(task ".out", "w", stdout); \
freopen(task ".err", "w", stderr); \
}
// Macroes - Optional
#ifdef OPTIONAL_FEATURE
#define pc(x) putchar(x)
#define gc() getchar()
#endif
//=====================================
// Auxilary Functions and Fast I/O
#ifdef OPTIONAL_FEATURE
template <class T, class R> T max(const T &__X, const R &__Y) {
return __X > __Y ? __X : __Y;
}
template <class T, class R> T min(const T &__X, const R &__Y) {
return __X < __Y ? __X : __Y;
}
template <class T, class R> void maximize(T &__X, R __Y) {
__X = __X > __Y ? __X : __Y;
}
template <class T, class R> void minimize(T &__X, R __Y) {
__X = __X < __Y ? __X : __Y;
}
template <class T> int getBit(T &__X, int __i) {
return ((__X >> __i) & 1) == 1;
}
template <class T> bool inRange(T __L, T __R, T __X) {
return __L <= __X && __X <= __R;
}
template <class T> T __abs(T __X) { return (__X < 0) ? -__X : __X; }
#endif
// Fast I/O
template <class T> inline void scan(T &__ret) {
__ret = T();
char c = 0;
bool neg = 0;
while (isdigit(c) == 0 && c != '-')
c = getchar();
if (c == '-') {
neg = 1;
c = getchar();
}
for (; isdigit(c) != 0; c = getchar())
__ret = __ret * 10 + c - '0';
__ret = (neg) ? -__ret : __ret;
}
template <class T> void print(T __X) {
if (__X < 0) {
putchar('-');
__X *= -1;
}
if (__X > 9)
print(__X / 10);
putchar(__X % 10 + '0');
}
//=====================================
// Constants
//=====================================
// Typedefs
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vii> vvii;
string s, t, res;
int m, n;
vvi dp;
//=====================================
// Functions and procedures
// File I/O and utilities
void FileInit() { FILEOP() }
void FileDebug() {
#ifdef DEBUG
FILEOP_DEBUG()
#else
FILEOP()
#endif
}
void FileClose() {
fclose(stdin);
fclose(stdout);
}
// Enter
void Enter() {
cin >> s >> t;
s = '$' + s;
t = '#' + t;
n = s.size() - 1;
m = t.size() - 1;
dp = vvi(n + 2, vi(m + 2, 0));
}
// Check
void Solve() {
FOR(i, 1, n) {
FOR(j, 1, m) {
maximize(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
if (s[i] == t[j])
maximize(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
int i = n, j = m;
while (i > 0 && j > 0) {
if (s[i] == t[j])
res = s[i] + res, --j, --i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else
--i;
}
cout << res << el;
}
// Main Procedure
int main() {
Enter();
Solve();
return 0;
}
//=============================================================================//
/** CTB, you are always in my heart and in my code <3 #30yearsCTB **/
//=============================================================================//
|
replace
| 177 | 178 | 177 | 178 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int main() {
string s;
string t;
cin >> s >> t;
int dp[100][100];
for (int i = 0; i <= s.length(); i++) {
for (int j = 0; j <= t.length(); j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[s.length()][t.length()];
int i = s.length(), j = t.length();
char ans[dp[i][j] + 1];
ans[dp[i][j]] = '\0';
int k = dp[s.length()][t.length()] - 1;
while (i >= 0 && j >= 0) {
if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
ans[k--] = s[i - 1];
i--;
j--;
} else if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int main() {
string s;
string t;
cin >> s >> t;
int m = s.length();
int n = t.length();
int dp[m + 5][n + 5];
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[s.length()][t.length()];
int i = s.length(), j = t.length();
char ans[dp[i][j] + 1];
ans[dp[i][j]] = '\0';
int k = dp[s.length()][t.length()] - 1;
while (i >= 0 && j >= 0) {
if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
ans[k--] = s[i - 1];
i--;
j--;
} else if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
cout << ans << endl;
}
|
replace
| 7 | 10 | 7 | 13 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> bool ChangeMax(T &a, const T &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> bool ChangeMin(T &a, const T &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
int main() {
string s, t;
cin >> s >> t;
const int slen = (int)s.size(), tlen = (int)t.size();
vector<vector<int>> dp(slen + 1, vector<int>(tlen + 1, 0));
for (int i = 1; i <= slen; ++i) {
for (int j = 1; j <= tlen; ++j) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i - 1] == t[j - 1]) {
ChangeMax(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
string ans;
int spos = slen, tpos = tlen;
while (spos > 0 || tpos > 0) {
if (s[spos - 1] == t[tpos - 1]) {
ans += s[spos - 1];
spos--;
tpos--;
} else {
if (dp[spos - 1][tpos] > dp[spos][tpos - 1])
spos--;
else
tpos--;
}
}
if (ans.size() > 0)
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
// int main(){
// string s,t; cin >> s >> t;
// static string mp[3001][3001] = {};
// int slen = (int)s.size(), tlen = (int)t.size();
// vector<vector<int>> dp(slen+1,vector<int>(tlen+1,0));
// for(int i = 1; i <= slen; ++i){
// for(int j = 1; j <= tlen; ++j){
// dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
// mp[i][j] = (dp[i-1][j] < dp[i][j-1] ? mp[i][j-1] : mp[i-1][j]);
// if(s[i-1] == t[j-1]){
// if(ChangeMax(dp[i][j],dp[i-1][j-1] + 1)) mp[i][j] = mp[i-1][j-1] +
// s[i-1];
// }
// mp[i-1][j-1]="";
// mp[i-1][j-1].shrink_to_fit();
// }
// }
// cout << mp[slen][tlen] << endl;
// return 0;
// }
|
#include <bits/stdc++.h>
using namespace std;
#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> bool ChangeMax(T &a, const T &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> bool ChangeMin(T &a, const T &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
int main() {
string s, t;
cin >> s >> t;
const int slen = (int)s.size(), tlen = (int)t.size();
vector<vector<int>> dp(slen + 1, vector<int>(tlen + 1, 0));
for (int i = 1; i <= slen; ++i) {
for (int j = 1; j <= tlen; ++j) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i - 1] == t[j - 1]) {
ChangeMax(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
}
string ans;
int spos = slen, tpos = tlen;
while (spos > 0 && tpos > 0) {
if (s[spos - 1] == t[tpos - 1]) {
ans += s[spos - 1];
spos--;
tpos--;
} else {
if (dp[spos - 1][tpos] > dp[spos][tpos - 1])
spos--;
else
tpos--;
}
}
if (ans.size() > 0)
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
// int main(){
// string s,t; cin >> s >> t;
// static string mp[3001][3001] = {};
// int slen = (int)s.size(), tlen = (int)t.size();
// vector<vector<int>> dp(slen+1,vector<int>(tlen+1,0));
// for(int i = 1; i <= slen; ++i){
// for(int j = 1; j <= tlen; ++j){
// dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
// mp[i][j] = (dp[i-1][j] < dp[i][j-1] ? mp[i][j-1] : mp[i-1][j]);
// if(s[i-1] == t[j-1]){
// if(ChangeMax(dp[i][j],dp[i-1][j-1] + 1)) mp[i][j] = mp[i-1][j-1] +
// s[i-1];
// }
// mp[i-1][j-1]="";
// mp[i-1][j-1].shrink_to_fit();
// }
// }
// cout << mp[slen][tlen] << endl;
// return 0;
// }
|
replace
| 53 | 54 | 53 | 54 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// #define int int64_t
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
template <typename String> String lcs(String const &a, String const &b) {
const int n = a.size(), m = b.size();
static int X[2048][2048], Y[2048][2048]; // 16MB x 2
rep(i, n + 1) X[i][0] = 0;
rep(i, m + 1) Y[0][i] = 0;
rep(i, n) rep(j, m) {
if (a[i] == b[j]) {
X[i + 1][j + 1] = X[i][j] + 1;
Y[i + 1][j + 1] = 0;
} else if (X[i + 1][j] < X[i][j + 1]) {
X[i + 1][j + 1] = X[i][j + 1];
Y[i + 1][j + 1] = +1;
} else {
X[i + 1][j + 1] = X[i + 1][j];
Y[i + 1][j + 1] = -1;
}
}
String c;
for (int i = n, j = m; i > 0 && j > 0;) {
if (Y[i][j] > 0)
--i;
else if (Y[i][j] < 0)
--j;
else {
c.push_back(a[i - 1]);
--i;
--j;
}
}
reverse(c.begin(), c.end());
return c;
}
signed main() {
//(1ll<<N)シフト演算のオーバーフローに気をつける
std::string x, y;
std::cin >> x >> y;
std::cout << lcs(x, y) << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
// #define int int64_t
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
template <typename String> String lcs(String const &a, String const &b) {
const int n = a.size(), m = b.size();
static int X[3030][3030], Y[3030][3030]; // 16MB x 2
rep(i, n + 1) X[i][0] = 0;
rep(i, m + 1) Y[0][i] = 0;
rep(i, n) rep(j, m) {
if (a[i] == b[j]) {
X[i + 1][j + 1] = X[i][j] + 1;
Y[i + 1][j + 1] = 0;
} else if (X[i + 1][j] < X[i][j + 1]) {
X[i + 1][j + 1] = X[i][j + 1];
Y[i + 1][j + 1] = +1;
} else {
X[i + 1][j + 1] = X[i + 1][j];
Y[i + 1][j + 1] = -1;
}
}
String c;
for (int i = n, j = m; i > 0 && j > 0;) {
if (Y[i][j] > 0)
--i;
else if (Y[i][j] < 0)
--j;
else {
c.push_back(a[i - 1]);
--i;
--j;
}
}
reverse(c.begin(), c.end());
return c;
}
signed main() {
//(1ll<<N)シフト演算のオーバーフローに気をつける
std::string x, y;
std::cin >> x >> y;
std::cout << lcs(x, y) << std::endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dp[3000][3000];
P pre[3000][3000];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
string s, t;
cin >> s >> t;
int len = 0;
P fin = P(0, 0);
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j]) {
if (dp[i][j] + 1 > dp[i + 1][j] && dp[i][j] + 1 > dp[i][j + 1]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
pre[i + 1][j + 1] = P(i, j);
if (len < dp[i + 1][j + 1]) {
fin = P(i, j);
len = dp[i + 1][j + 1];
}
} else if (dp[i][j + 1] > dp[i + 1][j]) {
dp[i + 1][j + 1] = dp[i][j + 1];
pre[i + 1][j + 1] = P(i, j + 1);
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
pre[i + 1][j + 1] = P(i + 1, j);
}
} else {
if (dp[i][j + 1] > dp[i + 1][j]) {
dp[i + 1][j + 1] = dp[i][j + 1];
pre[i + 1][j + 1] = P(i, j + 1);
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
pre[i + 1][j + 1] = P(i + 1, j);
}
}
}
}
// cout << dp[s.size()][t.size()] << endl;
vector<char> ans;
int l = fin.first + 1, r = fin.second + 1;
// cout << l << ' ' << r << endl;
while (l > 0 && r > 0) {
P p = pre[l][r];
if (s[l - 1] == t[r - 1] && l != p.first && r != p.second) {
ans.push_back(s[l - 1]);
// cout << l << ' ' << r << endl;
}
l = p.first;
r = p.second;
}
// cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[ans.size() - i - 1];
}
cout << endl;
}
|
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dp[3001][3001];
P pre[3001][3001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
string s, t;
cin >> s >> t;
int len = 0;
P fin = P(0, 0);
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j]) {
if (dp[i][j] + 1 > dp[i + 1][j] && dp[i][j] + 1 > dp[i][j + 1]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
pre[i + 1][j + 1] = P(i, j);
if (len < dp[i + 1][j + 1]) {
fin = P(i, j);
len = dp[i + 1][j + 1];
}
} else if (dp[i][j + 1] > dp[i + 1][j]) {
dp[i + 1][j + 1] = dp[i][j + 1];
pre[i + 1][j + 1] = P(i, j + 1);
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
pre[i + 1][j + 1] = P(i + 1, j);
}
} else {
if (dp[i][j + 1] > dp[i + 1][j]) {
dp[i + 1][j + 1] = dp[i][j + 1];
pre[i + 1][j + 1] = P(i, j + 1);
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
pre[i + 1][j + 1] = P(i + 1, j);
}
}
}
}
// cout << dp[s.size()][t.size()] << endl;
vector<char> ans;
int l = fin.first + 1, r = fin.second + 1;
// cout << l << ' ' << r << endl;
while (l > 0 && r > 0) {
P p = pre[l][r];
if (s[l - 1] == t[r - 1] && l != p.first && r != p.second) {
ans.push_back(s[l - 1]);
// cout << l << ' ' << r << endl;
}
l = p.first;
r = p.second;
}
// cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[ans.size() - i - 1];
}
cout << endl;
}
|
replace
| 13 | 15 | 13 | 15 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
int dp[N][N]; // dp[i][j] 到 i,j为止最长的公共子序列长度
int main() {
string s, t;
cin >> s >> t;
s = "0" + s;
t = "0" + t;
int ls = s.size(), lt = t.size();
for (int i = 1; i < ls; i++) {
for (int j = 1; j < lt; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]);
}
}
string ans = "";
for (int i = ls - 1, j = lt - 1; i && j;) {
if (s[i] == t[j])
ans += s[i], i--, j--;
else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 7;
int dp[N][N]; // dp[i][j] 到 i,j为止最长的公共子序列长度
int main() {
string s, t;
cin >> s >> t;
s = "0" + s;
t = "0" + t;
int ls = s.size(), lt = t.size();
for (int i = 1; i < ls; i++) {
for (int j = 1; j < lt; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]);
}
}
string ans = "";
for (int i = ls - 1, j = lt - 1; i && j;) {
if (s[i] == t[j])
ans += s[i], i--, j--;
else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << "\n";
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int memo[1005][1005]; /// ... for storing DP values ...
string a, b; /// ... Two Strings ...
int call(int len1, int len2) {
/// if two string come to the end then there are no substring can create ...
/// so we return Zero.
if (len1 == (int)a.size() || len2 == (int)b.size())
return 0;
/// ... if the value is saved before then return it ...
if (memo[len1][len2] != -1)
return memo[len1][len2];
/// ... if two charecture is matched ... then the length is increased by one
/// and we go to the next phase (i + 1, j + 1) ...
if (a[len1] == b[len2]) {
return memo[len1][len2] = 1 + call(len1 + 1, len2 + 1);
}
/**
if not then we go to either by removing charecture of first or form
second. then we collect the maximun the two function returns and saves it.
**/
else
return memo[len1][len2] = max(call(len1 + 1, len2), call(len1, len2 + 1));
}
/// ... printing LCS ...
vector<char> res;
void PrintLCS(int len1, int len2) {
if (len1 == (int)a.size() || len2 == (int)b.size())
return;
if (a[len1] == b[len2]) {
cout << a[len1];
PrintLCS(len1 + 1, len2 + 1);
} else {
if (memo[len1 + 1][len2] > memo[len1][len2 + 1])
PrintLCS(len1 + 1, len2);
else
PrintLCS(len1, len2 + 1);
}
}
int main() {
memset(memo, -1, sizeof(memo));
cin >> a >> b;
call(0, 0);
PrintLCS(0, 0);
}
|
#include <bits/stdc++.h>
using namespace std;
int memo[3005][3005]; /// ... for storing DP values ...
string a, b; /// ... Two Strings ...
int call(int len1, int len2) {
/// if two string come to the end then there are no substring can create ...
/// so we return Zero.
if (len1 == (int)a.size() || len2 == (int)b.size())
return 0;
/// ... if the value is saved before then return it ...
if (memo[len1][len2] != -1)
return memo[len1][len2];
/// ... if two charecture is matched ... then the length is increased by one
/// and we go to the next phase (i + 1, j + 1) ...
if (a[len1] == b[len2]) {
return memo[len1][len2] = 1 + call(len1 + 1, len2 + 1);
}
/**
if not then we go to either by removing charecture of first or form
second. then we collect the maximun the two function returns and saves it.
**/
else
return memo[len1][len2] = max(call(len1 + 1, len2), call(len1, len2 + 1));
}
/// ... printing LCS ...
vector<char> res;
void PrintLCS(int len1, int len2) {
if (len1 == (int)a.size() || len2 == (int)b.size())
return;
if (a[len1] == b[len2]) {
cout << a[len1];
PrintLCS(len1 + 1, len2 + 1);
} else {
if (memo[len1 + 1][len2] > memo[len1][len2 + 1])
PrintLCS(len1 + 1, len2);
else
PrintLCS(len1, len2 + 1);
}
}
int main() {
memset(memo, -1, sizeof(memo));
cin >> a >> b;
call(0, 0);
PrintLCS(0, 0);
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
// freopen("LCS.inp","r",stdin);
int i, j;
string s, t, k = "";
getline(cin, s);
getline(cin, t);
int f[s.length()][t.length()];
for (i = 0; i <= s.length(); i++)
f[i][0] = 0;
for (j = 0; j <= t.length(); j++)
f[0][j] = 0;
for (i = 1; i <= s.length(); i++)
for (j = 1; j <= t.length(); j++) {
if (s[i - 1] == t[j - 1])
f[i][j] = f[i - 1][j - 1] + 1;
else
f[i][j] = max(f[i - 1][j], f[i][j - 1]);
}
i = s.length();
j = t.length();
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
k = char(s[i - 1]) + k;
// cout<<"chon "<<i<<j<<s[i-1]<<endl;
i--;
j--;
} else {
if (f[i][j - 1] == f[i][j])
j--;
else
i--;
}
}
cout << k;
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
// freopen("LCS.inp","r",stdin);
int i, j;
string s, t, k = "";
getline(cin, s);
getline(cin, t);
int f[s.length() + 1][t.length() + 1];
for (i = 0; i <= s.length(); i++)
f[i][0] = 0;
for (j = 0; j <= t.length(); j++)
f[0][j] = 0;
for (i = 1; i <= s.length(); i++)
for (j = 1; j <= t.length(); j++) {
if (s[i - 1] == t[j - 1])
f[i][j] = f[i - 1][j - 1] + 1;
else
f[i][j] = max(f[i - 1][j], f[i][j - 1]);
}
i = s.length();
j = t.length();
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
k = char(s[i - 1]) + k;
// cout<<"chon "<<i<<j<<s[i-1]<<endl;
i--;
j--;
} else {
if (f[i][j - 1] == f[i][j])
j--;
else
i--;
}
}
cout << k;
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a) << 1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a, b) ((a + b) >> 1)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
const ll N = 1e3 + 5;
string A, B;
int n, m;
int dp[N][N];
string S;
void go(int x, int y) {
if (dp[x][y] == 0)
return;
if (dp[x][y] == dp[x - 1][y]) {
go(x - 1, y);
return;
}
if (dp[x][y] == dp[x][y - 1]) {
go(x, y - 1);
return;
}
S += A[x];
go(x - 1, y - 1);
}
int main() {
ios::sync_with_stdio(false);
cin >> A >> B;
n = (int)A.size();
m = (int)B.size();
A = "#" + A;
B = "#" + B;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (A[i] == B[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
go(n, m);
for (int i = dp[n][m] - 1; i >= 0; i--)
cout << S[i];
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a) << 1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a, b) ((a + b) >> 1)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
const ll N = 3e3 + 5;
string A, B;
int n, m;
int dp[N][N];
string S;
void go(int x, int y) {
if (dp[x][y] == 0)
return;
if (dp[x][y] == dp[x - 1][y]) {
go(x - 1, y);
return;
}
if (dp[x][y] == dp[x][y - 1]) {
go(x, y - 1);
return;
}
S += A[x];
go(x - 1, y - 1);
}
int main() {
ios::sync_with_stdio(false);
cin >> A >> B;
n = (int)A.size();
m = (int)B.size();
A = "#" + A;
B = "#" + B;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (A[i] == B[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
go(n, m);
for (int i = dp[n][m] - 1; i >= 0; i--)
cout << S[i];
cout << endl;
return 0;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define li long long int
const int N = 1e3 + 5;
const li mod = 1e9 + 7;
string a, b;
int n, m;
int dp[N][N];
int go(int x, int y) {
if (x >= n or y >= m)
return dp[x][y] = 0;
if (dp[x][y] != -1)
return dp[x][y];
int ans = 0;
if (a[x] == b[y])
ans = 1 + go(x + 1, y + 1);
else
ans = max(go(x, y + 1), go(x + 1, y));
return dp[x][y] = ans;
}
void reconstruct(int x, int y) {
if (x >= n or y >= m)
exit(0);
if (dp[x][y + 1] != -1 and dp[x][y] == dp[x][y + 1]) {
reconstruct(x, y + 1);
} else if (dp[x + 1][y] != -1 and dp[x][y] == dp[x + 1][y]) {
reconstruct(x + 1, y);
} else if (dp[x + 1][y + 1] != -1 and dp[x][y] == 1 + dp[x + 1][y + 1]) {
cout << a[x];
reconstruct(x + 1, y + 1);
}
}
void solve() {
cin >> a >> b;
n = (int)a.length();
m = (int)b.length();
memset(dp, -1, sizeof(dp));
go(0, 0);
reconstruct(0, 0);
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define li long long int
const int N = 3e3 + 5;
const li mod = 1e9 + 7;
string a, b;
int n, m;
int dp[N][N];
int go(int x, int y) {
if (x >= n or y >= m)
return dp[x][y] = 0;
if (dp[x][y] != -1)
return dp[x][y];
int ans = 0;
if (a[x] == b[y])
ans = 1 + go(x + 1, y + 1);
else
ans = max(go(x, y + 1), go(x + 1, y));
return dp[x][y] = ans;
}
void reconstruct(int x, int y) {
if (x >= n or y >= m)
exit(0);
if (dp[x][y + 1] != -1 and dp[x][y] == dp[x][y + 1]) {
reconstruct(x, y + 1);
} else if (dp[x + 1][y] != -1 and dp[x][y] == dp[x + 1][y]) {
reconstruct(x + 1, y);
} else if (dp[x + 1][y + 1] != -1 and dp[x][y] == 1 + dp[x + 1][y + 1]) {
cout << a[x];
reconstruct(x + 1, y + 1);
}
}
void solve() {
cin >> a >> b;
n = (int)a.length();
m = (int)b.length();
memset(dp, -1, sizeof(dp));
go(0, 0);
reconstruct(0, 0);
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define PB push_back
#define PII pair<long long, long long>
#define FAST \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const ll MAXN = 1e3 + 10, INF = 8e18, MOD = 1e9 + 10;
int lcs[MAXN][MAXN];
pair<int, int> parent[MAXN][MAXN];
int main() {
string a, b;
cin >> a >> b;
memset(lcs, 0, sizeof(lcs));
int n = (int)a.size(), m = (int)b.size();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
if (a[i - 1] == b[j - 1])
lcs[i][j] = lcs[i - 1][j - 1] + 1;
}
}
vector<char> v;
while (n && m) {
if (lcs[n][m] == lcs[n - 1][m])
n--;
else if (lcs[n][m] == lcs[n][m - 1])
m--;
else {
v.push_back(a[n - 1]);
n--, m--;
}
}
reverse(v.begin(), v.end());
for (auto u : v)
cout << u;
}
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define PB push_back
#define PII pair<long long, long long>
#define FAST \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const ll MAXN = 3e3 + 10, INF = 8e18, MOD = 1e9 + 10;
int lcs[MAXN][MAXN];
pair<int, int> parent[MAXN][MAXN];
int main() {
string a, b;
cin >> a >> b;
memset(lcs, 0, sizeof(lcs));
int n = (int)a.size(), m = (int)b.size();
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
if (a[i - 1] == b[j - 1])
lcs[i][j] = lcs[i - 1][j - 1] + 1;
}
}
vector<char> v;
while (n && m) {
if (lcs[n][m] == lcs[n - 1][m])
n--;
else if (lcs[n][m] == lcs[n][m - 1])
m--;
else {
v.push_back(a[n - 1]);
n--, m--;
}
}
reverse(v.begin(), v.end());
for (auto u : v)
cout << u;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 4e18, N = 3001;
string s, t;
ll dp[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
for (int i = 0; i <= s.size(); i += 1)
for (int j = 0; j <= t.size(); j += 1)
dp[i][j] = 0;
for (int i = 0; i <= s.size(); i += 1)
dp[i][0] = 0;
for (int i = 0; i <= t.size(); i += 1)
dp[0][i] = 0;
string ans;
for (int i = 1; i <= s.size(); i += 1) {
for (int j = 1; j <= t.size(); j += 1) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = s.size();
int j = t.size();
while (i >= 0 && j >= 0) {
if (dp[i][j] == dp[i - 1][j])
i -= 1;
else if (dp[i][j] == dp[i][j - 1])
j -= 1;
else
ans += s[i - 1], i -= 1, j -= 1;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 4e18, N = 3001;
string s, t;
ll dp[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
for (int i = 0; i <= s.size(); i += 1)
for (int j = 0; j <= t.size(); j += 1)
dp[i][j] = 0;
for (int i = 0; i <= s.size(); i += 1)
dp[i][0] = 0;
for (int i = 0; i <= t.size(); i += 1)
dp[0][i] = 0;
string ans;
for (int i = 1; i <= s.size(); i += 1) {
for (int j = 1; j <= t.size(); j += 1) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = s.size();
int j = t.size();
while (i >= 1 && j >= 1) {
if (dp[i][j] == dp[i - 1][j])
i -= 1;
else if (dp[i][j] == dp[i][j - 1])
j -= 1;
else
ans += s[i - 1], i -= 1, j -= 1;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 37 | 38 | 37 | 38 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define mem(x) memset(x, 0, sizeof(x));
#define what_is(x) cout << #x << " is " << x << flush << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;
const int maxn = 100010;
int n, w;
void solve() {
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
int dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp));
rep(i, 1, n + 1) {
rep(j, 1, m + 1) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string ans = "";
int i = n, j = m;
int flag = 0;
if (n > m)
flag = 1;
while (i > 0 || j > 0) {
if (dp[i - 1][j - 1] + 1 == dp[i][j]) {
ans += s[i - 1];
i--;
j--;
} else {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 1000000007
#define mem(x) memset(x, 0, sizeof(x));
#define what_is(x) cout << #x << " is " << x << flush << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;
const int maxn = 100010;
int n, w;
void solve() {
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
int dp[n + 1][m + 1];
memset(dp, 0, sizeof(dp));
rep(i, 1, n + 1) {
rep(j, 1, m + 1) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string ans = "";
int i = n, j = m;
int flag = 0;
if (n > m)
flag = 1;
while (i > 0 && j > 0) {
if (dp[i - 1][j - 1] + 1 == dp[i][j] && s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--;
j--;
} else {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
|
replace
| 42 | 44 | 42 | 44 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
const int N = 1e3 + 44;
const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;
int dp[N][N];
pair<int, int> p[N][N];
int a[N], b[N];
int main() {
boost;
string s, t;
cin >> s >> t;
int ns = s.size(), nt = t.size();
for (int i = 0; i < ns; ++i)
a[i + 1] = (int)(s[i] - 'a');
for (int i = 0; i < nt; ++i)
b[i + 1] = (int)(t[i] - 'a');
for (int i = 1; i <= ns; ++i) {
for (int j = 1; j <= nt; ++j) {
if (a[i] == b[j])
dp[i][j] = dp[i - 1][j - 1] + 1, p[i][j] = {i - 1, j - 1};
if (dp[i][j] <= dp[i - 1][j])
dp[i][j] = dp[i - 1][j], p[i][j] = {i - 1, j};
if (dp[i][j] <= dp[i][j - 1])
dp[i][j] = dp[i][j - 1], p[i][j] = {i, j - 1};
}
}
string ans = "";
while (ns && nt) {
if (p[ns][nt].first != ns && p[ns][nt].second != nt) {
ans += s[ns - 1];
}
tie(ns, nt) = p[ns][nt];
}
reverse(ans.begin(), ans.end());
cout << ans;
}
|
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
const int N = 4e3 + 44;
const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int inf = 1e9;
int dp[N][N];
pair<int, int> p[N][N];
int a[N], b[N];
int main() {
boost;
string s, t;
cin >> s >> t;
int ns = s.size(), nt = t.size();
for (int i = 0; i < ns; ++i)
a[i + 1] = (int)(s[i] - 'a');
for (int i = 0; i < nt; ++i)
b[i + 1] = (int)(t[i] - 'a');
for (int i = 1; i <= ns; ++i) {
for (int j = 1; j <= nt; ++j) {
if (a[i] == b[j])
dp[i][j] = dp[i - 1][j - 1] + 1, p[i][j] = {i - 1, j - 1};
if (dp[i][j] <= dp[i - 1][j])
dp[i][j] = dp[i - 1][j], p[i][j] = {i - 1, j};
if (dp[i][j] <= dp[i][j - 1])
dp[i][j] = dp[i][j - 1], p[i][j] = {i, j - 1};
}
}
string ans = "";
while (ns && nt) {
if (p[ns][nt].first != ns && p[ns][nt].second != nt) {
ans += s[ns - 1];
}
tie(ns, nt) = p[ns][nt];
}
reverse(ans.begin(), ans.end());
cout << ans;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
const long long inf = 1e18;
ll dp[3005][3005];
string find(string a, string b) {
ll n = a.length();
ll m = b.length();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
ll i = n;
ll j = m;
string ans = "";
while (i > 0 and j > 0) {
if (a[i - 1] == b[j - 1]) {
ans = a[i - 1] + ans;
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
cout << ans;
}
void testCase() {
// ll t; cin>>t; while(t--)
{
string a, b;
cin >> a >> b;
cout << find(a, b) << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
testCase();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
const long long inf = 1e18;
ll dp[3005][3005];
string find(string a, string b) {
ll n = a.length();
ll m = b.length();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
ll i = n;
ll j = m;
string ans = "";
while (i > 0 and j > 0) {
if (a[i - 1] == b[j - 1]) {
ans = a[i - 1] + ans;
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
return ans;
}
void testCase() {
// ll t; cin>>t; while(t--)
{
string a, b;
cin >> a >> b;
cout << find(a, b) << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
testCase();
return 0;
}
|
replace
| 37 | 38 | 37 | 38 |
-6
|
free(): invalid pointer
|
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
template <class T> istream &operator>>(istream &in, vector<T> &arr) {
for (auto &x : arr)
in >> x;
return in;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &arr) {
for (auto &x : arr)
out << x << ' ';
cout << "\n";
return out;
}
enum { NW, N, W };
void printlcs(string s, vector<vector<int>> dp, int i, int j) {
if (i == 0 || j == 0) {
return;
}
if (dp[i][j] == NW) {
printlcs(s, dp, i - 1, j - 1);
cout << s[i - 1];
} else if (dp[i][j] == N) {
printlcs(s, dp, i - 1, j);
} else if (dp[i][j] == W) {
printlcs(s, dp, i, j - 1);
}
}
void lcs(string s, string t) {
int size_s = s.size();
int size_t = t.size();
vector<vector<int>> dp(size_s + 1, vector<int>(size_t + 1));
vector<vector<int>> pdp(size_s + 1, vector<int>(size_t + 1));
for (int i = 0; i <= size_s; i++) {
for (int j = 0; j <= size_t; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
pdp[i][j] = NW;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
pdp[i][j] = N;
} else {
dp[i][j] = dp[i][j - 1];
pdp[i][j] = W;
}
}
}
printlcs(s, pdp, size_s, size_t);
}
int main() {
string s, t;
cin >> s >> t;
lcs(s, t);
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
template <class T> istream &operator>>(istream &in, vector<T> &arr) {
for (auto &x : arr)
in >> x;
return in;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &arr) {
for (auto &x : arr)
out << x << ' ';
cout << "\n";
return out;
}
enum { NW, N, W };
void printlcs(const string &s, vector<vector<int>> &dp, int i, int j) {
if (i == 0 || j == 0) {
return;
}
if (dp[i][j] == NW) {
printlcs(s, dp, i - 1, j - 1);
cout << s[i - 1];
} else if (dp[i][j] == N) {
printlcs(s, dp, i - 1, j);
} else if (dp[i][j] == W) {
printlcs(s, dp, i, j - 1);
}
}
void lcs(string s, string t) {
int size_s = s.size();
int size_t = t.size();
vector<vector<int>> dp(size_s + 1, vector<int>(size_t + 1));
vector<vector<int>> pdp(size_s + 1, vector<int>(size_t + 1));
for (int i = 0; i <= size_s; i++) {
for (int j = 0; j <= size_t; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
pdp[i][j] = NW;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
pdp[i][j] = N;
} else {
dp[i][j] = dp[i][j - 1];
pdp[i][j] = W;
}
}
}
printlcs(s, pdp, size_s, size_t);
}
int main() {
string s, t;
cin >> s >> t;
lcs(s, t);
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq(int x) { return x * x; }
////////////////////////////////////////////////////////////////////Header
const int maxn = 3000;
string s, t;
int dp[maxn][maxn];
int n, m;
int getdp(int a, int b) {
if (a < 1 || b < 1)
return dp[a][b] = 0;
int &ret = dp[a][b];
if (ret != -1)
return ret;
ret = 0;
if (s[a] == t[b])
ret = max(ret, getdp(a - 1, b - 1) + 1);
else
ret = max(getdp(a - 1, b), getdp(a, b - 1));
return ret;
}
int main() {
cio();
cin >> s >> t;
n = size(s), m = size(t);
s = '0' + s;
t = '0' + t;
memset(dp, -1, sizeof(dp));
getdp(n, m);
vector<char> ans;
int i = n, j = m;
while (i >= 1 && j >= 1) {
if (s[i] == t[j] && dp[i][j] == dp[i - 1][j - 1] + 1) {
ans.pb(s[i]);
i--, j--;
} else if (dp[i][j] == dp[i][j - 1])
j--;
else
i--;
}
reverse(all(ans));
for (auto ci : ans)
cout << ci;
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq(int x) { return x * x; }
////////////////////////////////////////////////////////////////////Header
const int maxn = 3004;
string s, t;
int dp[maxn][maxn];
int n, m;
int getdp(int a, int b) {
if (a < 1 || b < 1)
return dp[a][b] = 0;
int &ret = dp[a][b];
if (ret != -1)
return ret;
ret = 0;
if (s[a] == t[b])
ret = max(ret, getdp(a - 1, b - 1) + 1);
else
ret = max(getdp(a - 1, b), getdp(a, b - 1));
return ret;
}
int main() {
cio();
cin >> s >> t;
n = size(s), m = size(t);
s = '0' + s;
t = '0' + t;
memset(dp, -1, sizeof(dp));
getdp(n, m);
vector<char> ans;
int i = n, j = m;
while (i >= 1 && j >= 1) {
if (s[i] == t[j] && dp[i][j] == dp[i - 1][j - 1] + 1) {
ans.pb(s[i]);
i--, j--;
} else if (dp[i][j] == dp[i][j - 1])
j--;
else
i--;
}
reverse(all(ans));
for (auto ci : ans)
cout << ci;
cout << endl;
}
|
replace
| 60 | 61 | 60 | 61 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
const int N = 1e9 + 1;
int32_t main() {
IOS;
string s, t;
cin >> s >> t;
int n = s.length();
int m = t.length();
int C[n + 1][m + 1];
int B[n + 1][m + 1];
for (int i = 0; i <= m; i++) {
C[0][i] = 0;
}
for (int i = 0; i <= n; i++) {
C[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (char(t[j - 1]) == char(s[i - 1])) {
C[i][j] = C[i - 1][j - 1] + 1;
B[i][j] = 'D';
} else {
C[i][j] = max(C[i - 1][j], C[i][j - 1]);
if (C[i - 1][j] < C[i][j - 1]) {
B[i][j] = 'L';
} else {
B[i][j] = 'U';
}
}
}
}
// cout<<C[n][m]<<endl;
int i = n, j = m;
string str = "";
while (1) {
if (i == 0 && j == 0)
break;
if (B[i][j] == 'D') {
str = t[j - 1] + str;
i--, j--;
} else if (B[i][j] == 'L') {
j--;
} else
i--;
}
cout << str << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
const int N = 1e9 + 1;
int32_t main() {
IOS;
string s, t;
cin >> s >> t;
int n = s.length();
int m = t.length();
int C[n + 1][m + 1];
int B[n + 1][m + 1];
for (int i = 0; i <= m; i++) {
C[0][i] = 0;
}
for (int i = 0; i <= n; i++) {
C[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (char(t[j - 1]) == char(s[i - 1])) {
C[i][j] = C[i - 1][j - 1] + 1;
B[i][j] = 'D';
} else {
C[i][j] = max(C[i - 1][j], C[i][j - 1]);
if (C[i - 1][j] < C[i][j - 1]) {
B[i][j] = 'L';
} else {
B[i][j] = 'U';
}
}
}
}
// cout<<C[n][m]<<endl;
int i = n, j = m;
string str = "";
while (1) {
if (i == 0 || j == 0)
break;
if (B[i][j] == 'D') {
str = t[j - 1] + str;
i--, j--;
} else if (B[i][j] == 'L') {
j--;
} else
i--;
}
cout << str << endl;
return 0;
}
|
replace
| 53 | 54 | 53 | 54 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define f(i, a, b) for (i = a; i < b; i++)
#define fr(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
using namespace std;
int dp[3005][3005];
int main() {
string s1, s2, s3 = "";
cin >> s1 >> s2;
int n1 = s1.size(), n2 = s2.size(), i, j;
f(i, 1, n1 + 1) f(j, 1, n2 + 1) {
if (s1[i - 1] == s2[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
for (i = n1, j = n2; i > 0, j > 0;) {
if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
s3 += s1[i - 1];
i--;
j--;
} else if (dp[i][j] != dp[i - 1][j] && j > 0)
j--;
else
i--;
}
reverse(s3.begin(), s3.end());
cout << s3;
}
|
#include <bits/stdc++.h>
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define f(i, a, b) for (i = a; i < b; i++)
#define fr(i, a, b) for (i = a; i >= b; i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
using namespace std;
int dp[3005][3005];
int main() {
string s1, s2, s3 = "";
cin >> s1 >> s2;
int n1 = s1.size(), n2 = s2.size(), i, j;
f(i, 1, n1 + 1) f(j, 1, n2 + 1) {
if (s1[i - 1] == s2[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
for (i = n1, j = n2; i > 0 && j > 0;) {
if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) {
s3 += s1[i - 1];
i--;
j--;
} else if (dp[i][j] != dp[i - 1][j] && j > 0)
j--;
else
i--;
}
reverse(s3.begin(), s3.end());
cout << s3;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p03165
|
C++
|
Runtime Error
|
// In the name of God
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e3 + 10, mod = 1e9 + 7;
int dp[N][N];
pii par[N][N], lst;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
s = "!" + s;
t = "@" + t;
int ans = 0;
for (int i = 1; i < s.length(); i++)
for (int j = 1; j < t.length(); j++) {
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1),
par[i][j] = {i - 1, j - 1};
else {
if (dp[i - 1][j] > dp[i][j]) {
dp[i][j] = dp[i - 1][j];
par[i][j] = {i - 1, j};
}
if (dp[i][j - 1] > dp[i][j]) {
dp[i][j] = dp[i][j - 1];
par[i][j] = {i, j - 1};
}
}
if (dp[i][j] > ans) {
ans = dp[i][j];
lst = {i, j};
}
}
string ret = "";
while (lst.first != 0 && lst.second != 0) {
int i = lst.first, j = lst.second;
if (s[i] == t[j])
ret = ret + s[i];
lst = par[i][j];
}
reverse(ret.begin(), ret.end());
cout << ret;
return 0;
}
|
// In the name of God
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 3e3 + 10, mod = 1e9 + 7;
int dp[N][N];
pii par[N][N], lst;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s, t;
cin >> s >> t;
s = "!" + s;
t = "@" + t;
int ans = 0;
for (int i = 1; i < s.length(); i++)
for (int j = 1; j < t.length(); j++) {
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1),
par[i][j] = {i - 1, j - 1};
else {
if (dp[i - 1][j] > dp[i][j]) {
dp[i][j] = dp[i - 1][j];
par[i][j] = {i - 1, j};
}
if (dp[i][j - 1] > dp[i][j]) {
dp[i][j] = dp[i][j - 1];
par[i][j] = {i, j - 1};
}
}
if (dp[i][j] > ans) {
ans = dp[i][j];
lst = {i, j};
}
}
string ret = "";
while (lst.first != 0 && lst.second != 0) {
int i = lst.first, j = lst.second;
if (s[i] == t[j])
ret = ret + s[i];
lst = par[i][j];
}
reverse(ret.begin(), ret.end());
cout << ret;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03165
|
C++
|
Runtime Error
|
/*#include<iostream>
#include<algorithm>
using namespace std;
int knapsack(int c, int items, int values[], int w[])
{
int i = 0;
int p;
int dp[4][9];
for (; i < items; i++)
{
for (p = 0; p <= c; p++)
{
if (i == 0 || p == 0)
dp[i][p] = 0;
else if (w[i - 1] > p)
dp[i][p] = max(values[i] + dp[i - 1][p - w[i -
1]], dp[i - 1][p]); else dp[i][p] = dp[i - 1][p];
}
cout << "GGGG";
}
return dp[c][p];
}
int main()
{
cout << "GGGG";
/*map<int, int>m;
m[10] = 100;
m[5] = 25;
m[3] = 9;
m[4] = 16;
m.insert(make_pair(10, 700));
m.insert(make_pair(10, 600));
for (auto it = m.begin(); it != m.end(); it++)
cout << it->first << " " << it->second<<endl;*/
/*multimap<int, int>m;
m.insert(make_pair(10, 100));
m.insert(make_pair(20, 200));
m.insert(make_pair(30, 300));
m.insert(make_pair(10, 700));
m.insert(make_pair(20, 100));
for (auto it = m.begin(); it != m.end(); it++)
cout << it->first << " " << it->second << endl;
int values[] = { 30,50,60 };
int w[] = { 3,4,5 };
int tw = 8;
cout << "GGGG";
cout << knapsack(tw, 3, values, w);
}*/
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
void lcs(string s, string t, int m, int n) {
int dp[m + 1][n + 1];
int i, j;
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
/*for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
// cout << dp[m][n];
int index = dp[m][n];
// char values[index+1];*/
i = m;
j = n;
vector<char> v;
// values[index] = '\0';
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
v.push_back(s[i - 1]);
// values[index-1]=s[i-1];
i--;
j--;
index--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
for (auto itr = v.end() - 1; itr >= v.begin(); itr--)
cout << *itr;
// cout<<values;
}
int main() {
int m, n;
string s, t;
cin >> s >> t;
m = s.length();
n = t.length();
lcs(s, t, m, n);
}
|
/*#include<iostream>
#include<algorithm>
using namespace std;
int knapsack(int c, int items, int values[], int w[])
{
int i = 0;
int p;
int dp[4][9];
for (; i < items; i++)
{
for (p = 0; p <= c; p++)
{
if (i == 0 || p == 0)
dp[i][p] = 0;
else if (w[i - 1] > p)
dp[i][p] = max(values[i] + dp[i - 1][p - w[i -
1]], dp[i - 1][p]); else dp[i][p] = dp[i - 1][p];
}
cout << "GGGG";
}
return dp[c][p];
}
int main()
{
cout << "GGGG";
/*map<int, int>m;
m[10] = 100;
m[5] = 25;
m[3] = 9;
m[4] = 16;
m.insert(make_pair(10, 700));
m.insert(make_pair(10, 600));
for (auto it = m.begin(); it != m.end(); it++)
cout << it->first << " " << it->second<<endl;*/
/*multimap<int, int>m;
m.insert(make_pair(10, 100));
m.insert(make_pair(20, 200));
m.insert(make_pair(30, 300));
m.insert(make_pair(10, 700));
m.insert(make_pair(20, 100));
for (auto it = m.begin(); it != m.end(); it++)
cout << it->first << " " << it->second << endl;
int values[] = { 30,50,60 };
int w[] = { 3,4,5 };
int tw = 8;
cout << "GGGG";
cout << knapsack(tw, 3, values, w);
}*/
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
void lcs(string s, string t, int m, int n) {
int dp[m + 1][n + 1];
int i, j;
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
/*for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
// cout << dp[m][n];
int index = dp[m][n];
// char values[index+1];*/
i = m;
j = n;
vector<char> v;
// values[index] = '\0';
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
v.push_back(s[i - 1]);
// values[index-1]=s[i-1];
i--;
j--;
index--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
if (v.size() == 0)
cout << " ";
else {
for (auto itr = v.end() - 1; itr >= v.begin(); itr--)
cout << *itr;
}
// cout<<values;
}
int main() {
int m, n;
string s, t;
cin >> s >> t;
m = s.length();
n = t.length();
lcs(s, t, m, n);
}
|
replace
| 99 | 101 | 99 | 105 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define req(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
int n, m, x, y, q;
ll z, w = 0, sum = 0, ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
string s, t, ans;
cin >> s >> t;
int dp[301][301];
Fill(dp, 0);
rep(i, s.size() + 1) {
rep(j, t.size() + 1) {
if (s[i] == t[j])
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans += s[i - 1];
i--;
j--;
}
}
reverse(ALL(ans));
cout << ans << endl;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define req(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
int n, m, x, y, q;
ll z, w = 0, sum = 0, ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main(void) {
string s, t, ans;
cin >> s >> t;
int dp[3010][3010];
Fill(dp, 0);
rep(i, s.size() + 1) {
rep(j, t.size() + 1) {
if (s[i] == t[j])
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans += s[i - 1];
i--;
j--;
}
}
reverse(ALL(ans));
cout << ans << endl;
}
|
replace
| 30 | 31 | 30 | 31 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
#define _ % MOD
#define __ %= MOD
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b; \
}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
} // modular exponent
int main() {
ios_base::sync_with_stdio(false); // don't use printf and scanf
cin.tie(NULL); // cout<<fixed<<setprecision
string s, t;
vector<char> str;
getline(cin, s);
getline(cin, t);
int rows = s.length() + 1;
int cols = t.length() + 1;
int D[rows][cols];
int i, j;
for (i = 0; i < cols; i++)
D[0][i] = 0;
for (i = 0; i < rows; i++)
D[i][0] = 0;
for (i = 1; i < rows; i++) {
// int a=0;
for (j = 1; j < cols; j++) {
// cout<<"i = "<<i<<" j = "<<j<<" s["<<i-1<<"] = "<<s[i-1]<<"
//t["<<j-1<<"] = "<<t[j-1]<<"\n";
if (s[i - 1] == t[j - 1]) {
// a++;
// if(find(str.begin(),str.end(),s[i])==str.end())
// if(a==1)str.pb(s[i-1]);
D[i][j] = D[i - 1][j - 1] + 1;
} else {
D[i][j] = max(D[i - 1][j], D[i][j - 1]);
}
}
}
i = rows - 1;
j = cols - 1;
while (i || j) {
if (s[i - 1] == t[j - 1]) {
str.pb(s[i - 1]);
i--;
j--;
} else if (D[i - 1][j] >= D[i][j - 1])
i--;
else
j--;
}
// cout<<s[i-1]<<" chara "<<t[j-1]<<"\n";
// cout<<"size of lcs = "<<D[rows-1][cols-1]<<"\n";
reverse(str.begin(), str.end());
for (i = 0; i < str.size(); i++)
cout << str[i];
cout << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
#define _ % MOD
#define __ %= MOD
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b; \
}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
} // modular exponent
int main() {
ios_base::sync_with_stdio(false); // don't use printf and scanf
cin.tie(NULL); // cout<<fixed<<setprecision
string s, t;
vector<char> str;
getline(cin, s);
getline(cin, t);
int rows = s.length() + 1;
int cols = t.length() + 1;
int D[rows][cols];
int i, j;
for (i = 0; i < cols; i++)
D[0][i] = 0;
for (i = 0; i < rows; i++)
D[i][0] = 0;
for (i = 1; i < rows; i++) {
// int a=0;
for (j = 1; j < cols; j++) {
// cout<<"i = "<<i<<" j = "<<j<<" s["<<i-1<<"] = "<<s[i-1]<<"
//t["<<j-1<<"] = "<<t[j-1]<<"\n";
if (s[i - 1] == t[j - 1]) {
// a++;
// if(find(str.begin(),str.end(),s[i])==str.end())
// if(a==1)str.pb(s[i-1]);
D[i][j] = D[i - 1][j - 1] + 1;
} else {
D[i][j] = max(D[i - 1][j], D[i][j - 1]);
}
}
}
i = rows - 1;
j = cols - 1;
while (i && j) {
if (s[i - 1] == t[j - 1]) {
str.pb(s[i - 1]);
i--;
j--;
} else if (D[i - 1][j] >= D[i][j - 1])
i--;
else
j--;
}
// cout<<s[i-1]<<" chara "<<t[j-1]<<"\n";
// cout<<"size of lcs = "<<D[rows-1][cols-1]<<"\n";
reverse(str.begin(), str.end());
for (i = 0; i < str.size(); i++)
cout << str[i];
cout << "\n";
}
|
replace
| 93 | 94 | 93 | 94 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define trace(v) \
for (auto it = v.begin(); it != v.end(); it++) \
cerr << *it << " "; \
cerr << endl;
#define tr(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
int n, m;
int dp[3001][3001];
int LCS(string s1, string s2, int idx1, int idx2) {
if (idx1 >= n || idx2 >= m) {
return 0;
}
if (dp[idx1][idx2] != -1) {
return dp[idx1][idx2];
}
if (s1[idx1] == s2[idx2]) {
int ans = LCS(s1, s2, idx1 + 1, idx2 + 1);
++ans;
dp[idx1][idx2] = ans;
return ans;
} else {
int ans1 = LCS(s1, s2, idx1 + 1, idx2);
int ans2 = LCS(s1, s2, idx1, idx2 + 1);
if (ans1 > ans2) {
dp[idx1][idx2] = ans1;
return ans1;
} else {
dp[idx1][idx2] = ans2;
return ans2;
}
}
}
void solve() {
string s1, s2;
cin >> s1 >> s2;
n = sz(s1);
m = sz(s2);
forn(i, n) {
forn(j, m) { dp[i][j] = -1; }
}
int idx1 = 0, idx2 = 0;
LCS(s1, s2, idx1, idx2);
string final_string = "";
idx1 = 0, idx2 = 0;
while (idx1 < n && idx2 < m) {
if (s1[idx1] == s2[idx2]) {
final_string += s2[idx2];
idx1++;
idx2++;
} else if (dp[idx1 + 1][idx2] > dp[idx1][idx2 + 1]) {
idx1++;
} else {
idx2++;
}
}
cout << final_string << endl;
}
int main() {
zoom;
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define trace(v) \
for (auto it = v.begin(); it != v.end(); it++) \
cerr << *it << " "; \
cerr << endl;
#define tr(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
int n, m;
int dp[3001][3001];
int LCS(string &s1, string &s2, int idx1, int idx2) {
if (idx1 >= n || idx2 >= m) {
return 0;
}
if (dp[idx1][idx2] != -1) {
return dp[idx1][idx2];
}
if (s1[idx1] == s2[idx2]) {
int ans = LCS(s1, s2, idx1 + 1, idx2 + 1);
++ans;
dp[idx1][idx2] = ans;
return ans;
} else {
int ans1 = LCS(s1, s2, idx1 + 1, idx2);
int ans2 = LCS(s1, s2, idx1, idx2 + 1);
if (ans1 > ans2) {
dp[idx1][idx2] = ans1;
return ans1;
} else {
dp[idx1][idx2] = ans2;
return ans2;
}
}
}
void solve() {
string s1, s2;
cin >> s1 >> s2;
n = sz(s1);
m = sz(s2);
forn(i, n) {
forn(j, m) { dp[i][j] = -1; }
}
int idx1 = 0, idx2 = 0;
LCS(s1, s2, idx1, idx2);
string final_string = "";
idx1 = 0, idx2 = 0;
while (idx1 < n && idx2 < m) {
if (s1[idx1] == s2[idx2]) {
final_string += s2[idx2];
idx1++;
idx2++;
} else if (dp[idx1 + 1][idx2] > dp[idx1][idx2 + 1]) {
idx1++;
} else {
idx2++;
}
}
cout << final_string << endl;
}
int main() {
zoom;
ll t = 1;
// cin >> t;
while (t--) {
solve();
}
}
|
replace
| 55 | 56 | 55 | 56 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int dp[s.size() + 1][t.size() + 1];
for (int i = 0; i <= s.size(); i++)
dp[i][0] = 0;
for (int i = 0; i <= t.size(); i++)
dp[0][i] = 0;
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
if (dp[s.size()][t.size()] == 0) {
cout << ' ' << "\n";
return 0;
}
string com;
int i = s.size();
int j = t.size();
while (i != 0 || j != 0) {
if (s[i - 1] == t[j - 1]) {
com.push_back(s[i - 1]);
i--;
j--;
} else {
if (dp[i - 1][j] >= dp[i][j - 1])
i--;
else
j--;
}
}
reverse(com.begin(), com.end());
cout << com << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int dp[s.size() + 1][t.size() + 1];
for (int i = 0; i <= s.size(); i++)
dp[i][0] = 0;
for (int i = 0; i <= t.size(); i++)
dp[0][i] = 0;
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
if (dp[s.size()][t.size()] == 0) {
cout << ' ' << "\n";
return 0;
}
string com;
int i = s.size();
int j = t.size();
while (i != 0 && j != 0) {
if (s[i - 1] == t[j - 1]) {
com.push_back(s[i - 1]);
i--;
j--;
} else {
if (dp[i - 1][j] >= dp[i][j - 1])
i--;
else
j--;
}
}
reverse(com.begin(), com.end());
cout << com << "\n";
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define MAXN 1100
using namespace std;
int LCS[MAXN][MAXN];
char L[MAXN];
int main() {
string s1, s2;
cin >> s1 >> s2;
int x = s1.size();
int y = s2.size();
int i, j;
for (i = 0; i <= x; i++)
for (j = 0; j <= y; j++) {
if (i == 0 || j == 0)
LCS[i][j] = 0;
else if (s1[i - 1] == s2[j - 1]) {
LCS[i][j] = 1 + LCS[i - 1][j - 1];
} else {
LCS[i][j] = max(LCS[i - 1][j], LCS[i][j - 1]);
}
}
int index = LCS[x][y];
L[index + 1] = '\0';
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
L[index] = s1[i - 1];
i--;
j--;
index--;
} else {
if (LCS[i][j - 1] > LCS[i - 1][j]) {
j--;
} else
i--;
}
}
cout << L << endl;
}
|
#include <bits/stdc++.h>
#define MAXN 3500
using namespace std;
int LCS[MAXN][MAXN];
char L[MAXN];
int main() {
string s1, s2;
cin >> s1 >> s2;
int x = s1.size();
int y = s2.size();
int i, j;
for (i = 0; i <= x; i++)
for (j = 0; j <= y; j++) {
if (i == 0 || j == 0)
LCS[i][j] = 0;
else if (s1[i - 1] == s2[j - 1]) {
LCS[i][j] = 1 + LCS[i - 1][j - 1];
} else {
LCS[i][j] = max(LCS[i - 1][j], LCS[i][j - 1]);
}
}
int index = LCS[x][y];
L[index + 1] = '\0';
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
L[index] = s1[i - 1];
i--;
j--;
index--;
} else {
if (LCS[i][j - 1] > LCS[i - 1][j]) {
j--;
} else
i--;
}
}
cout << L << endl;
}
|
replace
| 1 | 2 | 1 | 2 |
0
| |
p03165
|
C++
|
Runtime Error
|
using namespace std;
#include <bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define FORD(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define TR(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define removeDuplicate(a) \
sort(a.begin(), a.end()); \
a.resize(distance(a.begin(), unique(a.begin(), a.end())))
const int N = 1e3 + 100;
const int MOD = 1e9 + 7;
int dp[N][N];
int main() {
#define TASK "TASK"
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
s = " " + s;
t = " " + t;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i] == t[j]) {
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 x = n, y = m;
while (x > 0 && y > 0) {
if (s[x] == t[y] and dp[x][y] > dp[x - 1][y] and dp[x][y] > dp[x][y - 1]) {
ans = ans + s[x];
x--;
y--;
} else {
if (dp[x - 1][y] > dp[x][y - 1]) {
x--;
} else {
y--;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
using namespace std;
#include <bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define FORD(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define TR(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define removeDuplicate(a) \
sort(a.begin(), a.end()); \
a.resize(distance(a.begin(), unique(a.begin(), a.end())))
const int N = 5e3 + 100;
const int MOD = 1e9 + 7;
int dp[N][N];
int main() {
#define TASK "TASK"
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
s = " " + s;
t = " " + t;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i] == t[j]) {
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 x = n, y = m;
while (x > 0 && y > 0) {
if (s[x] == t[y] and dp[x][y] > dp[x - 1][y] and dp[x][y] > dp[x][y - 1]) {
ans = ans + s[x];
x--;
y--;
} else {
if (dp[x - 1][y] > dp[x][y - 1]) {
x--;
} else {
y--;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03165
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
vector<vector<string>> st(s.size() + 1, vector<string>(t.size() + 1, ""));
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (st[i - 1][j].size() > st[i][j - 1].size()) {
st[i][j] = st[i - 1][j];
} else {
st[i][j] = st[i][j - 1];
}
if (s[i - 1] == t[j - 1] &&
(st[i - 1][j - 1].size() + 1) > st[i][j].size()) {
st[i][j] = st[i - 1][j - 1] + s[i - 1];
}
st[i - 1][j - 1].clear();
}
}
cout << st.back().back() << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
vector<vector<string>> st(s.size() + 1, vector<string>(t.size() + 1, ""));
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (st[i - 1][j].size() > st[i][j - 1].size()) {
st[i][j] = st[i - 1][j];
} else {
st[i][j] = st[i][j - 1];
}
if (s[i - 1] == t[j - 1] &&
(st[i - 1][j - 1].size() + 1) > st[i][j].size()) {
st[i][j] = st[i - 1][j - 1] + s[i - 1];
}
string().swap(st[i - 1][j - 1]);
}
}
cout << st.back().back() << endl;
}
|
replace
| 21 | 22 | 21 | 22 |
MLE
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
int dp[1010][1010];
int main() {
string a, b;
cin >> a >> b;
int n = a.size(), m = b.size();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = n, j = m;
string out = "";
int maxi = dp[n][m];
while (j > 0 && i > 0) {
if (a[i - 1] == b[j - 1]) {
if (dp[i - 1][j - 1] + 1 == dp[i][j]) {
out += b[j - 1];
i--;
j--;
maxi--;
}
} else if (dp[i - 1][j] == maxi)
i--;
else
j--;
}
for (int i = 0; i < out.size(); i++)
cout << out[out.size() - i - 1];
cout << endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int dp[3010][3010];
int main() {
string a, b;
cin >> a >> b;
int n = a.size(), m = b.size();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i - 1] == b[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int i = n, j = m;
string out = "";
int maxi = dp[n][m];
while (j > 0 && i > 0) {
if (a[i - 1] == b[j - 1]) {
if (dp[i - 1][j - 1] + 1 == dp[i][j]) {
out += b[j - 1];
i--;
j--;
maxi--;
}
} else if (dp[i - 1][j] == maxi)
i--;
else
j--;
}
for (int i = 0; i < out.size(); i++)
cout << out[out.size() - i - 1];
cout << endl;
}
|
replace
| 5 | 6 | 5 | 6 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.