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++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
const ll INF = 1LL << 60;
const ll mod = (int)1e9 + 7;
int main() {
// ll N; cin >> N;
// ll N,M; cin >> N >> M;
// string S; cin >> S;
// ll H,W; cin >> H >> W;
int dp[3100][3100] = {0};
string s, t;
cin >> s >> t;
rep(i, s.length()) {
rep(j, t.length()) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
}
}
string res = "";
int i = (int)s.size();
int j = (int)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 if (dp[i][j] == dp[i - 1][j - 1]) {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
}
/*
*/
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; i++)
const ll INF = 1LL << 60;
const ll mod = (int)1e9 + 7;
int main() {
// ll N; cin >> N;
// ll N,M; cin >> N >> M;
// string S; cin >> S;
// ll H,W; cin >> H >> W;
int dp[3100][3100] = {0};
string s, t;
cin >> s >> t;
rep(i, s.length()) {
rep(j, t.length()) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
}
}
string res = "";
int i = (int)s.size();
int j = (int)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 {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
}
/*
*/
|
replace
| 47 | 48 | 47 | 48 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
// Created by ahmed_drawy on 11/09/19.
/// dp educational contest atcoder
#include <bits/stdc++.h>
#include <string.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;
#define lp(i, start, end) for (int i = start; i < end; ++i)
#define lllp(i, start, end) for (ll i = start; i < end; ++i)
#define inN(arr, n) \
for (int i = 0; i < n; ++i) \
cin >> arr[i];
#define Rlp(i, start, end) for (int i = start; i > end; --i)
#define all(v) ((v).begin(), (v).end())
#define sz(v) (int)((v).size())
#define clr(v, d) memset(v, d, sizeof(v))
#define inf 0x3f3f3f3f
// #define dbg (v) for(auto it : v)cout<<it<<' ';
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> adj;
typedef pair<int, int> pii;
const double EPS = 1e-7;
const int OO = 1e6;
#define endl '\n'
#define cint(c) (int)c - '0';
#define itc(c) (char)c + 'A';
bool sortpair(const pair<int, int> &x, const pair<int, int> &y) {
return x.first != y.first ? x.first < y.first : x.second > y.second;
}
int dcomp(double x, double y) {
return fabs(x - y) <= EPS ? 0 : x > y ? 1 : -1;
}
void smile() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);
// freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);
#endif
}
#define fastin smile()
int n, m;
const int N = 3000 + 3;
int dp[N][N];
string s, t;
void build(int i, int j) {
if (i == n || j == m)
return;
if (s[i] == t[j]) {
cout << s[i];
build(i + 1, j + 1);
return;
}
if (dp[i + 1][j] > dp[i][j + 1])
build(i + 1, j);
else
build(i, j + 1);
return;
}
int main() {
fastin;
cin >> s >> t;
n = sz(s), m = sz(t);
for (int i = n - 1; i >= 0; --i) {
for (int j = m - 1; j >= 0; --j) {
int &ret = dp[i][j];
ret = 0;
if (s[i] == t[j])
ret = 1 + dp[i + 1][j + 1];
else {
ret = max(ret, dp[i + 1][j]);
ret = max(ret, dp[i][j + 1]);
}
}
}
build(0, 0);
}
|
// Created by ahmed_drawy on 11/09/19.
/// dp educational contest atcoder
#include <bits/stdc++.h>
#include <string.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;
#define lp(i, start, end) for (int i = start; i < end; ++i)
#define lllp(i, start, end) for (ll i = start; i < end; ++i)
#define inN(arr, n) \
for (int i = 0; i < n; ++i) \
cin >> arr[i];
#define Rlp(i, start, end) for (int i = start; i > end; --i)
#define all(v) ((v).begin(), (v).end())
#define sz(v) (int)((v).size())
#define clr(v, d) memset(v, d, sizeof(v))
#define inf 0x3f3f3f3f
// #define dbg (v) for(auto it : v)cout<<it<<' ';
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> adj;
typedef pair<int, int> pii;
const double EPS = 1e-7;
const int OO = 1e6;
#define endl '\n'
#define cint(c) (int)c - '0';
#define itc(c) (char)c + 'A';
bool sortpair(const pair<int, int> &x, const pair<int, int> &y) {
return x.first != y.first ? x.first < y.first : x.second > y.second;
}
int dcomp(double x, double y) {
return fabs(x - y) <= EPS ? 0 : x > y ? 1 : -1;
}
void smile() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
// freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);
// freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);
#endif
}
#define fastin smile()
int n, m;
const int N = 3000 + 3;
int dp[N][N];
string s, t;
void build(int i, int j) {
if (i == n || j == m)
return;
if (s[i] == t[j]) {
cout << s[i];
build(i + 1, j + 1);
return;
}
if (dp[i + 1][j] > dp[i][j + 1])
build(i + 1, j);
else
build(i, j + 1);
return;
}
int main() {
fastin;
cin >> s >> t;
n = sz(s), m = sz(t);
for (int i = n - 1; i >= 0; --i) {
for (int j = m - 1; j >= 0; --j) {
int &ret = dp[i][j];
ret = 0;
if (s[i] == t[j])
ret = 1 + dp[i + 1][j + 1];
else {
ret = max(ret, dp[i + 1][j]);
ret = max(ret, dp[i][j + 1]);
}
}
}
build(0, 0);
}
|
replace
| 40 | 41 | 40 | 41 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <cstdio> // 回溯输出
#include <cstring>
const int maxn = 3000;
char s[maxn], t[maxn];
int dp[maxn][maxn];
int max(int a, int b) { return a > b ? a : b; }
void print_string(int, int);
int main() {
scanf("%s %s", s + 1, t + 1);
memset(dp, 0, sizeof(dp));
int len1 = strlen(s + 1);
int len2 = strlen(t + 1);
int ans = 0;
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
if (i == len1 && j == len2)
ans = max(ans, dp[i][j]);
}
}
print_string(len1, len2);
printf("\n");
return 0;
}
void print_string(int i, int j) {
if (dp[i][j] == 0)
return;
if (s[i] == t[j] && dp[i][j] == dp[i - 1][j - 1] + 1) {
print_string(i - 1, j - 1);
printf("%c", s[i]);
}
else {
if (dp[i - 1][j] == dp[i][j])
print_string(i - 1, j);
else
print_string(i, j - 1);
}
}
|
#include <cstdio> // 回溯输出
#include <cstring>
const int maxn = 3000 + 5;
char s[maxn], t[maxn];
int dp[maxn][maxn];
int max(int a, int b) { return a > b ? a : b; }
void print_string(int, int);
int main() {
scanf("%s %s", s + 1, t + 1);
memset(dp, 0, sizeof(dp));
int len1 = strlen(s + 1);
int len2 = strlen(t + 1);
int ans = 0;
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
if (i == len1 && j == len2)
ans = max(ans, dp[i][j]);
}
}
print_string(len1, len2);
printf("\n");
return 0;
}
void print_string(int i, int j) {
if (dp[i][j] == 0)
return;
if (s[i] == t[j] && dp[i][j] == dp[i - 1][j - 1] + 1) {
print_string(i - 1, j - 1);
printf("%c", s[i]);
}
else {
if (dp[i - 1][j] == dp[i][j])
print_string(i - 1, j);
else
print_string(i, j - 1);
}
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <ctype.h>
#include <deque> //<< fixed << setprecision()
#include <iomanip>
#include <iostream>
#include <map>
#include <queue> //priority_queue
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));
struct point {
long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
double a =
(x2 * y3) - (x3 * y2) - (x1 * y3) + (x3 * y1) + (x1 * y2) - (x2 * y1);
a /= 2;
return fabs(a);
}
long double anyarea(point p[], int n) {
long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
for (int i = 0; i < n - 1; i++) {
sum1 += p[i].x * p[i + 1].y;
sum2 += p[i].y * p[i + 1].x;
}
return fabs((sum1 - sum2) * 0.5);
}
ll fastpow(ll base, ll p, ll m) {
if (p == 0)
return 1;
ll ans = fastpow(base, p / 2, m);
ans = ((ans % m) * (ans % m)) % m;
if (p % 2)
ans = ((base % m) * ans) % m;
return ans;
}
ll GCD(ll M, ll m) {
if (M % m == 0)
return m;
M %= m;
ll x1 = M, x2 = m;
m = min(x1, x2);
M = max(x1, x2);
return GCD(M, m);
}
ll lcm(ll M, ll m) { return (M * m) / GCD(max(M, m), min(M, m)); }
int n, n2, k;
string s, s2;
int dp[2005][2005];
int solve(int i, int j) {
if (dp[i][j] != -1) {
return dp[i][j];
}
if (i >= n || j >= n2)
return 0;
if (s[i] == s2[j]) {
return dp[i][j] = 1 + solve(i + 1, j + 1);
}
int m = 0, im = -1;
return dp[i][j] = max(solve(i, j + 1), solve(i + 1, j));
}
void fun(int i, int j) {
if (i >= n || j >= n2)
return;
if (s[i] == s2[j]) {
cout << s[i];
fun(i + 1, j + 1);
}
else if (dp[i][j] == (solve(i, j + 1))) {
fun(i, j + 1);
} else if (dp[i][j] == solve(i + 1, j)) {
fun(i + 1, j);
}
}
int main() {
cin >> s >> s2;
memset(dp, -1, sizeof dp);
n = s.size();
n2 = s2.size();
int x = solve(0, 0);
fun(0, 0);
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <ctype.h>
#include <deque> //<< fixed << setprecision()
#include <iomanip>
#include <iostream>
#include <map>
#include <queue> //priority_queue
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const double pi = (2 * acos(0));
struct point {
long double x, y;
};
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
double a =
(x2 * y3) - (x3 * y2) - (x1 * y3) + (x3 * y1) + (x1 * y2) - (x2 * y1);
a /= 2;
return fabs(a);
}
long double anyarea(point p[], int n) {
long double sum1 = p[n - 1].x * p[0].y, sum2 = p[n - 1].y * p[0].x;
for (int i = 0; i < n - 1; i++) {
sum1 += p[i].x * p[i + 1].y;
sum2 += p[i].y * p[i + 1].x;
}
return fabs((sum1 - sum2) * 0.5);
}
ll fastpow(ll base, ll p, ll m) {
if (p == 0)
return 1;
ll ans = fastpow(base, p / 2, m);
ans = ((ans % m) * (ans % m)) % m;
if (p % 2)
ans = ((base % m) * ans) % m;
return ans;
}
ll GCD(ll M, ll m) {
if (M % m == 0)
return m;
M %= m;
ll x1 = M, x2 = m;
m = min(x1, x2);
M = max(x1, x2);
return GCD(M, m);
}
ll lcm(ll M, ll m) { return (M * m) / GCD(max(M, m), min(M, m)); }
int n, n2, k;
string s, s2;
int dp[3005][3005];
int solve(int i, int j) {
if (dp[i][j] != -1) {
return dp[i][j];
}
if (i >= n || j >= n2)
return 0;
if (s[i] == s2[j]) {
return dp[i][j] = 1 + solve(i + 1, j + 1);
}
int m = 0, im = -1;
return dp[i][j] = max(solve(i, j + 1), solve(i + 1, j));
}
void fun(int i, int j) {
if (i >= n || j >= n2)
return;
if (s[i] == s2[j]) {
cout << s[i];
fun(i + 1, j + 1);
}
else if (dp[i][j] == (solve(i, j + 1))) {
fun(i, j + 1);
} else if (dp[i][j] == solve(i + 1, j)) {
fun(i + 1, j);
}
}
int main() {
cin >> s >> s2;
memset(dp, -1, sizeof dp);
n = s.size();
n2 = s2.size();
int x = solve(0, 0);
fun(0, 0);
}
|
replace
| 59 | 60 | 59 | 60 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string text1, text2, str;
getline(cin, text1);
getline(cin, text2);
int m = text1.size() + 1;
int n = text2.size() + 1;
text1 = '*' + text1;
text2 = '*' + text2;
int lcs[m][n];
for (int i = 0; i < n; i++)
lcs[0][i] = 0;
for (int i = 0; i < m; i++)
lcs[i][0] = 0;
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
if (text1[i] == text2[j])
lcs[i][j] = 1 + lcs[i - 1][j - 1];
else
lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
}
}
int i = m - 1;
int j = n - 1;
for (; i >= 1;) {
for (; j >= 1 && i >= 1;) {
if (lcs[i][j] == 1 + lcs[i - 1][j - 1] && text1[i] == text2[j]) {
str = text1[i] + str;
i = i - 1;
j = j - 1;
} else if (lcs[i][j] == lcs[i - 1][j])
i = i - 1;
else if (lcs[i][j] == lcs[i][j - 1])
j = j - 1;
else
break;
}
}
cout << str << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string text1, text2, str;
getline(cin, text1);
getline(cin, text2);
int m = text1.size() + 1;
int n = text2.size() + 1;
text1 = '*' + text1;
text2 = '*' + text2;
int lcs[m][n];
for (int i = 0; i < n; i++)
lcs[0][i] = 0;
for (int i = 0; i < m; i++)
lcs[i][0] = 0;
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
if (text1[i] == text2[j])
lcs[i][j] = 1 + lcs[i - 1][j - 1];
else
lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
}
}
int i = m - 1;
int j = n - 1;
while (j - 1 >= 0 && i - 1 >= 0) {
if (lcs[i][j] == 1 + lcs[i - 1][j - 1] && text1[i] == text2[j]) {
str = text1[i] + str;
i = i - 1;
j = j - 1;
} else if (lcs[i][j] == lcs[i - 1][j])
i = i - 1;
else if (lcs[i][j] == lcs[i][j - 1])
j = j - 1;
}
cout << str << "\n";
}
|
replace
| 28 | 41 | 28 | 38 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#ifndef TEMPLATE
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include <debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x, v) memset((x), (v), sizeof((x)));
#define A(x) (x).begin(), (x).end()
#define re(i, n) for (int i = 0; i < (int)n; i++)
#define rep(i, k, n) for (int i = k; i <= n; i++)
#define erp(i, k, n) for (int i = n; i >= k; i--)
#define input(v, n) re(i, n) cin >> v[i]
using vi = vector<int>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
using tp = tuple<int, int, int>;
using pi = pair<int, int>;
const int nax = 1e5 + 7;
const int mod = 1e9 + 7; // 1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int>::max() - (int)9e6;
#endif
// ===================== MANASH =================== //
int n;
char ch[3001][3001];
pair<int, int> par[3001][3001];
void test() {
string a, b;
cin >> a >> b;
int m;
n = sz(a), m = sz(b);
vvi dp(n + 1, vi(m + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
ch[i][j] = a[i - 1];
par[i][j] = {i - 1, j - 1};
} else if (dp[i - 1][j] > dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
ch[i][j] = ch[i - 1][j];
par[i][j] = par[i - 1][j];
} else {
dp[i][j] = dp[i][j - 1];
ch[i][j] = ch[i][j - 1];
par[i][j] = par[i][j - 1];
}
}
}
string res;
int i = n, j = m;
while (i and j) {
assert(ch[i][j]);
res.push_back(ch[i][j]);
auto [x, y] = par[i][j];
i = x, j = y;
}
reverse(A(res));
cout << res;
}
signed main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int T = 1;
// cin >> T;
for (int tt = 1; tt <= T; tt++) {
// cout << "Case #" << tt << " ";
test();
cout << "\n";
}
return 0;
}
|
#ifndef TEMPLATE
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#ifdef LOCAL
#include <debug.h>
#else
#define db(...) 21
#endif
#define mp make_pair
#define sz(a) ((int)(a).size())
#define mem(x, v) memset((x), (v), sizeof((x)));
#define A(x) (x).begin(), (x).end()
#define re(i, n) for (int i = 0; i < (int)n; i++)
#define rep(i, k, n) for (int i = k; i <= n; i++)
#define erp(i, k, n) for (int i = n; i >= k; i--)
#define input(v, n) re(i, n) cin >> v[i]
using vi = vector<int>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
using tp = tuple<int, int, int>;
using pi = pair<int, int>;
const int nax = 1e5 + 7;
const int mod = 1e9 + 7; // 1e9+2667 :: 0xcf : inf, 0xc0 -inf
const int inf = numeric_limits<int>::max() - (int)9e6;
#endif
// ===================== MANASH =================== //
int n;
char ch[3001][3001];
pair<int, int> par[3001][3001];
void test() {
string a, b;
cin >> a >> b;
int m;
n = sz(a), m = sz(b);
vvi dp(n + 1, vi(m + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
ch[i][j] = a[i - 1];
par[i][j] = {i - 1, j - 1};
} else if (dp[i - 1][j] > dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
ch[i][j] = ch[i - 1][j];
par[i][j] = par[i - 1][j];
} else {
dp[i][j] = dp[i][j - 1];
ch[i][j] = ch[i][j - 1];
par[i][j] = par[i][j - 1];
}
}
}
string res;
int i = n, j = m;
while (ch[i][j]) {
assert(ch[i][j]);
res.push_back(ch[i][j]);
auto [x, y] = par[i][j];
i = x, j = y;
}
reverse(A(res));
cout << res;
}
signed main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int T = 1;
// cin >> T;
for (int tt = 1; tt <= T; tt++) {
// cout << "Case #" << tt << " ";
test();
cout << "\n";
}
return 0;
}
|
replace
| 59 | 61 | 59 | 60 |
-11
| |
p03165
|
C++
|
Runtime Error
|
//
// Created by Ciafrino on 1/6/19.
//
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long lint;
int dp[100][100];
string get_lcs(string s, string t, int size_s, int size_t) {
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;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int idx = dp[size_s][size_t];
char lcs[idx + 1];
lcs[idx] = '\0';
int i = size_s, j = size_t;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
lcs[idx - 1] = s[i - 1];
--i;
--j;
--idx;
} else if (dp[i - 1][j] > dp[i][j - 1])
--i;
else
--j;
}
return lcs;
}
string read_string() {
char *str;
scanf("%ms", &str);
string result(str);
free(str);
return result;
}
int main() {
string s, t;
s = read_string();
t = read_string();
int size_s = s.size(), size_t = t.size();
string result = get_lcs(s, t, size_s, size_t);
cout << result;
return 0;
}
|
//
// Created by Ciafrino on 1/6/19.
//
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long lint;
int dp[3010][3010];
string get_lcs(string s, string t, int size_s, int size_t) {
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;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int idx = dp[size_s][size_t];
char lcs[idx + 1];
lcs[idx] = '\0';
int i = size_s, j = size_t;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
lcs[idx - 1] = s[i - 1];
--i;
--j;
--idx;
} else if (dp[i - 1][j] > dp[i][j - 1])
--i;
else
--j;
}
return lcs;
}
string read_string() {
char *str;
scanf("%ms", &str);
string result(str);
free(str);
return result;
}
int main() {
string s, t;
s = read_string();
t = read_string();
int size_s = s.size(), size_t = t.size();
string result = get_lcs(s, t, size_s, size_t);
cout << result;
return 0;
}
|
replace
| 33 | 34 | 33 | 34 |
0
| |
p03165
|
C++
|
Runtime Error
|
/*
* Note: This template uses some c++11 functions , so you have to compile it
* with c++11 flag. Example:- $ g++ -std=c++11 c++Template.cpp
*
*/
/******** All Required Header Files ********/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace __gnu_pbds;
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(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 REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MK(arr, n, type) type *arr = new type[n];
#define W(x) \
int x; \
cin >> x; \
while (x--)
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef priority_queue<int> PQB;
typedef priority_queue<int, VI, greater<int>> PQS;
typedef long long ll;
typedef long double ld;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
/****** Template of some basic operations *****/
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
/**********************************************/
/******** User-defined Function *******/
void c_p_c() {
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
}
/**************************************/
/********** Main() function **********/
int main() {
c_p_c();
string s1, s2;
cin >> s1 >> s2;
ll i, j;
ll n = s1.length();
ll m = s2.length();
ll dp[n + 1][m + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= m; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else 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 ans = "";
i = n, j = m;
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
ans += s1[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
/******** Main() Ends Here *************/
|
/*
* Note: This template uses some c++11 functions , so you have to compile it
* with c++11 flag. Example:- $ g++ -std=c++11 c++Template.cpp
*
*/
/******** All Required Header Files ********/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace __gnu_pbds;
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(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 REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MK(arr, n, type) type *arr = new type[n];
#define W(x) \
int x; \
cin >> x; \
while (x--)
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef priority_queue<int> PQB;
typedef priority_queue<int, VI, greater<int>> PQS;
typedef long long ll;
typedef long double ld;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
/****** Template of some basic operations *****/
template <typename T, typename U> inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void amax(T &x, U y) {
if (x < y)
x = y;
}
/**********************************************/
/******** User-defined Function *******/
void c_p_c() {
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
}
/**************************************/
/********** Main() function **********/
int main() {
// c_p_c();
string s1, s2;
cin >> s1 >> s2;
ll i, j;
ll n = s1.length();
ll m = s2.length();
ll dp[n + 1][m + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= m; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else 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 ans = "";
i = n, j = m;
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
ans += s1[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
/******** Main() Ends Here *************/
|
replace
| 113 | 114 | 113 | 114 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
// constant
const double EPS = 1e-10;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, n) for (ll i = n; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
// debug
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
// vector
// template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return
// vector<vector<T>> vec(H, vector<T>(W, v)); }
// view vector
template <typename T> void view(T e) { cerr << e << endl; }
template <typename T> void view(const vector<T> &v) {
for (const auto &e : v) {
cerr << e << " ";
}
cerr << endl;
}
template <typename T> void view(const vector<vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
// DP
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;
}
// ***************************************
int main() {
string s, t;
cin >> s >> t;
ll S = s.size();
ll T = t.size();
vector<vector<ll>> dp(S + 1, vector<ll>(T + 1, 0));
REP(i, S) {
REP(j, T) {
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]);
}
}
view(dp);
ll i = S, j = T;
string ans = "";
while (dp[i][j] > 0) {
while (dp[i][j] == dp[i][j - 1])
j--;
while (dp[i][j] == dp[i - 1][j])
i--;
i--;
j--;
ans = s[i] + ans;
}
cout << ans << endl;
return 0;
}
|
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
// constant
const double EPS = 1e-10;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, n) for (ll i = n; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
// debug
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
// vector
// template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return
// vector<vector<T>> vec(H, vector<T>(W, v)); }
// view vector
template <typename T> void view(T e) { cerr << e << endl; }
template <typename T> void view(const vector<T> &v) {
for (const auto &e : v) {
cerr << e << " ";
}
cerr << endl;
}
template <typename T> void view(const vector<vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
// DP
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;
}
// ***************************************
int main() {
string s, t;
cin >> s >> t;
ll S = s.size();
ll T = t.size();
vector<vector<ll>> dp(S + 1, vector<ll>(T + 1, 0));
REP(i, S) {
REP(j, T) {
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]);
}
}
ll i = S, j = T;
string ans = "";
while (dp[i][j] > 0) {
while (dp[i][j] == dp[i][j - 1])
j--;
while (dp[i][j] == dp[i - 1][j])
i--;
i--;
j--;
ans = s[i] + ans;
}
cout << ans << endl;
return 0;
}
|
delete
| 78 | 80 | 78 | 78 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[3000][3000];
int main() {
string s, t;
cin >> s;
cin >> t;
int n = s.length();
int 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;
continue;
}
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]);
}
}
}
string ss = "";
/*
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
}
}*/
int i = n, j = m;
int len = dp[n][m];
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ss += t[j - 1];
i--;
j--;
} else {
if (dp[i][j - 1] < dp[i - 1][j]) {
i--;
} else
j--;
}
}
reverse(ss.begin(), ss.end());
cout << ss << endl;
// cout<<dp[n][m]<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[3005][3005];
int main() {
string s, t;
cin >> s;
cin >> t;
int n = s.length();
int 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;
continue;
}
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]);
}
}
}
string ss = "";
/*
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
}
}*/
int i = n, j = m;
int len = dp[n][m];
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ss += t[j - 1];
i--;
j--;
} else {
if (dp[i][j - 1] < dp[i - 1][j]) {
i--;
} else
j--;
}
}
reverse(ss.begin(), ss.end());
cout << ss << endl;
// cout<<dp[n][m]<<endl;
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int DP[3001][3001];
string S, T, LCS;
void Print() {
int i = S.length(), j = T.length();
while (i && j) {
if (S[i - 1] == T[j - 1]) {
LCS += S[i - 1];
i--;
j--;
} else {
if (DP[i - 1][j] > DP[i][j - 1])
i--;
else
j--;
}
}
reverse(LCS.begin(), LCS.end());
cout << LCS << endl;
return;
}
int main() {
cin >> S >> T;
if (S.length() == 1) {
for (int i = 0; i < T.length(); i++)
if (S[0] == T[i]) {
cout << S[0] << endl;
return 0;
}
puts("");
return 0;
}
if (T.length() == 1) {
for (int i = 0; i < S.length(); i++)
if (T[0] == S[i]) {
cout << T[0] << endl;
return 0;
}
puts("");
return 0;
}
S += ' ';
T += ' ';
for (int i = 0; i < S.length(); i++)
if (T[0] == S[i])
DP[i + 1][1] = 1;
for (int i = 0; i < T.length(); i++)
if (S[0] == T[i])
DP[1][i + 1] = 1;
for (int i = 1; i < S.length(); i++)
for (int j = 1; j < T.length(); j++) {
if (S[i] == T[j])
DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i][j] + 1);
DP[i + 1][j] = max(DP[i + 1][j], DP[i][j]);
DP[i][j + 1] = max(DP[i][j + 1], DP[i][j]);
}
Print();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int DP[3002][3002];
string S, T, LCS;
void Print() {
int i = S.length(), j = T.length();
while (i && j) {
if (S[i - 1] == T[j - 1]) {
LCS += S[i - 1];
i--;
j--;
} else {
if (DP[i - 1][j] > DP[i][j - 1])
i--;
else
j--;
}
}
reverse(LCS.begin(), LCS.end());
cout << LCS << endl;
return;
}
int main() {
cin >> S >> T;
if (S.length() == 1) {
for (int i = 0; i < T.length(); i++)
if (S[0] == T[i]) {
cout << S[0] << endl;
return 0;
}
puts("");
return 0;
}
if (T.length() == 1) {
for (int i = 0; i < S.length(); i++)
if (T[0] == S[i]) {
cout << T[0] << endl;
return 0;
}
puts("");
return 0;
}
S += ' ';
T += ' ';
for (int i = 0; i < S.length(); i++)
if (T[0] == S[i])
DP[i + 1][1] = 1;
for (int i = 0; i < T.length(); i++)
if (S[0] == T[i])
DP[1][i + 1] = 1;
for (int i = 1; i < S.length(); i++)
for (int j = 1; j < T.length(); j++) {
if (S[i] == T[j])
DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i][j] + 1);
DP[i + 1][j] = max(DP[i + 1][j], DP[i][j]);
DP[i][j + 1] = max(DP[i][j + 1], DP[i][j]);
}
Print();
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Runtime Error
|
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int> a(n)
#define PQ(a) priority_queue<int> a
#define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int dp[s.size()][t.size()];
rep(i, s.size()) {
rep(j, t.size()) { dp[i][j] = 0; }
}
string res;
int n = s.size();
int m = t.size();
FOR(i, 1, n + 1) {
FOR(j, 1, m + 1) {
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 x = n, y = m;
int ndp = dp[x][y];
while (x > 0 & y > 0) {
if (ndp - 1 == dp[x - 1][y - 1] && s[x - 1] == t[y - 1]) {
x -= 1;
y -= 1;
ndp -= 1;
res = s[x] + res;
} else if (ndp == dp[x - 1][y]) {
x -= 1;
} else {
y -= 1;
}
}
cout << res << endl;
}
|
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int> a(n)
#define PQ(a) priority_queue<int> a
#define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int dp[s.size() + 1][t.size() + 1];
rep(i, s.size() + 1) {
rep(j, t.size() + 1) { dp[i][j] = 0; }
}
string res;
int n = s.size();
int m = t.size();
FOR(i, 1, n + 1) {
FOR(j, 1, m + 1) {
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 x = n, y = m;
int ndp = dp[x][y];
while (x > 0 & y > 0) {
if (ndp - 1 == dp[x - 1][y - 1] && s[x - 1] == t[y - 1]) {
x -= 1;
y -= 1;
ndp -= 1;
res = s[x] + res;
} else if (ndp == dp[x - 1][y]) {
x -= 1;
} else {
y -= 1;
}
}
cout << res << endl;
}
|
replace
| 25 | 28 | 25 | 28 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[3003][3003] = {};
int main() {
string s, t;
cin >> s >> t;
int n = (int)s.size();
int m = (int)t.size();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i * 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 = n;
int j = m;
string ans;
while (i * j > 0) {
while (dp[i][j] == dp[i - 1][j])
i--;
while (dp[i][j] == dp[i][j - 1])
j--;
ans += s[i - 1];
i--;
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[3003][3003] = {};
int main() {
string s, t;
cin >> s >> t;
int n = (int)s.size();
int m = (int)t.size();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i * 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 = n;
int j = m;
string ans;
while (i * j > 0 && dp[i][j] > 0) {
while (dp[i][j] == dp[i - 1][j])
i--;
while (dp[i][j] == dp[i][j - 1])
j--;
ans += s[i - 1];
i--;
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 7;
string s, t;
int dp[N][N];
pair<int, int> construct[N][N];
int solve(int i, int j) {
if (i == s.size() || j == t.size()) {
return 0;
}
if (dp[i][j] != -1)
return dp[i][j];
if (s[i] == t[j]) {
construct[i][j] = {i + 1, j + 1};
return dp[i][j] = 1 + solve(i + 1, j + 1);
} else {
int moveI = solve(i + 1, j);
int moveJ = solve(i, j + 1);
if (moveI > moveJ) {
construct[i][j] = {i + 1, j};
} else {
construct[i][j] = {i, j + 1};
}
return dp[i][j] = max(moveI, moveJ);
}
}
int main() {
cin >> s >> t;
memset(dp, -1, sizeof dp);
solve(0, 0);
pair<int, int> curr = {0, 0};
string ans = "";
while (curr.first < s.size() && curr.second < t.size()) {
if (s[curr.first] == t[curr.second]) {
ans += s[curr.first];
}
curr = construct[curr.first][curr.second];
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 7;
string s, t;
int dp[N][N];
pair<int, int> construct[N][N];
int solve(int i, int j) {
if (i == s.size() || j == t.size()) {
return 0;
}
if (dp[i][j] != -1)
return dp[i][j];
if (s[i] == t[j]) {
construct[i][j] = {i + 1, j + 1};
return dp[i][j] = 1 + solve(i + 1, j + 1);
} else {
int moveI = solve(i + 1, j);
int moveJ = solve(i, j + 1);
if (moveI > moveJ) {
construct[i][j] = {i + 1, j};
} else {
construct[i][j] = {i, j + 1};
}
return dp[i][j] = max(moveI, moveJ);
}
}
int main() {
cin >> s >> t;
memset(dp, -1, sizeof dp);
solve(0, 0);
pair<int, int> curr = {0, 0};
string ans = "";
while (curr.first < s.size() && curr.second < t.size()) {
if (s[curr.first] == t[curr.second]) {
ans += s[curr.first];
}
curr = construct[curr.first][curr.second];
}
cout << ans;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1e+9;
int main() {
static int dp[3010][3010], ma = 0, me[3010][3010];
string s, t, ans;
cin >> s >> t;
for (int i = 0; i < s.length(); ++i) {
for (int j = 0; j < t.length(); ++j) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
me[i + 1][j + 1] = 1;
} else if (dp[i + 1][j] > dp[i][j + 1]) {
dp[i + 1][j + 1] = dp[i + 1][j];
me[i + 1][j + 1] = 2;
} else {
dp[i + 1][j + 1] = dp[i][j + 1];
me[i + 1][j + 1] = 3;
}
}
}
for (int i = s.length(); i >= 0;) {
for (int j = t.length(); j >= 0;) {
if (me[i][j] == 3)
i--;
else if (me[i][j] == 2)
j--;
else if (me[i][j] == 1) {
i--;
j--;
ans.push_back(s[i]);
} else {
i--;
j--;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1e+9;
int main() {
static int dp[3010][3010], ma = 0, me[3010][3010];
string s, t, ans;
cin >> s >> t;
for (int i = 0; i < s.length(); ++i) {
for (int j = 0; j < t.length(); ++j) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
me[i + 1][j + 1] = 1;
} else if (dp[i + 1][j] > dp[i][j + 1]) {
dp[i + 1][j + 1] = dp[i + 1][j];
me[i + 1][j + 1] = 2;
} else {
dp[i + 1][j + 1] = dp[i][j + 1];
me[i + 1][j + 1] = 3;
}
}
}
for (int i = s.length(); i >= 0;) {
for (int j = t.length(); j >= 0;) {
if (me[i][j] == 3)
i--;
else if (me[i][j] == 2)
j--;
else if (me[i][j] == 1) {
i--;
j--;
ans.push_back(s[i]);
} else {
i = -1;
j = -1;
break;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 39 | 41 | 39 | 42 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
void doc() {
freopen("OB.inp", "r", stdin);
freopen("OB.out", "w", stdout);
}
const int MaxN = 3 * 1e3 + 5;
int f[MaxN][MaxN];
string s, t;
void Trace(int n, int m) {
if (n <= 0 || m <= 0)
return;
if (f[n][m] == f[n - 1][m])
Trace(n - 1, m);
else if (f[n][m] == f[n][m - 1])
Trace(n, m - 1);
else {
Trace(n - 1, m - 1);
cout << s[n - 1];
}
}
void solve() {
cin >> s >> t;
int n = s.length();
int m = t.length();
// int f[n + 1][m + 1];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
int x = i + 1;
int y = j + 1;
if (s[i] == t[j])
f[x][y] = f[x - 1][y - 1] + 1;
f[x][y] = max(f[x][y], max(f[x - 1][y], f[x][y - 1]));
}
// for(int i = 1; i <= n; i++){
// for(int j = 1; j <= m; j++)
// cout << f[i][j] << " ";
// cout << '\n';
// }
// cout << f[n][m];
Trace(n, m);
}
int main() {
// ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
doc();
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
void doc() {
freopen("OB.inp", "r", stdin);
freopen("OB.out", "w", stdout);
}
const int MaxN = 3 * 1e3 + 5;
int f[MaxN][MaxN];
string s, t;
void Trace(int n, int m) {
if (n <= 0 || m <= 0)
return;
if (f[n][m] == f[n - 1][m])
Trace(n - 1, m);
else if (f[n][m] == f[n][m - 1])
Trace(n, m - 1);
else {
Trace(n - 1, m - 1);
cout << s[n - 1];
}
}
void solve() {
cin >> s >> t;
int n = s.length();
int m = t.length();
// int f[n + 1][m + 1];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
int x = i + 1;
int y = j + 1;
if (s[i] == t[j])
f[x][y] = f[x - 1][y - 1] + 1;
f[x][y] = max(f[x][y], max(f[x - 1][y], f[x][y - 1]));
}
// for(int i = 1; i <= n; i++){
// for(int j = 1; j <= m; j++)
// cout << f[i][j] << " ";
// cout << '\n';
// }
// cout << f[n][m];
Trace(n, m);
}
int main() {
// ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
// doc();
solve();
}
|
replace
| 54 | 55 | 54 | 55 |
0
| |
p03165
|
C++
|
Runtime Error
|
/// Journey to the End of earth ///
/// Gunjan Kumar ///
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional> // for less
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define s(n) scanf("%d", &n)
#define ls(n) scanf("%lld", &n)
#define p(n) printf("%d", n)
// #define ln() printf("\n")
#define pln(n) printf("%d\n", n)
#define lpln(n) printf("%lld\n", n)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rev(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc \
ll t1; \
cin >> t1; \
while (t1--)
#define inp \
ll n; \
cin >> n; \
ll arr[n]; \
rep(i, 0, n) cin >> arr[i];
#define vect vector<ll>
#define sortv(v) sort(v.begin(), v.end())
#define lower(v, n) lower_bound(v.begin(), v.end(), n) - v.begin()
#define upper(v, n) upper_bound(v.begin(), v.end(), n) - v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln << endl
#define inf LONG_MAX
#define ninf LONG_MIN
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
const ll mod = 1e9 + 7;
const ll N = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("new.txt", "w", stdout);
#endif
string s, t;
cin >> s >> t;
int len1 = s.size();
int len2 = t.size();
int dp[len1 + 1][len2 + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; 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 = len1, j = len2;
while (i >= 1 && j >= 1) {
if (s[i - 1] == t[j - 1]) {
ans.pb(s[i - 1]);
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
/// Journey to the End of earth ///
/// Gunjan Kumar ///
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <functional> // for less
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define s(n) scanf("%d", &n)
#define ls(n) scanf("%lld", &n)
#define p(n) printf("%d", n)
// #define ln() printf("\n")
#define pln(n) printf("%d\n", n)
#define lpln(n) printf("%lld\n", n)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rev(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc \
ll t1; \
cin >> t1; \
while (t1--)
#define inp \
ll n; \
cin >> n; \
ll arr[n]; \
rep(i, 0, n) cin >> arr[i];
#define vect vector<ll>
#define sortv(v) sort(v.begin(), v.end())
#define lower(v, n) lower_bound(v.begin(), v.end(), n) - v.begin()
#define upper(v, n) upper_bound(v.begin(), v.end(), n) - v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln << endl
#define inf LONG_MAX
#define ninf LONG_MIN
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
const ll mod = 1e9 + 7;
const ll N = 1e5 + 5;
int main() {
string s, t;
cin >> s >> t;
int len1 = s.size();
int len2 = t.size();
int dp[len1 + 1][len2 + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; 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 = len1, j = len2;
while (i >= 1 && j >= 1) {
if (s[i - 1] == t[j - 1]) {
ans.pb(s[i - 1]);
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
delete
| 48 | 53 | 48 | 48 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4096;
string s, t;
int dp[MAXN][MAXN];
int ls, lt;
int pre[MAXN][MAXN];
void dfs(int x, int y) {
if (!x && !y)
return;
if (pre[x][y] == 1) {
dfs(x - 1, y - 1);
cout << s[x];
} else if (pre[x][y] == 2) {
dfs(x, y - 1);
} else
dfs(x - 1, y);
}
int main() {
cin >> s >> t;
ls = s.size();
lt = t.size();
s = '$' + s;
t = '$' + t;
for (int i = 1; i <= ls; i++) {
for (int j = 1; j <= lt; j++) {
if (s[i] == t[j])
dp[i][j] = dp[i - 1][j - 1] + 1, pre[i][j] = 1;
if (dp[i][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
pre[i][j] = 2;
}
if (dp[i][j] < dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
pre[i][j] = 3;
}
}
}
if (dp[ls][lt])
dfs(ls, lt);
else
cout << ' ';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4096;
string s, t;
int dp[MAXN][MAXN];
int ls, lt;
int pre[MAXN][MAXN];
void dfs(int x, int y) {
if (!x || !y)
return;
if (pre[x][y] == 1) {
dfs(x - 1, y - 1);
cout << s[x];
} else if (pre[x][y] == 2) {
dfs(x, y - 1);
} else
dfs(x - 1, y);
}
int main() {
cin >> s >> t;
ls = s.size();
lt = t.size();
s = '$' + s;
t = '$' + t;
for (int i = 1; i <= ls; i++) {
for (int j = 1; j <= lt; j++) {
if (s[i] == t[j])
dp[i][j] = dp[i - 1][j - 1] + 1, pre[i][j] = 1;
if (dp[i][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
pre[i][j] = 2;
}
if (dp[i][j] < dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
pre[i][j] = 3;
}
}
}
if (dp[ls][lt])
dfs(ls, lt);
else
cout << ' ';
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n;
char s[3000], t[3000];
vector<char> rs;
int slen, tlen;
void read() {
cin >> s;
cin >> t;
slen = strlen(s);
tlen = strlen(t);
}
int dp[3005][3005];
int solve() {
int i, j;
for (i = 0; i <= strlen(s); i++) {
dp[i][0] = 0;
}
for (i = 0; i <= strlen(t); i++) {
dp[0][i] = 0;
}
for (i = 1; i <= strlen(s); i++) {
for (j = 1; j <= strlen(t); 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]);
}
}
}
int k = dp[strlen(s)][strlen(t)];
int cnt = k;
i = slen;
j = tlen;
while (cnt > 0) {
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]) {
rs.push_back(s[i - 1]);
i--;
j--;
}
}
for (i = k - 1; i >= 0; i--)
cout << rs[i];
return 0;
}
int main() {
read();
solve();
return 0;
}
|
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n;
char s[3000], t[3000];
vector<char> rs;
int slen, tlen;
void read() {
cin >> s;
cin >> t;
slen = strlen(s);
tlen = strlen(t);
}
int dp[3005][3005];
int solve() {
int i, j;
for (i = 0; i <= strlen(s); i++) {
dp[i][0] = 0;
}
for (i = 0; i <= strlen(t); i++) {
dp[0][i] = 0;
}
for (i = 1; i <= strlen(s); i++) {
for (j = 1; j <= strlen(t); 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]);
}
}
}
int k = dp[strlen(s)][strlen(t)];
int cnt = k;
i = slen;
j = tlen;
while (cnt > 0) {
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]) {
rs.push_back(s[i - 1]);
i--;
j--;
cnt--;
}
}
for (i = k - 1; i >= 0; i--)
cout << rs[i];
return 0;
}
int main() {
read();
solve();
return 0;
}
|
insert
| 45 | 45 | 45 | 46 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
bool comp(int a, int b) { return a > b; }
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
fast;
string s1, s2;
cin >> s1 >> s2;
ll l1, l2;
l1 = s1.length();
l2 = s2.length();
int dp[1001][1001];
memset(dp, 0, sizeof(dp));
rep(i, 0, l1 + 1) {
rep(j, 0, l2 + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
// continue;
} else if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
// continue;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
ll i = l1, j = l2;
vector<char> c;
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 if (dp[i][j] != dp[i - 1][j - 1]) {
// cout<<s1[i-1];
c.push_back(s1[i - 1]);
i--;
j--;
}
}
// cout<<endl;
reverse(c.begin(), c.end());
for (auto x : c)
cout << x;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
bool comp(int a, int b) { return a > b; }
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
fast;
string s1, s2;
cin >> s1 >> s2;
ll l1, l2;
l1 = s1.length();
l2 = s2.length();
vector<vector<int>> dp(3010, vector<int>(3010, 0));
// memset(dp,0,sizeof(dp));
rep(i, 0, l1 + 1) {
rep(j, 0, l2 + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
// continue;
} else if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
// continue;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
ll i = l1, j = l2;
vector<char> c;
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 if (dp[i][j] != dp[i - 1][j - 1]) {
// cout<<s1[i-1];
c.push_back(s1[i - 1]);
i--;
j--;
}
}
// cout<<endl;
reverse(c.begin(), c.end());
for (auto x : c)
cout << x;
}
|
replace
| 42 | 44 | 42 | 44 |
0
| |
p03165
|
C++
|
Runtime Error
|
#pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
static inline DOUBLE ABS(DOUBLE a) { return 0 < a ? a : -a; };
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
#define ANS_MOD (1000000007)
static const DOUBLE d_PI = 3.14159265358979323846;
// static const DOUBLE d_PI = M_PI;
static inline bool DoubleIsEqual(DOUBLE a, DOUBLE b) {
return ABS(a - b) < DOUBLE_EPS;
}
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/*----------------------------------------------*/
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007)
class MODINT {
static SQWORD MOD;
SQWORD m_x;
public:
MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; };
MODINT() { m_x = 0; }
static void Init(SQWORD sqMod) { MOD = sqMod; }
MODINT &operator+=(const MODINT a) {
m_x = (m_x + a.m_x) % MOD;
return *this;
};
MODINT &operator-=(const MODINT a) {
m_x = (m_x - a.m_x + MOD) % MOD;
return *this;
};
MODINT &operator*=(const MODINT a) {
m_x = (m_x * a.m_x) % MOD;
return *this;
};
MODINT pow(SQWORD t) const {
if (!t)
return 1;
MODINT a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
MODINT operator+(const MODINT a) const {
MODINT res(*this);
return (res += a);
}
MODINT operator-(const MODINT a) const {
MODINT res(*this);
return (res -= a);
}
MODINT operator*(const MODINT a) const {
MODINT res(*this);
return (res *= a);
}
MODINT operator/(const MODINT a) const {
MODINT res(*this);
return (res /= a);
}
/* 逆元 */
MODINT inv() const { return pow(MOD - 2); }
/* 除算 */
MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); }
/* 整数版 */
MODINT &operator+=(const SQWORD a) {
*this += MODINT(a);
return *this;
};
MODINT &operator-=(const SQWORD a) {
*this -= MODINT(a);
return *this;
};
MODINT &operator*=(const SQWORD a) {
*this *= MODINT(a);
return *this;
};
MODINT &operator/=(const SQWORD a) {
*this /= MODINT(a);
return *this;
};
SQWORD getVal() { return m_x; };
};
SQWORD MODINT::MOD = ANS_MOD;
/*----------------------------------------------*/
#define N_MAX_STRING (3000)
static SQWORD s_aasqDpTbl[N_MAX_STRING + 1][N_MAX_STRING + 1];
static SQWORD s_aasqPrevTbl[N_MAX_STRING + 1][N_MAX_STRING + 1];
int main(void) {
string strS, strT;
cin >> strS;
cin >> strT;
SQWORD sqLenS = strS.size();
SQWORD sqLenT = strT.size();
/**
* dp[i][j]: S の i文字目・T の j文字目までで一致している文字数
*/
for (SQWORD sqI = 0; sqI <= sqLenS; sqI++) {
for (SQWORD sqJ = 0; sqJ <= sqLenT; sqJ++) {
if (strS[sqI] == strT[sqJ]) {
/* 一致 */
s_aasqDpTbl[sqI + 1][sqJ + 1] = s_aasqDpTbl[sqI][sqJ] + 1;
s_aasqPrevTbl[sqI + 1][sqJ + 1] = ((sqI << WORD_BITS) | sqJ);
} else {
/* 不一致 */
if (s_aasqDpTbl[sqI + 1][sqJ] < s_aasqDpTbl[sqI][sqJ]) {
s_aasqDpTbl[sqI + 1][sqJ] = s_aasqDpTbl[sqI][sqJ];
s_aasqPrevTbl[sqI + 1][sqJ] = ((sqI << WORD_BITS) | sqJ);
}
if (s_aasqDpTbl[sqI][sqJ + 1] < s_aasqDpTbl[sqI][sqJ]) {
s_aasqDpTbl[sqI][sqJ + 1] = s_aasqDpTbl[sqI][sqJ];
s_aasqPrevTbl[sqI][sqJ + 1] = ((sqI << WORD_BITS) | sqJ);
}
}
}
}
SQWORD sqPosS = sqLenS;
SQWORD sqPosT = sqLenT;
string strAns;
while ((0 < sqPosS) && (0 < sqPosT)) {
SQWORD sqPrevPosS = s_aasqPrevTbl[sqPosS][sqPosT] >> WORD_BITS;
SQWORD sqPrevPosT =
(s_aasqPrevTbl[sqPosS][sqPosT] << (QWORD_BITS - WORD_BITS)) >>
(QWORD_BITS - WORD_BITS);
sqPosS = sqPrevPosS;
sqPosT = sqPrevPosT;
if (strS[sqPosS] == strT[sqPosT]) {
strAns += strS[sqPosS];
}
// printf("%lld %lld\n", sqPrevPosS, sqPrevPosT);
}
if (0 < strAns.size()) {
reverse(strAns.begin(), strAns.end());
}
printf("%s\n", strAns.c_str());
return 0;
}
|
#pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
static inline DOUBLE ABS(DOUBLE a) { return 0 < a ? a : -a; };
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
#define ANS_MOD (1000000007)
static const DOUBLE d_PI = 3.14159265358979323846;
// static const DOUBLE d_PI = M_PI;
static inline bool DoubleIsEqual(DOUBLE a, DOUBLE b) {
return ABS(a - b) < DOUBLE_EPS;
}
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/*----------------------------------------------*/
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007)
class MODINT {
static SQWORD MOD;
SQWORD m_x;
public:
MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; };
MODINT() { m_x = 0; }
static void Init(SQWORD sqMod) { MOD = sqMod; }
MODINT &operator+=(const MODINT a) {
m_x = (m_x + a.m_x) % MOD;
return *this;
};
MODINT &operator-=(const MODINT a) {
m_x = (m_x - a.m_x + MOD) % MOD;
return *this;
};
MODINT &operator*=(const MODINT a) {
m_x = (m_x * a.m_x) % MOD;
return *this;
};
MODINT pow(SQWORD t) const {
if (!t)
return 1;
MODINT a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
MODINT operator+(const MODINT a) const {
MODINT res(*this);
return (res += a);
}
MODINT operator-(const MODINT a) const {
MODINT res(*this);
return (res -= a);
}
MODINT operator*(const MODINT a) const {
MODINT res(*this);
return (res *= a);
}
MODINT operator/(const MODINT a) const {
MODINT res(*this);
return (res /= a);
}
/* 逆元 */
MODINT inv() const { return pow(MOD - 2); }
/* 除算 */
MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); }
/* 整数版 */
MODINT &operator+=(const SQWORD a) {
*this += MODINT(a);
return *this;
};
MODINT &operator-=(const SQWORD a) {
*this -= MODINT(a);
return *this;
};
MODINT &operator*=(const SQWORD a) {
*this *= MODINT(a);
return *this;
};
MODINT &operator/=(const SQWORD a) {
*this /= MODINT(a);
return *this;
};
SQWORD getVal() { return m_x; };
};
SQWORD MODINT::MOD = ANS_MOD;
/*----------------------------------------------*/
#define N_MAX_STRING (3000)
static SQWORD s_aasqDpTbl[N_MAX_STRING + 2][N_MAX_STRING + 2];
static SQWORD s_aasqPrevTbl[N_MAX_STRING + 2][N_MAX_STRING + 2];
int main(void) {
string strS, strT;
cin >> strS;
cin >> strT;
SQWORD sqLenS = strS.size();
SQWORD sqLenT = strT.size();
/**
* dp[i][j]: S の i文字目・T の j文字目までで一致している文字数
*/
for (SQWORD sqI = 0; sqI <= sqLenS; sqI++) {
for (SQWORD sqJ = 0; sqJ <= sqLenT; sqJ++) {
if (strS[sqI] == strT[sqJ]) {
/* 一致 */
s_aasqDpTbl[sqI + 1][sqJ + 1] = s_aasqDpTbl[sqI][sqJ] + 1;
s_aasqPrevTbl[sqI + 1][sqJ + 1] = ((sqI << WORD_BITS) | sqJ);
} else {
/* 不一致 */
if (s_aasqDpTbl[sqI + 1][sqJ] < s_aasqDpTbl[sqI][sqJ]) {
s_aasqDpTbl[sqI + 1][sqJ] = s_aasqDpTbl[sqI][sqJ];
s_aasqPrevTbl[sqI + 1][sqJ] = ((sqI << WORD_BITS) | sqJ);
}
if (s_aasqDpTbl[sqI][sqJ + 1] < s_aasqDpTbl[sqI][sqJ]) {
s_aasqDpTbl[sqI][sqJ + 1] = s_aasqDpTbl[sqI][sqJ];
s_aasqPrevTbl[sqI][sqJ + 1] = ((sqI << WORD_BITS) | sqJ);
}
}
}
}
SQWORD sqPosS = sqLenS;
SQWORD sqPosT = sqLenT;
string strAns;
while ((0 < sqPosS) && (0 < sqPosT)) {
SQWORD sqPrevPosS = s_aasqPrevTbl[sqPosS][sqPosT] >> WORD_BITS;
SQWORD sqPrevPosT =
(s_aasqPrevTbl[sqPosS][sqPosT] << (QWORD_BITS - WORD_BITS)) >>
(QWORD_BITS - WORD_BITS);
sqPosS = sqPrevPosS;
sqPosT = sqPrevPosT;
if (strS[sqPosS] == strT[sqPosT]) {
strAns += strS[sqPosS];
}
// printf("%lld %lld\n", sqPrevPosS, sqPrevPosT);
}
if (0 < strAns.size()) {
reverse(strAns.begin(), strAns.end());
}
printf("%s\n", strAns.c_str());
return 0;
}
|
replace
| 260 | 262 | 260 | 262 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define dump_4(x1, x2, x3, x4) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
void solve(std::string s, std::string t) {
int N = sz(s);
int M = sz(t);
vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));
rep(i, N) {
rep(j, M) {
int p = dp.at(i + 1).at(j);
int q = dp.at(i).at(j + 1);
if (p > q) {
dp.at(i + 1).at(j + 1) = p;
} else {
dp.at(i + 1).at(j + 1) = q;
if (s.at(i) == t.at(j)) {
dp.at(i + 1).at(j + 1)++;
}
}
}
}
string ans = "";
int l = dp.at(N).at(M);
int i = N - 1;
int j = M - 1;
while (l > 0) {
if (s.at(i) == t.at(j)) {
ans += s.at(i);
i--;
j--;
l--;
} else if (dp.at(i + 1).at(j + 1) == dp.at(i).at(j + 1) && i > 0) {
i--;
} else if (j > 0) {
j--;
}
}
reverse(all(ans));
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
std::string s;
std::cin >> s;
std::string t;
std::cin >> t;
solve(s, t);
return 0;
}
|
#include <bits/stdc++.h>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << endl
#define dump_4(x1, x2, x3, x4) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5) \
cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
<< x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
const ll LINF = 2e18;
const int INF = 1e9;
void solve(std::string s, std::string t) {
int N = sz(s);
int M = sz(t);
vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));
rep(i, N) {
rep(j, M) {
if (s.at(i) == t.at(j))
dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
else
dp.at(i + 1).at(j + 1) = max(dp.at(i).at(j + 1), dp.at(i + 1).at(j));
}
}
string ans = "";
int l = dp.at(N).at(M);
int i = N - 1;
int j = M - 1;
while (l > 0) {
if (s.at(i) == t.at(j)) {
ans += s.at(i);
i--;
j--;
l--;
} else if (dp.at(i + 1).at(j + 1) == dp.at(i).at(j + 1) && i > 0) {
i--;
} else if (j > 0) {
j--;
}
}
reverse(all(ans));
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
std::string s;
std::cin >> s;
std::string t;
std::cin >> t;
solve(s, t);
return 0;
}
|
replace
| 46 | 56 | 46 | 50 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod = 1e9 + 7;
const int N = 3001;
int dp[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T = clock();
string s, t;
cin >> s >> t;
ll n = s.size(), m = t.size();
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= m; j++) {
if (i > 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j > 0)
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
if (i > 0 && j > 0 && s[i - 1] == t[j - 1])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
}
}
// cout<<dp[n][m];
ll i = n, j = m;
string ans;
while (i >= 0 && j >= 0) {
if (s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--, j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
cerr << "\n\nTIME: " << (double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
T = clock();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod = 1e9 + 7;
const int N = 3001;
int dp[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T = clock();
string s, t;
cin >> s >> t;
ll n = s.size(), m = t.size();
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= m; j++) {
if (i > 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j > 0)
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
if (i > 0 && j > 0 && s[i - 1] == t[j - 1])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
}
}
// cout<<dp[n][m];
ll i = n, j = m;
string ans;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--, j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
cerr << "\n\nTIME: " << (double)(clock() - T) / CLOCKS_PER_SEC << " sec\n";
T = clock();
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
0
|
TIME: 0.000113 sec
|
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1e18;
#define vfind(v, x) (find(all(v), x) != (v).end())
#define clr(c) (c).clear()
#define cres(c, n) (c).clear(), (c).resize(n)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fst first
#define scd second
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fr(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define fr1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define frr(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define frab(i, a, b, c) for (ll(i) = a; (i) <= (b); (i) += (c))
#define mst(A) memset((A), 0, sizeof(A));
using namespace std;
void write(vll &oneD) {
for (ll i = 0; i < oneD.size(); i++) {
printf("%lld ", oneD[i]);
}
printf("\n");
}
void write(vvll &twoD) {
for (ll i = 0; i < twoD.size(); i++) {
write(twoD[i]);
}
}
void write(vpll &oneDP) {
fr(i, oneDP.size()) { printf("%lld %lld\n", oneDP[i].fst, oneDP[i].scd); }
cout << "\n";
}
void write(map<ll, ll> &mpp) {
for (map<ll, ll>::iterator it = mpp.begin(); it != mpp.end(); it++) {
cout << it->fst << " : " << it->scd << endl;
}
cout << endl;
}
bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
if (a.first == b.first)
return (a.scd >= b.scd);
return (a.first < b.first);
}
vll seive;
vll primes;
void Seive() {
const ll maxn = 100005;
seive.resize(maxn);
fr(i, maxn) seive[i] = 1;
for (ll i = 2; i * i < maxn; i++) {
if (seive[i] == 1) {
for (ll j = i * i; j < maxn; j += i) {
seive[j] = 0;
}
}
}
primes.pb(2);
for (ll i = 3; i < maxn; i += 2) {
if (seive[i])
primes.pb(i);
}
}
ll isprime(ll N) {
if (N < 2 || (!(N & 1) && N != 2))
return 0;
for (ll i = 3; i * i <= N; i += 2) {
if (!(N % i))
return 0;
}
return 1;
}
ll power(ll x, ll y, ll m) {
long long int res = 1;
x = x % m;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % MOD;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
ll modinv(ll x, ll mod = MOD) { return power(x, mod - 2, mod); }
////////////////////////////////////////////////////////////////////////////////
ll T[3005][3005];
ll B[100001];
string s1, s2;
ll lcs(ll n, ll m) {
fr(i, n + 1) {
fr(j, m + 1) {
if (i == 0 || j == 0) {
T[i][j] = 0;
} else if (s1[i - 1] == s2[j - 1]) {
T[i][j] = 1 + T[i - 1][j - 1];
} else {
T[i][j] = max(T[i - 1][j], T[i][j - 1]);
}
}
}
int res = T[n][m];
ll p = res;
char s[res + 1];
// s[res] = '';
int i = n;
int j = m;
string s3;
while (j > 0 && i > 0) {
if (s1[i - 1] == s2[j - 1]) {
j--;
i--;
res--;
s[res] = (char)s1[i];
s3 = s3 + ((char)s1[i]);
} else if (T[i - 1][j] > T[i][j - 1]) {
i--;
} else
j--;
}
for (int i = s3.length() - 1; i >= 0; i--)
cout << s3[i];
// cout<<endl;
// cout<<s<<endl;
return p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("allo.txt", "r", stdin);
#endif
// freopen("out.txt","w",stdout);
ll a, b, c, d;
ll k, l, m, n, p, q, r, t, x, y;
// cin>>t;while(t--){ map<ll,ll> M;
// string s1,s2;
cin >> s1 >> s2;
n = s1.length();
m = s2.length();
p = lcs(n, m);
// cout<<p<<endl;
// }
}
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1e18;
#define vfind(v, x) (find(all(v), x) != (v).end())
#define clr(c) (c).clear()
#define cres(c, n) (c).clear(), (c).resize(n)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fst first
#define scd second
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fr(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define fr1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define frr(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define frab(i, a, b, c) for (ll(i) = a; (i) <= (b); (i) += (c))
#define mst(A) memset((A), 0, sizeof(A));
using namespace std;
void write(vll &oneD) {
for (ll i = 0; i < oneD.size(); i++) {
printf("%lld ", oneD[i]);
}
printf("\n");
}
void write(vvll &twoD) {
for (ll i = 0; i < twoD.size(); i++) {
write(twoD[i]);
}
}
void write(vpll &oneDP) {
fr(i, oneDP.size()) { printf("%lld %lld\n", oneDP[i].fst, oneDP[i].scd); }
cout << "\n";
}
void write(map<ll, ll> &mpp) {
for (map<ll, ll>::iterator it = mpp.begin(); it != mpp.end(); it++) {
cout << it->fst << " : " << it->scd << endl;
}
cout << endl;
}
bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
if (a.first == b.first)
return (a.scd >= b.scd);
return (a.first < b.first);
}
vll seive;
vll primes;
void Seive() {
const ll maxn = 100005;
seive.resize(maxn);
fr(i, maxn) seive[i] = 1;
for (ll i = 2; i * i < maxn; i++) {
if (seive[i] == 1) {
for (ll j = i * i; j < maxn; j += i) {
seive[j] = 0;
}
}
}
primes.pb(2);
for (ll i = 3; i < maxn; i += 2) {
if (seive[i])
primes.pb(i);
}
}
ll isprime(ll N) {
if (N < 2 || (!(N & 1) && N != 2))
return 0;
for (ll i = 3; i * i <= N; i += 2) {
if (!(N % i))
return 0;
}
return 1;
}
ll power(ll x, ll y, ll m) {
long long int res = 1;
x = x % m;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % MOD;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
ll modinv(ll x, ll mod = MOD) { return power(x, mod - 2, mod); }
////////////////////////////////////////////////////////////////////////////////
ll T[3005][3005];
ll B[100001];
string s1, s2;
ll lcs(ll n, ll m) {
fr(i, n + 1) {
fr(j, m + 1) {
if (i == 0 || j == 0) {
T[i][j] = 0;
} else if (s1[i - 1] == s2[j - 1]) {
T[i][j] = 1 + T[i - 1][j - 1];
} else {
T[i][j] = max(T[i - 1][j], T[i][j - 1]);
}
}
}
int res = T[n][m];
ll p = res;
char s[res + 1];
// s[res] = '';
int i = n;
int j = m;
string s3;
while (j > 0 && i > 0) {
if (s1[i - 1] == s2[j - 1]) {
j--;
i--;
res--;
s[res] = (char)s1[i];
s3 = s3 + ((char)s1[i]);
} else if (T[i - 1][j] > T[i][j - 1]) {
i--;
} else
j--;
}
for (int i = s3.length() - 1; i >= 0; i--)
cout << s3[i];
// cout<<endl;
// cout<<s<<endl;
return p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll a, b, c, d;
ll k, l, m, n, p, q, r, t, x, y;
// cin>>t;while(t--){ map<ll,ll> M;
// string s1,s2;
cin >> s1 >> s2;
n = s1.length();
m = s2.length();
p = lcs(n, m);
// cout<<p<<endl;
// }
}
|
delete
| 203 | 207 | 203 | 203 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define ar array
#define pb push_back
#define sz(X) ((int)(X).size())
#define ordered_set \
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define sort_unique(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define all(X) (X).begin(), (X).end()
#define No cout << "NO" << endl;
#define Yes cout << "YES" << endl;
#define nl cout << endl;
#define gc getchar //_unlocked
#define pc putchar //_unlocked
template <typename T> ostream &operator+(ostream &out, const vector<T> &vec) {
for (const auto &x : vec) {
out << x << " ";
}
out << "\n";
return out;
}
template <typename T> ostream &operator*(ostream &out, const vector<T> &vec) {
for (const auto &x : vec) {
out + x;
}
return out;
}
template <typename T> istream &operator>>(istream &in, vector<T> &vec) {
for (auto &x : vec) {
in >> x;
}
return in;
}
// DEBUG
void DBG() { cerr << "]" << endl; }
template <class H, class... T> void DBG(H h, T... t) {
cerr << ts(h);
if (sizeof...(t))
cerr << ", ";
DBG(t...);
}
#ifdef _DEBUG // compile with -DLOCAL
#define dbg(...) \
cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \
DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const ll INF = 1e9 + 6;
ll add(ll a, ll b) {
a += b;
return a % mod;
}
ll mul(ll a, ll b) {
a *= b;
return a % mod;
}
inline void lprint(int a) { // printf("%d ",a);
ll i = 0;
char S[20];
if (a == 0) {
pc('0');
pc('\n');
return;
}
while (a > 0) {
S[i++] = a % 10 + '0';
a = a / 10;
}
--i;
while (i >= 0)
pc(S[i--]);
pc('\n');
}
inline ll readInt() {
register bool minus = false;
ll result = 0;
register char ch;
ch = gc();
while (true) {
if (ch == '-')
break;
if (ch >= '0' && ch <= '9')
break;
ch = gc();
}
if (ch == '-')
minus = true;
else
result = ch - '0';
while (true) {
ch = gc();
if (ch < '0' || ch > '9')
break;
result = result * 10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
inline ll 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 dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MXN = 1e3 + 5;
int dp[MXN][MXN];
void solve() {
string a, b;
cin >> a >> b;
int n = sz(a);
int m = sz(b);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
string ans;
while (n > 0 && m > 0) {
if (a[n - 1] == b[m - 1]) {
ans += a[n - 1];
n--;
m--;
continue;
}
if (dp[n - 1][m] > dp[n][m - 1]) {
n--;
} else {
m--;
}
}
reverse(all(ans));
cout << ans << endl;
}
int 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
int t = 1;
// cin>>t;
while (t--)
solve();
// cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "
// ms" << '\n';
return 0;
}
// look if it requires ll
|
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define ar array
#define pb push_back
#define sz(X) ((int)(X).size())
#define ordered_set \
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define sort_unique(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define all(X) (X).begin(), (X).end()
#define No cout << "NO" << endl;
#define Yes cout << "YES" << endl;
#define nl cout << endl;
#define gc getchar //_unlocked
#define pc putchar //_unlocked
template <typename T> ostream &operator+(ostream &out, const vector<T> &vec) {
for (const auto &x : vec) {
out << x << " ";
}
out << "\n";
return out;
}
template <typename T> ostream &operator*(ostream &out, const vector<T> &vec) {
for (const auto &x : vec) {
out + x;
}
return out;
}
template <typename T> istream &operator>>(istream &in, vector<T> &vec) {
for (auto &x : vec) {
in >> x;
}
return in;
}
// DEBUG
void DBG() { cerr << "]" << endl; }
template <class H, class... T> void DBG(H h, T... t) {
cerr << ts(h);
if (sizeof...(t))
cerr << ", ";
DBG(t...);
}
#ifdef _DEBUG // compile with -DLOCAL
#define dbg(...) \
cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \
DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const ll INF = 1e9 + 6;
ll add(ll a, ll b) {
a += b;
return a % mod;
}
ll mul(ll a, ll b) {
a *= b;
return a % mod;
}
inline void lprint(int a) { // printf("%d ",a);
ll i = 0;
char S[20];
if (a == 0) {
pc('0');
pc('\n');
return;
}
while (a > 0) {
S[i++] = a % 10 + '0';
a = a / 10;
}
--i;
while (i >= 0)
pc(S[i--]);
pc('\n');
}
inline ll readInt() {
register bool minus = false;
ll result = 0;
register char ch;
ch = gc();
while (true) {
if (ch == '-')
break;
if (ch >= '0' && ch <= '9')
break;
ch = gc();
}
if (ch == '-')
minus = true;
else
result = ch - '0';
while (true) {
ch = gc();
if (ch < '0' || ch > '9')
break;
result = result * 10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
inline ll 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 dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MXN = 3e3 + 5;
int dp[MXN][MXN];
void solve() {
string a, b;
cin >> a >> b;
int n = sz(a);
int m = sz(b);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
string ans;
while (n > 0 && m > 0) {
if (a[n - 1] == b[m - 1]) {
ans += a[n - 1];
n--;
m--;
continue;
}
if (dp[n - 1][m] > dp[n][m - 1]) {
n--;
} else {
m--;
}
}
reverse(all(ans));
cout << ans << endl;
}
int 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
int t = 1;
// cin>>t;
while (t--)
solve();
// cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "
// ms" << '\n';
return 0;
}
// look if it requires ll
|
replace
| 136 | 137 | 136 | 137 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string S, T;
pair<int, int> dp[3009][3009];
int main() {
cin >> S >> T;
for (int i = 0; i <= 3000; i++) {
for (int j = 0; j <= 3000; j++)
dp[i][j] = make_pair(-1, -1);
}
dp[0][0] = make_pair(0, -1);
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] =
max(dp[i + 1][j + 1], make_pair(dp[i][j].first + 1, 0));
}
dp[i + 1][j] = max(dp[i + 1][j], make_pair(dp[i][j].first, 1));
dp[i][j + 1] = max(dp[i][j + 1], make_pair(dp[i][j].first, 2));
}
}
int maxn = 0;
pair<int, int> maxid = make_pair(-1, -1);
for (int i = 0; i <= S.size(); i++) {
for (int j = 0; j <= T.size(); j++) {
if (dp[i][j].first > maxn) {
maxn = dp[i][j].first;
maxid = make_pair(i, j);
}
}
}
string V;
while (maxid != make_pair(0, 0)) {
if (dp[maxid.first][maxid.second].second == 0) {
maxid.first--;
maxid.second--;
V += S[maxid.first];
}
if (dp[maxid.first][maxid.second].second == 1)
maxid.first--;
if (dp[maxid.first][maxid.second].second == 2)
maxid.second--;
}
reverse(V.begin(), V.end());
cout << V << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string S, T;
pair<int, int> dp[3009][3009];
int main() {
cin >> S >> T;
for (int i = 0; i <= 3000; i++) {
for (int j = 0; j <= 3000; j++)
dp[i][j] = make_pair(-1, -1);
}
dp[0][0] = make_pair(0, -1);
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] =
max(dp[i + 1][j + 1], make_pair(dp[i][j].first + 1, 0));
}
dp[i + 1][j] = max(dp[i + 1][j], make_pair(dp[i][j].first, 1));
dp[i][j + 1] = max(dp[i][j + 1], make_pair(dp[i][j].first, 2));
}
}
int maxn = -1;
pair<int, int> maxid = make_pair(-1, -1);
for (int i = 0; i <= S.size(); i++) {
for (int j = 0; j <= T.size(); j++) {
if (dp[i][j].first > maxn) {
maxn = dp[i][j].first;
maxid = make_pair(i, j);
}
}
}
string V;
while (maxid != make_pair(0, 0)) {
if (dp[maxid.first][maxid.second].second == 0) {
maxid.first--;
maxid.second--;
V += S[maxid.first];
}
if (dp[maxid.first][maxid.second].second == 1)
maxid.first--;
if (dp[maxid.first][maxid.second].second == 2)
maxid.second--;
}
reverse(V.begin(), V.end());
cout << V << endl;
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
#define inf 2e16
const int N = 2e5 + 11, K = 20, S = 1e3 + 11;
const int mod = 1e9 + 7;
int dp[111][111], n, m;
int main() {
#ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);
#endif
string a, b;
cin >> a >> b;
n = a.size(), m = b.size();
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; 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 j = 0;
for (int i = 0; i < n; i++) {
while (j < m) {
if (dp[i][j] == dp[i + 1][j])
break;
else if (a[i] == b[j] && dp[i][j] == dp[i + 1][j + 1] + 1) {
printf("%c", b[j++]);
break;
} else
j++;
}
}
return 0;
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ppi pair<int, int>
#define mp make_pair
#define inf 2e16
const int N = 2e5 + 11, K = 20, S = 1e3 + 11;
const int mod = 1e9 + 7;
int dp[3011][3011], n, m;
int main() {
#ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);
#endif
string a, b;
cin >> a >> b;
n = a.size(), m = b.size();
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; 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 j = 0;
for (int i = 0; i < n; i++) {
while (j < m) {
if (dp[i][j] == dp[i + 1][j])
break;
else if (a[i] == b[j] && dp[i][j] == dp[i + 1][j + 1] + 1) {
printf("%c", b[j++]);
break;
} else
j++;
}
}
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll, ll>
string s, t;
ll a, b;
ll dp[3010][3010];
string ans;
ll solve(ll i, ll j) {
if (i == 0 || j == 0) {
return 0;
}
// ll ans=0;
if (s[i - 1] == t[j - 1]) {
dp[i][j] = 1 + solve(i - 1, j - 1);
return dp[i][j];
} else {
dp[i][j] = max(solve(i - 1, j), solve(i, j - 1));
return dp[i][j];
}
// dp[i][j]=ans;
// return dp[i][j];
}
int main() {
fast;
cin >> s >> t;
a = s.length();
b = t.length();
memset(dp, -1, sizeof(dp));
ll axr = solve(a, b);
ll i = a;
ll j = b;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += t[j - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll, ll>
string s, t;
ll a, b;
ll dp[3010][3010];
string ans;
ll solve(ll i, ll j) {
if (i == 0 || j == 0) {
return 0;
}
// ll ans=0;
if (dp[i][j] != -1) {
return dp[i][j];
}
if (s[i - 1] == t[j - 1]) {
dp[i][j] = 1 + solve(i - 1, j - 1);
return dp[i][j];
} else {
dp[i][j] = max(solve(i - 1, j), solve(i, j - 1));
return dp[i][j];
}
// dp[i][j]=ans;
// return dp[i][j];
}
int main() {
fast;
cin >> s >> t;
a = s.length();
b = t.length();
memset(dp, -1, sizeof(dp));
ll axr = solve(a, b);
ll i = a;
ll j = b;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += t[j - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
insert
| 22 | 22 | 22 | 25 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
vector<vector<int>> dp(a.length() + 1, vector<int>(b.length() + 1, 0));
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 - 1][j], dp[i][j - 1]);
}
}
}
int i = a.length();
int j = b.length();
string ans;
while (i > 0 || j > 0) {
if (a[i - 1] == b[j - 1]) {
ans += a[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
vector<vector<int>> dp(a.length() + 1, vector<int>(b.length() + 1, 0));
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 - 1][j], dp[i][j - 1]);
}
}
}
int i = a.length();
int j = b.length();
string ans;
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
ans += a[i - 1];
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string LCS(string s, string t) {
int n = s.length();
int m = t.length();
// int dp[n+1][m+1];
int **dp = new int *[n + 1];
for (int i = 0; i <= n; i++) {
dp[i] = new int[m + 1];
}
// base case
for (int j = 0; j <= m; j++) {
dp[n][j] = 0;
}
for (int i = 0; i <= n; i++) {
dp[i][m] = 0;
}
// fill dp array
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 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<=n;i++){
for(int j=0;j<=m;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
// cout<<dp[0][0];
string ans = "";
// now backtrack the dp array to find the string
int i = 0, j = 0;
while (i <= n && j <= m) {
if (s[i] == t[j]) {
ans += s[i];
i++;
j++;
} else if (dp[i + 1][j] < dp[i][j + 1]) {
j++;
} else {
i++;
}
}
return ans;
}
int main() {
string s, t;
cin >> s >> t;
string ans = LCS(s, t);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string LCS(string s, string t) {
int n = s.length();
int m = t.length();
// int dp[n+1][m+1];
int **dp = new int *[n + 1];
for (int i = 0; i <= n; i++) {
dp[i] = new int[m + 1];
}
// base case
for (int j = 0; j <= m; j++) {
dp[n][j] = 0;
}
for (int i = 0; i <= n; i++) {
dp[i][m] = 0;
}
// fill dp array
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 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<=n;i++){
for(int j=0;j<=m;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
// cout<<dp[0][0];
string ans = "";
// now backtrack the dp array to find the string
int i = 0, j = 0;
while (i < n && j < m) {
if (s[i] == t[j]) {
ans += s[i];
i++;
j++;
} else if (dp[i + 1][j] < dp[i][j + 1]) {
j++;
} else {
i++;
}
}
return ans;
}
int main() {
string s, t;
cin >> s >> t;
string ans = LCS(s, t);
cout << ans << endl;
return 0;
}
|
replace
| 41 | 42 | 41 | 42 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
string S, T;
int dp[1010][1010];
int main() {
cin >> S >> T;
int n = (int)S.size();
int m = (int)T.size();
// LCSの長さを求める
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
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]);
}
}
// dpテーブルからLCSを復元
string ans = "";
int left_chars = dp[n][m]; // あと何文字残っているか
for (int i = n; i > 0; i--) {
for (int j = m; j > 0; j--) {
if (dp[i - 1][j] == dp[i][j - 1] && dp[i][j - 1] == dp[i - 1][j - 1] &&
dp[i - 1][j - 1] != dp[i][j] && dp[i][j] == left_chars) {
ans = (char)S[i - 1] + ans;
left_chars--;
break; // 同じ箇所の文字は1回だけ使用可能
}
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
string S, T;
int dp[3010][3010];
int main() {
cin >> S >> T;
int n = (int)S.size();
int m = (int)T.size();
// LCSの長さを求める
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
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]);
}
}
// dpテーブルからLCSを復元
string ans = "";
int left_chars = dp[n][m]; // あと何文字残っているか
for (int i = n; i > 0; i--) {
for (int j = m; j > 0; j--) {
if (dp[i - 1][j] == dp[i][j - 1] && dp[i][j - 1] == dp[i - 1][j - 1] &&
dp[i - 1][j - 1] != dp[i][j] && dp[i][j] == left_chars) {
ans = (char)S[i - 1] + ans;
left_chars--;
break; // 同じ箇所の文字は1回だけ使用可能
}
}
}
cout << ans << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < t.length(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
string ans = "";
int j = t.length();
int i = s.length();
while (i > 0 || j > 0) {
if (s[i - 1] == t[j - 1]) {
ans = s[i - 1] + ans;
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 main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < t.length(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
string ans = "";
int j = t.length();
int i = s.length();
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans = s[i - 1] + ans;
i--;
j--;
} else {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
j--;
}
}
}
cout << ans << endl;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03165
|
C++
|
Runtime Error
|
//
// Created by 13783 on 2020/4/2.
//
#include <iostream>
using namespace std;
string s, t;
const int len = 3e3;
int dp[len][len];
int n;
void solve() {
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < t.length(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
string ans;
int i = s.length(), j = t.length();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j - 1] == dp[i][j]) {
j--;
} else {
i--;
j--;
ans = s[i] + ans;
}
}
cout << ans;
}
int main() {
cin >> s >> t;
solve();
return 0;
}
|
//
// Created by 13783 on 2020/4/2.
//
#include <iostream>
using namespace std;
string s, t;
const int len = 3e3 + 2;
int dp[len][len];
int n;
void solve() {
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j < t.length(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
string ans;
int i = s.length(), j = t.length();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j - 1] == dp[i][j]) {
j--;
} else {
i--;
j--;
ans = s[i] + ans;
}
}
cout << ans;
}
int main() {
cin >> s >> t;
solve();
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// Your code here!
// int dp[3001][3001] = {{}};
vector<vector<int>> dp(3001, vector<int>(3001, 0));
string S, T;
cin >> S;
cin >> T;
for (int i = 1; i < S.size() + 1; i++) {
for (int j = 1; j < T.size() + 1; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (S[i - 1] == T[j - 1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
if (dp[S.size()][T.size()] > 0) {
int i = S.size();
int j = T.size();
char output[3001];
long long count_output = 0;
while (i > 0) {
while (j > 0) {
if (dp[i][j] == dp[i - 1][j - 1] + 1 && dp[i][j] == dp[i - 1][j] + 1 &&
dp[i][j] == dp[i][j - 1] + 1) {
output[dp[S.size()][T.size()] - count_output - 1] = S[i - 1];
count_output++;
i--;
j--;
} else if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
}
}
for (int i = 0; i < count_output; i++)
cout << output[i];
} else
cout << ' ';
}
|
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// Your code here!
// int dp[3001][3001] = {{}};
vector<vector<int>> dp(3001, vector<int>(3001, 0));
string S, T;
cin >> S;
cin >> T;
for (int i = 1; i < S.size() + 1; i++) {
for (int j = 1; j < T.size() + 1; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (S[i - 1] == T[j - 1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
if (dp[S.size()][T.size()] > 0) {
int i = S.size();
int j = T.size();
char output[3001];
long long count_output = 0;
long long count = 0;
while (true) {
if (i == 0 and j == 0)
break;
if (i > 0 && j > 0 && dp[i][j] == dp[i - 1][j - 1]) {
i--;
j--;
} else if (i > 0 && dp[i][j] == dp[i - 1][j])
i--;
else if (j > 0 && dp[i][j] == dp[i][j - 1])
j--;
else {
output[dp[S.size()][T.size()] - count_output - 1] = S[i - 1];
count_output++;
i--;
j--;
}
}
for (int i = 0; i < count_output; i++)
cout << output[i];
} else
cout << ' ';
}
|
replace
| 24 | 36 | 24 | 41 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005;
int dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int len_s = (int)s.size();
int len_t = (int)t.size();
memset(dp, 0, sizeof dp);
for (int i = 1; i <= len_s; i++) {
for (int j = 1; j <= len_t; 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]);
}
}
int i = len_s, j = len_t;
string ans = "";
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(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005;
int dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int len_s = (int)s.size();
int len_t = (int)t.size();
memset(dp, 0, sizeof dp);
for (int i = 1; i <= len_s; i++) {
for (int j = 1; j <= len_t; 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]);
}
}
int i = len_s, j = len_t;
string ans = "";
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(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// DEFINE and
// TYPEDEF--------------------------------------------------------------
// For actual content check from line 85
#define FORG(i, a, n) \
for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \
a < n ? ++i : --i) // for - general
#define FORZ(i, n) for (lld i = 0; i < (lld)n; ++i) // for - zero
#define FORGI(i, a, n, inc) \
for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \
a < n ? i += inc : i -= inc) // for - general incremental
#define FORZI(i, n, inc) \
for (lld i = 0; i < (lld)n; i += inc) // for - zero incremental
#define SPEEDUP \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define MEM(a, val) memset(a, val, sizeof(a));
#define all(m) m.begin(), m.end()
#define sz(m) (lld) m.size()
#define st first
#define nd second
#define pb push_back
#define DEC(x) fixed << setprecision(x)
typedef long long int lld;
typedef unsigned long long int ulld;
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &a) {
in >> a.st >> a.nd;
return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
out << a.st << " " << a.nd;
return out;
}
template <typename T, typename T1> T amax(T &a, T1 b) {
if (b > a)
a = b;
return a;
}
template <typename T, typename T1> T amin(T &a, T1 b) {
if (b < a)
a = b;
return a;
}
// DEBUGGER------------------------------------------------------------------------
// #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of
// variables
#define DEBUGON
#define ZINDA \
cerr << "\nIdhar-ich hai apun!!\n"; // to debug if code reached that point
#ifdef DEBUGON
vector<string> vec_splitter(string s) {
for (char &c : s)
c = c == ',' ? ' ' : c;
stringstream ss;
ss << s;
vector<string> res;
for (string z; ss >> z; res.push_back(z))
;
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << "): ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__);
#define DEBUG(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__);
#else
#define debug(...) 320;
#define DEBUG(...) 320;
#endif
lld power(lld b, lld e) {
assert(e >= 0);
if (e == 0)
return 1;
if (e % 2 == 1)
return b * power(b * b, (e - 1) / 2);
else
return power(b * b, e / 2);
}
lld power(lld b, lld e, lld m) {
assert(e >= 0);
if (e == 0)
return 1;
if (e % 2 == 1)
return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m;
else
return power(((b % m) * (b % m)) % m, e / 2, m) % m;
}
#define endl '\n'
const long double pi = acos(-1);
constexpr int mod = 1e9 + 7; // 1000000007
// endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------
lld dp[3007][3007];
pair<lld, lld> path[3007][3007];
void swagWaalaFunction() {
lld n, m;
string a, b, ans;
cin >> a >> b;
n = sz(a);
m = sz(b);
MEM(dp, 0);
FORZ(i, 3007)
FORZ(j, 3007)
path[i][j] = {0, 0};
if (a[0] == b[0]) {
dp[0][0] = 1;
path[0][0] = {-1, -1};
}
FORZ(i, n)
FORZ(j, m) {
if (i) {
dp[i][j] = dp[i - 1][j];
path[i][j] = {-1, 0};
}
if (j and dp[i][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
path[i][j] = {0, -1};
}
if (a[i] == b[j]) {
lld add = 1;
if (i and j)
add += dp[i - 1][j - 1];
if (add > dp[i][j]) {
dp[i][j] = add;
path[i][j] = {-1, -1};
}
}
assert(!(path[i][j].st == 0 and path[i][j].nd == 0));
}
lld i = n - 1, j = m - 1;
while (i >= 0 and j >= 0) {
pair<lld, lld> temp = path[i][j];
if (temp.st == -1 and temp.nd == -1)
ans += a[i];
i += temp.st;
j += temp.nd;
}
reverse(ans.begin(), ans.end());
// DEBUG(dp[n-1][m-1]);
cout << ans << endl;
return;
}
int main() {
SPEEDUP;
lld tc = 1;
// cin>>tc;
#ifdef PRIMES
sieve();
#endif
#ifdef CHOOSE
nCrModInit();
#endif
FORZ(i, tc) {
// cout<<"Case #"<<i+1<<": ";
swagWaalaFunction();
}
// cerr<<"\n"<<timeKyaHorhaH;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// DEFINE and
// TYPEDEF--------------------------------------------------------------
// For actual content check from line 85
#define FORG(i, a, n) \
for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \
a < n ? ++i : --i) // for - general
#define FORZ(i, n) for (lld i = 0; i < (lld)n; ++i) // for - zero
#define FORGI(i, a, n, inc) \
for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \
a < n ? i += inc : i -= inc) // for - general incremental
#define FORZI(i, n, inc) \
for (lld i = 0; i < (lld)n; i += inc) // for - zero incremental
#define SPEEDUP \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define MEM(a, val) memset(a, val, sizeof(a));
#define all(m) m.begin(), m.end()
#define sz(m) (lld) m.size()
#define st first
#define nd second
#define pb push_back
#define DEC(x) fixed << setprecision(x)
typedef long long int lld;
typedef unsigned long long int ulld;
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &a) {
in >> a.st >> a.nd;
return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
out << a.st << " " << a.nd;
return out;
}
template <typename T, typename T1> T amax(T &a, T1 b) {
if (b > a)
a = b;
return a;
}
template <typename T, typename T1> T amin(T &a, T1 b) {
if (b < a)
a = b;
return a;
}
// DEBUGGER------------------------------------------------------------------------
// #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of
// variables
#define DEBUGON
#define ZINDA \
cerr << "\nIdhar-ich hai apun!!\n"; // to debug if code reached that point
#ifdef DEBUGON
vector<string> vec_splitter(string s) {
for (char &c : s)
c = c == ',' ? ' ' : c;
stringstream ss;
ss << s;
vector<string> res;
for (string z; ss >> z; res.push_back(z))
;
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << "): ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__);
#define DEBUG(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__);
#else
#define debug(...) 320;
#define DEBUG(...) 320;
#endif
lld power(lld b, lld e) {
assert(e >= 0);
if (e == 0)
return 1;
if (e % 2 == 1)
return b * power(b * b, (e - 1) / 2);
else
return power(b * b, e / 2);
}
lld power(lld b, lld e, lld m) {
assert(e >= 0);
if (e == 0)
return 1;
if (e % 2 == 1)
return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m;
else
return power(((b % m) * (b % m)) % m, e / 2, m) % m;
}
#define endl '\n'
const long double pi = acos(-1);
constexpr int mod = 1e9 + 7; // 1000000007
// endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------
lld dp[3007][3007];
pair<lld, lld> path[3007][3007];
void swagWaalaFunction() {
lld n, m;
string a, b, ans;
cin >> a >> b;
n = sz(a);
m = sz(b);
MEM(dp, 0);
FORZ(i, 3007)
FORZ(j, 3007)
path[i][j] = {-1, 0};
if (a[0] == b[0]) {
dp[0][0] = 1;
path[0][0] = {-1, -1};
}
FORZ(i, n)
FORZ(j, m) {
if (i) {
dp[i][j] = dp[i - 1][j];
path[i][j] = {-1, 0};
}
if (j and dp[i][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
path[i][j] = {0, -1};
}
if (a[i] == b[j]) {
lld add = 1;
if (i and j)
add += dp[i - 1][j - 1];
if (add > dp[i][j]) {
dp[i][j] = add;
path[i][j] = {-1, -1};
}
}
assert(!(path[i][j].st == 0 and path[i][j].nd == 0));
}
lld i = n - 1, j = m - 1;
while (i >= 0 and j >= 0) {
pair<lld, lld> temp = path[i][j];
if (temp.st == -1 and temp.nd == -1)
ans += a[i];
i += temp.st;
j += temp.nd;
}
reverse(ans.begin(), ans.end());
// DEBUG(dp[n-1][m-1]);
cout << ans << endl;
return;
}
int main() {
SPEEDUP;
lld tc = 1;
// cin>>tc;
#ifdef PRIMES
sieve();
#endif
#ifdef CHOOSE
nCrModInit();
#endif
FORZ(i, tc) {
// cout<<"Case #"<<i+1<<": ";
swagWaalaFunction();
}
// cerr<<"\n"<<timeKyaHorhaH;
return 0;
}
|
replace
| 140 | 141 | 140 | 141 |
-11
| |
p03165
|
C++
|
Runtime Error
|
/*
[Gnana Deepak]
[August 01, 2020 7:44 PM]
[F - LCS]
[https://atcoder.jp/contests/dp/tasks/dp_f]
[2000 ms]
[1024 MB]
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ld = long double;
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define F first
#define S second
#define orderKey order_of_key
#define findOrder find_by_order
#define s(x) set<x>
#define um(x, y) unordered_map<x, y>
#define m(x, y) map<x, y>
#define p(x, y) pair<x, y>
#define v(x) vector<x>
#define min_heap(t) priority_queue<t, vector<t>, greater<t>>
#define max_heap(t) priority_queue<t>
#define ordered_set(x) \
tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ss(v) stable_sort(all(v))
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define stprs(x) cout << fixed << setprecision(x);
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define bs binary_search
#define deb(x) cout << #x << "=" << x << '\n';
#define scn(v1) \
for (auto &x : v1) \
cin >> x;
#define R(x) reverse(all(x));
#define lb lower_bound
#define ub upper_bound
const char nl = '\n';
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const ld PI = acos(-1);
const int N = 3000;
const int imx = LLONG_MAX;
int DP[N + 1][N + 1];
void accio_ac(void) {
string S, T;
cin >> S >> T;
int s = S.length();
int t = T.length();
fori(i, 0, s) fori(j, 0, t) {
if (i == 0 or 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]);
}
}
}
stack<char> Stack;
int i = s - 1;
int j = t - 1;
while (i >= 0 and j >= 0) {
if (S[i] == T[j]) {
Stack.push(S[i]);
--i;
--j;
} else {
if (DP[i - 1][j] > DP[i][j - 1]) {
--i;
} else {
--j;
}
}
}
while (!Stack.empty()) {
cout << Stack.top();
Stack.pop();
}
cout << endl;
}
int32_t main(void) {
fastio;
int __ = 1;
// cin >> __;
while (__--) {
accio_ac();
}
return 0;
}
|
/*
[Gnana Deepak]
[August 01, 2020 7:44 PM]
[F - LCS]
[https://atcoder.jp/contests/dp/tasks/dp_f]
[2000 ms]
[1024 MB]
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ld = long double;
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define F first
#define S second
#define orderKey order_of_key
#define findOrder find_by_order
#define s(x) set<x>
#define um(x, y) unordered_map<x, y>
#define m(x, y) map<x, y>
#define p(x, y) pair<x, y>
#define v(x) vector<x>
#define min_heap(t) priority_queue<t, vector<t>, greater<t>>
#define max_heap(t) priority_queue<t>
#define ordered_set(x) \
tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ss(v) stable_sort(all(v))
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define stprs(x) cout << fixed << setprecision(x);
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define bs binary_search
#define deb(x) cout << #x << "=" << x << '\n';
#define scn(v1) \
for (auto &x : v1) \
cin >> x;
#define R(x) reverse(all(x));
#define lb lower_bound
#define ub upper_bound
const char nl = '\n';
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const ld PI = acos(-1);
const int N = 3000;
const int imx = LLONG_MAX;
int DP[N + 1][N + 1];
void accio_ac(void) {
string S, T;
cin >> S >> T;
int s = S.length();
int t = T.length();
fori(i, 0, s) fori(j, 0, t) {
if (i == 0 or 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]);
}
}
}
stack<char> Stack;
int i = s - 1;
int j = t - 1;
while (i >= 0 and j >= 0) {
if (S[i] == T[j]) {
Stack.push(S[i]);
--i;
--j;
} else {
if (DP[i][j + 1] > DP[i + 1][j]) {
--i;
} else {
--j;
}
}
}
while (!Stack.empty()) {
cout << Stack.top();
Stack.pop();
}
cout << endl;
}
int32_t main(void) {
fastio;
int __ = 1;
// cin >> __;
while (__--) {
accio_ac();
}
return 0;
}
|
replace
| 83 | 84 | 83 | 84 |
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;
int slen, tlen, dp[305][305] = {0};
cin >> s;
cin >> t;
slen = s.length();
tlen = t.length();
s = " " + s;
t = " " + t;
for (int i = 1; i <= slen; i++) {
for (int j = 1; j <= tlen; 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]);
}
}
}
// cout<<" ";
// for(auto x:t){
// cout<<x<<" ";
// }
// cout<<endl;
// for(int i=0;i<=slen; i++){
// cout<<s[i]<<" ";
// for(int j=0; j<=tlen; j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
vector<char> ans;
int i = slen, j = tlen;
while (i > 0 && j > 0) {
while (i > 0 && dp[i - 1][j] == dp[i][j]) {
i--;
}
while (j > 0 && dp[i][j - 1] == dp[i][j]) {
j--;
}
ans.push_back(s[i]);
i--;
j--;
}
reverse(ans.begin(), ans.end());
for (auto x : ans) {
cout << x;
}
}
|
#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;
int slen, tlen, dp[3005][3005] = {0};
cin >> s;
cin >> t;
slen = s.length();
tlen = t.length();
s = " " + s;
t = " " + t;
for (int i = 1; i <= slen; i++) {
for (int j = 1; j <= tlen; 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]);
}
}
}
// cout<<" ";
// for(auto x:t){
// cout<<x<<" ";
// }
// cout<<endl;
// for(int i=0;i<=slen; i++){
// cout<<s[i]<<" ";
// for(int j=0; j<=tlen; j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
vector<char> ans;
int i = slen, j = tlen;
while (i > 0 && j > 0) {
while (i > 0 && dp[i - 1][j] == dp[i][j]) {
i--;
}
while (j > 0 && dp[i][j - 1] == dp[i][j]) {
j--;
}
ans.push_back(s[i]);
i--;
j--;
}
reverse(ans.begin(), ans.end());
for (auto x : ans) {
cout << x;
}
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001], i, j;
string s, t, ans;
int main() {
cin >> s >> t;
s += '$';
t += '%';
for (; i < s.size(); i++) {
for (j = 0; j < t.size(); j++) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
if (s[i] == t[j])
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
}
}
for (i = s.size() - 1, j = t.size() - 1; i + j;) {
if (i && dp[i - 1][j] == dp[i][j])
i--;
else if (j && dp[i][j - 1] == dp[i][j])
j--;
else
i--, j--, ans += s[i];
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[3002][3002], i, j;
string s, t, ans;
int main() {
cin >> s >> t;
s += '$';
t += '%';
for (; i < s.size(); i++) {
for (j = 0; j < t.size(); j++) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
if (s[i] == t[j])
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
}
}
for (i = s.size() - 1, j = t.size() - 1; i + j;) {
if (i && dp[i - 1][j] == dp[i][j])
i--;
else if (j && dp[i][j - 1] == dp[i][j])
j--;
else
i--, j--, ans += s[i];
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
string t;
pair<int, int> nexty[3005][3005];
int dp[3005][3005];
int solve(int i, int j) {
if (i == s.size() || j == t.size()) {
return 0;
}
int &res = dp[i][j];
if (res != -1) {
return res;
}
if (s[i] == t[j]) {
nexty[i][j] = {i + 1, j + 1};
return res = 1 + solve(i + 1, j + 1);
}
int ss = solve(i + 1, j);
int tt = solve(i, j + 1);
if (ss > tt) {
nexty[i][j] = {i + 1, j};
} else {
nexty[i][j] = {i, j + 1};
}
return max(ss, tt);
}
int main() {
cin >> s >> t;
fill(&dp[0][0], &dp[0][0] + 3005 * 3005, -1);
int len = solve(0, 0);
vector<char> res;
auto pp = make_pair(0, 0);
set<pair<int, int>> seen;
while (pp.first != s.size() && pp.second != t.size()) {
assert(!seen.count(pp));
seen.insert(pp);
if (s[pp.first] == t[pp.second]) {
res.push_back(s[pp.first]);
}
pp = nexty[pp.first][pp.second];
}
for (char c : res) {
cout << c;
}
cout << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
string t;
pair<int, int> nexty[3005][3005];
int dp[3005][3005];
int solve(int i, int j) {
if (i == s.size() || j == t.size()) {
return 0;
}
int &res = dp[i][j];
if (res != -1) {
return res;
}
if (s[i] == t[j]) {
nexty[i][j] = {i + 1, j + 1};
return res = 1 + solve(i + 1, j + 1);
}
int ss = solve(i + 1, j);
int tt = solve(i, j + 1);
if (ss > tt) {
nexty[i][j] = {i + 1, j};
} else {
nexty[i][j] = {i, j + 1};
}
return res = max(ss, tt);
}
int main() {
cin >> s >> t;
fill(&dp[0][0], &dp[0][0] + 3005 * 3005, -1);
int len = solve(0, 0);
vector<char> res;
auto pp = make_pair(0, 0);
set<pair<int, int>> seen;
while (pp.first != s.size() && pp.second != t.size()) {
assert(!seen.count(pp));
seen.insert(pp);
if (s[pp.first] == t[pp.second]) {
res.push_back(s[pp.first]);
}
pp = nexty[pp.first][pp.second];
}
for (char c : res) {
cout << c;
}
cout << '\n';
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define E esit(0)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int INF = 1e9 + 7;
int dp[1001][1001];
string s, s1, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s >> s1;
ll n = s.size(), m = s1.size();
s = " " + s;
s1 = " " + s1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i] == s1[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
while (n != 0 && m != 0) {
if (s[n] == s1[m]) {
ans += s[n];
n--;
m--;
} else {
if (dp[n - 1][m] > dp[n][m - 1])
n--;
else
m--;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i];
}
}
|
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define E esit(0)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int INF = 1e9 + 7;
int dp[3001][3001];
string s, s1, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s >> s1;
ll n = s.size(), m = s1.size();
s = " " + s;
s1 = " " + s1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i] == s1[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
while (n != 0 && m != 0) {
if (s[n] == s1[m]) {
ans += s[n];
n--;
m--;
} else {
if (dp[n - 1][m] > dp[n][m - 1])
n--;
else
m--;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i];
}
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9 + 7)
#define mp make_pair
#define testcases \
ll t; \
cin >> t; \
while (t--)
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
s = "*" + s;
t = "*" + t;
vector<vector<int>> dp(1001, vector<int>(1001, 0));
vector<vector<int>> v(1001, vector<int>(1001, 0));
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];
v[i][j] = 1;
continue;
} else if (dp[i - 1][j] > dp[i][j - 1])
v[i][j] = 2;
else
v[i][j] = 3;
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
// cout<<dp[n][m]<<" ";
string ans = "";
while (n != 0 && m != 0) {
if (v[n][m] == 1)
ans.pb(s[n]), n -= 1, m -= 1;
else if (v[n][m] == 2)
n--;
else
m--;
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9 + 7)
#define mp make_pair
#define testcases \
ll t; \
cin >> t; \
while (t--)
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, t;
cin >> s >> t;
int n = s.length(), m = t.length();
s = "*" + s;
t = "*" + t;
vector<vector<int>> dp(3001, vector<int>(3001, 0));
vector<vector<int>> v(3001, vector<int>(3001, 0));
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];
v[i][j] = 1;
continue;
} else if (dp[i - 1][j] > dp[i][j - 1])
v[i][j] = 2;
else
v[i][j] = 3;
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
// cout<<dp[n][m]<<" ";
string ans = "";
while (n != 0 && m != 0) {
if (v[n][m] == 1)
ans.pb(s[n]), n -= 1, m -= 1;
else if (v[n][m] == 2)
n--;
else
m--;
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
replace
| 24 | 26 | 24 | 26 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// #include <string>
using namespace std;
#define typeof(x) __typeof__(x)
#define bit(x, i) (x & (1 << i)) // select the bit of position i of x
#define lowbit(x) ((x) & ((x) ^ ((x)-1))) // get the lowest bit of x
#define hBit(msb, n) \
asm("bsrl %1,%0" \
: "=r"(msb) \
: "r"(n)) // get the highest bit of x, maybe the fastest
#define max(a, b) (a < b ? b : a)
// #define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i, l, r) (l < i && i < r) // the next for are for checking bound
#define LINR(i, l, r) (l <= i && i <= r)
#define LIN(i, l, r) (l <= i && i < r)
#define INR(i, l, r) (l < i && i <= r)
#define F(i, L, R) for (int i = L; i < R; i++) // next four are for "for loops"
#define FIN(i, L, R) for (int i = L; i <= R; i++)
#define FF(i, L, R) for (int i = L; i > R; i--)
#define FFIN(i, L, R) for (int i = L; i >= R; i--)
#define getI(a) \
scanf("%d", &a) // next three are handy ways to get ints, it's also force you
// to use '&' sign
#define getII(a, b) scanf("%d%d", &a, &b)
#define getIII(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define getLL(a) scanf("%lld", &a)
#define g_s(n) \
int(n); \
scanf( \
"%d", \
&(n)) // handy if the input is right after the definition of a variable
#define g_s2(n, m) \
int(n), (m); \
scanf("%d %d", &(n), &(m))
#define g_s3(n, m, k) \
int(n), (m), (k); \
scanf("%d %d %d", &(n), &(m), &(k))
#define TESTS \
g_s(testow); \
while (testow--) // for multilple cases problems
#define whileZ \
int T; \
getI(T); \
while (T--) // the same as above
#define getS(x) scanf("%s", x) // get a char* string
#define MEM(a, x) memset(a, x, sizeof(a)) // set elements of array to some value
#define char2Int(c) (c - '0')
#define lastEle(vec) vec[vec.size() - 1]
#define SZ(x) ((int)((x).size()))
#define REMAX(a, b) (a) = max((a), (b)) // set a to the maximum of a and b
#define REMIN(a, b) (a) = min((a), (b));
#define FOREACH(i, t) \
for (typeof(t.begin()) i = t.begin(); i != t.end(); \
i++) // traverse an STL data structure
#define ALL(c) (c).begin(), (c).end() // handy for function like "sort()"
#define PRESENT(c, x) ((c).find(x) != (c).end())
#define CPRESENT(c, x) (find(ALL(c), x) != (c).end())
#define ll \
long long // data types used often, but you don't want to type them time by
// time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS \
ios_base::sync_with_stdio(0); // to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
// for map, pair
#define mp make_pair
#define fi first
#define se second
// for debug
inline void pisz(int n) { printf("%d\n", n); }
#define DBG(vari) cerr << #vari << " = " << (vari) << endl;
#define printA(a, L, R) FIN(jk, L, R) cout << a[jk] << (jk == R ? '\n' : ' ')
#define printV(a) printA(a, 0, a.size() - 1)
#define MAXN 10000
#define sf scanf
#define pf printf
// for vectors
#define pb push_back
typedef int elem_t;
typedef vector<int> vi;
typedef vector<string> vstr;
typedef vector<set<int>> vset;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> ii;
typedef vector<ii> vii;
// directions
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, -1, 0, 1};
const int drr[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dcc[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, vector<T> t) {
F(i, 0, SZ(t)) s << t[i] << " ";
return s;
}
bool ckmin(int &a, int b) { return b < a ? a = b, true : false; }
bool ckmax(int &a, int b) { return b > a ? a = b, true : false; }
class UnionFind {
private:
vi rank, p;
public:
UnionFind(int n) {
F(i, 0, n) p.pb(i);
rank.assign(n, 1);
}
int findSet(int s) { return (p[s] == s) ? s : (p[s] = findSet(p[s])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
if (isSameSet(i, j))
return;
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y]) {
p[y] = x;
rank[x] += rank[y];
} else {
p[x] = y;
// if(rank[x]==rank[y])rank[y]++;
rank[y] += rank[x];
}
}
int sz(int x) {
int px = findSet(x);
return rank[px];
}
};
double x_y(int x1, int y1, int x2, int y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int dp[3001][3001];
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
int cn = 0;
string s1, s2;
cin >> s1 >> s2;
// cout<<s1<<" "<<s2<<endl;
// MEM(dp,0);
F(i, 0, s1.size() + 5) { F(j, 0, s2.size() + 5) dp[i][j] = 0; }
// if(s1[0]==s2[0])dp[0][0]=1;
F(i, 1, s1.size() + 1) {
F(j, 1, s2.size() + 1) {
if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
}
// dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
}
}
int sz1 = (int)s1.size() - 1, sz2 = (int)s2.size() - 1;
// cout<<sz1<<" "<<sz2<<" "<<dp[3][4]<<endl;
// cout<<dp[sz1+1][sz2+1]<<endl;
string ans = "";
int nwi = sz1 + 1, nwj = sz2 + 1;
while (nwi > 0 && nwj > 0) {
if (dp[nwi - 1][nwj] == dp[nwi][nwj]) {
nwi--;
} else if (dp[nwi][nwj - 1] == dp[nwi][nwj])
nwj--;
else {
ans += s1[nwi - 1];
nwi--;
nwj--;
}
}
// F(k,0,s1.size()+1){
// printA(dp[k],0,s2.size());
// }
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
// #include <string>
using namespace std;
#define typeof(x) __typeof__(x)
#define bit(x, i) (x & (1 << i)) // select the bit of position i of x
#define lowbit(x) ((x) & ((x) ^ ((x)-1))) // get the lowest bit of x
#define hBit(msb, n) \
asm("bsrl %1,%0" \
: "=r"(msb) \
: "r"(n)) // get the highest bit of x, maybe the fastest
#define max(a, b) (a < b ? b : a)
// #define abs(x) (x<0?(-x):x) // big bug here if "-x" is not surrounded by "()"
#define IN(i, l, r) (l < i && i < r) // the next for are for checking bound
#define LINR(i, l, r) (l <= i && i <= r)
#define LIN(i, l, r) (l <= i && i < r)
#define INR(i, l, r) (l < i && i <= r)
#define F(i, L, R) for (int i = L; i < R; i++) // next four are for "for loops"
#define FIN(i, L, R) for (int i = L; i <= R; i++)
#define FF(i, L, R) for (int i = L; i > R; i--)
#define FFIN(i, L, R) for (int i = L; i >= R; i--)
#define getI(a) \
scanf("%d", &a) // next three are handy ways to get ints, it's also force you
// to use '&' sign
#define getII(a, b) scanf("%d%d", &a, &b)
#define getIII(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define getLL(a) scanf("%lld", &a)
#define g_s(n) \
int(n); \
scanf( \
"%d", \
&(n)) // handy if the input is right after the definition of a variable
#define g_s2(n, m) \
int(n), (m); \
scanf("%d %d", &(n), &(m))
#define g_s3(n, m, k) \
int(n), (m), (k); \
scanf("%d %d %d", &(n), &(m), &(k))
#define TESTS \
g_s(testow); \
while (testow--) // for multilple cases problems
#define whileZ \
int T; \
getI(T); \
while (T--) // the same as above
#define getS(x) scanf("%s", x) // get a char* string
#define MEM(a, x) memset(a, x, sizeof(a)) // set elements of array to some value
#define char2Int(c) (c - '0')
#define lastEle(vec) vec[vec.size() - 1]
#define SZ(x) ((int)((x).size()))
#define REMAX(a, b) (a) = max((a), (b)) // set a to the maximum of a and b
#define REMIN(a, b) (a) = min((a), (b));
#define FOREACH(i, t) \
for (typeof(t.begin()) i = t.begin(); i != t.end(); \
i++) // traverse an STL data structure
#define ALL(c) (c).begin(), (c).end() // handy for function like "sort()"
#define PRESENT(c, x) ((c).find(x) != (c).end())
#define CPRESENT(c, x) (find(ALL(c), x) != (c).end())
#define ll \
long long // data types used often, but you don't want to type them time by
// time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS \
ios_base::sync_with_stdio(0); // to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
// for map, pair
#define mp make_pair
#define fi first
#define se second
// for debug
inline void pisz(int n) { printf("%d\n", n); }
#define DBG(vari) cerr << #vari << " = " << (vari) << endl;
#define printA(a, L, R) FIN(jk, L, R) cout << a[jk] << (jk == R ? '\n' : ' ')
#define printV(a) printA(a, 0, a.size() - 1)
#define MAXN 10000
#define sf scanf
#define pf printf
// for vectors
#define pb push_back
typedef int elem_t;
typedef vector<int> vi;
typedef vector<string> vstr;
typedef vector<set<int>> vset;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef pair<int, int> ii;
typedef vector<ii> vii;
// directions
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, -1, 0, 1};
const int drr[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dcc[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, vector<T> t) {
F(i, 0, SZ(t)) s << t[i] << " ";
return s;
}
bool ckmin(int &a, int b) { return b < a ? a = b, true : false; }
bool ckmax(int &a, int b) { return b > a ? a = b, true : false; }
class UnionFind {
private:
vi rank, p;
public:
UnionFind(int n) {
F(i, 0, n) p.pb(i);
rank.assign(n, 1);
}
int findSet(int s) { return (p[s] == s) ? s : (p[s] = findSet(p[s])); }
bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
void unionSet(int i, int j) {
if (isSameSet(i, j))
return;
int x = findSet(i), y = findSet(j);
if (rank[x] > rank[y]) {
p[y] = x;
rank[x] += rank[y];
} else {
p[x] = y;
// if(rank[x]==rank[y])rank[y]++;
rank[y] += rank[x];
}
}
int sz(int x) {
int px = findSet(x);
return rank[px];
}
};
double x_y(int x1, int y1, int x2, int y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int dp[3050][3050];
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
int cn = 0;
string s1, s2;
cin >> s1 >> s2;
// cout<<s1<<" "<<s2<<endl;
// MEM(dp,0);
F(i, 0, s1.size() + 5) { F(j, 0, s2.size() + 5) dp[i][j] = 0; }
// if(s1[0]==s2[0])dp[0][0]=1;
F(i, 1, s1.size() + 1) {
F(j, 1, s2.size() + 1) {
if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
}
// dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
}
}
int sz1 = (int)s1.size() - 1, sz2 = (int)s2.size() - 1;
// cout<<sz1<<" "<<sz2<<" "<<dp[3][4]<<endl;
// cout<<dp[sz1+1][sz2+1]<<endl;
string ans = "";
int nwi = sz1 + 1, nwj = sz2 + 1;
while (nwi > 0 && nwj > 0) {
if (dp[nwi - 1][nwj] == dp[nwi][nwj]) {
nwi--;
} else if (dp[nwi][nwj - 1] == dp[nwi][nwj])
nwj--;
else {
ans += s1[nwi - 1];
nwi--;
nwj--;
}
}
// F(k,0,s1.size()+1){
// printA(dp[k],0,s2.size());
// }
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
|
replace
| 147 | 148 | 147 | 148 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#define FAST \
std::ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define DECIMAL(n) \
std::cout << std::fixed; \
std::cout << std::setprecision(n);
#define hell 1000000007
#define narak 998244353
#define PI 3.14159265358979323844
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) *max_element(ALL(v))
#define minc(v) *min_element(ALL(v))
#define sqr(a) (a) * (a)
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define inputarr(a, n) \
for (int xxx = 0; xxx < n; ++xxx) \
cin >> a[xxx]
#define initarr(a, n, x) \
for (int xxx = 0; xxx < n; ++xxx) \
a[xxx] = x
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data, n, commands) \
for (int xxx = 0; xxx < n; xxx++) { \
int tmp; \
cin >> tmp; \
data.pb(tmp); \
commands \
}
#define inset(data, n, commands) \
for (int xxx = 0; xxx < n; xxx++) { \
int tmp; \
cin >> tmp; \
data.insert(tmp); \
commands \
}
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl
#define debug cerr << "bhau" << endl
#define between(n, a, b) (a <= n && n <= b)
#define clamp(n, a, b) (((n) < (a)) ? (a) : (((n) > (b)) ? (b) : (n)))
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
template <typename T, typename U> static inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> static inline void amax(T &x, U y) {
if (x < y)
x = y;
}
std::mt19937_64
rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
/*----------------------Graph Moves----------------*/
// const int fx[]={+1,-1,+0,+0};
// const int fy[]={+0,+0,+1,-1};
// const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
// const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
// const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
// const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
/*------------------------------------------------*/
// primes for hashing 937,991,1013,1409,1741
pii operator+(pii a, pii b) { return {a.fi + b.fi, a.se + b.se}; }
pll operator+(pll a, pll b) { return {a.fi + b.fi, a.se + b.se}; }
std::ostream &operator<<(std::ostream &out, pii a) {
out << a.fi << " " << a.se << endl;
return out;
}
std::ostream &operator<<(std::ostream &out, pll a) {
out << a.fi << " " << a.se << endl;
return out;
}
std::istream &operator>>(std::istream &in, pii &a) {
in >> a.fi >> a.se;
return in;
}
std::istream &operator>>(std::istream &in, pll &a) {
in >> a.fi >> a.se;
return in;
}
using namespace std;
using namespace __gnu_pbds;
string s, t;
int n, m;
ll dp[3001][3001];
pii p[3001][3001];
ll rec(int a, int b) {
if (a < 0 || b < 0)
return 0;
if (dp[a][b] != -1)
return dp[a][b];
if (s[a] == t[b]) {
p[a][b] = {a - 1, b - 1};
return rec(a - 1, b - 1) + 1;
}
dp[a][b] = max(rec(a - 1, b), rec(a, b - 1));
if (dp[a][b] == rec(a - 1, b))
p[a][b] = {a - 1, b};
else
p[a][b] = {a, b - 1};
return dp[a][b];
}
void meowmeow321() {
cin >> s >> t;
n = sl(s);
m = sl(t);
for (int i = 0; i < 3001; ++i) {
for (int j = 0; j < 3001; ++j) {
dp[i][j] = -1;
}
}
rec(n - 1, m - 1);
string ans = "";
int cur = 0;
int lx, ly;
lx = n - 1, ly = m - 1;
for (int i = 0; i < 9 * 1000000; ++i) {
if (cur == dp[n - 1][m - 1])
break;
int wx, wy;
wx = p[lx][ly].fi;
wy = p[lx][ly].se;
if (wx == (lx - 1) && wy == (ly - 1))
cur++, ans += s[lx];
lx = wx;
ly = wy;
}
REVERSE(ans);
cout << ans << endl;
}
int main() {
FAST;
int testcases = 1;
// cin>>testcases;
for (int i = 0; i < testcases; ++i) {
meowmeow321();
}
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#define FAST \
std::ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define DECIMAL(n) \
std::cout << std::fixed; \
std::cout << std::setprecision(n);
#define hell 1000000007
#define narak 998244353
#define PI 3.14159265358979323844
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) *max_element(ALL(v))
#define minc(v) *min_element(ALL(v))
#define sqr(a) (a) * (a)
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define inputarr(a, n) \
for (int xxx = 0; xxx < n; ++xxx) \
cin >> a[xxx]
#define initarr(a, n, x) \
for (int xxx = 0; xxx < n; ++xxx) \
a[xxx] = x
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(a, x) for (auto &a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data, n, commands) \
for (int xxx = 0; xxx < n; xxx++) { \
int tmp; \
cin >> tmp; \
data.pb(tmp); \
commands \
}
#define inset(data, n, commands) \
for (int xxx = 0; xxx < n; xxx++) { \
int tmp; \
cin >> tmp; \
data.insert(tmp); \
commands \
}
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl
#define debug cerr << "bhau" << endl
#define between(n, a, b) (a <= n && n <= b)
#define clamp(n, a, b) (((n) < (a)) ? (a) : (((n) > (b)) ? (b) : (n)))
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
template <typename T, typename U> static inline void amin(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> static inline void amax(T &x, U y) {
if (x < y)
x = y;
}
std::mt19937_64
rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
/*----------------------Graph Moves----------------*/
// const int fx[]={+1,-1,+0,+0};
// const int fy[]={+0,+0,+1,-1};
// const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
// const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
// const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
// const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
/*------------------------------------------------*/
// primes for hashing 937,991,1013,1409,1741
pii operator+(pii a, pii b) { return {a.fi + b.fi, a.se + b.se}; }
pll operator+(pll a, pll b) { return {a.fi + b.fi, a.se + b.se}; }
std::ostream &operator<<(std::ostream &out, pii a) {
out << a.fi << " " << a.se << endl;
return out;
}
std::ostream &operator<<(std::ostream &out, pll a) {
out << a.fi << " " << a.se << endl;
return out;
}
std::istream &operator>>(std::istream &in, pii &a) {
in >> a.fi >> a.se;
return in;
}
std::istream &operator>>(std::istream &in, pll &a) {
in >> a.fi >> a.se;
return in;
}
using namespace std;
using namespace __gnu_pbds;
string s, t;
int n, m;
ll dp[3001][3001];
pii p[3001][3001];
ll rec(int a, int b) {
if (a < 0 || b < 0)
return 0;
if (dp[a][b] != -1)
return dp[a][b];
if (s[a] == t[b]) {
p[a][b] = {a - 1, b - 1};
return rec(a - 1, b - 1) + 1;
}
dp[a][b] = max(rec(a - 1, b), rec(a, b - 1));
if (dp[a][b] == rec(a - 1, b))
p[a][b] = {a - 1, b};
else
p[a][b] = {a, b - 1};
return dp[a][b];
}
void meowmeow321() {
cin >> s >> t;
n = sl(s);
m = sl(t);
for (int i = 0; i < 3001; ++i) {
for (int j = 0; j < 3001; ++j) {
dp[i][j] = -1;
}
}
rec(n - 1, m - 1);
string ans = "";
int cur = 0;
int lx, ly;
lx = n - 1, ly = m - 1;
for (int i = 0; lx >= 0 && ly >= 0; ++i) {
if (cur == dp[n - 1][m - 1])
break;
int wx, wy;
wx = p[lx][ly].fi;
wy = p[lx][ly].se;
if (wx == (lx - 1) && wy == (ly - 1))
cur++, ans += s[lx];
lx = wx;
ly = wy;
}
REVERSE(ans);
cout << ans << endl;
}
int main() {
FAST;
int testcases = 1;
// cin>>testcases;
for (int i = 0; i < testcases; ++i) {
meowmeow321();
}
return 0;
}
|
replace
| 162 | 163 | 162 | 163 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
const int MSIZE = 3003;
int dp[MSIZE][MSIZE];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
memset(dp, 0, sizeof dp);
int n = s.size();
int m = t.size();
s = " " + s;
t = " " + t;
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], dp[i - 1][j - 1] + (s[i] == t[j])});
}
}
int x = n;
int y = m;
string answer = "";
if (dp[n][m] == 0) {
return 0;
}
while (x && y) {
while (x && dp[x - 1][y] == dp[x][y])
x--;
while (y && dp[x][y - 1] == dp[x][y])
y--;
answer.push_back(s[x]);
x--, y--;
}
reverse(answer.begin(), answer.end());
cout << answer << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
const int MSIZE = 3003;
int dp[MSIZE][MSIZE];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
memset(dp, 0, sizeof dp);
int n = s.size();
int m = t.size();
s = " " + s;
t = " " + t;
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], dp[i - 1][j - 1] + (s[i] == t[j])});
}
}
int x = n;
int y = m;
string answer = "";
while (dp[x][y]) {
while (x && dp[x - 1][y] == dp[x][y])
x--;
while (y && dp[x][y - 1] == dp[x][y])
y--;
answer.push_back(s[x]);
x--, y--;
}
reverse(answer.begin(), answer.end());
cout << answer << endl;
}
|
replace
| 33 | 38 | 33 | 34 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (long long i = o; i < n; i++)
#define oneforall \
ios::sync_with_stdio(false); \
cin.tie(0);
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long>> vpll;
typedef vector<pair<int, int>> vpii;
int main() {
oneforall char a[10000], b[10000];
cin >> a + 1 >> b + 1;
ll asize = 0;
ll bsize = 0;
while (a[asize + 1]) {
asize++;
}
while (b[bsize + 1]) {
bsize++;
}
ll dp[10000010][10000010];
FOR(i, 0, 10000010) FOR(j, 0, 10000010) { dp[i][j] = 0; }
FOR(i, 1, asize + 1) {
FOR(j, 1, bsize + 1) {
if (a[i] == b[j])
dp[i][j] = dp[i - 1][j - 1] + 1;
else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
string x;
while (asize and bsize) {
if (a[asize] == b[bsize]) {
x += a[asize];
asize--;
bsize--;
} else if (dp[asize - 1][bsize] > dp[asize][bsize - 1])
asize--;
else
bsize--;
}
reverse(x.begin(), x.end());
cout << x;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (long long i = o; i < n; i++)
#define oneforall \
ios::sync_with_stdio(false); \
cin.tie(0);
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long>> vpll;
typedef vector<pair<int, int>> vpii;
int main() {
oneforall char a[10000], b[10000];
cin >> a + 1 >> b + 1;
ll asize = 0;
ll bsize = 0;
while (a[asize + 1]) {
asize++;
}
while (b[bsize + 1]) {
bsize++;
}
ll dp[3001][3001];
FOR(i, 0, 3001) FOR(j, 0, 3001) { dp[i][j] = 0; }
FOR(i, 1, asize + 1) {
FOR(j, 1, bsize + 1) {
if (a[i] == b[j])
dp[i][j] = dp[i - 1][j - 1] + 1;
else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
string x;
while (asize and bsize) {
if (a[asize] == b[bsize]) {
x += a[asize];
asize--;
bsize--;
} else if (dp[asize - 1][bsize] > dp[asize][bsize - 1])
asize--;
else
bsize--;
}
reverse(x.begin(), x.end());
cout << x;
return 0;
}
|
replace
| 22 | 24 | 22 | 24 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll, ll>>>;
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
vector<ll> InputVec(ll N) {
vector<ll> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
return A;
}
void OutputVec(vector<ll> A) {
for (int i = 0; i < A.size(); ++i) {
cout << A[i] << ",";
}
cout << endl;
}
vector<vector<ll>> InputVec2d(ll H, ll W) {
vector<vector<ll>> A(H);
for (int yi = 0; yi < H; ++yi) {
A[yi] = vector<ll>(W);
}
for (int yi = 0; yi < H; ++yi) {
for (int xi = 0; xi < W; ++xi) {
cin >> A[yi][xi];
}
}
}
void OutputVec2d(vector<vector<ll>> A) {
for (int yi = 0; yi < A.size(); ++yi) {
for (int xi = 0; xi < A[yi].size(); ++xi) {
cout << A[yi][xi] << ",";
}
cout << endl;
}
}
int main() {
string s, t;
cin >> s >> t;
ll S = s.size();
ll T = t.size();
vector<vector<ll>> memo(S);
for (int i = 0; i < S; ++i) {
memo[i] = vector<ll>(T);
}
for (int yi = 0; yi < S; ++yi) {
for (int xi = 0; xi < T; ++xi) {
memo[yi][xi] = -1;
}
}
bool judge = false;
for (int yi = 0; yi < S; ++yi) {
if (s[yi] == t[0] || judge) {
memo[yi][0] = 1;
judge = true;
} else {
memo[yi][0] = 0;
}
}
judge = false;
for (int xi = 1; xi < T; ++xi) {
if (s[0] == t[xi] || judge) {
memo[0][xi] = 1;
judge = true;
} else {
memo[0][xi] = 0;
}
}
for (int yi = 1; yi < S; ++yi) {
for (int xi = 1; xi < T; ++xi) {
if (s[yi] == t[xi]) {
memo[yi][xi] = memo[yi - 1][xi - 1] + 1;
} else {
memo[yi][xi] = max(memo[yi - 1][xi], memo[yi][xi - 1]);
}
}
}
ll x, y;
y = S - 1;
x = T - 1;
stack<char> stack;
if (memo[S - 1][T - 1] == 0) {
cout << "" << endl;
return 0;
}
while (memo[y][x] > 0) {
if (y != 0 && memo[y][x] == memo[y - 1][x]) {
y--;
continue;
}
if (x != 0 && memo[y][x] == memo[y][x - 1]) {
x--;
continue;
}
stack.push(s[y]);
y--;
x--;
}
// OutputVec2d(memo);
while (!stack.empty()) {
cout << stack.top();
stack.pop();
}
cout << endl;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll, ll>>>;
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
vector<ll> InputVec(ll N) {
vector<ll> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
return A;
}
void OutputVec(vector<ll> A) {
for (int i = 0; i < A.size(); ++i) {
cout << A[i] << ",";
}
cout << endl;
}
vector<vector<ll>> InputVec2d(ll H, ll W) {
vector<vector<ll>> A(H);
for (int yi = 0; yi < H; ++yi) {
A[yi] = vector<ll>(W);
}
for (int yi = 0; yi < H; ++yi) {
for (int xi = 0; xi < W; ++xi) {
cin >> A[yi][xi];
}
}
}
void OutputVec2d(vector<vector<ll>> A) {
for (int yi = 0; yi < A.size(); ++yi) {
for (int xi = 0; xi < A[yi].size(); ++xi) {
cout << A[yi][xi] << ",";
}
cout << endl;
}
}
int main() {
string s, t;
cin >> s >> t;
ll S = s.size();
ll T = t.size();
vector<vector<ll>> memo(S);
for (int i = 0; i < S; ++i) {
memo[i] = vector<ll>(T);
}
for (int yi = 0; yi < S; ++yi) {
for (int xi = 0; xi < T; ++xi) {
memo[yi][xi] = -1;
}
}
bool judge = false;
for (int yi = 0; yi < S; ++yi) {
if (s[yi] == t[0] || judge) {
memo[yi][0] = 1;
judge = true;
} else {
memo[yi][0] = 0;
}
}
judge = false;
for (int xi = 1; xi < T; ++xi) {
if (s[0] == t[xi] || judge) {
memo[0][xi] = 1;
judge = true;
} else {
memo[0][xi] = 0;
}
}
for (int yi = 1; yi < S; ++yi) {
for (int xi = 1; xi < T; ++xi) {
if (s[yi] == t[xi]) {
memo[yi][xi] = memo[yi - 1][xi - 1] + 1;
} else {
memo[yi][xi] = max(memo[yi - 1][xi], memo[yi][xi - 1]);
}
}
}
ll x, y;
y = S - 1;
x = T - 1;
stack<char> stack;
if (memo[S - 1][T - 1] == 0) {
cout << "" << endl;
return 0;
}
while ((y >= 0 && x >= 0) && memo[y][x] > 0) {
if (y != 0 && memo[y][x] == memo[y - 1][x]) {
y--;
continue;
}
if (x != 0 && memo[y][x] == memo[y][x - 1]) {
x--;
continue;
}
stack.push(s[y]);
y--;
x--;
}
// OutputVec2d(memo);
while (!stack.empty()) {
cout << stack.top();
stack.pop();
}
cout << endl;
}
|
replace
| 99 | 100 | 99 | 100 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 1e3 + 10;
string A, B;
ll N, M;
ll dp[MAX][MAX];
int solve(int i, int j) {
if (i >= N || j >= M)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
int ans = 0;
if (A[i] == B[j]) {
ans = 1 + solve(i + 1, j + 1);
} else {
ans = max(solve(i + 1, j), solve(i, j + 1));
}
return dp[i][j] = ans;
}
void path(int i, int j) {
if (i >= N || j >= M)
return;
if (A[i] == B[j]) {
cout << A[i];
path(i + 1, j + 1);
} else {
if (solve(i + 1, j) == dp[i][j]) {
path(i + 1, j);
} else if (solve(i, j + 1) == dp[i][j]) {
path(i, j + 1);
}
}
}
int main() {
memset(dp, -1, sizeof dp);
cin >> A >> B;
N = A.size();
M = B.size();
solve(0, 0);
path(0, 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 3e3 + 10;
string A, B;
ll N, M;
ll dp[MAX][MAX];
int solve(int i, int j) {
if (i >= N || j >= M)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
int ans = 0;
if (A[i] == B[j]) {
ans = 1 + solve(i + 1, j + 1);
} else {
ans = max(solve(i + 1, j), solve(i, j + 1));
}
return dp[i][j] = ans;
}
void path(int i, int j) {
if (i >= N || j >= M)
return;
if (A[i] == B[j]) {
cout << A[i];
path(i + 1, j + 1);
} else {
if (solve(i + 1, j) == dp[i][j]) {
path(i + 1, j);
} else if (solve(i, j + 1) == dp[i][j]) {
path(i, j + 1);
}
}
}
int main() {
memset(dp, -1, sizeof dp);
cin >> A >> B;
N = A.size();
M = B.size();
solve(0, 0);
path(0, 0);
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 5;
int n, m;
int dp[MAX_N][MAX_N];
char s[MAX_N], t[MAX_N], ans[MAX_N];
int main() {
// dp[i][j] = maximum lcs using first i chars from s and first j chars from t
// if s[i] == t[j], then there is a match, so, dp[i][j] = 1 + dp[i - 1][j - 1]
// (we take the two chars) Else, there is no match, so we take the best option
// from dp[i - 1][j], dp[i][j - 1];
int l;
cin >> (s + 1) >> (t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
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]);
}
}
}
l = 0;
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 {
--n;
--m;
ans[l++] = s[1 + n];
}
}
reverse(ans, ans + l);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e3 + 5;
int n, m;
int dp[MAX_N][MAX_N];
char s[MAX_N], t[MAX_N], ans[MAX_N];
int main() {
// dp[i][j] = maximum lcs using first i chars from s and first j chars from t
// if s[i] == t[j], then there is a match, so, dp[i][j] = 1 + dp[i - 1][j - 1]
// (we take the two chars) Else, there is no match, so we take the best option
// from dp[i - 1][j], dp[i][j - 1];
int l;
cin >> (s + 1) >> (t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
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]);
}
}
}
l = 0;
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 {
--n;
--m;
ans[l++] = s[1 + n];
}
}
reverse(ans, ans + l);
cout << ans;
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_LENGTH = 3012;
string s, t, dp[MAX_LENGTH][MAX_LENGTH];
int main() {
cin >> s >> t;
int s_length = s.size(), t_length = t.size();
if (s[0] == t[0])
dp[0][0] = s[0];
for (int i = 1; i < t_length; ++i) {
if (t[i] == s[0] && dp[0][i - 1].empty())
dp[0][i] = s[0];
else
dp[0][i] = dp[0][i - 1];
}
int tst = 0;
for (int i = 1; i < s_length; ++i) {
if (tst % 2 == 0) {
if (s[i] == t[0] && dp[0][0].size() == 0)
dp[1][0] = s[i];
else
dp[1][0] = dp[0][0];
}
else {
if (s[i] == t[0] && dp[1][0].size() == 0)
dp[0][0] = s[i];
else
dp[0][0] = dp[1][0];
}
for (int j = 1; j < t_length; ++j) {
if (tst % 2 == 0) {
if (s[i] == t[j])
dp[1][j] = dp[0][j - 1] + s[i];
else if (dp[1][j - 1].size() > dp[0][j].size())
dp[1][j] = dp[1][j - 1];
else
dp[1][j] = dp[0][j];
} else {
if (s[i] == t[j])
dp[0][j] = dp[1][j - 1] + s[i];
else if (dp[0][j - 1].size() > dp[1][j].size())
dp[0][j] = dp[0][j - 1];
else
dp[0][j] = dp[1][j];
}
}
tst++;
}
if (dp[0][t_length - 1].size() > dp[1][t_length - 1].size())
cout << dp[0][t_length - 1] << endl;
else
cout << dp[1][t_length - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_LENGTH = 3012;
string s, t, dp[2][MAX_LENGTH];
int main() {
cin >> s >> t;
int s_length = s.size(), t_length = t.size();
if (s[0] == t[0])
dp[0][0] = s[0];
for (int i = 1; i < t_length; ++i) {
if (t[i] == s[0] && dp[0][i - 1].empty())
dp[0][i] = s[0];
else
dp[0][i] = dp[0][i - 1];
}
int tst = 0;
for (int i = 1; i < s_length; ++i) {
if (tst % 2 == 0) {
if (s[i] == t[0] && dp[0][0].size() == 0)
dp[1][0] = s[i];
else
dp[1][0] = dp[0][0];
}
else {
if (s[i] == t[0] && dp[1][0].size() == 0)
dp[0][0] = s[i];
else
dp[0][0] = dp[1][0];
}
for (int j = 1; j < t_length; ++j) {
if (tst % 2 == 0) {
if (s[i] == t[j])
dp[1][j] = dp[0][j - 1] + s[i];
else if (dp[1][j - 1].size() > dp[0][j].size())
dp[1][j] = dp[1][j - 1];
else
dp[1][j] = dp[0][j];
} else {
if (s[i] == t[j])
dp[0][j] = dp[1][j - 1] + s[i];
else if (dp[0][j - 1].size() > dp[1][j].size())
dp[0][j] = dp[0][j - 1];
else
dp[0][j] = dp[1][j];
}
}
tst++;
}
if (dp[0][t_length - 1].size() > dp[1][t_length - 1].size())
cout << dp[0][t_length - 1] << endl;
else
cout << dp[1][t_length - 1] << endl;
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
TLE
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long
using namespace std;
string a, b;
const int MAXN = 3005;
ll dp[MAXN][MAXN];
int n, m;
string ans;
ll solve(int i, int j) {
if (i == n)
return 0;
if (j == m)
return 0;
ll r = dp[i][j];
if (r != -1)
return r;
if (a[i] == b[j])
r = solve(i + 1, j + 1) + 1;
else
r = max(solve(i + 1, j), solve(i, j + 1));
return r;
}
void build(int i, int j) {
if (i == n)
return;
if (j == m)
return;
ll answer = solve(i, j);
if (a[i] == b[j] && answer == solve(i + 1, j + 1) + 1) {
ans.push_back(a[i]);
build(i + 1, j + 1);
} else if (answer == solve(i + 1, j))
build(i + 1, j);
else if (answer == solve(i, j + 1))
build(i, j + 1);
return;
}
int main() {
fast;
cin >> a >> b;
n = a.size();
m = b.size();
memset(dp, -1, sizeof dp);
solve(0, 0);
build(0, 0);
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long
using namespace std;
string a, b;
const int MAXN = 3005;
ll dp[MAXN][MAXN];
int n, m;
string ans;
ll solve(int i, int j) {
if (i == n)
return 0;
if (j == m)
return 0;
ll r = dp[i][j];
if (r != -1)
return r;
if (a[i] == b[j])
r = solve(i + 1, j + 1) + 1;
else
r = max(solve(i + 1, j), solve(i, j + 1));
return dp[i][j] = r;
}
void build(int i, int j) {
if (i == n)
return;
if (j == m)
return;
ll answer = solve(i, j);
if (a[i] == b[j] && answer == solve(i + 1, j + 1) + 1) {
ans.push_back(a[i]);
build(i + 1, j + 1);
} else if (answer == solve(i + 1, j))
build(i + 1, j);
else if (answer == solve(i, j + 1))
build(i, j + 1);
return;
}
int main() {
fast;
cin >> a >> b;
n = a.size();
m = b.size();
memset(dp, -1, sizeof dp);
solve(0, 0);
build(0, 0);
cout << ans << "\n";
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
//
// Created by Pulak on 18-11-2019.
//
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int s1 = a.size();
int s2 = b.size();
vector<vector<int>> dp(5000, vector<int>(5000));
for (int i = 0; i <= s1; ++i) {
for (int j = 0; j <= s2; ++j) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (a[i - 1] == b[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
}
string ans;
int k = s1, j = s2;
while (k > 0 || j > 0) {
if (a[k - 1] == b[j - 1]) {
ans += a[k - 1];
k--;
j--;
} else {
if (dp[k - 1][j] > dp[k][j - 1])
k--;
else
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans;
}
|
//
// Created by Pulak on 18-11-2019.
//
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int s1 = a.size();
int s2 = b.size();
vector<vector<int>> dp(5000, vector<int>(5000));
for (int i = 0; i <= s1; ++i) {
for (int j = 0; j <= s2; ++j) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (a[i - 1] == b[j - 1]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
}
string ans;
int k = s1, j = s2;
while (k > 0 && j > 0) {
if (a[k - 1] == b[j - 1]) {
ans += a[k - 1];
k--;
j--;
} else {
if (dp[k - 1][j] > dp[k][j - 1])
k--;
else
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans;
}
|
replace
| 26 | 27 | 26 | 27 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
int main() {
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int dp[1010][1010];
rep(i, n + 1) {
rep(j, m + 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]);
}
}
string res = "";
int i = n, j = m;
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 {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
int main() {
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int dp[3010][3010];
rep(i, n + 1) {
rep(j, m + 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]);
}
}
string res = "";
int i = n, j = m;
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 {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// C++14 (GCC 5.4.1)
#define LLINF (1LL << 60)
typedef long long ll;
#define mod 1000000007
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define rrepd(i, a, b) for (int i = (a); i >= (b); i--)
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline T divrup(T a, T b) {
if (a % b)
return a / b + 1;
else
return a / b;
}
template <typename T> inline string toString(const T &a) {
ostringstream oss;
oss << a;
return oss.str();
}
#define dbg_v1(i, V) \
do { \
cout << "-v1----\n"; \
rep(i, V.size()) cout << " " << i << "\t:" << V[i] << endl; \
cout << endl; \
} while (0)
#define dbg_v2(i, k, V) \
do { \
cout << "-v2----\n"; \
rep(i, V.size()) { \
rep(k, V[0].size()) cout << " " << V[i][k]; \
cout << endl; \
} \
} while (0)
int main() {
ios::sync_with_stdio(false); // stdoutとcoutの同期解除
cin.tie(nullptr); // cinとcoutの同期解除
string s, t;
cin >> s >> t;
vector<vector<int>> dp(3000, vector<int>(3000, 0));
int ss = s.size(), ts = t.size();
rep(i, ss) rep(k, ts) {
if (s[i] == t[k])
chmax(dp[i + 1][k + 1], dp[i][k] + 1);
chmax(dp[i + 1][k + 1], dp[i + 1][k]);
chmax(dp[i + 1][k + 1], dp[i][k + 1]);
}
string ans = "";
int d = dp[ss][ts];
while (true) {
if (d == 0)
break;
if (dp[ss - 1][ts] == d)
ss--;
else if (dp[ss][ts - 1] == d)
ts--;
else {
ans = s[ss - 1] + ans;
ss--, ts--, d--;
}
}
cout << ans << endl;
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
// C++14 (GCC 5.4.1)
#define LLINF (1LL << 60)
typedef long long ll;
#define mod 1000000007
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define rrepd(i, a, b) for (int i = (a); i >= (b); i--)
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline T divrup(T a, T b) {
if (a % b)
return a / b + 1;
else
return a / b;
}
template <typename T> inline string toString(const T &a) {
ostringstream oss;
oss << a;
return oss.str();
}
#define dbg_v1(i, V) \
do { \
cout << "-v1----\n"; \
rep(i, V.size()) cout << " " << i << "\t:" << V[i] << endl; \
cout << endl; \
} while (0)
#define dbg_v2(i, k, V) \
do { \
cout << "-v2----\n"; \
rep(i, V.size()) { \
rep(k, V[0].size()) cout << " " << V[i][k]; \
cout << endl; \
} \
} while (0)
int main() {
ios::sync_with_stdio(false); // stdoutとcoutの同期解除
cin.tie(nullptr); // cinとcoutの同期解除
string s, t;
cin >> s >> t;
vector<vector<int>> dp(3001, vector<int>(3001, 0));
int ss = s.size(), ts = t.size();
rep(i, ss) rep(k, ts) {
if (s[i] == t[k])
chmax(dp[i + 1][k + 1], dp[i][k] + 1);
chmax(dp[i + 1][k + 1], dp[i + 1][k]);
chmax(dp[i + 1][k + 1], dp[i][k + 1]);
}
string ans = "";
int d = dp[ss][ts];
while (true) {
if (d == 0)
break;
if (dp[ss - 1][ts] == d)
ss--;
else if (dp[ss][ts - 1] == d)
ts--;
else {
ans = s[ss - 1] + ans;
ss--, ts--, d--;
}
}
cout << ans << endl;
return (0);
}
|
replace
| 61 | 62 | 61 | 62 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int dp[3000][3000];
string li, ne;
int f(int i, int j) {
if (i == li.size() || j == ne.size())
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (li[i] == ne[j])
return dp[i][j] = 1 + f(i + 1, j + 1);
return dp[i][j] = max(f(i + 1, j), f(i, j + 1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
cin >> li >> ne;
f(0, 0);
int i = 0, j = 0;
while (dp[i][j] > 0) {
if (li[i] == ne[j])
cout << li[i], ++i, ++j;
else if (dp[i][j + 1] < dp[i + 1][j])
++i;
else
++j;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int dp[3001][3001];
string li, ne;
int f(int i, int j) {
if (i == li.size() || j == ne.size())
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (li[i] == ne[j])
return dp[i][j] = 1 + f(i + 1, j + 1);
return dp[i][j] = max(f(i + 1, j), f(i, j + 1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
cin >> li >> ne;
f(0, 0);
int i = 0, j = 0;
while (dp[i][j] > 0) {
if (li[i] == ne[j])
cout << li[i], ++i, ++j;
else if (dp[i][j + 1] < dp[i + 1][j])
++i;
else
++j;
}
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define ios \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const ll mod = 1000000007;
using namespace std;
string a, b;
int d[1010][1010];
void lcs(int n, int m) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (j == 0 or i == 0)
d[i][j] = 0;
else if (a[i - 1] == b[j - 1])
d[i][j] = d[i - 1][j - 1] + 1;
else
d[i][j] = max(d[i - 1][j], d[i][j - 1]);
}
}
string ans;
int i = n, j = m;
while (i > 0 and j > 0) {
if (a[i - 1] == b[j - 1]) {
i--, j--;
ans += a[i];
continue;
}
if (d[i - 1][j] > d[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
}
int main() {
cin >> a >> b;
lcs(a.size(), b.size());
return 0;
}
/*
AGGTAB
GXTXAYB
*/
|
#include <bits/stdc++.h>
#define ll long long
#define ios \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const ll mod = 1000000007;
using namespace std;
string a, b;
int d[3010][3010];
void lcs(int n, int m) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (j == 0 or i == 0)
d[i][j] = 0;
else if (a[i - 1] == b[j - 1])
d[i][j] = d[i - 1][j - 1] + 1;
else
d[i][j] = max(d[i - 1][j], d[i][j - 1]);
}
}
string ans;
int i = n, j = m;
while (i > 0 and j > 0) {
if (a[i - 1] == b[j - 1]) {
i--, j--;
ans += a[i];
continue;
}
if (d[i - 1][j] > d[i][j - 1])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans;
}
int main() {
cin >> a >> b;
lcs(a.size(), b.size());
return 0;
}
/*
AGGTAB
GXTXAYB
*/
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define Ds 1
#define Dt 2
#define Db 3
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int S = int(1e3) + 10;
const ll MOD = ll(1e9) + 7;
string s, t;
int dp[S][S], mv[S][S];
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
int n = sz(s);
int m = sz(t);
rep(i, 1, n + 1) rep(j, 1, m + 1) {
mv[i][j] = Ds;
if (dp[i][j] < dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
mv[i][j] = Ds;
}
if (dp[i][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
mv[i][j] = Dt;
}
if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) {
dp[i][j] = dp[i - 1][j - 1] + 1;
mv[i][j] = Db;
}
}
int ci = n, cj = m;
string res;
while (ci > 0 && cj > 0) {
if (mv[ci][cj] == Ds)
ci--;
else if (mv[ci][cj] == Dt)
cj--;
else {
res.push_back(s[ci - 1]);
ci--;
cj--;
}
}
reverse(all(res));
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define Ds 1
#define Dt 2
#define Db 3
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int S = int(3e3) + 10;
const ll MOD = ll(1e9) + 7;
string s, t;
int dp[S][S], mv[S][S];
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
int n = sz(s);
int m = sz(t);
rep(i, 1, n + 1) rep(j, 1, m + 1) {
mv[i][j] = Ds;
if (dp[i][j] < dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
mv[i][j] = Ds;
}
if (dp[i][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
mv[i][j] = Dt;
}
if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) {
dp[i][j] = dp[i - 1][j - 1] + 1;
mv[i][j] = Db;
}
}
int ci = n, cj = m;
string res;
while (ci > 0 && cj > 0) {
if (mv[ci][cj] == Ds)
ci--;
else if (mv[ci][cj] == Dt)
cj--;
else {
res.push_back(s[ci - 1]);
ci--;
cj--;
}
}
reverse(all(res));
cout << res << endl;
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
const int vx[4] = {0, 1, -1, 0};
const int vy[4] = {1, 0, 0, -1};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll
string s, t;
string dp[2][3001];
int size[2][3001];
signed main() {
cin >> s >> t;
rep(i, s.size()) {
rep(j, t.size()) {
if (s[i] == t[j]) {
if (i == 0 || j == 0) {
dp[i % 2][j] = s[i];
size[i % 2][j] = 1;
} else {
dp[i % 2][j] = dp[(i + 1) % 2][j - 1] + s[i];
size[i % 2][j] = size[(i + 1) % 2][j - 1] + 1;
}
} else {
if (i == 0 && j == 0)
continue;
else if (i == 0 ||
j != 0 && size[(i + 1) % 2][j] < size[i % 2][j - 1]) {
dp[i % 2][j] = dp[i % 2][j - 1];
size[i % 2][j] = size[i % 2][j - 1];
} else {
dp[i % 2][j] = dp[(i + 1) % 2][j];
size[i % 2][j] = size[(i + 1) % 2][j];
}
}
}
}
cout << dp[(s.size() + 1) % 2][t.size() - 1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
const int vx[4] = {0, 1, -1, 0};
const int vy[4] = {1, 0, 0, -1};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll
string s, t;
string dp[2][3001];
int size[2][3001];
signed main() {
cin >> s >> t;
rep(i, s.size()) {
rep(j, t.size()) {
if (s[i] == t[j]) {
if (i == 0 || j == 0) {
dp[i % 2][j] = s[i];
size[i % 2][j] = 1;
} else if (size[i % 2][j] < size[(i + 1) % 2][j - 1] + 1) {
dp[i % 2][j] = dp[(i + 1) % 2][j - 1] + s[i];
size[i % 2][j] = size[(i + 1) % 2][j - 1] + 1;
}
} else {
if (i == 0 && j == 0)
continue;
else if (i == 0 ||
j != 0 && size[(i + 1) % 2][j] < size[i % 2][j - 1]) {
dp[i % 2][j] = dp[i % 2][j - 1];
size[i % 2][j] = size[i % 2][j - 1];
} else {
dp[i % 2][j] = dp[(i + 1) % 2][j];
size[i % 2][j] = size[(i + 1) % 2][j];
}
}
}
}
cout << dp[(s.size() + 1) % 2][t.size() - 1] << endl;
}
|
replace
| 35 | 36 | 35 | 36 |
TLE
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
const int M = 3e3 + 4;
string s, t, ans = "";
int dp[M][M], a, b, cnt, vis[M][M];
void fun(int x, int y) {
if (x <= 0 || y <= 0 || cnt < 0)
return;
if (s[x] == t[y] && dp[x][y] == cnt) {
ans += s[x];
cnt--;
fun(x - 1, y - 1);
} else {
fun(x, y - 1);
fun(x - 1, y);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s >> t;
a = s.length();
b = t.length();
s = " " + s;
t = " " + t;
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= b; j++) {
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
cnt = dp[a][b];
fun(a, b);
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 3e3 + 4;
string s, t, ans = "";
int dp[M][M], a, b, cnt, vis[M][M];
void fun(int x, int y) {
if (x <= 0 || y <= 0 || cnt < 0)
return;
if (s[x] == t[y] && dp[x][y] == cnt) {
ans += s[x];
cnt--;
fun(x - 1, y - 1);
} else {
if (dp[x][y - 1] > dp[x - 1][y])
fun(x, y - 1);
else
fun(x - 1, y);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s >> t;
a = s.length();
b = t.length();
s = " " + s;
t = " " + t;
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= b; j++) {
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
cnt = dp[a][b];
fun(a, b);
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
replace
| 13 | 15 | 13 | 17 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 2;
char res[N];
ll dp[N][N];
int main() {
string s, t;
cin >> s >> t;
ll ns = s.length();
ll nt = t.length();
for (int i = 1; i <= ns; i++) {
for (int j = 1; j <= nt; 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]);
}
}
ll i = ns;
ll j = nt;
ll rc = 0;
while (i != 0 && j != 0) {
if (s[i - 1] == t[j - 1]) {
rc++;
res[rc] = s[i - 1];
i--;
j--;
} else {
if (dp[i - 1][j] >= dp[i][j - 1])
i--;
else
j--;
}
}
for (int i = rc; i >= 1; i--)
cout << res[i];
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 2;
char res[N];
ll dp[N][N];
int main() {
string s, t;
cin >> s >> t;
ll ns = s.length();
ll nt = t.length();
for (int i = 1; i <= ns; i++) {
for (int j = 1; j <= nt; 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]);
}
}
ll i = ns;
ll j = nt;
ll rc = 0;
while (i != 0 && j != 0) {
if (s[i - 1] == t[j - 1]) {
rc++;
res[rc] = s[i - 1];
i--;
j--;
} else {
if (dp[i - 1][j] >= dp[i][j - 1])
i--;
else
j--;
}
}
for (int i = rc; i >= 1; i--)
cout << res[i];
cout << endl;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int solution() {
string s, t;
getline(cin, s);
getline(cin, t);
ll n = s.length();
ll m = t.length();
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
for (ll i = 1; i <= n; i++) {
for (ll 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]);
}
}
string ans = "";
ll i = n, j = m;
while (i >= 0 && j >= 0) {
if (s[i - 1] == t[j - 1]) {
ans.insert(ans.begin(), s[i - 1]);
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
cout << ans << "\n";
return 0;
}
int main() {
int T = 1; // cin>>T;
while (T--)
solution();
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int solution() {
string s, t;
getline(cin, s);
getline(cin, t);
ll n = s.length();
ll m = t.length();
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
for (ll i = 1; i <= n; i++) {
for (ll 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]);
}
}
string ans = "";
ll i = n, j = m;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans.insert(ans.begin(), s[i - 1]);
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
cout << ans << "\n";
return 0;
}
int main() {
int T = 1; // cin>>T;
while (T--)
solution();
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p03165
|
C++
|
Runtime Error
|
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define ii int64_t
#define PI 3.14
#define lli long long int
#define li long int
#define deb(x) cout << "\nhi" << x << "\n"
#define mod 1000000007
#define f(x, n) for (int x = 0; x < n; ++x)
#define ff(x, y, z) for (x = y; x <= z; ++x)
#define fio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// while(scanf("%d",&n)!=EOF)
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t, ans;
int64_t i, j, x, y;
int dp[304][304];
memset(dp, 0, sizeof(dp));
cin >> s >> t;
for (i = 1; i <= s.length(); i++)
for (j = 1; j <= t.length(); 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.length();
j = t.length();
while (true) {
if (i > 0 && dp[i][j] == dp[i - 1][j])
i--;
else if (j > 0 && dp[i][j] == dp[i][j - 1])
j--;
else if (i > 0 && j > 0 && s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--;
j--;
}
else
break;
}
reverse(ans.begin(), ans.end());
cout << ans;
}
|
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define ii int64_t
#define PI 3.14
#define lli long long int
#define li long int
#define deb(x) cout << "\nhi" << x << "\n"
#define mod 1000000007
#define f(x, n) for (int x = 0; x < n; ++x)
#define ff(x, y, z) for (x = y; x <= z; ++x)
#define fio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// while(scanf("%d",&n)!=EOF)
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, t, ans;
int64_t i, j, x, y;
int dp[3004][3004];
memset(dp, 0, sizeof(dp));
cin >> s >> t;
for (i = 1; i <= s.length(); i++)
for (j = 1; j <= t.length(); 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.length();
j = t.length();
while (true) {
if (i > 0 && dp[i][j] == dp[i - 1][j])
i--;
else if (j > 0 && dp[i][j] == dp[i][j - 1])
j--;
else if (i > 0 && j > 0 && s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i--;
j--;
}
else
break;
}
reverse(ans.begin(), ans.end());
cout << ans;
}
|
replace
| 39 | 40 | 39 | 40 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < 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)
#define ll long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef long long ui64;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
// ui64 mx=1000*1000*1000+3;
// ui64 dp[mx];
int dp[309][309];
int main() {
string m, n;
cin >> m >> n;
int M = m.size(), N = n.size();
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 (m[i - 1] == n[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 len = dp[M][N];
int i = M, j = N;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i][j - 1]) {
j--;
} else if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
ans += m[i - 1];
i--;
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < 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)
#define ll long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef long long ui64;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
// ui64 mx=1000*1000*1000+3;
// ui64 dp[mx];
int dp[3009][3009];
int main() {
string m, n;
cin >> m >> n;
int M = m.size(), N = n.size();
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 (m[i - 1] == n[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 len = dp[M][N];
int i = M, j = N;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i][j - 1]) {
j--;
} else if (dp[i][j] == dp[i - 1][j]) {
i--;
} else {
ans += m[i - 1];
i--;
j--;
}
}
reverse(ans.begin(), ans.end());
cout << ans;
return 0;
}
|
replace
| 31 | 32 | 31 | 32 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 3100;
const ll mod = 1e9 + 7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x, exit(0);
#define migmig \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ms(x, y) memset(x, y, sizeof x);
#define file_init \
freopen("input.txt", "r+", stdin); \
freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod) {
ll res = 1;
while (b) {
if (b & 1) {
res = (a * res) % md;
}
a = (a * a) % md;
b >>= 1;
}
return (res);
}
string s;
string t;
int dp[maxn][maxn];
int par[maxn][maxn];
int32_t main() {
migmig cin >> s;
cin >> t;
int n = s.size(), m = t.size();
s = "." + s;
t = '.' + t;
pii mx = {0, 0};
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;
par[i][j] = 3;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
par[i][j] = 2;
} else {
dp[i][j] = dp[i][j - 1];
par[i][j] = 1;
}
if (dp[i][j] > dp[mx.first][mx.second])
mx = {i, j};
}
}
string ans = "";
while (mx != pii(0, 0)) {
auto [f, s] = mx;
if (par[f][s] == 3) {
ans = t[s] + ans;
}
int bz = par[f][s] >= 2;
s -= par[f][s] % 2;
f -= bz;
mx = {f, s};
}
cout << ans;
return (0);
}
|
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 3100;
const ll mod = 1e9 + 7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x, exit(0);
#define migmig \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ms(x, y) memset(x, y, sizeof x);
#define file_init \
freopen("input.txt", "r+", stdin); \
freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod) {
ll res = 1;
while (b) {
if (b & 1) {
res = (a * res) % md;
}
a = (a * a) % md;
b >>= 1;
}
return (res);
}
string s;
string t;
int dp[maxn][maxn];
int par[maxn][maxn];
int32_t main() {
migmig cin >> s;
cin >> t;
int n = s.size(), m = t.size();
s = "." + s;
t = '.' + t;
pii mx = {0, 0};
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;
par[i][j] = 3;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
par[i][j] = 2;
} else {
dp[i][j] = dp[i][j - 1];
par[i][j] = 1;
}
if (dp[i][j] > dp[mx.first][mx.second])
mx = {i, j};
}
}
string ans = "";
while (mx != pii(0, 0)) {
auto [f, s] = mx;
if (par[f][s] == 3) {
ans = t[s] + ans;
}
int bz = par[f][s] >= 2;
s -= par[f][s] % 2;
f -= bz;
mx = {f, s};
if (par[f][s] == 0)
break;
}
cout << ans;
return (0);
}
|
insert
| 80 | 80 | 80 | 82 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
/// BISMILLAHIR RAHMANIR RAHEEM
/// ALLAH IS WATCHING ME
/// ALLAH save us from COVID-19.Amin.
/// █▀█─█──█──█▀█─█─█
/// █▄█─█──█──█▄█─█▄█
/// █─█─█▄─█▄─█─█─█─█
/// كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
/// Every soul shall taste death.
/// TODO::
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/// order_of_key return number of elements less than x.
/// find_by_order return index.
using namespace std;
using namespace __gnu_pbds;
#define MOHAMMAD \
ios::sync_with_stdio(0); \
cin.tie(0);
#define all(x) (x).begin(), (x).end()
#define AE cout << fixed << setprecision(10);
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {1, -1, 0, 0}; // 4-direction...........
int dy4[] = {0, 0, 1, -1};
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
// debug
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ",";
os << *it;
}
return os << "]";
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define dbg(args...) \
do { \
cerr << #args << " : "; \
faltu(args); \
} while (0)
void faltu() { cerr << endl; }
template <typename T> void faltu(T a[], int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
cerr << arg << ' ';
faltu(rest...);
}
// #else
// #define dbg(args...)
//*********************************************** The END
//**********************************************************************************************************************************
using ll = long long;
const ll N = 1e3 + 10;
const ll INF = 1e18;
ll dp[N + 1][N + 1];
string s, t, res = "";
ll recur(ll i, ll j) {
if (i == s.size())
return 0;
if (j == t.size())
return 0;
ll &ret = dp[i][j];
if (~ret)
return ret;
ll mx = 0;
if (s[i] == t[j])
mx = max(mx, 1 + recur(i + 1, j + 1));
mx = max(mx, recur(i + 1, j));
mx = max(mx, recur(i, j + 1));
return ret = mx;
}
string build(ll i, ll j) {
if (i == s.size())
return "";
if (j == t.size())
return "";
string ans = "";
if (s[i] == t[j]) {
ans = s[i] + build(i + 1, j + 1);
return ans;
// dbg ( ans );
// return ans;
}
if (recur(i + 1, j) > recur(i, j + 1)) {
ans = build(i + 1, j);
} else
ans = build(i, j + 1);
// dbg ( ans );
return ans;
}
int main() {
MOHAMMAD
memset(dp, -1, sizeof dp);
cin >> s >> t;
cout << build(0, 0);
}
/*
Alhamdulillah
*/
|
/// BISMILLAHIR RAHMANIR RAHEEM
/// ALLAH IS WATCHING ME
/// ALLAH save us from COVID-19.Amin.
/// █▀█─█──█──█▀█─█─█
/// █▄█─█──█──█▄█─█▄█
/// █─█─█▄─█▄─█─█─█─█
/// كُلُّ نَفْسٍ ذَآئِقَةُ الْمَوْت
/// Every soul shall taste death.
/// TODO::
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/// order_of_key return number of elements less than x.
/// find_by_order return index.
using namespace std;
using namespace __gnu_pbds;
#define MOHAMMAD \
ios::sync_with_stdio(0); \
cin.tie(0);
#define all(x) (x).begin(), (x).end()
#define AE cout << fixed << setprecision(10);
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {1, -1, 0, 0}; // 4-direction...........
int dy4[] = {0, 0, 1, -1};
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
// debug
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ",";
os << *it;
}
return os << "]";
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define dbg(args...) \
do { \
cerr << #args << " : "; \
faltu(args); \
} while (0)
void faltu() { cerr << endl; }
template <typename T> void faltu(T a[], int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
cerr << arg << ' ';
faltu(rest...);
}
// #else
// #define dbg(args...)
//*********************************************** The END
//**********************************************************************************************************************************
using ll = long long;
const ll N = 3e3 + 10;
const ll INF = 1e18;
ll dp[N + 1][N + 1];
string s, t, res = "";
ll recur(ll i, ll j) {
if (i == s.size())
return 0;
if (j == t.size())
return 0;
ll &ret = dp[i][j];
if (~ret)
return ret;
ll mx = 0;
if (s[i] == t[j])
mx = max(mx, 1 + recur(i + 1, j + 1));
mx = max(mx, recur(i + 1, j));
mx = max(mx, recur(i, j + 1));
return ret = mx;
}
string build(ll i, ll j) {
if (i == s.size())
return "";
if (j == t.size())
return "";
string ans = "";
if (s[i] == t[j]) {
ans = s[i] + build(i + 1, j + 1);
return ans;
// dbg ( ans );
// return ans;
}
if (recur(i + 1, j) > recur(i, j + 1)) {
ans = build(i + 1, j);
} else
ans = build(i, j + 1);
// dbg ( ans );
return ans;
}
int main() {
MOHAMMAD
memset(dp, -1, sizeof dp);
cin >> s >> t;
cout << build(0, 0);
}
/*
Alhamdulillah
*/
|
replace
| 105 | 106 | 105 | 106 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// int dp[3100][3100];
int dp[50][50];
int main() {
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
dp[i][0] = 0;
}
for (int j = 0; j < t.size(); ++j) {
dp[0][j] = 0;
}
// memset(dp, 0, sizeof(dp)); // kottinoga raku
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] = max(dp[i + 1][j], dp[i][j] + 1);
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j + 1]);
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
// fukugen
string res = "";
int i = (int)s.size();
int j = (int)t.size();
while (i > 0 && j > 0) {
// (i-1, j) -> (i, j) と更新されていた場合
if (dp[i][j] == dp[i - 1][j]) {
--i; // DP の遷移を遡る
}
// (i, j-1) -> (i, j) と更新されていた場合
else if (dp[i][j] == dp[i][j - 1]) {
--j; // DP の遷移を遡る
}
// (i-1, j-1) -> (i, j) と更新されていた場合
else {
res = s[i - 1] +
res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
--i, --j; // DP の遷移を遡る
}
}
// cout << dp[s.size()][t.size()] << endl;
cout << res << endl;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int dp[3100][3100];
int main() {
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
dp[i][0] = 0;
}
for (int j = 0; j < t.size(); ++j) {
dp[0][j] = 0;
}
// memset(dp, 0, sizeof(dp)); // kottinoga raku
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] = max(dp[i + 1][j], dp[i][j] + 1);
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j + 1]);
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
// fukugen
string res = "";
int i = (int)s.size();
int j = (int)t.size();
while (i > 0 && j > 0) {
// (i-1, j) -> (i, j) と更新されていた場合
if (dp[i][j] == dp[i - 1][j]) {
--i; // DP の遷移を遡る
}
// (i, j-1) -> (i, j) と更新されていた場合
else if (dp[i][j] == dp[i][j - 1]) {
--j; // DP の遷移を遡る
}
// (i-1, j-1) -> (i, j) と更新されていた場合
else {
res = s[i - 1] +
res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
--i, --j; // DP の遷移を遡る
}
}
// cout << dp[s.size()][t.size()] << endl;
cout << res << endl;
}
|
replace
| 6 | 8 | 6 | 7 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
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++) {
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][j - 1], dp[i - 1][j]);
}
}
char ch[dp[n][m] + 1];
int i = n, j = m;
while (i > 0 || j > 0) {
if (s[i - 1] == t[j - 1]) {
ch[dp[i][j]] = s[i - 1];
i--, j--;
} else if (dp[i - 1][j] < dp[i][j - 1]) {
j--;
} else
i--;
}
for (int i = 1; i <= dp[n][m]; i++)
cout << ch[i];
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
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++) {
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][j - 1], dp[i - 1][j]);
}
}
char ch[dp[n][m] + 1];
int i = n, j = m;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ch[dp[i][j]] = s[i - 1];
i--, j--;
} else if (dp[i - 1][j] < dp[i][j - 1]) {
j--;
} else
i--;
}
for (int i = 1; i <= dp[n][m]; i++)
cout << ch[i];
cout << endl;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2000;
long long f[maxn + 5][maxn + 5];
int main() {
string s, s1 = "", ans = "";
long long i, j, m, n;
cin >> s1 >> s;
if (s1.length() > s.length())
swap(s1, s);
m = s.length();
n = s1.length();
s = 'l' + s;
s1 = 'l' + s1;
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
if (s[i] == s1[j])
f[i][j] = f[i - 1][j - 1] + 1;
else
f[i][j] = max(f[i - 1][j], f[i][j - 1]);
}
}
while (f[m][n] > 0) {
if (s[m] == s1[n])
ans += s[m], m--, n--;
else if (f[m][n] == f[m][n - 1])
n--;
else
m--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3000;
long long f[maxn + 5][maxn + 5];
int main() {
string s, s1 = "", ans = "";
long long i, j, m, n;
cin >> s1 >> s;
if (s1.length() > s.length())
swap(s1, s);
m = s.length();
n = s1.length();
s = 'l' + s;
s1 = 'l' + s1;
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
if (s[i] == s1[j])
f[i][j] = f[i - 1][j - 1] + 1;
else
f[i][j] = max(f[i - 1][j], f[i][j - 1]);
}
}
while (f[m][n] > 0) {
if (s[m] == s1[n])
ans += s[m], m--, n--;
else if (f[m][n] == f[m][n - 1])
n--;
else
m--;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int lcs(string s, string t, int n, int m) {
if (n >= s.size() || m >= t.size()) {
dp[n][m] = 0;
return 0;
}
if (dp[n][m] != -1)
return dp[n][m];
int ans;
if (s[n] == t[m]) {
if (dp[n + 1][m + 1] == -1)
dp[n + 1][m + 1] = lcs(s, t, n + 1, m + 1);
ans = 1 + dp[n + 1][m + 1];
} else {
if (dp[n][m + 1] == -1)
dp[n][m + 1] = lcs(s, t, n, m + 1);
if (dp[n + 1][m] == -1)
dp[n + 1][m] = lcs(s, t, n + 1, m);
if (dp[n + 1][m] > dp[n][m + 1])
ans = dp[n + 1][m];
else
ans = dp[n][m + 1];
}
dp[n][m] = ans;
return ans;
}
int main() {
for (int i = 0; i < 3000; i++)
for (int j = 0; j <= 3000; j++)
dp[i][j] = -1;
string s, t;
cin >> s >> t;
lcs(s, t, 0, 0);
string str = "";
int i = 0, j = 0;
while (i < s.size() && j < t.size()) {
if (s[i] == t[j]) {
str += s[i];
i++;
j++;
} else if (dp[i + 1][j] > dp[i][j + 1])
i++;
else
j++;
}
cout << str << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int lcs(string &s, string &t, int n, int m) {
if (n >= s.size() || m >= t.size()) {
dp[n][m] = 0;
return 0;
}
if (dp[n][m] != -1)
return dp[n][m];
int ans;
if (s[n] == t[m]) {
if (dp[n + 1][m + 1] == -1)
dp[n + 1][m + 1] = lcs(s, t, n + 1, m + 1);
ans = 1 + dp[n + 1][m + 1];
} else {
if (dp[n][m + 1] == -1)
dp[n][m + 1] = lcs(s, t, n, m + 1);
if (dp[n + 1][m] == -1)
dp[n + 1][m] = lcs(s, t, n + 1, m);
if (dp[n + 1][m] > dp[n][m + 1])
ans = dp[n + 1][m];
else
ans = dp[n][m + 1];
}
dp[n][m] = ans;
return ans;
}
int main() {
for (int i = 0; i < 3000; i++)
for (int j = 0; j <= 3000; j++)
dp[i][j] = -1;
string s, t;
cin >> s >> t;
lcs(s, t, 0, 0);
string str = "";
int i = 0, j = 0;
while (i < s.size() && j < t.size()) {
if (s[i] == t[j]) {
str += s[i];
i++;
j++;
} else if (dp[i + 1][j] > dp[i][j + 1])
i++;
else
j++;
}
cout << str << endl;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
{ \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
}
typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i, a, b) for (ll i = a; i <= b; ++i)
#define REV(i, a, b) for (ll i = a; i >= b; i--)
#define pll pair<ll, ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define min_pq priority_queue<ll, vector<ll>, greater<ll>>
#define max_pq priority_queue<ll>
#define deci(n) fixed << setprecision(n)
#define INF 1e18
ll mod = 1000000007;
////__RANGE__UPDATE___///
vector<ll> initializeDiffArray(vector<ll> &A);
void update(vector<ll> &D, ll l, ll r, ll x);
void getArray(vector<ll> &A, vector<ll> &D);
////__RANGE__UPDATE___///
ll min(ll a, ll b);
ll max(ll a, ll b);
ll gcd(ll a, ll b);
void swap(ll *a, ll *b);
ll lcm(ll a, ll b);
ll modpower(ll x, ll y, ll p);
// Only for integer y's
ll power(ll x, ll y);
ll modulo(ll value, ll m);
ll myXOR(ll x, ll y);
ll diff(ll a, ll b);
int main() {
IOS;
/* #ifdef DEBUG
freopen("std.in", "r", stdin);
freopen("std.out", "w", stdout);
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif */
ll rep = 1;
// cin>>rep;
while (rep--) {
string s, t;
cin >> s >> t;
ll n = s.length();
ll m = t.length();
ll DP[n + 1][m + 1][2];
REP(i, 0, n) {
DP[i][0][0] = 0;
DP[i][0][1] = 0;
}
REP(i, 0, m) {
DP[0][i][0] = 0;
DP[i][0][1] = 0;
}
REP(i, 1, n) {
REP(j, 1, m) {
if (s[i - 1] == t[j - 1]) {
DP[i][j][0] = DP[i - 1][j - 1][0] + 1;
DP[i][j][1] = 1;
} else {
if (DP[i - 1][j][0] > DP[i][j - 1][0]) {
DP[i][j][0] = DP[i - 1][j][0];
DP[i][j][1] = 2;
} else {
DP[i][j][0] = DP[i][j - 1][0];
DP[i][j][1] = 3;
}
}
}
}
ll i, j;
i = n, j = m;
t = "";
while (1) {
if (DP[i][j][1] == 0)
break;
if (DP[i][j][1] == 1) {
t = t + s[i - 1];
i--;
j--;
} else if (DP[i][j][1] == 2)
i--;
else
j--;
}
reverse(t.begin(), t.end());
cout << t << '\n';
}
return 0;
}
ll myXOR(ll x, ll y) { return (x | y) & (~x | ~y); }
ll min(ll a, ll b) {
if (a > b)
return b;
return a;
}
ll max(ll a, ll b) {
if (a < b)
return b;
return a;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll diff(ll a, ll b) {
if (a > b)
return a - b;
return b - a;
}
void swap(ll *a, ll *b) {
ll t = *a;
*a = *b;
*b = t;
}
ll lcm(ll a, ll b) {
if (a == 0)
return b;
if (b == 0)
return a;
return (a * b) / gcd(a, b);
}
ll modpower(ll x, ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll power(ll x, ll y) {
ll temp;
if (y == 0)
return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
ll modulo(ll value, ll m) {
ll mod = value % m;
if (value < 0) {
mod += m;
}
return mod;
}
vector<ll> initializeDiffArray(vector<ll> &A) {
ll n = A.size();
// We use one extra space because
// update(l, r, x) updates D[r+1]
vector<ll> D(n + 1);
D[0] = A[0], D[n] = 0;
for (ll i = 1; i < n; i++)
D[i] = A[i] - A[i - 1];
return D;
}
// Does range update
void update(vector<ll> &D, ll l, ll r, ll x) {
D[l] += x;
D[r + 1] -= x;
}
// Prints updated Array
void getArray(vector<ll> &A, vector<ll> &D) {
for (ll i = 0; i < A.size(); i++) {
if (i == 0)
A[i] = D[i];
// Note that A[0] or D[0] decides
// values of rest of the elements.
else
A[i] = D[i] + A[i - 1];
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
{ \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
}
typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i, a, b) for (ll i = a; i <= b; ++i)
#define REV(i, a, b) for (ll i = a; i >= b; i--)
#define pll pair<ll, ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define min_pq priority_queue<ll, vector<ll>, greater<ll>>
#define max_pq priority_queue<ll>
#define deci(n) fixed << setprecision(n)
#define INF 1e18
ll mod = 1000000007;
////__RANGE__UPDATE___///
vector<ll> initializeDiffArray(vector<ll> &A);
void update(vector<ll> &D, ll l, ll r, ll x);
void getArray(vector<ll> &A, vector<ll> &D);
////__RANGE__UPDATE___///
ll min(ll a, ll b);
ll max(ll a, ll b);
ll gcd(ll a, ll b);
void swap(ll *a, ll *b);
ll lcm(ll a, ll b);
ll modpower(ll x, ll y, ll p);
// Only for integer y's
ll power(ll x, ll y);
ll modulo(ll value, ll m);
ll myXOR(ll x, ll y);
ll diff(ll a, ll b);
int main() {
IOS;
/* #ifdef DEBUG
freopen("std.in", "r", stdin);
freopen("std.out", "w", stdout);
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif */
ll rep = 1;
// cin>>rep;
while (rep--) {
string s, t;
cin >> s >> t;
ll n = s.length();
ll m = t.length();
ll DP[n + 1][m + 1][2];
REP(i, 0, n) {
DP[i][0][0] = 0;
DP[i][0][1] = 0;
}
REP(i, 0, m) {
DP[0][i][0] = 0;
DP[0][i][1] = 0;
}
REP(i, 1, n) {
REP(j, 1, m) {
if (s[i - 1] == t[j - 1]) {
DP[i][j][0] = DP[i - 1][j - 1][0] + 1;
DP[i][j][1] = 1;
} else {
if (DP[i - 1][j][0] > DP[i][j - 1][0]) {
DP[i][j][0] = DP[i - 1][j][0];
DP[i][j][1] = 2;
} else {
DP[i][j][0] = DP[i][j - 1][0];
DP[i][j][1] = 3;
}
}
}
}
ll i, j;
i = n, j = m;
t = "";
while (1) {
if (DP[i][j][1] == 0)
break;
if (DP[i][j][1] == 1) {
t = t + s[i - 1];
i--;
j--;
} else if (DP[i][j][1] == 2)
i--;
else
j--;
}
reverse(t.begin(), t.end());
cout << t << '\n';
}
return 0;
}
ll myXOR(ll x, ll y) { return (x | y) & (~x | ~y); }
ll min(ll a, ll b) {
if (a > b)
return b;
return a;
}
ll max(ll a, ll b) {
if (a < b)
return b;
return a;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll diff(ll a, ll b) {
if (a > b)
return a - b;
return b - a;
}
void swap(ll *a, ll *b) {
ll t = *a;
*a = *b;
*b = t;
}
ll lcm(ll a, ll b) {
if (a == 0)
return b;
if (b == 0)
return a;
return (a * b) / gcd(a, b);
}
ll modpower(ll x, ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll power(ll x, ll y) {
ll temp;
if (y == 0)
return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
ll modulo(ll value, ll m) {
ll mod = value % m;
if (value < 0) {
mod += m;
}
return mod;
}
vector<ll> initializeDiffArray(vector<ll> &A) {
ll n = A.size();
// We use one extra space because
// update(l, r, x) updates D[r+1]
vector<ll> D(n + 1);
D[0] = A[0], D[n] = 0;
for (ll i = 1; i < n; i++)
D[i] = A[i] - A[i - 1];
return D;
}
// Does range update
void update(vector<ll> &D, ll l, ll r, ll x) {
D[l] += x;
D[r + 1] -= x;
}
// Prints updated Array
void getArray(vector<ll> &A, vector<ll> &D) {
for (ll i = 0; i < A.size(); i++) {
if (i == 0)
A[i] = D[i];
// Note that A[0] or D[0] decides
// values of rest of the elements.
else
A[i] = D[i] + A[i - 1];
}
}
|
replace
| 73 | 74 | 73 | 74 |
0
| |
p03165
|
C++
|
Runtime Error
|
// turmak-_-
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define nl "\n"
#define IOI return 0;
#define pb push_back
#define ll long long
#define ld long double
#define IOS \
ios_base ::sync_with_stdio(NULL); \
cin.tie(0); \
cout.tie(0);
#define pii pair<int, int>
#define X first
#define Y second
using namespace std;
const int N = (int)2e5 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int UNDEF = -1;
pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int dp[400][400];
pii p[400][400];
int main() {
IOS
// freopen("lepus.in", "r", stdin);
// freopen("lepus.out", "w", stdout);
string a,
b;
cin >> a >> b;
int n = a.size();
int m = b.size();
a = ' ' + a;
b = ' ' + b;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i] == b[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
p[i][j] = {i - 1, j - 1};
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
if (dp[i][j - 1] > dp[i - 1][j]) {
p[i][j] = {i, j - 1};
} else {
p[i][j] = {i - 1, j};
}
}
}
}
pii cur = {n, m};
string s;
while (true) {
if (a[cur.X] == b[cur.Y])
s = a[cur.X] + s;
if (cur.X <= 1 && cur.Y <= 1) {
break;
}
pii Next = p[cur.X][cur.Y];
cur.X = Next.X, cur.Y = Next.Y;
}
cout << s;
IOI
}
|
// turmak-_-
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define nl "\n"
#define IOI return 0;
#define pb push_back
#define ll long long
#define ld long double
#define IOS \
ios_base ::sync_with_stdio(NULL); \
cin.tie(0); \
cout.tie(0);
#define pii pair<int, int>
#define X first
#define Y second
using namespace std;
const int N = (int)2e5 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int UNDEF = -1;
pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int dp[4000][4000];
pii p[4000][4000];
int main() {
IOS
// freopen("lepus.in", "r", stdin);
// freopen("lepus.out", "w", stdout);
string a,
b;
cin >> a >> b;
int n = a.size();
int m = b.size();
a = ' ' + a;
b = ' ' + b;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i] == b[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
p[i][j] = {i - 1, j - 1};
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
if (dp[i][j - 1] > dp[i - 1][j]) {
p[i][j] = {i, j - 1};
} else {
p[i][j] = {i - 1, j};
}
}
}
}
pii cur = {n, m};
string s;
while (true) {
if (a[cur.X] == b[cur.Y])
s = a[cur.X] + s;
if (cur.X <= 1 && cur.Y <= 1) {
break;
}
pii Next = p[cur.X][cur.Y];
cur.X = Next.X, cur.Y = Next.Y;
}
cout << s;
IOI
}
|
replace
| 25 | 27 | 25 | 27 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
typedef long long ll;
#define w first
#define v second
#define ii pair<ll, ll>
using namespace std;
string s, t;
const int N = 1010;
int m, n;
int mem[N][N];
int dp(int i, int j) {
if (i == n || j == m)
return 0;
int &ret = mem[i][j];
if (ret != -1)
return ret;
ret = 0;
if (s[i] == t[j])
ret = 1 + dp(i + 1, j + 1);
return ret = max({ret, dp(i + 1, j), dp(i, j + 1)});
}
void getpath(int i, int j) {
if (i == n || j == m)
return;
int &ret = mem[i][j];
if (s[i] == t[j]) {
printf("%c", s[i]);
getpath(i + 1, j + 1);
return;
}
if (mem[i + 1][j] > mem[i][j + 1])
getpath(i + 1, j);
else
getpath(i, j + 1);
}
int main() {
memset(mem, -1, sizeof mem);
cin >> s >> t;
n = s.length();
m = t.length();
// printf("%d\n" , dp(0,0));
dp(0, 0);
getpath(0, 0);
}
|
#include <bits/stdc++.h>
typedef long long ll;
#define w first
#define v second
#define ii pair<ll, ll>
using namespace std;
string s, t;
const int N = 3010;
int m, n;
int mem[N][N];
int dp(int i, int j) {
if (i == n || j == m)
return 0;
int &ret = mem[i][j];
if (ret != -1)
return ret;
ret = 0;
if (s[i] == t[j])
ret = 1 + dp(i + 1, j + 1);
return ret = max({ret, dp(i + 1, j), dp(i, j + 1)});
}
void getpath(int i, int j) {
if (i == n || j == m)
return;
int &ret = mem[i][j];
if (s[i] == t[j]) {
printf("%c", s[i]);
getpath(i + 1, j + 1);
return;
}
if (mem[i + 1][j] > mem[i][j + 1])
getpath(i + 1, j);
else
getpath(i, j + 1);
}
int main() {
memset(mem, -1, sizeof mem);
cin >> s >> t;
n = s.length();
m = t.length();
// printf("%d\n" , dp(0,0));
dp(0, 0);
getpath(0, 0);
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e+7;
const int N = 1e3 + 5;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i, l, m) for (int i = l; i < m; i++)
#define vii vector<int>
#define vpr vector<pair<ll, ll>>
ll pwr(ll x, ll y);
bool isprime(int n);
string s, t, ans = "";
int lca[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s >> t;
int s_sz = s.size(), t_sz = t.size();
fr(i, 0, s_sz + 1) {
fr(j, 0, t_sz + 1) {
if (i == 0 || j == 0) {
lca[i][j] = 0;
} else if (s[i - 1] == t[j - 1]) {
lca[i][j] = (1 + lca[i - 1][j - 1]);
} else {
lca[i][j] = max(lca[i - 1][j], lca[i][j - 1]);
}
// cout<<lca[i][j]<<' ';
}
// cout<<endl;
}
int i = s_sz, j = t_sz;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i -= 1;
j -= 1;
} else if (lca[i - 1][j] > lca[i][j - 1]) {
i -= 1;
} else {
j -= 1;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
ll pwr(ll x, ll y) {
ll ans = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
ans = (x * (ans % mod)) % mod;
x = (x * x) % mod;
y = y / 2;
}
return ans % mod;
}
bool isprime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e+7;
const int N = 3e3 + 5;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i, l, m) for (int i = l; i < m; i++)
#define vii vector<int>
#define vpr vector<pair<ll, ll>>
ll pwr(ll x, ll y);
bool isprime(int n);
string s, t, ans = "";
int lca[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s >> t;
int s_sz = s.size(), t_sz = t.size();
fr(i, 0, s_sz + 1) {
fr(j, 0, t_sz + 1) {
if (i == 0 || j == 0) {
lca[i][j] = 0;
} else if (s[i - 1] == t[j - 1]) {
lca[i][j] = (1 + lca[i - 1][j - 1]);
} else {
lca[i][j] = max(lca[i - 1][j], lca[i][j - 1]);
}
// cout<<lca[i][j]<<' ';
}
// cout<<endl;
}
int i = s_sz, j = t_sz;
while (i > 0 && j > 0) {
if (s[i - 1] == t[j - 1]) {
ans += s[i - 1];
i -= 1;
j -= 1;
} else if (lca[i - 1][j] > lca[i][j - 1]) {
i -= 1;
} else {
j -= 1;
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
ll pwr(ll x, ll y) {
ll ans = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
ans = (x * (ans % mod)) % mod;
x = (x * x) % mod;
y = y / 2;
}
return ans % mod;
}
bool isprime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
// Target Expert
/*
* Author : raj1307 - Raj Singh
* Institute : Jalpaiguri Government Engineering College
* Date : 3.08.19
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
// #define DEBUG
#ifdef DEBUG
#define deb(...) \
cerr << "Line:" << __LINE__ << " "; \
__f(#__VA_ARGS__, __VA_ARGS__)
#define debarr(a, n) \
cerr << #a << " : "; \
for (int i = 0; i < n; i++) \
cerr << a[i] << " "; \
cerr << endl;
#define debmat(mat, row, col) \
cerr << #mat << " :\n"; \
for (int i = 0; i < row; i++) { \
for (int j = 0; j < col; j++) \
cerr << mat[i][j] << " "; \
cerr << endl; \
}
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define deb(...) \
{}
#define debarr(a, n) \
{}
#define debmat(mat, row, col) \
{}
#define endl "\n"
#endif
#define fio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define fr(i, a, b) for (int i = (a); i < (b); ++i)
#define fb(i, b, a) for (int i = (b); i > (a); --i)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rr return
#define int long long
#define pb push_back
#define sz(x) ((int)x.size())
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int min(int a, int b) {
if (a > b)
return b;
else
return a;
}
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e18 + 5;
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
const int N = 5e5 + 5;
int n, W;
int cache[3005][3005];
string a, b, output = "";
int dp(int x, int y) {
if (x < 0 or y < 0)
return 0;
else if (cache[x][y] != -1)
return cache[x][y];
else if (a[x] == b[y])
return 1 + dp(x - 1, y - 1);
else {
cache[x][y] = max(dp(x - 1, y), dp(x, y - 1));
return cache[x][y];
}
}
void path(int x, int y) {
if (x < 0 or y < 0)
return;
int ans = dp(x, y);
if (a[x] == b[y]) {
output += a[x];
return path(x - 1, y - 1);
} else {
if (ans == dp(x - 1, y))
return path(x - 1, y);
return path(x, y - 1);
}
}
void solve() {
cin >> a >> b;
memset(cache, -1, sizeof(cache));
dp(sz(a) - 1, sz(b) - 1);
path(sz(a) - 1, sz(b) - 1);
reverse(output.begin(), output.end());
;
cout << output;
}
signed main() {
fio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
// Target Expert
/*
* Author : raj1307 - Raj Singh
* Institute : Jalpaiguri Government Engineering College
* Date : 3.08.19
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
// #define DEBUG
#ifdef DEBUG
#define deb(...) \
cerr << "Line:" << __LINE__ << " "; \
__f(#__VA_ARGS__, __VA_ARGS__)
#define debarr(a, n) \
cerr << #a << " : "; \
for (int i = 0; i < n; i++) \
cerr << a[i] << " "; \
cerr << endl;
#define debmat(mat, row, col) \
cerr << #mat << " :\n"; \
for (int i = 0; i < row; i++) { \
for (int j = 0; j < col; j++) \
cerr << mat[i][j] << " "; \
cerr << endl; \
}
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define deb(...) \
{}
#define debarr(a, n) \
{}
#define debmat(mat, row, col) \
{}
#define endl "\n"
#endif
#define fio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define fr(i, a, b) for (int i = (a); i < (b); ++i)
#define fb(i, b, a) for (int i = (b); i > (a); --i)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rr return
#define int long long
#define pb push_back
#define sz(x) ((int)x.size())
int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int min(int a, int b) {
if (a > b)
return b;
else
return a;
}
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e18 + 5;
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
const int N = 5e5 + 5;
int n, W;
int cache[3005][3005];
string a, b, output = "";
int dp(int x, int y) {
if (x < 0 or y < 0)
return 0;
else if (cache[x][y] != -1)
return cache[x][y];
else if (a[x] == b[y])
return 1 + dp(x - 1, y - 1);
else {
cache[x][y] = max(dp(x - 1, y), dp(x, y - 1));
return cache[x][y];
}
}
void path(int x, int y) {
if (x < 0 or y < 0)
return;
int ans = dp(x, y);
if (a[x] == b[y]) {
output += a[x];
return path(x - 1, y - 1);
} else {
if (ans == dp(x - 1, y))
return path(x - 1, y);
return path(x, y - 1);
}
}
void solve() {
cin >> a >> b;
memset(cache, -1, sizeof(cache));
dp(sz(a) - 1, sz(b) - 1);
path(sz(a) - 1, sz(b) - 1);
reverse(output.begin(), output.end());
;
cout << output;
}
signed main() {
fio;
cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
replace
| 164 | 169 | 164 | 165 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int mod = 1000000007;
const ll INF = 1LL << 60;
int main() {
string S, T;
cin >> S >> T;
vector<vector<int>> dp(S.size() + 2, vector<int>(T.size() + 2, 0));
vector<vector<pair<int, int>>> par(
S.size() + 2, vector<pair<int, int>>(T.size() + 2, make_pair(-1, -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;
par[i][j] = make_pair(i - 1, j - 1);
} else {
if (dp[i - 1][j] >= dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
par[i][j] = make_pair(i - 1, j);
} else {
dp[i][j] = dp[i][j - 1];
par[i][j] = make_pair(i, j - 1);
}
}
}
}
int i = S.size();
int j = T.size();
string ans;
while (i > 0 || j > 0) {
if (dp[i][j] != dp[par[i][j].first][par[i][j].second])
ans += S[par[i][j].first];
int m = i, n = j;
i = par[m][n].first;
j = par[m][n].second;
}
reverse(all(ans));
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int mod = 1000000007;
const ll INF = 1LL << 60;
int main() {
string S, T;
cin >> S >> T;
vector<vector<int>> dp(S.size() + 2, vector<int>(T.size() + 2, 0));
vector<vector<pair<int, int>>> par(
S.size() + 2, vector<pair<int, int>>(T.size() + 2, make_pair(-1, -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;
par[i][j] = make_pair(i - 1, j - 1);
} else {
if (dp[i - 1][j] >= dp[i][j - 1]) {
dp[i][j] = dp[i - 1][j];
par[i][j] = make_pair(i - 1, j);
} else {
dp[i][j] = dp[i][j - 1];
par[i][j] = make_pair(i, j - 1);
}
}
}
}
int i = S.size();
int j = T.size();
string ans;
while (i && j) {
if (dp[i][j] != dp[par[i][j].first][par[i][j].second])
ans += S[par[i][j].first];
int m = i, n = j;
i = par[m][n].first;
j = par[m][n].second;
}
reverse(all(ans));
cout << ans << endl;
}
|
replace
| 35 | 36 | 35 | 36 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i)
#define repprev(i, a, b) for (ll i = b - 1; i >= a; i--)
#define reprev(i, n) repprev(i, 0, n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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;
}
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
#define pb push_back
#define mp make_pair
using P = pair<ll, ll>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vc = vector<char>;
using vp = vector<P>;
#define V vector
#define o_vvt(o1, o2, o3, o4, name, ...) name
#define vvt0(t) V<V<t>>
#define vvt1(t, a) V<V<t>> a
#define vvt2(t, a, b) V<V<t>> a(b)
#define vvt3(t, a, b, c) V<V<t>> a(b, V<t>(c))
#define vvt4(t, a, b, c, d) V<V<t>> a(b, V<t>(c, d))
#define vvl(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(ll, __VA_ARGS__)
#define vvb(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(bool, __VA_ARGS__)
#define vvs(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(string, __VA_ARGS__)
#define vvd(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(double, __VA_ARGS__)
#define vvc(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(char, __VA_ARGS__)
#define vvp(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(P, __VA_ARGS__)
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
#define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__)
#define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__)
#define vns(name, ...) auto name = make_v<string>(__VA_ARGS__)
#define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__)
#define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__)
#define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll LLINF = 1LL << 60;
const int INTINF = 1 << 30;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(ll n) : par(n, -1) {}
void init(ll n) { par.assign(n, -1); }
ll root(ll x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(ll x, ll y) { return root(x) == root(y); }
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) { return -par[root(x)]; }
};
template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
const T INF = numeric_limits<T>::max();
using P = pair<T, int>;
int n = G.size();
vector<T> d(n, INF);
vector<int> b(n, -1);
priority_queue<P, vector<P>, greater<P>> q;
d[s] = 0;
q.emplace(d[s], s);
while (!q.empty()) {
P p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (auto &e : G[v]) {
int u = e.first;
T c = e.second;
if (d[u] > d[v] + c) {
d[u] = d[v] + c;
b[u] = v;
q.emplace(d[u], u);
}
}
}
return d;
}
int64_t power(int64_t x, int64_t n, int64_t mod) {
int64_t ret = 1;
while (n > 0) {
if (n & 1)
(ret *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ret;
}
vector<int> sieve_of_eratosthenes(int n) {
vector<int> primes(n);
for (int i = 2; i < n; ++i)
primes[i] = i;
for (int i = 2; i * i < n; ++i)
if (primes[i])
for (int j = i * i; j < n; j += i)
primes[j] = 0;
return primes;
}
struct Dice {
int s[6];
int &top() { return s[0]; }
int &south() { return s[1]; }
int &east() { return s[2]; }
int &west() { return s[3]; }
int &north() { return s[4]; }
int &bottom() { return s[5]; }
void roll(char c) {
// the view from above
// N
// W E
// S
string b("EWNSRL");
int v[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4},
{0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}};
for (int k = 0; k < 6; k++) {
if (b[k] != c)
continue;
int t = s[v[k][0]];
s[v[k][0]] = s[v[k][1]];
s[v[k][1]] = s[v[k][2]];
s[v[k][2]] = s[v[k][3]];
s[v[k][3]] = t;
}
}
using ll = long long;
ll hash() {
ll res = 0;
for (int i = 0; i < 6; i++)
res = res * 256 + s[i];
return res;
}
bool operator==(const Dice &d) const {
for (int i = 0; i < 6; i++)
if (s[i] != d.s[i])
return 0;
return 1;
}
};
vector<Dice> makeDices(Dice d) {
vector<Dice> res;
for (int i = 0; i < 6; i++) {
Dice t(d);
if (i == 1)
t.roll('N');
if (i == 2)
t.roll('S');
if (i == 3)
t.roll('S'), t.roll('S');
if (i == 4)
t.roll('L');
if (i == 5)
t.roll('R');
for (int k = 0; k < 4; k++) {
res.push_back(t);
t.roll('E');
}
}
return res;
}
std::vector<ll> divisor(ll n) // nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using Graph = vector<vector<int>>;
// 深さ優先探索
vector<bool> seen;
void gdfs(const Graph &G, int v) {
seen[v] = true; // v を訪問済にする
// v から行ける各頂点 next_v について
for (auto next_v : G[v]) {
if (seen[next_v])
continue; // next_v が探索済だったらスルー
gdfs(G, next_v); // 再帰的に探索
}
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
vvl(dp, s.size(), t.size());
rep(i, s.size()) {
rep(j, t.size()) {
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]);
}
}
string ans = "";
ll i = s.size();
ll 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;
}
|
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i)
#define repprev(i, a, b) for (ll i = b - 1; i >= a; i--)
#define reprev(i, n) repprev(i, 0, n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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;
}
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
#define pb push_back
#define mp make_pair
using P = pair<ll, ll>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vd = vector<double>;
using vc = vector<char>;
using vp = vector<P>;
#define V vector
#define o_vvt(o1, o2, o3, o4, name, ...) name
#define vvt0(t) V<V<t>>
#define vvt1(t, a) V<V<t>> a
#define vvt2(t, a, b) V<V<t>> a(b)
#define vvt3(t, a, b, c) V<V<t>> a(b, V<t>(c))
#define vvt4(t, a, b, c, d) V<V<t>> a(b, V<t>(c, d))
#define vvl(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(ll, __VA_ARGS__)
#define vvb(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(bool, __VA_ARGS__)
#define vvs(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(string, __VA_ARGS__)
#define vvd(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(double, __VA_ARGS__)
#define vvc(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(char, __VA_ARGS__)
#define vvp(...) \
o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(P, __VA_ARGS__)
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
#define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__)
#define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__)
#define vns(name, ...) auto name = make_v<string>(__VA_ARGS__)
#define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__)
#define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__)
#define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll LLINF = 1LL << 60;
const int INTINF = 1 << 30;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(ll n) : par(n, -1) {}
void init(ll n) { par.assign(n, -1); }
ll root(ll x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(ll x, ll y) { return root(x) == root(y); }
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) { return -par[root(x)]; }
};
template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
const T INF = numeric_limits<T>::max();
using P = pair<T, int>;
int n = G.size();
vector<T> d(n, INF);
vector<int> b(n, -1);
priority_queue<P, vector<P>, greater<P>> q;
d[s] = 0;
q.emplace(d[s], s);
while (!q.empty()) {
P p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (auto &e : G[v]) {
int u = e.first;
T c = e.second;
if (d[u] > d[v] + c) {
d[u] = d[v] + c;
b[u] = v;
q.emplace(d[u], u);
}
}
}
return d;
}
int64_t power(int64_t x, int64_t n, int64_t mod) {
int64_t ret = 1;
while (n > 0) {
if (n & 1)
(ret *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ret;
}
vector<int> sieve_of_eratosthenes(int n) {
vector<int> primes(n);
for (int i = 2; i < n; ++i)
primes[i] = i;
for (int i = 2; i * i < n; ++i)
if (primes[i])
for (int j = i * i; j < n; j += i)
primes[j] = 0;
return primes;
}
struct Dice {
int s[6];
int &top() { return s[0]; }
int &south() { return s[1]; }
int &east() { return s[2]; }
int &west() { return s[3]; }
int &north() { return s[4]; }
int &bottom() { return s[5]; }
void roll(char c) {
// the view from above
// N
// W E
// S
string b("EWNSRL");
int v[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4},
{0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}};
for (int k = 0; k < 6; k++) {
if (b[k] != c)
continue;
int t = s[v[k][0]];
s[v[k][0]] = s[v[k][1]];
s[v[k][1]] = s[v[k][2]];
s[v[k][2]] = s[v[k][3]];
s[v[k][3]] = t;
}
}
using ll = long long;
ll hash() {
ll res = 0;
for (int i = 0; i < 6; i++)
res = res * 256 + s[i];
return res;
}
bool operator==(const Dice &d) const {
for (int i = 0; i < 6; i++)
if (s[i] != d.s[i])
return 0;
return 1;
}
};
vector<Dice> makeDices(Dice d) {
vector<Dice> res;
for (int i = 0; i < 6; i++) {
Dice t(d);
if (i == 1)
t.roll('N');
if (i == 2)
t.roll('S');
if (i == 3)
t.roll('S'), t.roll('S');
if (i == 4)
t.roll('L');
if (i == 5)
t.roll('R');
for (int k = 0; k < 4; k++) {
res.push_back(t);
t.roll('E');
}
}
return res;
}
std::vector<ll> divisor(ll n) // nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
using Graph = vector<vector<int>>;
// 深さ優先探索
vector<bool> seen;
void gdfs(const Graph &G, int v) {
seen[v] = true; // v を訪問済にする
// v から行ける各頂点 next_v について
for (auto next_v : G[v]) {
if (seen[next_v])
continue; // next_v が探索済だったらスルー
gdfs(G, next_v); // 再帰的に探索
}
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
vvl(dp, s.size() + 1, t.size() + 1);
rep(i, s.size()) {
rep(j, t.size()) {
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]);
}
}
string ans = "";
ll i = s.size();
ll 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;
}
|
replace
| 285 | 286 | 285 | 286 |
-11
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[2001][2001];
int main() {
string s, t;
cin >> s;
cin >> t;
int lens = s.length();
int lent = t.length();
// dp[i][j] is len lcs of 0-i-1 and 0-j-1
// dp[i][j] = if(s[i-1]==t[j-1]) 1 + dp[i-1][j-1]
// dp[i][j] = max(dp[i-1][j],dp[i][j-1])
// int dp[lens+1][lent+1] = {0};
dp[0][0] = 0;
for (int i = 1; i <= lens; i++) {
for (int j = 1; j <= lent; 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]);
}
// printf("dp[%d][%d] = %d\n",i,j,dp[i][j]);
}
}
int i = lens;
int j = lent;
string ans = "";
while (i >= 1 && j >= 1) {
if (s[i - 1] == t[j - 1]) {
i--;
j--;
ans += s[i];
} else {
if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
}
reverse(ans.begin(), ans.end());
// cout<<dp[lens][lent]<<endl;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main() {
string s, t;
cin >> s;
cin >> t;
int lens = s.length();
int lent = t.length();
// dp[i][j] is len lcs of 0-i-1 and 0-j-1
// dp[i][j] = if(s[i-1]==t[j-1]) 1 + dp[i-1][j-1]
// dp[i][j] = max(dp[i-1][j],dp[i][j-1])
// int dp[lens+1][lent+1] = {0};
dp[0][0] = 0;
for (int i = 1; i <= lens; i++) {
for (int j = 1; j <= lent; 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]);
}
// printf("dp[%d][%d] = %d\n",i,j,dp[i][j]);
}
}
int i = lens;
int j = lent;
string ans = "";
while (i >= 1 && j >= 1) {
if (s[i - 1] == t[j - 1]) {
i--;
j--;
ans += s[i];
} else {
if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
}
reverse(ans.begin(), ans.end());
// cout<<dp[lens][lent]<<endl;
cout << ans << endl;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Runtime Error
|
/// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define FASTIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define IN freopen("input.txt", "r+", stdin)
#define OUT freopen("output.txt", "w+", stdout)
#define DBG cout << "Hi there" << endl;
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << " -- " << #x << ": " << (x) << "\n"
#define CHECK_BIT(var, pos) ((var) & (1 << (pos)))
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
const ll MAX = 998244353;
const ll MAX2 = 1271309838631957LL;
long double PI = acosl(-1);
const ll INF = 1e15;
const int NMAX = 1e5 + 5;
const int MAXLG = log2(NMAX) + 1;
const int oo = 1e5 + 10;
const int sz = 100005;
const int MOD = 10000019;
const double EPS = 1e-9;
/// code starts from here
void solve() {
string a, b;
cin >> a >> b;
int n = a.size();
int m = b.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
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]);
}
}
stack<char> s;
int i = n, j = m;
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
i--;
j--;
s.push(a[i]);
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
while (!s.empty()) {
cout << s.top();
s.pop();
}
cout << endl;
}
int main() {
#ifndef ONLINE_JUDGE
IN;
#endif
FASTIO;
int tc = 1;
// cin >> tc;
while (tc--) {
solve();
}
}
|
/// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define FASTIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define IN freopen("input.txt", "r+", stdin)
#define OUT freopen("output.txt", "w+", stdout)
#define DBG cout << "Hi there" << endl;
#define all(x) (x).begin(), (x).end()
#define fap(x) cout << " -- " << #x << ": " << (x) << "\n"
#define CHECK_BIT(var, pos) ((var) & (1 << (pos)))
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
const ll MAX = 998244353;
const ll MAX2 = 1271309838631957LL;
long double PI = acosl(-1);
const ll INF = 1e15;
const int NMAX = 1e5 + 5;
const int MAXLG = log2(NMAX) + 1;
const int oo = 1e5 + 10;
const int sz = 100005;
const int MOD = 10000019;
const double EPS = 1e-9;
/// code starts from here
void solve() {
string a, b;
cin >> a >> b;
int n = a.size();
int m = b.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
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]);
}
}
stack<char> s;
int i = n, j = m;
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
i--;
j--;
s.push(a[i]);
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else
j--;
}
while (!s.empty()) {
cout << s.top();
s.pop();
}
cout << endl;
}
int main() {
// #ifndef ONLINE_JUDGE
// IN;
// #endif
FASTIO;
int tc = 1;
// cin >> tc;
while (tc--) {
solve();
}
}
|
replace
| 78 | 81 | 78 | 81 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3;
string s, t;
int dp[N + 1][N + 1];
int f(unsigned int i, unsigned int j) {
if (i == s.size() || j == t.size())
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (s[i] == t[j])
return dp[i][j] = f(i + 1, j + 1) + 1;
return dp[i][j] = max(f(i + 1, j), f(i, j + 1));
}
void p(unsigned int i, unsigned int j) {
if (i == s.size() || j == t.size())
return;
if (s[i] == t[j]) {
cout << s[i];
p(i + 1, j + 1);
return;
}
if (i == s.size() - 1)
return p(i, j + 1);
if (j == t.size() - 1)
return p(i + 1, j);
if (dp[i + 1][j] > dp[i][j + 1])
return p(i + 1, j);
return p(i, j + 1);
}
int main() {
cin >> s >> t;
memset(dp, -1, sizeof dp);
f(0, 0);
p(0, 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e3;
string s, t;
int dp[N + 1][N + 1];
int f(unsigned int i, unsigned int j) {
if (i == s.size() || j == t.size())
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (s[i] == t[j])
return dp[i][j] = f(i + 1, j + 1) + 1;
return dp[i][j] = max(f(i + 1, j), f(i, j + 1));
}
void p(unsigned int i, unsigned int j) {
if (i == s.size() || j == t.size())
return;
if (s[i] == t[j]) {
cout << s[i];
p(i + 1, j + 1);
return;
}
if (i == s.size() - 1)
return p(i, j + 1);
if (j == t.size() - 1)
return p(i + 1, j);
if (dp[i + 1][j] > dp[i][j + 1])
return p(i + 1, j);
return p(i, j + 1);
}
int main() {
cin >> s >> t;
memset(dp, -1, sizeof dp);
f(0, 0);
p(0, 0);
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class T> istream &operator>>(istream &is, vector<T> &xs) {
for (auto &x : xs)
is >> x;
return is;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &xs) {
for (unsigned int i = 0; i < xs.size(); ++i)
os << (i ? " " : "") << xs[i];
return os;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
void debug(istringstream &) {}
template <char sep = ',', class Head, class... Tail>
void debug(istringstream &iss, Head &&head, Tail &&...tail) {
string name;
getline(iss, name, ',');
cerr << sep << name << "=" << head;
debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
do { \
istringstream ss(#__VA_ARGS__); \
debug<' '>(ss, __VA_ARGS__); \
cerr << endl; \
} while (0)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
int dp[3010][3010];
int prv[3010][3010];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
string S, T;
cin >> S >> T;
int N = SZ(S);
int M = SZ(T);
REP(i, N) REP(j, M) {
if (S[i] == T[j]) {
if (dp[i + 1][j + 1] < dp[i][j] + 1) {
dp[i + 1][j + 1] = dp[i][j] + 1;
prv[i + 1][j + 1] = 2;
}
}
if (dp[i + 1][j] < dp[i][j]) {
dp[i + 1][j] = dp[i][j];
prv[i + 1][j] = 0;
}
if (dp[i][j + 1] < dp[i][j]) {
dp[i][j + 1] = dp[i][j];
prv[i][j + 1] = 1;
}
}
int ii = 0, jj = 0;
REP(i, N + 1) REP(j, M + 1) if (dp[ii][jj] < dp[i][j]) ii = i, jj = j;
// cout << dp[ii][jj] << endl;
string ans;
while (ii + jj) {
int p = prv[ii][jj];
if (p == 2) {
--ii;
--jj;
ans += S[ii];
} else if (p == 1) {
--jj;
} else {
--ii;
}
}
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class T> istream &operator>>(istream &is, vector<T> &xs) {
for (auto &x : xs)
is >> x;
return is;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &xs) {
for (unsigned int i = 0; i < xs.size(); ++i)
os << (i ? " " : "") << xs[i];
return os;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
void debug(istringstream &) {}
template <char sep = ',', class Head, class... Tail>
void debug(istringstream &iss, Head &&head, Tail &&...tail) {
string name;
getline(iss, name, ',');
cerr << sep << name << "=" << head;
debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
do { \
istringstream ss(#__VA_ARGS__); \
debug<' '>(ss, __VA_ARGS__); \
cerr << endl; \
} while (0)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
int dp[3010][3010];
int prv[3010][3010];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
string S, T;
cin >> S >> T;
int N = SZ(S);
int M = SZ(T);
REP(i, N) REP(j, M) {
if (S[i] == T[j]) {
if (dp[i + 1][j + 1] < dp[i][j] + 1) {
dp[i + 1][j + 1] = dp[i][j] + 1;
prv[i + 1][j + 1] = 2;
}
}
if (dp[i + 1][j] < dp[i][j]) {
dp[i + 1][j] = dp[i][j];
prv[i + 1][j] = 0;
}
if (dp[i][j + 1] < dp[i][j]) {
dp[i][j + 1] = dp[i][j];
prv[i][j + 1] = 1;
}
}
int ii = 0, jj = 0;
REP(i, N + 1) REP(j, M + 1) if (dp[ii][jj] < dp[i][j]) ii = i, jj = j;
// cout << dp[ii][jj] << endl;
string ans;
while (ii && jj) {
int p = prv[ii][jj];
if (p == 2) {
--ii;
--jj;
ans += S[ii];
} else if (p == 1) {
--jj;
} else {
--ii;
}
}
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
|
replace
| 108 | 109 | 108 | 109 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define MAXN 3010
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
int n, m, dp[MAXN][MAXN];
int b[MAXN][MAXN];
string s, t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s >> t;
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;
b[i][j] = 2;
continue;
}
if (dp[i - 1][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
b[i][j] = 1;
} else {
dp[i][j] = dp[i - 1][j];
b[i][j] = 0;
}
}
}
vector<char> v;
// cout << dp[n][m];
int i = n, j = m;
while (i > 0 or j > 0) {
if (b[i][j] == 2) {
v.pb(s[i - 1]);
i--;
j--;
}
if (b[i][j] == 1)
j--;
if (b[i][j] == 0)
i--;
}
reverse(v.begin(), v.end());
for (auto i : v)
cout << i;
}
|
#include <bits/stdc++.h>
#define MAXN 3010
#define pii pair<int, int>
#define pb push_back
typedef long long ll;
using namespace std;
int n, m, dp[MAXN][MAXN];
int b[MAXN][MAXN];
string s, t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> s >> t;
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;
b[i][j] = 2;
continue;
}
if (dp[i - 1][j] < dp[i][j - 1]) {
dp[i][j] = dp[i][j - 1];
b[i][j] = 1;
} else {
dp[i][j] = dp[i - 1][j];
b[i][j] = 0;
}
}
}
vector<char> v;
// cout << dp[n][m];
int i = n, j = m;
while (i > 0 and j > 0) {
if (b[i][j] == 2) {
v.pb(s[i - 1]);
i--;
j--;
}
if (b[i][j] == 1)
j--;
if (b[i][j] == 0)
i--;
}
reverse(v.begin(), v.end());
for (auto i : v)
cout << i;
}
|
replace
| 36 | 37 | 36 | 37 |
0
| |
p03165
|
C++
|
Memory Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <unistd.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for (ll i = (a); i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++)
template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
bool p_comp_fs(const P p1, const P p2) { return p1.first < p2.first; };
bool p_comp_fg(const P p1, const P p2) { return p1.first > p2.first; };
bool p_comp_ss(const P p1, const P p2) { return p1.second < p2.second; };
bool p_comp_sg(const P p1, const P p2) { return p1.second > p2.second; };
template <typename T> vector<T> uniquen(vector<T> vec) {
vec.erase(unique(vec.begin(), vec.end()), vec.end());
return vec;
}
string bigger(string s1, string s2) {
if (s1.size() > s2.size())
return s1;
else
return s2;
}
int main() {
string s, t;
cin >> s >> t;
vvs dp(s.size() + 10, vs(t.size() + 10, ""));
REP(i, s.size()) {
REP(j, t.size()) {
if (s[i] == t[j])
dp[i + 1][j + 1] = bigger(dp[i][j] + s[i], dp[i + 1][j + 1]);
dp[i + 1][j + 1] = bigger(dp[i + 1][j + 1], dp[i + 1][j]);
dp[i + 1][j + 1] = bigger(dp[i + 1][j + 1], dp[i][j + 1]);
}
}
cout << dp[s.size()][t.size()] << endstr;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <unistd.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for (ll i = (a); i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++)
template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
bool p_comp_fs(const P p1, const P p2) { return p1.first < p2.first; };
bool p_comp_fg(const P p1, const P p2) { return p1.first > p2.first; };
bool p_comp_ss(const P p1, const P p2) { return p1.second < p2.second; };
bool p_comp_sg(const P p1, const P p2) { return p1.second > p2.second; };
template <typename T> vector<T> uniquen(vector<T> vec) {
vec.erase(unique(vec.begin(), vec.end()), vec.end());
return vec;
}
string bigger(string s1, string s2) {
if (s1.size() > s2.size())
return s1;
else
return s2;
}
int main() {
string s, t;
cin >> s >> t;
vvs dp(s.size() + 10, vs(t.size() + 10, ""));
REP(i, s.size()) {
REP(j, t.size()) {
if (s[i] == t[j])
dp[i + 1][j + 1] = bigger(dp[i][j] + s[i], dp[i + 1][j + 1]);
dp[i + 1][j + 1] = bigger(dp[i + 1][j + 1], dp[i + 1][j]);
dp[i + 1][j + 1] = bigger(dp[i + 1][j + 1], dp[i][j + 1]);
}
if (i >= 3)
vs().swap(dp[i - 2]);
}
cout << dp[s.size()][t.size()] << endstr;
return 0;
}
|
insert
| 66 | 66 | 66 | 68 |
MLE
| |
p03165
|
C++
|
Runtime Error
|
//============================================================================
// Name : f
// Date : Wed Feb 20 10:59:11 CST 2019
// Author : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) \
{ \
cout << x[a]; \
if (a < n - 1) \
cout << " "; \
}
#define pvi(x, v) \
if (v) \
pvar(x); \
fora(a, x) cout << a << " "; \
cout << "\n"
#define par(x, s, n, v) \
if (v) \
pvar(x); \
fori(y, s, n) prt(x, y, n) cout << "\n"
#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <class T> void amax(T &a, T b) { a = max(a, b); }
const int inf = (int)1e9 + 7;
void solve() {
string ss, tt;
cin >> ss >> tt;
int a = sz(ss), b = sz(tt);
using pip = pair<int, pii>;
vector<vector<pip>> dp(a + 1, vector<pip>(b + 1, {-inf, {0, 0}}));
dp[0][0] = {0, {0, 0}};
fori(i, 0, a) {
fori(j, 0, b) {
amax(dp[i + 1][j + 1],
{dp[i][j].first + (ss[i] == tt[j] ? 1 : 0), {i, j}});
amax(dp[i + 1][j], {dp[i][j].first, {i, j}});
amax(dp[i][j + 1], {dp[i][j].first, {i, j}});
}
}
pip mx = {0, {0, 0}};
fori(i, 0, a + 1) {
fori(j, 0, b + 1) { amax(mx, {dp[i][j].first, {i, j}}); }
}
trace(dp, mx);
pii cur = mx.second;
string ret;
while (mx.first && !(cur.first == 0 || cur.second == 0)) {
int i = cur.first, j = cur.second;
pii pre = dp[i][j].second;
if (pre == pii(i - 1, j - 1)) {
assert(ss[i - 1] == tt[j - 1]);
ret = ss[i - 1] + ret;
}
cur = pre;
}
output(ret);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
|
//============================================================================
// Name : f
// Date : Wed Feb 20 10:59:11 CST 2019
// Author : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) \
{ \
cout << x[a]; \
if (a < n - 1) \
cout << " "; \
}
#define pvi(x, v) \
if (v) \
pvar(x); \
fora(a, x) cout << a << " "; \
cout << "\n"
#define par(x, s, n, v) \
if (v) \
pvar(x); \
fori(y, s, n) prt(x, y, n) cout << "\n"
#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <class T> void amax(T &a, T b) { a = max(a, b); }
const int inf = (int)1e9 + 7;
void solve() {
string ss, tt;
cin >> ss >> tt;
int a = sz(ss), b = sz(tt);
using pip = pair<int, pii>;
vector<vector<pip>> dp(a + 1, vector<pip>(b + 1, {-inf, {0, 0}}));
dp[0][0] = {0, {0, 0}};
fori(i, 0, a) {
fori(j, 0, b) {
if (ss[i] == tt[j]) {
amax(dp[i + 1][j + 1], {dp[i][j].first + 1, {i, j}});
}
amax(dp[i + 1][j], {dp[i][j].first, {i, j}});
amax(dp[i][j + 1], {dp[i][j].first, {i, j}});
}
}
pip mx = {0, {0, 0}};
fori(i, 0, a + 1) {
fori(j, 0, b + 1) { amax(mx, {dp[i][j].first, {i, j}}); }
}
trace(dp, mx);
pii cur = mx.second;
string ret;
while (mx.first && !(cur.first == 0 || cur.second == 0)) {
int i = cur.first, j = cur.second;
pii pre = dp[i][j].second;
if (pre == pii(i - 1, j - 1)) {
assert(ss[i - 1] == tt[j - 1]);
ret = ss[i - 1] + ret;
}
cur = pre;
}
output(ret);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
|
replace
| 58 | 60 | 58 | 61 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;
using namespace std;
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;
}
ll mod = 1e9 + 7;
int main() {
int dp[100][100] = {};
string s, t;
cin >> s >> t;
rep(a, s.size()) {
rep(b, t.size()) {
if (s[a] == t[b]) {
dp[a + 1][b + 1] = dp[a][b] + 1;
}
chmax(dp[a + 1][b + 1], dp[a + 1][b]);
chmax(dp[a + 1][b + 1], dp[a][b + 1]);
}
}
string ans = "";
int a = (int)s.size(), b = (int)t.size();
while (a > 0 && b > 0) {
if (dp[a][b] == dp[a - 1][b]) {
a--;
} else if (dp[a][b] == dp[a][b - 1]) {
b--;
} else {
ans = s[a - 1] + ans;
a--, b--;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long int;
using namespace std;
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;
}
ll mod = 1e9 + 7;
int main() {
int dp[3010][3010] = {};
string s, t;
cin >> s >> t;
rep(a, s.size()) {
rep(b, t.size()) {
if (s[a] == t[b]) {
dp[a + 1][b + 1] = dp[a][b] + 1;
}
chmax(dp[a + 1][b + 1], dp[a + 1][b]);
chmax(dp[a + 1][b + 1], dp[a][b + 1]);
}
}
string ans = "";
int a = (int)s.size(), b = (int)t.size();
while (a > 0 && b > 0) {
if (dp[a][b] == dp[a - 1][b]) {
a--;
} else if (dp[a][b] == dp[a][b - 1]) {
b--;
} else {
ans = s[a - 1] + ans;
a--, b--;
}
}
cout << ans << endl;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define REP(i, n) for (i = 0; i < (n); ++i)
#define FOR(i, l, h) for (i = (l); i <= (h); ++i)
#define FORD(i, h, l) for (i = (h); i >= (l); --i)
#define max(a, b) a > b ? a : b
#define min(a, b) a > b ? b : a
using namespace std;
//*********************************
//******problem F DP contest LCS ***
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
ll int m, n;
n = s1.length();
m = s2.length();
int dp[m + 2][n + 2];
// memset(dp,0,sizeof(dp));
for (ll int i = 0; i <= n; i++) {
for (ll int j = 0; j <= m; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
// ans += s1[i];
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int lclen = dp[n][m];
string ans(lclen, '.');
ll int i = n, j = m;
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
ans[lclen - 1] = s1[i - 1];
i--;
j--;
lclen--;
} else if (dp[i - 1][j] < dp[i][j - 1])
j--;
else
i--;
}
// cout<<dp[n][m]<<"\n";
// reverse(ans.begin(),ans.end());
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define REP(i, n) for (i = 0; i < (n); ++i)
#define FOR(i, l, h) for (i = (l); i <= (h); ++i)
#define FORD(i, h, l) for (i = (h); i >= (l); --i)
#define max(a, b) a > b ? a : b
#define min(a, b) a > b ? b : a
using namespace std;
//*********************************
//******problem F DP contest LCS ***
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
ll int m, n;
n = s1.length();
m = s2.length();
vector<vector<int>> dp(n + 2, vector<int>(m + 2, 0));
// memset(dp,0,sizeof(dp));
for (ll int i = 0; i <= n; i++) {
for (ll int j = 0; j <= m; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (s1[i - 1] == s2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
// ans += s1[i];
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
int lclen = dp[n][m];
string ans(lclen, '.');
ll int i = n, j = m;
while (i > 0 && j > 0) {
if (s1[i - 1] == s2[j - 1]) {
ans[lclen - 1] = s1[i - 1];
i--;
j--;
lclen--;
} else if (dp[i - 1][j] < dp[i][j - 1])
j--;
else
i--;
}
// cout<<dp[n][m]<<"\n";
// reverse(ans.begin(),ans.end());
cout << ans;
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p03165
|
C++
|
Runtime Error
|
/*
kaafi fucked up
*/
#define SET
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#define DEBUG
#include <bits/stdc++.h>
#include <string>
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (long long i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define srt(v) sort(v.begin(), v.end())
#define rev_srt(v) sort(v.rbegin(), v.rend())
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
#ifdef SET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_multi_set;
#endif
#define nl '\n'
#define sp " "
#define precision(x) cout << fixed << setprecision(x);
#define fio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
template <typename T> void debugv(vector<T> a) {
#ifdef DEBUG
for (auto i : a) {
cout << i << sp;
}
cout << nl;
return;
#endif
return;
}
template <typename T> void debuga(T *a, int n, int beg = 0) {
#ifdef DEBUG
f(i, beg, beg + n) { cout << a[i] << sp; }
cout << nl;
return;
#endif
return;
}
void logg(string s) {
#ifdef DEBUG
cout << s << nl;
#endif
}
template <class T> inline bool remax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T> inline bool remin(T &a, T b) { return a > b ? a = b, 1 : 0; }
ll md = 1000000007;
// const ll MXSZ= (ll)5e5;
// ll fact[MXSZ];
// ll mi[MXSZ];
// ll my_gcd(ll n, ll m)
// {
// if (n % m == 0)
// return m;
// if (n < m)
// swap(n, m);
// while (m > 0)
// {
// n = n % m;
// swap(n, m);
// }
// return n;
// }
ll pw(ll a, ll b) {
ll c = 1, m = a % md;
while (b) {
if (b & 1)
c = (c * m) % md;
m = (m * m) % md;
b /= 2;
}
return c;
}
ll modinv(ll n) { return pw(n, md - 2); }
inline ll add(ll a, ll b) { return (md + a % md + b % md) % md; }
inline ll subt(ll a, ll b) { return (a % md - b % md + md) % md; }
inline ll mult(ll a, ll b) { return (1ll * (a % md) * (b % md)) % md; }
// ll ncr(int n, int r)
// {
// if (!n)
// return 1;
// return mult(fact[n], mult(mi[r], mi[n - r]));
// }
// void pre()
// {
// fact[0] = 1;
// ll lim = MXSZ;
// f(i, 1, lim) fact[i] = mult(i, fact[i - 1]);
// f(i, 0, lim) mi[i] = modinv(fact[i]);
// // f(i, 0, 10) cout << mi[i] << sp;
// // cout << nl;
// }
template <class T> T myceil(T a, T b) {
if (a % b)
return (a / b) + 1;
else
return a / b;
};
const ll MX = 1e3 + 5;
ll dp[MX][MX];
ll btr[MX][MX][2];
ll fl[MX][MX];
ll last[MX];
void solvetestcase(ll tcn) {
string s, t;
cin >> s;
cin >> t;
ll n = s.size();
ll m = t.size();
f(i, 1, n + 1) f(j, 1, m + 1) {
dp[i][j] = max({dp[i][j - 1], dp[i - 1][j],
dp[i - 1][j - 1] + (s[i - 1] == t[j - 1])});
if (dp[i][j] == dp[i - 1][j - 1] + (s[i - 1] == t[j - 1])) {
btr[i][j][0] = i - 1;
btr[i][j][1] = j - 1;
fl[i][j] = (s[i - 1] == t[j - 1]);
} else if (dp[i][j] == dp[i][j - 1]) {
btr[i][j][0] = i;
btr[i][j][1] = j - 1;
} else {
btr[i][j][0] = i - 1;
btr[i][j][1] = j;
}
}
if (!dp[n][m]) {
cout << "\n";
return;
}
string ans;
int x = n;
int y = m;
// cout<<dp[n][m]<<nl;
while (x > 0 && y > 0) {
if (fl[x][y])
ans.pb(s[x - 1]);
ll xx = x;
x = btr[x][y][0];
y = btr[xx][y][1];
}
reverse(all(ans));
cout << ans << nl;
}
int main() {
fio;
int t = 1;
// cin >> t;
// pre();
f(i, 1, t + 1) {
// cout << "Case #" << i << ": ";
solvetestcase(i);
// cout << nl;
}
return 0;
};
|
/*
kaafi fucked up
*/
#define SET
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#define DEBUG
#include <bits/stdc++.h>
#include <string>
#define pb push_back
#define mp make_pair
#define f(i, a, b) for (long long i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define srt(v) sort(v.begin(), v.end())
#define rev_srt(v) sort(v.rbegin(), v.rend())
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
#ifdef SET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_multi_set;
#endif
#define nl '\n'
#define sp " "
#define precision(x) cout << fixed << setprecision(x);
#define fio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
template <typename T> void debugv(vector<T> a) {
#ifdef DEBUG
for (auto i : a) {
cout << i << sp;
}
cout << nl;
return;
#endif
return;
}
template <typename T> void debuga(T *a, int n, int beg = 0) {
#ifdef DEBUG
f(i, beg, beg + n) { cout << a[i] << sp; }
cout << nl;
return;
#endif
return;
}
void logg(string s) {
#ifdef DEBUG
cout << s << nl;
#endif
}
template <class T> inline bool remax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <class T> inline bool remin(T &a, T b) { return a > b ? a = b, 1 : 0; }
ll md = 1000000007;
// const ll MXSZ= (ll)5e5;
// ll fact[MXSZ];
// ll mi[MXSZ];
// ll my_gcd(ll n, ll m)
// {
// if (n % m == 0)
// return m;
// if (n < m)
// swap(n, m);
// while (m > 0)
// {
// n = n % m;
// swap(n, m);
// }
// return n;
// }
ll pw(ll a, ll b) {
ll c = 1, m = a % md;
while (b) {
if (b & 1)
c = (c * m) % md;
m = (m * m) % md;
b /= 2;
}
return c;
}
ll modinv(ll n) { return pw(n, md - 2); }
inline ll add(ll a, ll b) { return (md + a % md + b % md) % md; }
inline ll subt(ll a, ll b) { return (a % md - b % md + md) % md; }
inline ll mult(ll a, ll b) { return (1ll * (a % md) * (b % md)) % md; }
// ll ncr(int n, int r)
// {
// if (!n)
// return 1;
// return mult(fact[n], mult(mi[r], mi[n - r]));
// }
// void pre()
// {
// fact[0] = 1;
// ll lim = MXSZ;
// f(i, 1, lim) fact[i] = mult(i, fact[i - 1]);
// f(i, 0, lim) mi[i] = modinv(fact[i]);
// // f(i, 0, 10) cout << mi[i] << sp;
// // cout << nl;
// }
template <class T> T myceil(T a, T b) {
if (a % b)
return (a / b) + 1;
else
return a / b;
};
const ll MX = 3e3 + 5;
ll dp[MX][MX];
ll btr[MX][MX][2];
ll fl[MX][MX];
ll last[MX];
void solvetestcase(ll tcn) {
string s, t;
cin >> s;
cin >> t;
ll n = s.size();
ll m = t.size();
f(i, 1, n + 1) f(j, 1, m + 1) {
dp[i][j] = max({dp[i][j - 1], dp[i - 1][j],
dp[i - 1][j - 1] + (s[i - 1] == t[j - 1])});
if (dp[i][j] == dp[i - 1][j - 1] + (s[i - 1] == t[j - 1])) {
btr[i][j][0] = i - 1;
btr[i][j][1] = j - 1;
fl[i][j] = (s[i - 1] == t[j - 1]);
} else if (dp[i][j] == dp[i][j - 1]) {
btr[i][j][0] = i;
btr[i][j][1] = j - 1;
} else {
btr[i][j][0] = i - 1;
btr[i][j][1] = j;
}
}
if (!dp[n][m]) {
cout << "\n";
return;
}
string ans;
int x = n;
int y = m;
// cout<<dp[n][m]<<nl;
while (x > 0 && y > 0) {
if (fl[x][y])
ans.pb(s[x - 1]);
ll xx = x;
x = btr[x][y][0];
y = btr[xx][y][1];
}
reverse(all(ans));
cout << ans << nl;
}
int main() {
fio;
int t = 1;
// cin >> t;
// pre();
f(i, 1, t + 1) {
// cout << "Case #" << i << ": ";
solvetestcase(i);
// cout << nl;
}
return 0;
};
|
replace
| 146 | 147 | 146 | 147 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str = "";
string a, b;
cin >> a >> b;
int sa = a.length();
int sb = b.length();
int dp[sb + 1][sa + 1];
for (int i = 0; i < sa + 1; i++)
dp[0][i] = 0;
for (int i = 0; i < sb + 1; i++)
dp[i][0] = 0;
for (int i = 1; i < sb + 1; i++)
for (int j = 1; j < sa + 1; j++) {
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]);
}
int i = sb;
int j = sa;
while (i || j) {
if (a[j - 1] == b[i - 1]) {
str += a[j - 1];
i--;
j--;
continue;
}
if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(str.begin(), str.end());
cout << str;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str = "";
string a, b;
cin >> a >> b;
int sa = a.length();
int sb = b.length();
int dp[sb + 1][sa + 1];
for (int i = 0; i < sa + 1; i++)
dp[0][i] = 0;
for (int i = 0; i < sb + 1; i++)
dp[i][0] = 0;
for (int i = 1; i < sb + 1; i++)
for (int j = 1; j < sa + 1; j++) {
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]);
}
int i = sb;
int j = sa;
while (i > 0 && j > 0) {
if (a[j - 1] == b[i - 1]) {
str += a[j - 1];
i--;
j--;
continue;
}
if (dp[i - 1][j] > dp[i][j - 1])
i--;
else
j--;
}
reverse(str.begin(), str.end());
cout << str;
}
|
replace
| 23 | 24 | 23 | 24 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int dp[3001][3001];
int main() {
char s[3001], s1[3001];
cin >> s >> s1;
int len = strlen(s), len1 = strlen(s1);
for (int i = 1; i <= len; i++) {
for (int j = 1; j <= len1; j++) {
if (s[i - 1] == s1[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
vector<char> s2;
int i = len, j = len1;
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 {
s2.push_back(s[i - 1]);
i--, j--;
}
}
reverse(s2.begin(), s2.end());
for (char c : s2)
cout << c;
}
|
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int dp[3001][3001];
int main() {
char s[3001], s1[3001];
cin >> s >> s1;
int len = strlen(s), len1 = strlen(s1);
for (int i = 1; i <= len; i++) {
for (int j = 1; j <= len1; j++) {
if (s[i - 1] == s1[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
vector<char> s2;
int i = len, j = len1;
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 {
s2.push_back(s[i - 1]);
i--, j--;
}
}
reverse(s2.begin(), s2.end());
for (char c : s2)
cout << c;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string a, b, s = "";
int arr[3001][3001], alen, blen;
void dp(string a, string b) {
alen = a.length(), blen = b.length();
for (int i = 0; i <= blen; i++) {
for (int j = 0; j <= alen; j++) {
int k = i - 1, l = j - 1;
if (i == 0 || j == 0)
arr[i][j] = 0;
else {
if (a[l] == b[k]) {
arr[i][j] = 1 + arr[i - 1][j - 1];
} else
arr[i][j] += max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int curmax = arr[blen][alen];
for (int i = blen; i > 0; i--) {
for (int j = alen; j > 0; j--) {
if (arr[i][j] == curmax && arr[i][j] > arr[i - 1][j] &&
arr[i][j] > arr[i][j - 1]) {
s = a[j - 1] + s;
curmax -= 1;
if (j != 1)
i -= 1;
}
}
}
}
int main() {
cin >> a >> b;
dp(a, b);
cout << s;
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b, s = "";
int arr[3001][3001], alen, blen;
void dp(string a, string b) {
alen = a.length(), blen = b.length();
for (int i = 0; i <= blen; i++) {
for (int j = 0; j <= alen; j++) {
int k = i - 1, l = j - 1;
if (i == 0 || j == 0)
arr[i][j] = 0;
else {
if (a[l] == b[k]) {
arr[i][j] = 1 + arr[i - 1][j - 1];
} else
arr[i][j] += max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int curmax = arr[blen][alen];
int i = blen, j = alen;
while (i > 0 && j > 0) {
if (arr[i][j] == curmax && arr[i][j] > arr[i - 1][j] &&
arr[i][j] > arr[i][j - 1]) {
s = a[j - 1] + s;
curmax -= 1;
i -= 1;
j -= 1;
} else if (arr[i - 1][j] > arr[i][j - 1])
i -= 1;
else
j -= 1;
}
}
int main() {
cin >> a >> b;
dp(a, b);
cout << s;
}
|
replace
| 22 | 33 | 22 | 34 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string a, b;
cin >> a;
cin >> b;
a = ' ' + a;
b = ' ' + b;
int A = a.length();
int B = b.length();
int dp[A][B];
for (int i = 0; i < A; i++) {
for (int j = 0; j < B; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
} else if (a[i] == b[j]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = A - 1, j = B - 1;
string ans = "";
while (i > 0 || j > 0) {
if (a[i] == b[j]) {
ans = a[i] + ans;
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string a, b;
cin >> a;
cin >> b;
a = ' ' + a;
b = ' ' + b;
int A = a.length();
int B = b.length();
int dp[A][B];
for (int i = 0; i < A; i++) {
for (int j = 0; j < B; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
} else if (a[i] == b[j]) {
dp[i][j] = 1 + dp[i - 1][j - 1];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = A - 1, j = B - 1;
string ans = "";
while (i > 0 && j > 0) {
if (a[i] == b[j]) {
ans = a[i] + ans;
i--;
j--;
} else if (dp[i - 1][j] > dp[i][j - 1]) {
i--;
} else {
j--;
}
}
cout << ans;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
static int t[2001][2001];
void nhap() { cin >> s1 >> s2; }
void qhd() {
for (int i = 1; i <= (int)s1.length(); i++)
for (int j = 1; j <= (int)s2.length(); j++)
if (s1[i - 1] == s2[j - 1])
t[i][j] = t[i - 1][j - 1] + 1;
else
t[i][j] = max(t[i][j - 1], t[i - 1][j]);
int i = (int)s1.length();
int j = (int)s2.length();
string res = "";
while (i != 0 && j != 0) {
if (s1[i - 1] == s2[j - 1]) {
res = s1[i - 1] + res;
i--;
j--;
} else if (t[i][j] == t[i - 1][j])
i--;
else
j--;
}
cout << res;
}
int main() {
nhap();
qhd();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
static int t[3005][3005];
void nhap() { cin >> s1 >> s2; }
void qhd() {
for (int i = 1; i <= (int)s1.length(); i++)
for (int j = 1; j <= (int)s2.length(); j++)
if (s1[i - 1] == s2[j - 1])
t[i][j] = t[i - 1][j - 1] + 1;
else
t[i][j] = max(t[i][j - 1], t[i - 1][j]);
int i = (int)s1.length();
int j = (int)s2.length();
string res = "";
while (i != 0 && j != 0) {
if (s1[i - 1] == s2[j - 1]) {
res = s1[i - 1] + res;
i--;
j--;
} else if (t[i][j] == t[i - 1][j])
i--;
else
j--;
}
cout << res;
}
int main() {
nhap();
qhd();
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;
int dp[3000 + 1][3000 + 1];
int main() {
string s, t, ans;
cin >> s >> t;
fill(dp[0], dp[3000 + 1], 0);
for (int i = 0; i < s.size(); ++i) {
int foo = 0;
for (int j = 0; j < t.size(); ++j) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
if (dp[i][j + 1] > dp[i + 1][j]) {
dp[i + 1][j + 1] = dp[i][j + 1];
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
}
}
}
}
int sl = s.size();
int tl = t.size();
int l = dp[sl][tl];
while (l > -1) {
if (s[sl - 1] == t[tl - 1]) {
ans.push_back(s[sl - 1]);
sl--;
tl--;
l--;
} else if (dp[sl][tl] == dp[sl - 1][tl]) {
sl--;
} else {
tl--;
}
}
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;
int dp[3000 + 1][3000 + 1];
int main() {
string s, t, ans;
cin >> s >> t;
fill(dp[0], dp[3000 + 1], 0);
for (int i = 0; i < s.size(); ++i) {
int foo = 0;
for (int j = 0; j < t.size(); ++j) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
if (dp[i][j + 1] > dp[i + 1][j]) {
dp[i + 1][j + 1] = dp[i][j + 1];
} else {
dp[i + 1][j + 1] = dp[i + 1][j];
}
}
}
}
int sl = s.size();
int tl = t.size();
int l = dp[sl][tl];
while (l > 0) {
if (s[sl - 1] == t[tl - 1]) {
ans.push_back(s[sl - 1]);
sl--;
tl--;
l--;
} else if (dp[sl][tl] == dp[sl - 1][tl]) {
sl--;
} else {
tl--;
}
}
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
|
replace
| 34 | 35 | 34 | 35 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second
#define MOD 1000000007
#define pb push_back
#define test cout << "debuged\n";
#define INF 10000000000
#define si 1000000
#define debug(x) cout << x << "\n";
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output", "w", stdout);
#endif
string s, d;
cin >> s >> d;
ll n = s.size(), m = d.size();
ll dp[n + 10][m + 10];
vector<char> ans;
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= m; j++)
dp[i][j] = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (s[i - 1] == d[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, j = m;
while (j > 0 and i > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
ans.pb(s[i - 1]);
i--;
j--;
}
}
reverse(ans.begin(), ans.end());
for (auto x : ans)
cout << x;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second
#define MOD 1000000007
#define pb push_back
#define test cout << "debuged\n";
#define INF 10000000000
#define si 1000000
#define debug(x) cout << x << "\n";
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s, d;
cin >> s >> d;
ll n = s.size(), m = d.size();
ll dp[n + 10][m + 10];
vector<char> ans;
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= m; j++)
dp[i][j] = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (s[i - 1] == d[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, j = m;
while (j > 0 and i > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
ans.pb(s[i - 1]);
i--;
j--;
}
}
reverse(ans.begin(), ans.end());
for (auto x : ans)
cout << x;
}
|
replace
| 15 | 19 | 15 | 16 |
0
| |
p03165
|
C++
|
Runtime Error
|
//============================================================================
// Name : f
// Date : Wed Feb 20 10:59:11 CST 2019
// Author : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) \
{ \
cout << x[a]; \
if (a < n - 1) \
cout << " "; \
}
#define pvi(x, v) \
if (v) \
pvar(x); \
fora(a, x) cout << a << " "; \
cout << "\n"
#define par(x, s, n, v) \
if (v) \
pvar(x); \
fori(y, s, n) prt(x, y, n) cout << "\n"
#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <class T> void amax(T &a, T b) { a = max(a, b); }
void solve() {
string ss, tt;
cin >> ss >> tt;
int a = sz(ss), b = sz(tt);
using pip = pair<int, pii>;
vector<vector<pip>> dp(a + 1, vector<pip>(b + 1, {0, {0, 0}}));
fori(i, 0, a) {
fori(j, 0, b) {
amax(dp[i + 1][j + 1],
{dp[i][j].first + (ss[i] == tt[j] ? 1 : 0), {i, j}});
amax(dp[i + 1][j], {dp[i][j].first, {i, j}});
amax(dp[i][j + 1], {dp[i][j].first, {i, j}});
}
}
pip mx = {0, {0, 0}};
fori(i, 0, a + 1) {
fori(j, 0, b + 1) { amax(mx, {dp[i][j].first, {i, j}}); }
}
pii cur = mx.second;
string ret;
while (mx.first && !(cur.first == 0 || cur.second == 0)) {
int i = cur.first, j = cur.second;
pii pre = dp[i][j].second;
if (pre == pii(i - 1, j - 1)) {
assert(ss[i - 1] == tt[j - 1]);
ret = ss[i - 1] + ret;
}
cur = pre;
}
output(ret);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
|
//============================================================================
// Name : f
// Date : Wed Feb 20 10:59:11 CST 2019
// Author : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) \
{ \
cout << x[a]; \
if (a < n - 1) \
cout << " "; \
}
#define pvi(x, v) \
if (v) \
pvar(x); \
fora(a, x) cout << a << " "; \
cout << "\n"
#define par(x, s, n, v) \
if (v) \
pvar(x); \
fori(y, s, n) prt(x, y, n) cout << "\n"
#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <class T> void amax(T &a, T b) { a = max(a, b); }
void solve() {
string ss, tt;
cin >> ss >> tt;
int a = sz(ss), b = sz(tt);
using pip = pair<int, pii>;
vector<vector<pip>> dp(a + 1, vector<pip>(b + 1, {0, {0, 0}}));
fori(i, 0, a) {
fori(j, 0, b) {
amax(dp[i + 1][j + 1],
{dp[i][j].first + (ss[i] == tt[j] ? 1 : 0), {i, j}});
amax(dp[i + 1][j], {dp[i][j].first, {i, j}});
amax(dp[i][j + 1], {dp[i][j].first, {i, j}});
}
}
pip mx = {0, {0, 0}};
fori(i, 0, a + 1) {
fori(j, 0, b + 1) { amax(mx, {dp[i][j].first, {i, j}}); }
}
pii cur = mx.second;
string ret;
while (mx.first && !(cur.first == 0 || cur.second == 0)) {
int i = cur.first, j = cur.second;
pii pre = dp[i][j].second;
if (pre == pii(i - 1, j - 1)) {
if (ss[i - 1] == tt[j - 1]) {
ret = ss[i - 1] + ret;
}
}
cur = pre;
}
output(ret);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
|
replace
| 74 | 76 | 74 | 77 |
0
| |
p03165
|
C++
|
Time Limit Exceeded
|
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define ll 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 mp make_pair
#define all(a) (a).begin(), (a).end()
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define endl '\n'
// #define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
// mp::cpp_int
#define pp pair<pii, pii>
const int hell = 1000000007;
int power(int a, int b) {
if (b == 0)
return 1;
if (b == 1)
return a;
int t = power(a, b / 2);
t %= hell;
t *= t;
t %= hell;
if (b % 2)
return (t * a) % hell;
else
return t;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b - a % b, a % b);
}
int digitsum(int x) {
while (x > 9) {
int ans = 0;
while (x != 0) {
ans += x % 10;
x /= 10;
}
x = ans;
}
return x;
}
int pw(int a, int b) {
int x = a;
rep(i, 1, b) { a = a * x; }
return a;
}
int lcs[3001][3001];
string a, b;
int LCS(int n, int m) {
if (n == 0 || m == 0)
return 0;
if (lcs[n][m])
return lcs[n][m];
int t;
if (a[n - 1] == b[m - 1]) {
t = LCS(n - 1, m - 1) + 1;
} else
t = max(LCS(n - 1, m), LCS(n, m - 1));
lcs[n][m] = t;
return t;
}
int solve() {
cin >> a >> b;
int n = a.size();
int m = b.size();
memset(lcs, 0, sizeof(lcs));
LCS(n, m);
int i = n, j = m;
string ans = "";
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
ans += a[i - 1]; // cout<<a[i-1]<<endl;
i--;
j--;
continue;
}
if (lcs[i - 1][j] > lcs[i][j - 1]) {
i--;
} else
j--;
}
reverse(all(ans));
cout << ans;
return 0;
}
signed main() {
int t = 1;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
clock_t time_req;
// Without using pow function
time_req = clock();
// cin>>t;
int k = 1;
while (t--) {
// cout<<"case #"<<k<<":"<<" ";k++;
solve();
}
time_req = clock() - time_req;
// cout <<endl<< "Processor time taken is "
//<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define ll 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 mp make_pair
#define all(a) (a).begin(), (a).end()
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define endl '\n'
// #define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
// mp::cpp_int
#define pp pair<pii, pii>
const int hell = 1000000007;
int power(int a, int b) {
if (b == 0)
return 1;
if (b == 1)
return a;
int t = power(a, b / 2);
t %= hell;
t *= t;
t %= hell;
if (b % 2)
return (t * a) % hell;
else
return t;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b - a % b, a % b);
}
int digitsum(int x) {
while (x > 9) {
int ans = 0;
while (x != 0) {
ans += x % 10;
x /= 10;
}
x = ans;
}
return x;
}
int pw(int a, int b) {
int x = a;
rep(i, 1, b) { a = a * x; }
return a;
}
int lcs[3001][3001];
string a, b;
int LCS(int n, int m) {
if (n == 0 || m == 0)
return 0;
if (lcs[n][m])
return lcs[n][m];
int t;
if (a[n - 1] == b[m - 1]) {
t = LCS(n - 1, m - 1) + 1;
} else
t = max(LCS(n - 1, m), LCS(n, m - 1));
lcs[n][m] = t;
return t;
}
int solve() {
cin >> a >> b;
int n = a.size();
int m = b.size();
memset(lcs, 0, sizeof(lcs));
lcs[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i - 1] == b[j - 1]) {
lcs[i][j] = 1 + lcs[i - 1][j - 1];
} else {
lcs[i][j] = max(lcs[i][j - 1], lcs[i - 1][j]);
}
}
}
int i = n, j = m;
string ans = "";
while (i > 0 && j > 0) {
if (a[i - 1] == b[j - 1]) {
ans += a[i - 1]; // cout<<a[i-1]<<endl;
i--;
j--;
continue;
}
if (lcs[i - 1][j] > lcs[i][j - 1]) {
i--;
} else
j--;
}
reverse(all(ans));
cout << ans;
return 0;
}
signed main() {
int t = 1;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
clock_t time_req;
// Without using pow function
time_req = clock();
// cin>>t;
int k = 1;
while (t--) {
// cout<<"case #"<<k<<":"<<" ";k++;
solve();
}
time_req = clock() - time_req;
// cout <<endl<< "Processor time taken is "
//<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}
|
replace
| 125 | 126 | 125 | 136 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define INF (ll)1e9 + 7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t, res = "";
cin >> s >> t;
int T = t.size(), S = s.size();
int dp[301][301] = {};
rep(i, S) {
rep(j, T) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]);
}
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j + 1]);
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i + 1][j + 1]);
}
}
while (S > 0 && T > 0) {
if (dp[S][T] == dp[S - 1][T])
S--;
else if (dp[S][T] == dp[S][T - 1])
T--;
else {
res = s[S - 1] + res;
T--;
S--;
}
}
cout << res << endl;
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define INF (ll)1e9 + 7
#define LLINF (ll)1e30
// #define int ll
using namespace std;
const int MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t, res = "";
cin >> s >> t;
int T = t.size(), S = s.size();
int dp[3010][3010] = {};
rep(i, S) {
rep(j, T) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]);
}
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j + 1]);
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i + 1][j + 1]);
}
}
while (S > 0 && T > 0) {
if (dp[S][T] == dp[S - 1][T])
S--;
else if (dp[S][T] == dp[S][T - 1])
T--;
else {
res = s[S - 1] + res;
T--;
S--;
}
}
cout << res << endl;
return 0;
}
|
replace
| 37 | 38 | 37 | 38 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[1002][1002];
string sa, sb;
int rec(int a, int b) {
if (a == sa.size() or b == sb.size())
return 0;
if (dp[a][b] != -1)
return dp[a][b];
// dp[a][b]=0;
if (sa[a] == sb[b]) {
dp[a][b] = rec(a + 1, b + 1) + 1;
} else
dp[a][b] = max(rec(a + 1, b), rec(a, b + 1));
return dp[a][b];
}
void recons(int a, int b) {
if (a == sa.size() or b == sb.size())
return;
else if (dp[a][b] == rec(a + 1, b + 1) + 1 and sa[a] == sb[b]) {
cout << sb[b];
recons(a + 1, b + 1);
} else {
if (dp[a][b] == rec(a + 1, b))
recons(a + 1, b);
else if (dp[a][b] == rec(a, b + 1))
recons(a, b + 1);
}
}
int main() {
// freopen("entra.in","r",stdin);
// freopen("sale.out","w",stdout);
// cin>>sa>>sb;
while (getline(cin, sa)) {
getline(cin, sb);
memset(dp, -1, sizeof dp);
rec(0, 0);
recons(0, 0);
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[3003][3003];
string sa, sb;
int rec(int a, int b) {
if (a == sa.size() or b == sb.size())
return 0;
if (dp[a][b] != -1)
return dp[a][b];
// dp[a][b]=0;
if (sa[a] == sb[b]) {
dp[a][b] = rec(a + 1, b + 1) + 1;
} else
dp[a][b] = max(rec(a + 1, b), rec(a, b + 1));
return dp[a][b];
}
void recons(int a, int b) {
if (a == sa.size() or b == sb.size())
return;
else if (dp[a][b] == rec(a + 1, b + 1) + 1 and sa[a] == sb[b]) {
cout << sb[b];
recons(a + 1, b + 1);
} else {
if (dp[a][b] == rec(a + 1, b))
recons(a + 1, b);
else if (dp[a][b] == rec(a, b + 1))
recons(a, b + 1);
}
}
int main() {
// freopen("entra.in","r",stdin);
// freopen("sale.out","w",stdout);
// cin>>sa>>sb;
while (getline(cin, sa)) {
getline(cin, sb);
memset(dp, -1, sizeof dp);
rec(0, 0);
recons(0, 0);
cout << "\n";
}
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
int N;
string s, t;
int DP[3002][3002]; // sのi文字目までとtのj文字目まで探索し、その最大共通個数
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s >> t;
rep(i, s.size()) {
rep(j, t.size()) {
if (s[i] == t[j]) {
DP[i + 1][j + 1] = max(DP[i][j] + 1, DP[i + 1][j + 1]);
}
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]);
}
}
string ans = "";
int i = s.size();
int j = t.size();
while (i > 1 && j > 1) {
if (DP[i][j] == DP[i - 1][j])
i--;
if (DP[i][j] == DP[i][j - 1])
j--;
if (DP[i][j] == DP[i - 1][j - 1]) {
ans = ans[i - 1] + ans;
i--;
j--;
}
}
cout << ans << "\n";
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
int N;
string s, t;
int DP[3002][3002]; // sのi文字目までとtのj文字目まで探索し、その最大共通個数
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s >> t;
rep(i, s.size()) {
rep(j, t.size()) {
if (s[i] == t[j]) {
DP[i + 1][j + 1] = max(DP[i][j] + 1, DP[i + 1][j + 1]);
}
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]);
}
}
string ans = "";
int s_idx = (int)s.size();
int t_idx = (int)t.size();
while (s_idx > 0 && t_idx > 0) {
if (DP[s_idx][t_idx] == DP[s_idx - 1][t_idx])
s_idx--;
else if (DP[s_idx][t_idx] == DP[s_idx][t_idx - 1])
t_idx--;
else {
ans = s[s_idx - 1] + ans;
s_idx--;
t_idx--;
}
}
cout << ans << "\n";
return 0;
}
|
replace
| 36 | 47 | 36 | 47 |
TLE
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[1009][1009];
int solve(int idx1, int idx2) {
if (idx1 >= a.length() || idx2 >= b.length())
return 0;
if (dp[idx1][idx2] != -1)
return dp[idx1][idx2];
if (a[idx1] == b[idx2]) {
dp[idx1][idx2] = solve(idx1 + 1, idx2 + 1) + 1;
} else {
dp[idx1][idx2] = max(solve(idx1 + 1, idx2), solve(idx1, idx2 + 1));
}
return dp[idx1][idx2];
}
void build(int idx1, int idx2) {
if (idx1 >= a.length() || idx2 >= b.length())
return;
if (a[idx1] == b[idx2]) {
cout << a[idx1];
idx1++;
idx2++;
} else if (dp[idx1][idx2] == solve(idx1 + 1, idx2)) {
idx1++;
} else if (dp[idx1][idx2] == solve(idx1, idx2 + 1)) {
idx2++;
}
build(idx1, idx2);
return;
}
int main() {
memset(dp, -1, sizeof(dp));
cin >> a >> b;
solve(0, 0);
build(0, 0);
}
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[3009][3009];
int solve(int idx1, int idx2) {
if (idx1 >= a.length() || idx2 >= b.length())
return 0;
if (dp[idx1][idx2] != -1)
return dp[idx1][idx2];
if (a[idx1] == b[idx2]) {
dp[idx1][idx2] = solve(idx1 + 1, idx2 + 1) + 1;
} else {
dp[idx1][idx2] = max(solve(idx1 + 1, idx2), solve(idx1, idx2 + 1));
}
return dp[idx1][idx2];
}
void build(int idx1, int idx2) {
if (idx1 >= a.length() || idx2 >= b.length())
return;
if (a[idx1] == b[idx2]) {
cout << a[idx1];
idx1++;
idx2++;
} else if (dp[idx1][idx2] == solve(idx1 + 1, idx2)) {
idx1++;
} else if (dp[idx1][idx2] == solve(idx1, idx2 + 1)) {
idx2++;
}
build(idx1, idx2);
return;
}
int main() {
memset(dp, -1, sizeof(dp));
cin >> a >> b;
solve(0, 0);
build(0, 0);
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03165
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ms(x, t) memset(x, t, sizeof(x))
typedef long long int ll;
typedef unsigned long long int ull;
const int limit = 3e3 + 1;
const int inf = 1e7;
int main() {
string s, t;
cin >> s >> t;
int sl = s.length();
int tl = t.length();
int m[sl + 1][tl + 1];
stack<char> st;
ms(m, 0);
for (int i = 1; i <= sl; i++) {
for (int j = 1; j <= tl; j++) {
if (s[i - 1] == t[j - 1]) {
m[i][j] = 1 + m[i - 1][j - 1];
} else {
m[i][j] = max(m[i][j - 1], m[i - 1][j]);
}
}
}
int i = sl;
int j = tl;
for (; i != 0 || j != 0;) {
if (m[i][j] == m[i - 1][j - 1] + 1) {
st.push(s[i - 1]);
i--;
j--;
} else if (m[i][j] == m[i - 1][j]) {
i--;
} else {
j--;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ms(x, t) memset(x, t, sizeof(x))
typedef long long int ll;
typedef unsigned long long int ull;
const int limit = 3e3 + 1;
const int inf = 1e7;
int main() {
string s, t;
cin >> s >> t;
int sl = s.length();
int tl = t.length();
int m[sl + 1][tl + 1];
stack<char> st;
ms(m, 0);
for (int i = 1; i <= sl; i++) {
for (int j = 1; j <= tl; j++) {
if (s[i - 1] == t[j - 1]) {
m[i][j] = 1 + m[i - 1][j - 1];
} else {
m[i][j] = max(m[i][j - 1], m[i - 1][j]);
}
}
}
int i = sl;
int j = tl;
for (; i != 0 && j != 0;) {
if (s[i - 1] == t[j - 1]) {
st.push(s[i - 1]);
i--;
j--;
} else if (m[i][j] == m[i - 1][j]) {
i--;
} else {
j--;
}
}
while (!st.empty()) {
cout << st.top();
st.pop();
}
cout << endl;
return 0;
}
|
replace
| 27 | 29 | 27 | 29 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.