problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9
values |
|---|---|---|---|---|---|---|---|
p03165 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"
const ll L = 3e3 + 10;
ll dp[L][L];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
for (ll i = 0; i < sz(s); i++) {
for (ll j = 0; j < sz(t); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
}
else {
dp[i + 1][j + 1] =
max(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
}
}
}
ll cx = sz(s);
ll cy = sz(t);
string res = "";
while (cx && cy) {
if (dp[cx][cy] == dp[cx - 1][cy]) {
cx--;
}
if (dp[cx][cy] == dp[cx][cy - 1]) {
cy--;
}
else {
cx--;
cy--;
res = s[cx] + res;
}
}
// reverse(all(res));
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"
const ll L = 3e3 + 10;
ll dp[L][L];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
for (ll i = 0; i < sz(s); i++) {
for (ll j = 0; j < sz(t); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
}
else {
dp[i + 1][j + 1] =
max(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
}
}
}
ll cx = sz(s);
ll cy = sz(t);
string res = "";
while (cx && cy) {
if (dp[cx][cy] == dp[cx - 1][cy]) {
cx--;
}
else if (dp[cx][cy] == dp[cx][cy - 1]) {
cy--;
}
else {
cx--;
cy--;
res = s[cx] + res;
}
}
cout << res << endl;
return 0;
} | [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 972,981 | 972,980 | u616547520 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"
const ll L = 3e3 + 5;
ll dp[L][L];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
for (ll i = 0; i < sz(s); i++) {
for (ll j = 0; j < sz(t); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
}
else {
dp[i + 1][j + 1] =
max(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
}
}
}
ll cx = sz(s);
ll cy = sz(t);
string res = "";
while (cx && cy) {
if (dp[cx][cy] == dp[cx - 1][cy]) {
cx--;
}
if (dp[cx][cy] == dp[cx][cy - 1]) {
cy--;
}
else {
cx--;
cy--;
res = s[cx] + res;
}
}
// reverse(all(res));
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd __gcd
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"
const ll L = 3e3 + 10;
ll dp[L][L];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
for (ll i = 0; i < sz(s); i++) {
for (ll j = 0; j < sz(t); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
}
else {
dp[i + 1][j + 1] =
max(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
}
}
}
ll cx = sz(s);
ll cy = sz(t);
string res = "";
while (cx && cy) {
if (dp[cx][cy] == dp[cx - 1][cy]) {
cx--;
}
else if (dp[cx][cy] == dp[cx][cy - 1]) {
cy--;
}
else {
cx--;
cy--;
res = s[cx] + res;
}
}
cout << res << endl;
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change",
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 972,982 | 972,980 | u616547520 | cpp |
p03165 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;
int dp[3005][3005];
void chmax(int &a, int b) {
a = max(a, b);
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size();
int k = t.size();
s += '&';
t += '*';
rep(i, n) rep(j, k) {
chmax(dp[i + 1][j], dp[i][j]);
chmax(dp[i][j + 1], dp[i][j]);
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
}
string ans;
int i = n, j = k;
while (i + j) {
int x = dp[i][j];
if (i && dp[i - 1][j] == x) {
i--;
} else if (j && dp[i][j - 1] == x) {
j--;
} else {
i--;
j--;
ans += s[i];
}
}
reverse(all(ans));
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;
int dp[3005][3005];
void chmax(int &a, int b) {
a = max(a, b);
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size();
int k = t.size();
s += '&';
t += '*';
rep(i, n + 1) rep(j, k + 1) {
chmax(dp[i + 1][j], dp[i][j]);
chmax(dp[i][j + 1], dp[i][j]);
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
}
string ans;
int i = n, j = k;
while (i + j) {
int x = dp[i][j];
if (i && dp[i - 1][j] == x) {
i--;
} else if (j && dp[i][j - 1] == x) {
j--;
} else {
i--;
j--;
ans += s[i];
}
}
reverse(all(ans));
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 973,002 | 973,003 | u274883254 | cpp |
p03165 | #define NDEBUG
NDEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T> using vec2d = std::vector<std::vector<T>>;
template <class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
return vec2d<T>(n1, vec<T>(n2, initValue));
}
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define all(c) c.begin(), c.end()
// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END
// Section with adoption of array and vector algorithms.
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
// template <class T> using StdTree = tree<T, null_type, less<T>,
// rb_tree_tag,tree_order_statistics_node_update>;
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N> struct bytetype {};
/// caide keep
template <uint64_t N> struct minimal_uint : bytetype<bytecount(N)> {};
} // namespace template_util
template <class T> T next(istream &in) {
T ret;
in >> ret;
return ret;
}
void solve(istream &in, ostream &out) {
auto s = next<string>(in);
auto t = next<string>(in);
vec2d<int> f = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
vec2d<int> p = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
f[0][0] = 0;
FOR(i, s.length()) {
FOR(j, t.length()) {
if (f[i][j] != -1) {
if (f[i + 1][j] < f[i][j]) {
f[i + 1][j] = f[i][j];
p[i + 1][j] = 0;
}
if (f[i][j + 1] < f[i][j]) {
f[i][j + 1] = f[i][j];
p[i][j + 1] = 1;
}
if (s[i] == t[j]) {
if (f[i + 1][j + 1] < f[i][j] + 1) {
f[i + 1][j + 1] = f[i][j] + 1;
p[i + 1][j + 1] = 2;
}
}
}
}
}
int res = 0;
int bi = -1, bj = -1;
FOR(i, s.length() + 1) {
FOR(j, t.length() + 1) {
if (res < f[i][j]) {
res = f[i][j];
bi = i;
bj = j;
}
}
}
string r;
while (bi != 0 || bj != 0) {
if (p[bi][bj] == 2) {
r.push_back(s[bi - 1]);
--bi;
--bj;
} else if (p[bi][bj] == 0) {
--bi;
} else {
--bj;
}
}
reverse(all(r));
out << r << "\n";
}
//#include <fstream>
int main() {
// ifstream fin("bridges.in");
// ofstream fout("bridges.out");
solve(cin, cout);
// solve(fin, fout);
return 0;
}
| #define NDEBUG
NDEBUG
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T> using vec2d = std::vector<std::vector<T>>;
template <class T>
vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {
return vec2d<T>(n1, vec<T>(n2, initValue));
}
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define all(c) c.begin(), c.end()
// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END
// Section with adoption of array and vector algorithms.
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
// template <class T> using StdTree = tree<T, null_type, less<T>,
// rb_tree_tag,tree_order_statistics_node_update>;
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N> struct bytetype {};
/// caide keep
template <uint64_t N> struct minimal_uint : bytetype<bytecount(N)> {};
} // namespace template_util
template <class T> T next(istream &in) {
T ret;
in >> ret;
return ret;
}
void solve(istream &in, ostream &out) {
auto s = next<string>(in);
auto t = next<string>(in);
vec2d<int> f = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
vec2d<int> p = makeVec2d<int>(s.length() + 1, t.length() + 1, -1);
f[0][0] = 0;
FOR(i, s.length()) {
FOR(j, t.length()) {
if (f[i][j] != -1) {
if (f[i + 1][j] < f[i][j]) {
f[i + 1][j] = f[i][j];
p[i + 1][j] = 0;
}
if (f[i][j + 1] < f[i][j]) {
f[i][j + 1] = f[i][j];
p[i][j + 1] = 1;
}
if (s[i] == t[j]) {
if (f[i + 1][j + 1] < f[i][j] + 1) {
f[i + 1][j + 1] = f[i][j] + 1;
p[i + 1][j + 1] = 2;
}
}
}
}
}
int res = 0;
int bi = 0, bj = 0;
FOR(i, s.length() + 1) {
FOR(j, t.length() + 1) {
if (res < f[i][j]) {
res = f[i][j];
bi = i;
bj = j;
}
}
}
string r;
while (bi != 0 || bj != 0) {
if (p[bi][bj] == 2) {
r.push_back(s[bi - 1]);
--bi;
--bj;
} else if (p[bi][bj] == 0) {
--bi;
} else {
--bj;
}
}
reverse(all(r));
out << r << "\n";
}
//#include <fstream>
int main() {
// ifstream fin("bridges.in");
// ofstream fout("bridges.out");
solve(cin, cout);
// solve(fin, fout);
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 973,011 | 973,012 | u060679524 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++)
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> DP(s.size() + 1, vector<int>(t.size() + 1, 0));
REP(i, 1, s.size() + 1) {
REP(j, 1, t.size() + 1) {
if (s[i] == t[j])
DP[i][j] = max(DP[i][j], DP[i - 1][j - 1] + 1);
DP[i][j] = max(DP[i][j], DP[i][j - 1]);
DP[i][j] = max(DP[i][j], DP[i - 1][j]);
}
}
/*
REP(i, 0, s.size()+1){
REP(j, 0, t.size()+1){
cout << DP[i][j] << " ";
}
cout << endl;
}
*/
int i = s.size();
int j = t.size();
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] + ans;
i--;
j--;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for (int i = (int)(init); i < (int)(n); i++)
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> DP(s.size() + 1, vector<int>(t.size() + 1, 0));
REP(i, 1, s.size() + 1) {
REP(j, 1, t.size() + 1) {
if (s[i - 1] == t[j - 1])
DP[i][j] = max(DP[i][j], DP[i - 1][j - 1] + 1);
DP[i][j] = max(DP[i][j], DP[i][j - 1]);
DP[i][j] = max(DP[i][j], DP[i - 1][j]);
}
}
/*
REP(i, 0, s.size()+1){
REP(j, 0, t.size()+1){
cout << DP[i][j] << " ";
}
cout << endl;
}
*/
int i = s.size();
int j = t.size();
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] + ans;
i--;
j--;
}
}
cout << ans << endl;
} | [
"control_flow.branch.if.condition.change"
] | 973,106 | 973,107 | u559424030 | cpp |
p03165 | #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvb vector<vb>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pb push_back
#define sz(s) (int)(s.size())
#define mp make_pair
#define all(a) (a).begin(), (a).end()
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;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll keta(ll n) {
string s = to_string(n);
ll num = s.size();
return num;
}
const ll INF = 1LL << 60;
const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};
struct Edge {
int to;
int weight;
Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
class UnionFind {
public:
vi Parent, diff_weight;
UnionFind(int n) {
Parent = vi(n, -1);
diff_weight = vi(n, 0);
}
int root(int a) {
if (Parent[a] < 0)
return a;
int r = root(Parent[a]);
diff_weight[a] += diff_weight[Parent[a]];
return Parent[a] = r;
}
int weight(int a) {
root(a);
return diff_weight[a];
}
bool issame(int a, int b) { return root(a) == root(b); }
int size(int a) { return -Parent[root(a)]; }
// weight(b) - weight(a) = w となるように繋ぐ
// 数直線上で a........b となっていてその距離が w 、のようなイメージ
bool merge(int a, int b, int w = 0) {
w += weight(a);
w -= weight(b);
a = root(a);
b = root(b);
if (a == b)
return false;
if (size(a) < size(b))
swap(a, b), w = -w;
Parent[a] += Parent[b];
Parent[b] = a;
diff_weight[b] = w;
return true;
}
int diff(int a, int b) { return weight(b) - weight(a); }
};
vi MP(string s) {
vi A(s.size() + 1);
A[0] = -1;
int j = -1;
rep(i, s.size()) {
while (j >= 0 && s[i] != s[j])
j = A[j];
j++;
A[i + 1] = j;
}
return A;
}
vi Manacher(string s) {
vi R(s.size());
int i = 0, j = 0;
while (i < s.size()) {
while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && i + k < s.size() && k + R[i - k] < j)
R[i + k] = R[i - k], k++;
i += k;
j -= k;
}
return R;
}
vi Z_algorithm(string &s) {
vi Z(s.size());
Z[0] = s.size();
int i = 1, j = 0;
while (i < s.size()) {
while (i + j < s.size() && s[j] == s[i + j])
j++;
Z[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.size() && k + Z[k] < j)
Z[i + k] = Z[k], ++k;
i += k;
j -= k;
}
return Z;
}
const int MAX = 1e6 + 1;
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(ll n, ll k) {
if (n >= MAX) {
ll tmp = 1;
rep(i, k) {
tmp *= (n - i);
tmp %= MOD;
}
return tmp * finv[k] % MOD;
}
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll POW(ll x, ll n) {
ll ret = 1;
if (n < 0) { // n < 0 にも対応
n *= -1;
x = inv[x];
}
while (0 < n) {
if (n % 2 == 0) {
x = x * x % MOD;
n /= 2;
} else {
ret = ret * x % MOD;
n--;
}
}
return ret;
}
int dp[3010][3010];
int main() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
rep(i, n) rep(j, m) {
// dp[i][j] を dp[i+1][j], dp[i][j+1], dp[i+1][j+1] に配る
// printf("i:%d j:%d dp[i][j]:%d\n", i, j, dp[i][j]);
chmax(dp[i + 1][j], dp[i][j]);
chmax(dp[i][j + 1], dp[i][j]);
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
else
chmax(dp[i + 1][j + 1], dp[i][j]);
}
// rep(i,n+1) rep(j,m+1) {
// if(j < m) printf("%d ", dp[i][j]);
// else printf("%d\n", dp[i][j]);
// }
string ans;
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 {
i--;
j--;
ans = s[i] + ans;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define vvb vector<vb>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pb push_back
#define sz(s) (int)(s.size())
#define mp make_pair
#define all(a) (a).begin(), (a).end()
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;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll keta(ll n) {
string s = to_string(n);
ll num = s.size();
return num;
}
const ll INF = 1LL << 60;
const int dh[4] = {1, 0, -1, 0};
const int dw[4] = {0, 1, 0, -1};
struct Edge {
int to;
int weight;
Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;
class UnionFind {
public:
vi Parent, diff_weight;
UnionFind(int n) {
Parent = vi(n, -1);
diff_weight = vi(n, 0);
}
int root(int a) {
if (Parent[a] < 0)
return a;
int r = root(Parent[a]);
diff_weight[a] += diff_weight[Parent[a]];
return Parent[a] = r;
}
int weight(int a) {
root(a);
return diff_weight[a];
}
bool issame(int a, int b) { return root(a) == root(b); }
int size(int a) { return -Parent[root(a)]; }
// weight(b) - weight(a) = w となるように繋ぐ
// 数直線上で a........b となっていてその距離が w 、のようなイメージ
bool merge(int a, int b, int w = 0) {
w += weight(a);
w -= weight(b);
a = root(a);
b = root(b);
if (a == b)
return false;
if (size(a) < size(b))
swap(a, b), w = -w;
Parent[a] += Parent[b];
Parent[b] = a;
diff_weight[b] = w;
return true;
}
int diff(int a, int b) { return weight(b) - weight(a); }
};
vi MP(string s) {
vi A(s.size() + 1);
A[0] = -1;
int j = -1;
rep(i, s.size()) {
while (j >= 0 && s[i] != s[j])
j = A[j];
j++;
A[i + 1] = j;
}
return A;
}
vi Manacher(string s) {
vi R(s.size());
int i = 0, j = 0;
while (i < s.size()) {
while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j])
++j;
R[i] = j;
int k = 1;
while (i - k >= 0 && i + k < s.size() && k + R[i - k] < j)
R[i + k] = R[i - k], k++;
i += k;
j -= k;
}
return R;
}
vi Z_algorithm(string &s) {
vi Z(s.size());
Z[0] = s.size();
int i = 1, j = 0;
while (i < s.size()) {
while (i + j < s.size() && s[j] == s[i + j])
j++;
Z[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.size() && k + Z[k] < j)
Z[i + k] = Z[k], ++k;
i += k;
j -= k;
}
return Z;
}
const int MAX = 1e6 + 1;
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(ll n, ll k) {
if (n >= MAX) {
ll tmp = 1;
rep(i, k) {
tmp *= (n - i);
tmp %= MOD;
}
return tmp * finv[k] % MOD;
}
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll POW(ll x, ll n) {
ll ret = 1;
if (n < 0) { // n < 0 にも対応
n *= -1;
x = inv[x];
}
while (0 < n) {
if (n % 2 == 0) {
x = x * x % MOD;
n /= 2;
} else {
ret = ret * x % MOD;
n--;
}
}
return ret;
}
int dp[3010][3010];
int main() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
rep(i, n + 1) rep(j, m + 1) {
// dp[i][j] を dp[i+1][j], dp[i][j+1], dp[i+1][j+1] に配る
// printf("i:%d j:%d dp[i][j]:%d\n", i, j, dp[i][j]);
chmax(dp[i + 1][j], dp[i][j]);
chmax(dp[i][j + 1], dp[i][j]);
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
else
chmax(dp[i + 1][j + 1], dp[i][j]);
}
// rep(i,n+1) rep(j,m+1) {
// if(j < m) printf("%d ", dp[i][j]);
// else printf("%d\n", dp[i][j]);
// }
string ans;
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 {
i--;
j--;
ans = s[i] + ans;
}
}
cout << ans << endl;
}
| [
"expression.operation.binary.add"
] | 973,113 | 973,114 | u354567428 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dp[3010][3010];
int main() {
string s, t;
cin >> s >> t;
rep(i, 3010) rep(j, 3010) dp[i][j] = 0;
dp[0][0] = 0;
rep(i, s.length()) rep(j, t.length()) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + s[i];
} else {
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
}
// cout << "i: " << i << " j:" << j << " dp[" << i+1 << "][" << j+1 << "]:"
// << dp[i+1][j+1] << endl;
}
string ans = "";
int x = s.length(), y = t.length();
while (x > 0 && y > 0) {
if (dp[x][y] == dp[x - 1][y]) {
x--;
} else if (dp[x][y] == dp[x][y - 1]) {
y--;
} else {
x--;
y--;
ans = s[x] + ans;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dp[3010][3010];
int main() {
string s, t;
cin >> s >> t;
rep(i, 3010) rep(j, 3010) dp[i][j] = 0;
dp[0][0] = 0;
rep(i, s.length()) rep(j, t.length()) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
}
// cout << "i: " << i << " j:" << j << " dp[" << i+1 << "][" << j+1 << "]:"
// << dp[i+1][j+1] << endl;
}
string ans = "";
int x = s.length(), y = t.length();
while (x > 0 && y > 0) {
if (dp[x][y] == dp[x - 1][y]) {
x--;
} else if (dp[x][y] == dp[x][y - 1]) {
y--;
} else {
x--;
y--;
ans = s[x] + ans;
}
}
cout << ans << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"expression.operation.binary.change"
] | 973,115 | 973,116 | u808943968 | cpp |
p03165 | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MX 3003
int dp[MX][MX];
int main() {
string s, t;
cin >> s >> t;
for (int i = 1; i <= s.size(); ++i) {
for (int j = 1; j <= t.size(); ++j) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
stack<int> st;
int i = s.size();
int j = t.size();
while (dp[i][j] != 0) {
if (dp[i][j] == dp[i - 1][j])
i = i - 1;
else if (dp[i][j] == dp[j - 1][i])
j = j - 1;
else {
st.push(i);
i = i - 1;
j = j - 1;
}
}
while (!st.empty())
cout << s[st.top() - 1], st.pop();
cout << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MX 3003
int dp[MX][MX];
int main() {
string s, t;
cin >> s >> t;
for (int i = 1; i <= s.size(); ++i) {
for (int j = 1; j <= t.size(); ++j) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
stack<int> st;
int i = s.size();
int j = t.size();
while (dp[i][j] != 0) {
if (dp[i][j] == dp[i - 1][j])
i = i - 1;
else if (dp[i][j] == dp[i][j - 1])
j = j - 1;
else {
st.push(i);
i = i - 1;
j = j - 1;
}
}
while (!st.empty())
cout << s[st.top() - 1], st.pop();
cout << endl;
}
| [
"control_flow.branch.if.condition.change"
] | 973,131 | 973,132 | u559654669 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP2(i, j, n) for (int i = j; i < n; i++)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
string S, T;
cin >> S >> T;
int slen = S.length();
int tlen = T.length();
int dp[slen + 1][tlen + 1] = {};
REP(i, slen) {
REP(j, tlen) {
// i番目の文字とj番目の文字が同じなら増やす.
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]);
}
}
// REP(i,slen+1){
// REP(j,tlen+1){
// cout<<dp[i][j]<<' ';
// }
// cout << endl;
// }
string ans = "";
int x = slen + 1, y = tlen + 1;
while (x > 0 && y > 0) {
// cout<<x<<' '<<y<<endl;
if (dp[x][y] == dp[x - 1][y]) {
--x;
} else if (dp[x][y] == dp[x][y - 1]) {
--y;
} else {
--x;
--y;
ans = S[x] + ans;
}
}
// cout<<ans << endl;
// cout << (ans =="axb") <<endl;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP2(i, j, n) for (int i = j; i < n; i++)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
string S, T;
cin >> S >> T;
int slen = S.length();
int tlen = T.length();
int dp[slen + 1][tlen + 1] = {};
REP(i, slen) {
REP(j, tlen) {
// i番目の文字とj番目の文字が同じなら増やす.
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]);
}
}
// REP(i,slen+1){
// REP(j,tlen+1){
// cout<<dp[i][j]<<' ';
// }
// cout << endl;
// }
string ans = "";
int x = slen, y = tlen;
while (x > 0 && y > 0) {
// cout<<x<<' '<<y<<endl;
if (dp[x][y] == dp[x - 1][y]) {
--x;
} else if (dp[x][y] == dp[x][y - 1]) {
--y;
} else {
--x;
--y;
ans = S[x] + ans;
}
}
cout << ans << endl;
} | [
"expression.operation.binary.remove"
] | 973,163 | 973,164 | u908393090 | cpp |
p03165 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
short dp[3003][3003];
int main() {
string s, t;
cin >> s >> t;
int ss, ts;
ss = s.size();
ts = t.size();
// int dp[ss+1][ts+1];
rep(i, ts + 1) dp[0][i] = 0;
rep(i, ss + 1) dp[i][0] = 0;
rep(i, ss) {
rep(j, ts) {
if ((s[i] == t[j]) && (dp[i][j] == dp[i][j + 1]) &&
(dp[i][j] == dp[i + 1][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]);
}
}
}
// rep(i, ss+1) {rep(j, ts+1) cout << dp[i][j]; cout << endl;}
if (dp[ss][ts] == 0)
cout << "" << endl;
else {
string ans = "";
for (int i = ss, j = ts; (i > 0) && (j > 0);) {
// cout << ss-si << "," << ts-ti << endl;
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans = t[j - 1] + ans;
i--;
}
}
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
short dp[3003][3003];
int main() {
string s, t;
cin >> s >> t;
int ss, ts;
ss = s.size();
ts = t.size();
// int dp[ss+1][ts+1];
rep(i, ts + 1) dp[0][i] = 0;
rep(i, ss + 1) dp[i][0] = 0;
rep(i, ss) {
rep(j, ts) {
if ((s[i] == t[j]) && (dp[i][j] == dp[i][j + 1]) &&
(dp[i][j] == dp[i + 1][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]);
}
}
}
if (dp[ss][ts] == 0)
cout << "" << endl;
else {
string ans = "";
for (int i = ss, j = ts; (i > 0) && (j > 0);) {
// cout << ss-si << "," << ts-ti << endl;
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans = t[j - 1] + ans;
i--;
j--;
}
}
cout << ans << endl;
}
}
| [
"expression.unary.arithmetic.add"
] | 973,190 | 973,191 | u164112876 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define rrep2(i, n) for (int i = (n); i > 0; --i)
#define srep(i, s, n) for (int i = s; i < (n); ++i)
#define rsrep(i, s, n) for (int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define aall(a) (a), (a) + countof(a) // for array sorting
#define raall(a) (a), (a) + countof(a), greater<>()
#define show(x) cout << #x << " = " << x << endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) \
{ \
if (f) \
puts("YES"); \
else \
puts("NO"); \
}
#define yns(f) \
{ \
if (f) \
puts("Yes"); \
else \
puts("No"); \
}
#define show_ary(...) \
{ \
cout << #__VA_ARGS__ << " = "; \
for (const auto &x : (__VA_ARGS__)) { \
cout << x << " "; \
} \
cout << endl; \
}
#define show_pair(...) \
cout << #__VA_ARGS__ << " = " << endl; \
for (const auto &x : (__VA_ARGS__)) { \
cout << " " << x.fi << " : " << x.se << endl; \
}
#define out_ary(...) \
{ \
int n = (__VA_ARGS__).size(); \
rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n - 1 ? " " : "\n"); \
}
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9 + 7;
int main() {
string s, t;
cin >> s >> t;
int sl = s.length();
int tl = t.length();
vvint dp(sl + 1, vint(tl + 1, 0));
rep(i, sl) rep(j, tl) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][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 = sl, j = tl;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
--i;
else if (dp[i][j] == dp[i - 1][j])
--j;
else {
ans = s[i - 1] + ans;
--i;
--j;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define rrep2(i, n) for (int i = (n); i > 0; --i)
#define srep(i, s, n) for (int i = s; i < (n); ++i)
#define rsrep(i, s, n) for (int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define aall(a) (a), (a) + countof(a) // for array sorting
#define raall(a) (a), (a) + countof(a), greater<>()
#define show(x) cout << #x << " = " << x << endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) \
{ \
if (f) \
puts("YES"); \
else \
puts("NO"); \
}
#define yns(f) \
{ \
if (f) \
puts("Yes"); \
else \
puts("No"); \
}
#define show_ary(...) \
{ \
cout << #__VA_ARGS__ << " = "; \
for (const auto &x : (__VA_ARGS__)) { \
cout << x << " "; \
} \
cout << endl; \
}
#define show_pair(...) \
cout << #__VA_ARGS__ << " = " << endl; \
for (const auto &x : (__VA_ARGS__)) { \
cout << " " << x.fi << " : " << x.se << endl; \
}
#define out_ary(...) \
{ \
int n = (__VA_ARGS__).size(); \
rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n - 1 ? " " : "\n"); \
}
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9 + 7;
int main() {
string s, t;
cin >> s >> t;
int sl = s.length();
int tl = t.length();
vvint dp(sl + 1, vint(tl + 1, 0));
rep(i, sl) rep(j, tl) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][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 = sl, j = tl;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
--i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else {
ans = s[i - 1] + ans;
--i;
--j;
}
}
cout << ans << endl;
return 0;
} | [
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 973,258 | 973,259 | u365512540 | cpp |
p03165 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
// ****************************************CODE***************************************//
string s, t;
ll dp[3100][3100];
int main() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[i])
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 = "";
ll i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i - 1][j] == dp[i][j])
i--;
else if (dp[i][j - 1] == dp[i][j])
j--;
else {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
// ****************************************CODE***************************************//
string s, t;
ll dp[3100][3100];
int main() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = 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 = "";
ll i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i - 1][j] == dp[i][j])
i--;
else if (dp[i][j - 1] == dp[i][j])
j--;
else {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 973,264 | 973,265 | u195054737 | cpp |
p03165 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
// ****************************************CODE***************************************//
string s, t;
ll dp[3100][3100];
int main() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[i])
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i + 1][j]);
dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j + 1]);
}
}
string res = "";
ll i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i - 1][j] == dp[i][j])
i--;
else if (dp[i][j - 1] == dp[i][j])
j--;
else {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;
// ****************************************CODE***************************************//
string s, t;
ll dp[3100][3100];
int main() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = 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 = "";
ll i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i - 1][j] == dp[i][j])
i--;
else if (dp[i][j - 1] == dp[i][j])
j--;
else {
res = s[i - 1] + res;
i--;
j--;
}
}
cout << res << endl;
} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"assignment.value.change",
"call.function.change"
] | 973,266 | 973,265 | u195054737 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int n, m;
n = s.size(), m = t.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string ans = "";
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 - 1][j])
j--;
else {
ans = s[i - 1] + ans;
i--;
j--;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int n, m;
n = s.size(), m = t.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i - 1] == t[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
string ans = "";
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 {
ans = s[i - 1] + ans;
i--;
j--;
}
}
cout << ans << endl;
} | [
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 973,279 | 973,280 | u735499035 | cpp |
p03165 | #include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
string s, t;
cin >> s >> t;
ll sn = sz(s);
ll tn = sz(t);
vvll dp(sn + 1, vll(tn + 1));
for (int i = 0; i < sn; i++) {
for (int j = 0; j < tn; j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
}
}
}
ll i = sz(s);
ll j = sz(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] + ans;
i--;
j--;
}
}
COUT(ans);
} | #include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
string s, t;
cin >> s >> t;
ll sn = sz(s);
ll tn = sz(t);
vvll dp(sn + 1, vll(tn + 1));
for (int i = 0; i < sn; i++) {
for (int j = 0; j < tn; j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
}
}
}
ll i = sz(s);
ll j = sz(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] + ans;
i--;
j--;
}
}
COUT(ans);
}
| [
"assignment.change"
] | 973,281 | 973,282 | u103850114 | cpp |
p03165 | // https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<vector<int>> dp;
char solve(const string &s, int &r, int &c, int target) {
if (r > 0 && dp[r - 1][c] == target) {
r -= 1;
return solve(s, r, c, target);
} else if (c > 0 && dp[r][c - 1] == target) {
c -= 1;
return solve(s, r, c, target);
} else {
return s[c];
}
}
int main() {
string s, t;
cin >> s >> t;
int rows = s.length() + 1;
int cols = t.length() + 1;
dp.resize(rows, vector<int>(cols, 0));
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < cols - 1; 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]);
}
}
}
// rep(i, rows) {
// rep(j, cols) { printf("%d ", dp[i][j]); }
// cout << endl;
// }
// cout << endl;
int r = rows - 1;
int c = cols - 1;
int target;
string ans;
target = dp[r][c];
while (target > 0) {
char ch = solve(t, r, c, target);
ans += ch;
target -= 1;
r -= 1;
c -= 1;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| // https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<vector<int>> dp;
char solve(const string &s, int &r, int &c, int target) {
if (r > 0 && dp[r - 1][c] == target) {
r -= 1;
return solve(s, r, c, target);
} else if (c > 0 && dp[r][c - 1] == target) {
c -= 1;
return solve(s, r, c, target);
} else {
return s[c - 1];
}
}
int main() {
string s, t;
cin >> s >> t;
int rows = s.length() + 1;
int cols = t.length() + 1;
dp.resize(rows, vector<int>(cols, 0));
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < cols - 1; 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]);
}
}
}
// rep(i, rows) {
// rep(j, cols) { printf("%d ", dp[i][j]); }
// cout << endl;
// }
// cout << endl;
int r = rows - 1;
int c = cols - 1;
int target;
string ans;
target = dp[r][c];
while (target > 0) {
char ch = solve(t, r, c, target);
ans += ch;
target -= 1;
r -= 1;
c -= 1;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 973,308 | 973,309 | u864329440 | cpp |
p03165 | // https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<vector<int>> dp;
char solve(const string &s, int &r, int &c, int target) {
if (r > 0 && dp[r - 1][c] == target) {
r -= 1;
return solve(s, r, c, target);
} else if (c > 0 && dp[r][c] == target) {
c -= 1;
return solve(s, r, c, target);
} else {
return s[c];
}
}
int main() {
string s, t;
cin >> s >> t;
int rows = s.length() + 1;
int cols = t.length() + 1;
dp.resize(rows, vector<int>(cols, 0));
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < cols - 1; 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]);
}
}
}
// rep(i, rows) {
// rep(j, cols) { printf("%d ", dp[i][j]); }
// cout << endl;
// }
// cout << endl;
int r = rows - 1;
int c = cols - 1;
int target;
string ans;
target = dp[r][c];
while (target > 0) {
char ch = solve(t, r, c, target);
ans += ch;
target -= 1;
r -= 1;
c -= 1;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| // https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<vector<int>> dp;
char solve(const string &s, int &r, int &c, int target) {
if (r > 0 && dp[r - 1][c] == target) {
r -= 1;
return solve(s, r, c, target);
} else if (c > 0 && dp[r][c - 1] == target) {
c -= 1;
return solve(s, r, c, target);
} else {
return s[c - 1];
}
}
int main() {
string s, t;
cin >> s >> t;
int rows = s.length() + 1;
int cols = t.length() + 1;
dp.resize(rows, vector<int>(cols, 0));
for (int i = 0; i < rows - 1; i++) {
for (int j = 0; j < cols - 1; 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]);
}
}
}
// rep(i, rows) {
// rep(j, cols) { printf("%d ", dp[i][j]); }
// cout << endl;
// }
// cout << endl;
int r = rows - 1;
int c = cols - 1;
int target;
string ans;
target = dp[r][c];
while (target > 0) {
char ch = solve(t, r, c, target);
ans += ch;
target -= 1;
r -= 1;
c -= 1;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 973,310 | 973,309 | u864329440 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
int arr[3005][3005];
// char arr2[1000000];
int main() {
int test;
scanf("%d", &test);
// for(int xx=1;xx<=test;xx++)
//{
string a, b;
cin >> a >> b;
int len1 = a.size();
int len2 = b.size();
for (int i = 0; i <= len1; i++) {
arr[i][0] = 0;
}
for (int i = 0; i <= len2; i++) {
arr[0][i] = 0;
}
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (a[i] == b[j]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int res = arr[len1][len2];
string cc;
while (len1 >= 0 && len2 >= 0) {
if (len1 == 0 || len2 == 0) {
break;
}
if (arr[len1 - 1][len2] == arr[len1][len2]) {
len1--;
} else if (arr[len1][len2 - 1] == arr[len1][len2]) {
len2--;
} else {
cc += a[len1 - 1];
// arr2[p++]=a[len1-1];
len1--;
len2--;
}
}
reverse(cc.begin(), cc.end());
// cout<<cc<<endl;
cout << cc << endl;
memset(arr, 0, sizeof(arr));
//}
}
| #include <bits/stdc++.h>
using namespace std;
int arr[3005][3005];
// char arr2[1000000];
int main() {
int test;
scanf("%d", &test);
// for(int xx=1;xx<=test;xx++)
//{
string a, b;
cin >> a >> b;
int len1 = a.size();
int len2 = b.size();
for (int i = 0; i <= len1; i++) {
arr[i][0] = 0;
}
for (int i = 0; i <= len2; i++) {
arr[0][i] = 0;
}
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (a[i - 1] == b[j - 1]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int res = arr[len1][len2];
string cc;
while (len1 >= 0 && len2 >= 0) {
if (len1 == 0 || len2 == 0) {
break;
}
if (arr[len1 - 1][len2] == arr[len1][len2]) {
len1--;
} else if (arr[len1][len2 - 1] == arr[len1][len2]) {
len2--;
} else {
cc += a[len1 - 1];
// arr2[p++]=a[len1-1];
len1--;
len2--;
}
}
reverse(cc.begin(), cc.end());
// cout<<cc<<endl;
cout << cc << endl;
memset(arr, 0, sizeof(arr));
//}
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 973,324 | 973,325 | u285938905 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
int arr[1000][1000];
// char arr2[1000000];
int main() {
int test;
scanf("%d", &test);
// for(int xx=1;xx<=test;xx++)
//{
string a, b;
cin >> a >> b;
int len1 = a.size();
int len2 = b.size();
for (int i = 0; i <= len1; i++) {
arr[i][0] = 0;
}
for (int i = 0; i <= len2; i++) {
arr[0][i] = 0;
}
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (a[i] == b[j]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int res = arr[len1][len2];
string cc;
while (len1 >= 0 && len2 >= 0) {
if (len1 == 0 || len2 == 0) {
break;
}
if (arr[len1 - 1][len2] == arr[len1][len2]) {
len1--;
} else if (arr[len1][len2 - 1] == arr[len1][len2]) {
len2--;
} else {
cc += a[len1 - 1];
// arr2[p++]=a[len1-1];
len1--;
len2--;
}
}
reverse(cc.begin(), cc.end());
// cout<<cc<<endl;
cout << cc << endl;
memset(arr, 0, sizeof(arr));
//}
}
| #include <bits/stdc++.h>
using namespace std;
int arr[3005][3005];
// char arr2[1000000];
int main() {
int test;
scanf("%d", &test);
// for(int xx=1;xx<=test;xx++)
//{
string a, b;
cin >> a >> b;
int len1 = a.size();
int len2 = b.size();
for (int i = 0; i <= len1; i++) {
arr[i][0] = 0;
}
for (int i = 0; i <= len2; i++) {
arr[0][i] = 0;
}
for (int i = 1; i <= len1; i++) {
for (int j = 1; j <= len2; j++) {
if (a[i - 1] == b[j - 1]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int res = arr[len1][len2];
string cc;
while (len1 >= 0 && len2 >= 0) {
if (len1 == 0 || len2 == 0) {
break;
}
if (arr[len1 - 1][len2] == arr[len1][len2]) {
len1--;
} else if (arr[len1][len2 - 1] == arr[len1][len2]) {
len2--;
} else {
cc += a[len1 - 1];
// arr2[p++]=a[len1-1];
len1--;
len2--;
}
}
reverse(cc.begin(), cc.end());
// cout<<cc<<endl;
cout << cc << endl;
memset(arr, 0, sizeof(arr));
//}
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 973,326 | 973,325 | u285938905 | cpp |
p03165 | #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>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pdd, int> ptemp;
typedef pair<ll, ll> pll;
typedef pair<int, vector<int>> pivi;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, vi> mivi;
#define rep(i, a, b) for (i = a; i <= b; ++i)
#define rev(i, a, b) for (i = a; i >= b; --i)
#define all(x) x.begin(), x.end()
#define google(x) cout << "Case #" << x << ": ";
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
// #define MAX_N 200006
// #define modulo 1000000007
// #define modulo 163577857
#define modulo 998244353
#define PI 3.14159265358979323846264338327
#define ordered_set(type) \
tree<type, null_type, less<type>, rb_tree_tag, \
tree_order_statistics_node_update>
// order_of_key: The number of items in a set that are strictly smaller than k
// find_by_order: It returns an iterator to the ith largest element
ll inf = 1e9 + 7;
// const int maxn = (1<<20);
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << " ]";
}
template <class T> ostream &operator<<(ostream &os, set<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << " ]";
}
template <class T, class R> ostream &operator<<(ostream &os, map<T, R> V) {
os << "[ ";
for (auto v : V)
os << "(" << v.first << ":" << v.second << ")";
return os << " ]";
}
template <class T, class R> ostream &operator<<(ostream &os, pair<T, R> V) {
return os << "(" << V.first << "," << V.second << ")";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}
clock_t clk = clock();
#define checktime() \
cout << "\nTime Elapsed : " << float(clock() - clk) / CLOCKS_PER_SEC << endl
#else
#define trace(...) ;
#define checktime() ;
#endif
int i, j, k;
const ll maxn = 1e9 + 5;
int main() {
io;
int t = 1;
// cin >> t;
while (t--) {
string s, t;
cin >> s >> t;
int n1 = s.size(), n2 = t.size();
int dp[n1 + 1][n2 + 1];
memset(dp, 0, sizeof(dp));
rep(i, 1, n1) {
rep(j, 1, n2) {
dp[i][j] = max(dp[i][j - 1], max(dp[i - 1][j], dp[i][j]));
if (s[i - 1] == t[j - 1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
int mx[n1 + 1] = {0};
// rep(i, 1, n1) {
// rep(j, 1, n2) {
// cout << dp[i][j] << " ";
// }
// cout << "\n";
// }
rep(i, 1, n1) rep(j, 1, n2) mx[i] = max(mx[i], dp[i][j]);
string ans = "";
int last = n2;
rev(i, n1, 1) {
int mx[2] = {0};
rep(k, 0, 1) { rep(j, 1, last) mx[k] = max(mx[k], dp[i - k][j]); }
if (mx[0] != mx[1]) {
ans += s[i - 1];
rep(j, 1, last) if (dp[i][j] == mx[0]) {
last = j;
break;
}
}
}
reverse(all(ans));
cout << ans << "\n";
}
// checktime();
} | #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>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#define io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pdd, int> ptemp;
typedef pair<ll, ll> pll;
typedef pair<int, vector<int>> pivi;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<int, vi> mivi;
#define rep(i, a, b) for (i = a; i <= b; ++i)
#define rev(i, a, b) for (i = a; i >= b; --i)
#define all(x) x.begin(), x.end()
#define google(x) cout << "Case #" << x << ": ";
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
// #define MAX_N 200006
// #define modulo 1000000007
// #define modulo 163577857
#define modulo 998244353
#define PI 3.14159265358979323846264338327
#define ordered_set(type) \
tree<type, null_type, less<type>, rb_tree_tag, \
tree_order_statistics_node_update>
// order_of_key: The number of items in a set that are strictly smaller than k
// find_by_order: It returns an iterator to the ith largest element
ll inf = 1e9 + 7;
// const int maxn = (1<<20);
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << " ]";
}
template <class T> ostream &operator<<(ostream &os, set<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << " ]";
}
template <class T, class R> ostream &operator<<(ostream &os, map<T, R> V) {
os << "[ ";
for (auto v : V)
os << "(" << v.first << ":" << v.second << ")";
return os << " ]";
}
template <class T, class R> ostream &operator<<(ostream &os, pair<T, R> V) {
return os << "(" << V.first << "," << V.second << ")";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}
clock_t clk = clock();
#define checktime() \
cout << "\nTime Elapsed : " << float(clock() - clk) / CLOCKS_PER_SEC << endl
#else
#define trace(...) ;
#define checktime() ;
#endif
int i, j, k;
const ll maxn = 1e9 + 5;
int main() {
io;
int t = 1;
// cin >> t;
while (t--) {
string s, t;
cin >> s >> t;
int n1 = s.size(), n2 = t.size();
int dp[n1 + 1][n2 + 1];
memset(dp, 0, sizeof(dp));
rep(i, 1, n1) {
rep(j, 1, n2) {
dp[i][j] = max(dp[i][j - 1], max(dp[i - 1][j], dp[i][j]));
if (s[i - 1] == t[j - 1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
int mx[n1 + 1] = {0};
// rep(i, 1, n1) {
// rep(j, 1, n2) {
// cout << dp[i][j] << " ";
// }
// cout << "\n";
// }
rep(i, 1, n1) rep(j, 1, n2) mx[i] = max(mx[i], dp[i][j]);
string ans = "";
int last = n2;
rev(i, n1, 1) {
int mx[2] = {0};
rep(k, 0, 1) { rep(j, 1, last) mx[k] = max(mx[k], dp[i - k][j]); }
if (mx[0] != mx[1]) {
ans += s[i - 1];
rep(j, 1, last) if (dp[i][j] == mx[0]) {
last = j - 1;
break;
}
}
}
reverse(all(ans));
cout << ans << "\n";
}
// checktime();
} | [
"assignment.change"
] | 973,338 | 973,339 | u890290031 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep2(i, m, n) for (int i = int(m); i < int(n); i++)
#define drep2(i, m, n) for (int i = int(m - 1); i >= int(n); i--)
#define rep(i, n) rep2(i, 0, n)
#define drep (i, n) drep2(i, n, 0)
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int MOD = int(1e9) + 7;
int main() {
string s, t;
cin >> s;
cin >> t;
int S = (int)s.size();
int T = (int)t.size();
int dp[S + 1][T + 1];
rep(i, S + 1) rep(j, T + 1) dp[i][j] = 0;
rep(a, S) rep(b, T) {
dp[a + 1][b + 1] = max(dp[a][b + 1], dp[a + 1][b]);
if (s[a] == t[b])
dp[a + 1][b + 1] = max(dp[a + 1][b + 1], dp[a][b] + 1);
}
string ans = "";
int i = S;
int j = T;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
if (dp[i][j] == dp[i][j - 1])
j--;
else if (dp[i][j] == dp[i - 1][j - 1] + 1) {
ans = s[i - 1] + ans;
i--;
j--;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep2(i, m, n) for (int i = int(m); i < int(n); i++)
#define drep2(i, m, n) for (int i = int(m - 1); i >= int(n); i--)
#define rep(i, n) rep2(i, 0, n)
#define drep (i, n) drep2(i, n, 0)
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int MOD = int(1e9) + 7;
int main() {
string s, t;
cin >> s;
cin >> t;
int S = (int)s.size();
int T = (int)t.size();
int dp[S + 1][T + 1];
rep(i, S + 1) rep(j, T + 1) dp[i][j] = 0;
rep(a, S) rep(b, T) {
dp[a + 1][b + 1] = max(dp[a][b + 1], dp[a + 1][b]);
if (s[a] == t[b])
dp[a + 1][b + 1] = max(dp[a + 1][b + 1], dp[a][b] + 1);
}
string ans = "";
int i = S;
int j = T;
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] + 1) {
ans = s[i - 1] + ans;
i--;
j--;
}
}
cout << ans << endl;
return 0;
}
| [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 973,397 | 973,398 | u525008368 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll N, W;
vector<ll> w, v;
vector<vector<ll>> dp;
/*void solve(ll i,ll j){
if(dp[i][j]!=-1){
continue;
}
ll res = 0;
if(i==N){
res = 0;
}else if(dp[i][j]+w[i]>W){
res = solve(i+1,j);
}else{
res = min(solve(i+1,j),solve(i+1,j+v[i])+w[i]);
}
}*/
int main(void) {
cin >> N >> W;
w.resize(N);
v.resize(N);
for (ll i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
dp = vector<vector<ll>>(N + 10, vector<ll>(100010));
for (int i = 0; i < N + 10; i++) {
for (int j = 0; j < 100010; j++) {
dp[i][j] = 1LL << 60;
// cout<<dp[i][j]<<endl;
}
}
dp[0][0] = 0;
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < 100010; j++) {
if (j - v[i] >= 0) {
chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
} else {
chmin(dp[i + 1][j], dp[i][j]);
}
}
}
ll ans = 0;
for (ll j = 0; j < 100010; j++) {
if (dp[N][j] <= W)
ans = j;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll N, W;
vector<ll> w, v;
vector<vector<ll>> dp;
/*void solve(ll i,ll j){
if(dp[i][j]!=-1){
continue;
}
ll res = 0;
if(i==N){
res = 0;
}else if(dp[i][j]+w[i]>W){
res = solve(i+1,j);
}else{
res = min(solve(i+1,j),solve(i+1,j+v[i])+w[i]);
}
}*/
int main(void) {
cin >> N >> W;
w.resize(N);
v.resize(N);
for (ll i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
dp = vector<vector<ll>>(N + 10, vector<ll>(100010));
for (int i = 0; i < N + 10; i++) {
for (int j = 0; j < 100010; j++) {
dp[i][j] = 1LL << 60;
// cout<<dp[i][j]<<endl;
}
}
dp[0][0] = 0;
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < 100010; j++) {
if (j - v[i] >= 0) {
chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
chmin(dp[i + 1][j], dp[i][j]);
}
}
ll ans = 0;
for (ll j = 0; j < 100010; j++) {
if (dp[N][j] <= W)
ans = j;
}
cout << ans << endl;
}
| [] | 973,441 | 973,442 | u876784108 | cpp |
p03164 | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
// dp[ i ][ sum_v ] := i-1 番目までの品物から価値が sum_v
// 以上を達成するように選んだときの、重さの総和 sum_w の最小値
int N;
ll W, weight[MAX_N], value[MAX_N];
// DPテーブル
long long dp[MAX_N][MAX_V];
int main() {
cin >> N >> W;
REP(i, N) cin >> weight[i] >> value[i];
REP(i, MAX_N) {
REP(j, MAX_V) { dp[i][j] = INF; }
}
dp[0][0] = 0;
REP(i, N) {
REP(sum_v, MAX_N) {
if (sum_v - value[i] >= 0)
chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
// i 番目の品物を選ばない場合
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ll res = 0;
REP(sum_v, MAX_V) {
if (dp[N][sum_v] <= W)
res = sum_v;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
// dp[ i ][ sum_v ] := i-1 番目までの品物から価値が sum_v
// 以上を達成するように選んだときの、重さの総和 sum_w の最小値
int N;
ll W, weight[MAX_N], value[MAX_N];
// DPテーブル
long long dp[MAX_N][MAX_V];
int main() {
cin >> N >> W;
REP(i, N) cin >> weight[i] >> value[i];
REP(i, MAX_N) {
REP(j, MAX_V) { dp[i][j] = INF; }
}
dp[0][0] = 0;
REP(i, N) {
REP(sum_v, MAX_V) {
if (sum_v - value[i] >= 0)
chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
// i 番目の品物を選ばない場合
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ll res = 0;
REP(sum_v, MAX_V) {
if (dp[N][sum_v] <= W)
res = sum_v;
}
cout << res << endl;
return 0;
} | [] | 973,448 | 973,449 | u824337972 | cpp |
p03164 | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
// dp[ i ][ sum_v ] := i-1 番目までの品物から価値が sum_v
// 以上を達成するように選んだときの、重さの総和 sum_w の最小値
int N;
ll W, weight[MAX_N], value[MAX_N];
// DPテーブル
long long dp[MAX_N][MAX_V];
int main() {
cin >> N >> W;
REP(i, N) cin >> weight[i] >> value[i];
REP(i, MAX_N) {
REP(j, MAX_V) { dp[i][j] = INF; }
}
dp[0][0] = 0;
REP(i, N) {
REP(sum_v, MAX_N) {
if (sum_v - value[i] >= 0) {
chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
}
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ll res = 0;
REP(sum_v, MAX_V) {
if (dp[N][sum_v] <= W)
res = sum_v;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
const int MAX_N = 110;
const int MAX_V = 100100;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
// dp[ i ][ sum_v ] := i-1 番目までの品物から価値が sum_v
// 以上を達成するように選んだときの、重さの総和 sum_w の最小値
int N;
ll W, weight[MAX_N], value[MAX_N];
// DPテーブル
long long dp[MAX_N][MAX_V];
int main() {
cin >> N >> W;
REP(i, N) cin >> weight[i] >> value[i];
REP(i, MAX_N) {
REP(j, MAX_V) { dp[i][j] = INF; }
}
dp[0][0] = 0;
REP(i, N) {
REP(sum_v, MAX_V) {
if (sum_v - value[i] >= 0)
chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
// i 番目の品物を選ばない場合
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ll res = 0;
REP(sum_v, MAX_V) {
if (dp[N][sum_v] <= W)
res = sum_v;
}
cout << res << endl;
return 0;
} | [] | 973,450 | 973,449 | u824337972 | cpp |
p03164 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][1001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a >> b;
items.push_back({a, b});
}
for (int i = 1; i < 1001; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 100; j++) {
if (j - items[i - 1].second < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
dp[i][j] = min(dp[i - 1][j],
dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
}
}
li ans = 0;
for (int i = 1; i <= n; i++) {
for (li j = 1; j <= 100; j++) {
if (dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][100001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a >> b;
items.push_back({a, b});
}
for (int i = 1; i < 100001; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 100001; j++) {
if (j - items[i - 1].second < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
dp[i][j] = min(dp[i - 1][j],
dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
}
}
li ans = 0;
for (int i = 1; i <= n; i++) {
for (li j = 1; j < 100001; j++) {
if (dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans;
// system("pause");
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 973,462 | 973,461 | u190504030 | cpp |
p03164 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][1001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a >> b;
items.push_back({a, b});
}
for (int i = 1; i < 1001; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 100; j++) {
if (j - items[i - 1].second < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
dp[i][j] = min(dp[i - 1][j],
dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
}
}
li ans = 0;
for (int i = 1; i <= n; i++) {
for (li j = 1; j <= 20; j++) {
if (dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][100001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a >> b;
items.push_back({a, b});
}
for (int i = 1; i < 100001; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 100001; j++) {
if (j - items[i - 1].second < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
dp[i][j] = min(dp[i - 1][j],
dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
}
}
li ans = 0;
for (int i = 1; i <= n; i++) {
for (li j = 1; j < 100001; j++) {
if (dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans;
// system("pause");
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 973,463 | 973,461 | u190504030 | cpp |
p03164 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][1001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a >> b;
items.push_back({a, b});
}
for (int i = 1; i < 1001; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 20; j++) {
if (j - items[i - 1].second < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
dp[i][j] = min(dp[i - 1][j],
dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
}
}
li ans = 0;
for (int i = 1; i <= n; i++) {
for (li j = 1; j <= 20; j++) {
if (dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, dp[101][100001], a, b, w, inf = 99999999999;
vector<pair<li, li>> items;
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a >> b;
items.push_back({a, b});
}
for (int i = 1; i < 100001; i++) {
dp[0][i] = inf;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 100001; j++) {
if (j - items[i - 1].second < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
dp[i][j] = min(dp[i - 1][j],
dp[i - 1][j - items[i - 1].second] + items[i - 1].first);
}
}
li ans = 0;
for (int i = 1; i <= n; i++) {
for (li j = 1; j < 100001; j++) {
if (dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans;
// system("pause");
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 973,464 | 973,461 | u190504030 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define ff first
#define ss second
#define se set<ll>
#define inf 10000000000000000
int main() {
#ifdef APNA_IO
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
ll a[100001];
for (ll i = 0; i <= 100000; i++) {
a[i] = 1234567890;
}
a[0] = 0;
ll w, m;
cin >> w;
pll b[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> b[i].ff >> b[i].ss;
}
for (ll i = 1; i <= n; i++) {
for (ll j = 100000; j >= 0; j--) {
if (a[j] != 1234567890) {
if (b[i].ss + j < 100001) {
m = min(b[i].ff + a[j], a[j + b[i].ss]);
a[j + b[i].ss] = m;
}
}
}
}
ll d = 0;
for (ll i = 1; i <= 100000; i++) {
if (a[i] == w) {
d = i;
}
}
cout << d << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define ff first
#define ss second
#define se set<ll>
#define inf 10000000000000000
int main() {
#ifdef APNA_IO
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
ll a[100001];
for (ll i = 0; i <= 100000; i++) {
a[i] = 1234567890;
}
a[0] = 0;
ll w, m;
cin >> w;
pll b[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> b[i].ff >> b[i].ss;
}
for (ll i = 1; i <= n; i++) {
for (ll j = 100000; j >= 0; j--) {
if (a[j] != 1234567890) {
if (b[i].ss + j < 100001) {
m = min(b[i].ff + a[j], a[j + b[i].ss]);
a[j + b[i].ss] = m;
}
}
}
}
ll d = 0;
for (ll i = 1; i <= 100000; i++) {
if (a[i] <= w) {
d = i;
}
}
cout << d << endl;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 973,471 | 973,472 | u511137896 | cpp |
p03164 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;
ump mp;
int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true) {
mp = ump();
#pragma clang diagnostic pop
#endif
ll n, W;
cin >> n >> W;
ll w[n], v[n];
rep(i, n) cin >> w[i] >> v[i];
ll dp[n + 1][half_inf + 100];
rep(i, n + 1) rep(j, half_inf + 100) dp[i][j] = ll_inf;
dp[0][0] = 0;
rep(i, n) {
repone(j, half_inf) {
dp[i + 1][j] = dp[i][j];
if (j >= v[i] && dp[i][j - v[i]] != ll_inf) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
}
}
ll ans = 0;
rep(i, half_inf + 100) {
if (dp[n][i] <= W)
ans = max(i, ans);
}
cout << ans << endl;
#ifdef MY_DEBUG
}
#endif
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repone(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for (auto i : mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;
ump mp;
int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true) {
mp = ump();
#pragma clang diagnostic pop
#endif
ll n, W;
cin >> n >> W;
ll w[n], v[n];
rep(i, n) cin >> w[i] >> v[i];
ll dp[n + 1][half_inf + 100];
rep(i, n + 1) rep(j, half_inf + 100) dp[i][j] = ll_inf;
dp[0][0] = 0;
rep(i, n) {
rep(j, half_inf + 100) {
dp[i + 1][j] = dp[i][j];
if (j >= v[i] && dp[i][j - v[i]] != ll_inf) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
}
}
ll ans = 0;
rep(i, half_inf + 100) {
if (dp[n][i] <= W)
ans = max(i, ans);
}
cout << ans << endl;
#ifdef MY_DEBUG
}
#endif
return 0;
} | [
"expression.operation.binary.add"
] | 973,473 | 973,474 | u136378781 | cpp |
p03164 | #include <iostream>
using namespace std;
int main() {
int a = 0, b = 0;
cin >> a >> b;
int items[a + 1][2] = {0};
int sum = 0;
for (int i = 1; i <= a; i++) {
cin >> items[i][0] >> items[i][1];
sum += items[i][1];
}
long long int arr[sum + 1] = {0};
for (int j = sum; j >= 0; j--) {
arr[j] = 1e12;
}
for (int i = 1; i <= a; i++)
for (int j = sum; j >= items[i][1]; j--)
arr[j] = min(arr[j - items[i][1]] + items[i][0], arr[j]);
while (arr[sum] > b)
sum--;
cout << sum << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a = 0, b = 0;
cin >> a >> b;
int items[a + 1][2] = {0};
int sum = 0;
for (int i = 1; i <= a; i++) {
cin >> items[i][0] >> items[i][1];
sum += items[i][1];
}
long long int arr[sum + 1] = {0};
for (int j = sum; j > 0; j--) {
arr[j] = 1e12;
}
for (int i = 1; i <= a; i++)
for (int j = sum; j >= items[i][1]; j--)
arr[j] = min(arr[j - items[i][1]] + items[i][0], arr[j]);
while (arr[sum] > b)
sum--;
cout << sum << endl;
cin >> sum;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 973,477 | 973,478 | u223578409 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf = 1e18;
void min_self(ll &a, ll b) { a = min(a, b); }
const int N = 110;
int n, W;
int main() {
scanf("%d%d", &n, &W);
vector<ll> weight(n);
vector<ll> value(n);
for (int i = 0; i < n; ++i) {
cin >> weight[i] >> value[i];
}
ll sum = 0;
for (int x : value) {
sum += x;
}
vector<ll> dp(sum + 1, inf);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int va = sum - value[i]; va >= 0; --va) {
min_self(dp[va + value[i]], dp[va] + weight[i]);
}
}
ll ans = inf;
for (int i = 0; i <= sum; ++i) {
if (dp[i] <= W) {
ans = max(ans, (ll)i);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf = 1e18;
void min_self(ll &a, ll b) { a = min(a, b); }
const int N = 110;
int n, W;
int main() {
scanf("%d%d", &n, &W);
vector<ll> weight(n);
vector<ll> value(n);
for (int i = 0; i < n; ++i) {
cin >> weight[i] >> value[i];
}
ll sum = 0;
for (int x : value) {
sum += x;
}
vector<ll> dp(sum + 1, inf);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int va = sum - value[i]; va >= 0; --va) {
min_self(dp[va + value[i]], dp[va] + weight[i]);
}
}
ll ans = 0;
for (int i = 0; i <= sum; ++i) {
if (dp[i] <= W) {
ans = max(ans, (ll)i);
}
}
cout << ans << endl;
return 0;
} | [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 973,479 | 973,480 | u763404917 | cpp |
p03164 | #include <bits/stdc++.h>
#include <limits.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a, n) a.resize(n)
#define test(t) \
ll t; \
cin >> t; \
while (t--)
#define forn(i, e) for (int i = 0; i < e; i++)
#define forsn(i, s, e) for (int i = s; i < e; i++)
#define rforn(i, s) for (int i = s; i >= 0; i--)
#define rforsn(i, s, e) for (int i = s; i >= e; i--)
#define fillv(a, k) memset(a, k, sizeof(a))
#define filla(a, k, n) memset(a, k, sizeof(a[0]) * n)
#define leadzero(a) __builtin_clz(a) // count leading zeros
#define trailzero(a) __builtin_ctz(a) // count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout << "\n"
#define sp cout << " "
#define spaceprint(a, i, s, n) \
{ \
forsn(i, s, n) { \
cout << a[i]; \
sp; \
} \
}
#define lineprint(a, i, s, n) \
{ \
forsn(i, s, n) { \
cout << a[i]; \
ln; \
} \
}
#define maxe(a) *max_element(a.begin(), a.end())
#define maxi(a) max_element(a.begin(), a.end()) - a.begin()
#define mine(a) *min_element(a.begin(), a.end())
#define mini(a) min_element(a.begin(), a.end()) - a.begin()
#define all(c) c.begin(), c.end()
#define trav(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) \
(find(all(container), element) != \
container.end()) // check the presence of element
// copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll, ll> p64;
typedef pair<int, int> p32;
typedef pair<int, p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int, int> m32;
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
#define sumv(v) accumulate(all(v), ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies<ll>())
int main() {
ll n, W;
cin >> n >> W;
ll w[n + 1];
ll v[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
ll dp[n + 1][100003];
fillv(dp, 0);
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= 100000; j++) {
dp[i][j] = INT_MAX - 1;
}
}
ll maxx = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= 100000; j++) {
if (j - v[i] < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
if (dp[i - 1][j - v[i]] < INT_MAX - 1 || j == v[i]) {
if (j == v[i])
dp[i][j] = min(w[i], dp[i][j]);
else
dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i][j]);
if (maxx < j && dp[i][j] <= W) {
maxx = j;
}
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << maxx << endl;
} | #include <bits/stdc++.h>
#include <limits.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a, n) a.resize(n)
#define test(t) \
ll t; \
cin >> t; \
while (t--)
#define forn(i, e) for (int i = 0; i < e; i++)
#define forsn(i, s, e) for (int i = s; i < e; i++)
#define rforn(i, s) for (int i = s; i >= 0; i--)
#define rforsn(i, s, e) for (int i = s; i >= e; i--)
#define fillv(a, k) memset(a, k, sizeof(a))
#define filla(a, k, n) memset(a, k, sizeof(a[0]) * n)
#define leadzero(a) __builtin_clz(a) // count leading zeros
#define trailzero(a) __builtin_ctz(a) // count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout << "\n"
#define sp cout << " "
#define spaceprint(a, i, s, n) \
{ \
forsn(i, s, n) { \
cout << a[i]; \
sp; \
} \
}
#define lineprint(a, i, s, n) \
{ \
forsn(i, s, n) { \
cout << a[i]; \
ln; \
} \
}
#define maxe(a) *max_element(a.begin(), a.end())
#define maxi(a) max_element(a.begin(), a.end()) - a.begin()
#define mine(a) *min_element(a.begin(), a.end())
#define mini(a) min_element(a.begin(), a.end()) - a.begin()
#define all(c) c.begin(), c.end()
#define trav(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) \
(find(all(container), element) != \
container.end()) // check the presence of element
// copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll, ll> p64;
typedef pair<int, int> p32;
typedef pair<int, p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int, int> m32;
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
#define sumv(v) accumulate(all(v), ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies<ll>())
int main() {
ll n, W;
cin >> n >> W;
ll w[n + 1];
ll v[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
ll dp[n + 1][100003];
fillv(dp, 0);
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= 100000; j++) {
dp[i][j] = INT_MAX - 1;
}
}
ll maxx = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= 100000; j++) {
if (j - v[i] < 0) {
dp[i][j] = dp[i - 1][j];
continue;
}
if (dp[i - 1][j - v[i]] < INT_MAX - 1 || j == v[i]) {
if (j == v[i])
dp[i][j] = min(w[i], dp[i - 1][j]);
else
dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
if (maxx < j && dp[i][j] <= W) {
maxx = j;
}
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << maxx << endl;
} | [] | 973,489 | 973,490 | u535349616 | cpp |
p03164 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll w[102], v[102], dp[102][100005];
int main() {
int n;
ll W;
scanf("%d %lld", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%lld %lld", &w[i], &v[i]);
}
for (int i = 1; i < 100005; i++)
dp[0][i] = 1e18;
for (int i = 1; i <= n; i++) {
dp[i][100001] = 1e18;
for (int j = 100000; j >= 0; j--) {
dp[i][j] = min(dp[i][j + 1], dp[i - 1][j]);
if (j >= v[i]) {
dp[i][j] = min(dp[i][j + 1], dp[i - 1][j - v[i]] + w[i]);
}
}
}
for (int i = 100000; i >= 0; i--) {
if (dp[n][i] <= W) {
printf("%d", i);
return 0;
}
}
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll w[102], v[102], dp[102][100005];
int main() {
int n;
ll W;
scanf("%d %lld", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%lld %lld", &w[i], &v[i]);
}
for (int i = 1; i < 100005; i++)
dp[0][i] = 1e18;
for (int i = 1; i <= n; i++) {
dp[i][100001] = 1e18;
for (int j = 100000; j >= 0; j--) {
dp[i][j] = min(dp[i][j + 1], dp[i - 1][j]);
if (j >= v[i]) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
}
for (int i = 100000; i >= 0; i--) {
if (dp[n][i] <= W) {
printf("%d", i);
return 0;
}
}
} | [
"expression.operation.binary.remove"
] | 973,500 | 973,501 | u385306891 | cpp |
p03164 | // Resting_Prince
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000009
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
int main() {
ios;
ll n, w, i, j, k, l, o, p = 0, a[105], b[105];
ll dp[102055];
cin >> n >> w;
p = 1;
memset(dp, mod, sizeof(dp));
dp[0] = 0;
rep(j, 0, n - 1) {
cin >> a[j] >> b[j];
rep(i, 0, p) { // cout<<dp[i]+a[j]<<":";
if (dp[i] <= w)
dp[i + b[j]] = min(dp[i + b[j]], dp[i] + a[j]);
}
p += b[j];
}
o = 0;
rep(i, 1, p) { // cout<<dp[i];
if (dp[i] <= w)
o = i;
}
cout << o;
return 0;
}
| // Resting_Prince
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000009
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
int main() {
ios;
ll n, w, i, j, k, l, o, p = 0, a[105], b[105];
ll dp[102055];
cin >> n >> w;
p = 1;
memset(dp, mod, sizeof(dp));
dp[0] = 0;
rep(j, 0, n - 1) {
cin >> a[j] >> b[j];
repr(i, p, 0) {
if (dp[i] <= w)
dp[i + b[j]] = min(dp[i + b[j]], dp[i] + a[j]); // cout<<dp[i]+a[j]<<":";
}
p += b[j];
}
o = 0;
rep(i, 1, p) { // cout<<dp[i];
if (dp[i] <= w)
o = i;
}
cout << o;
return 0;
}
| [
"identifier.change",
"call.function.change",
"call.arguments.change",
"call.arguments.add"
] | 973,502 | 973,503 | u640930204 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
typedef long long ll;
const int INF = 1e9;
const int MAX_N = 105;
const int MAX_V = 1005;
// input
ll N, W;
vector<ll> w(MAX_N), v(MAX_N);
// dp
ll dp[MAX_N][MAX_N * MAX_V];
int main() {
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
//初期値
rep(i, MAX_N) rep(j, MAX_N * MAX_V) { dp[i][j] = INF; }
dp[0][0] = 0;
rep(i, N) rep(j, MAX_N * MAX_V) {
if (j + v[i] <= MAX_N * MAX_V) {
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
ll ans = 0;
rep(j, MAX_N * MAX_V) {
if (dp[N][j] <= W)
ans = j;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (int i = 0; i < int(N); ++i)
typedef long long ll;
const int INF = 1e10;
const int MAX_N = 105;
const int MAX_V = 1005;
// input
ll N, W;
vector<ll> w(MAX_N), v(MAX_N);
// dp
ll dp[MAX_N][MAX_N * MAX_V];
int main() {
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
//初期値
rep(i, MAX_N) rep(j, MAX_N * MAX_V) { dp[i][j] = INF; }
dp[0][0] = 0;
rep(i, N) rep(j, MAX_N * MAX_V) {
if (j + v[i] <= MAX_N * MAX_V) {
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
ll ans = 0;
rep(j, MAX_N * MAX_V) {
if (dp[N][j] <= W)
ans = j;
}
cout << ans << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 973,506 | 973,507 | u106297876 | cpp |
p03164 | #include <bits/stdc++.h>
#define INF 1e10;
using namespace std;
typedef long long ll;
int main(void) {
int N, W;
cin >> N >> W;
ll w[N + 1], v[N + 1];
ll sum = 0;
for (int i = 0; i < N; i++) {
cin >> w[i + 1] >> v[i + 1];
sum += v[i + 1];
}
ll dp[N + 1][sum + 1];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= sum; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= sum; j++) {
if (j < v[i])
dp[i][j] = dp[i - 1][j];
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
}
}
ll res;
for (int j = 0; j <= sum; j++) {
if (dp[N][j] <= W)
res = j;
}
cout << res << endl;
}
| #include <bits/stdc++.h>
#define INF 1e10;
using namespace std;
typedef long long ll;
int main(void) {
int N, W;
cin >> N >> W;
ll w[N + 1], v[N + 1];
ll sum = 0;
for (int i = 0; i < N; i++) {
cin >> w[i + 1] >> v[i + 1];
sum += v[i + 1];
}
ll dp[N + 10][sum + 100];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= sum; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= sum; j++) {
if (j < v[i])
dp[i][j] = dp[i - 1][j];
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
}
}
ll res;
for (int j = 0; j <= sum; j++) {
if (dp[N][j] <= W)
res = j;
}
cout << res << endl;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 973,512 | 973,513 | u413492096 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FAST_IO \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define endl "\n"
#define printarr(arr, n) \
for (int i = 0; i < n; i++) \
cout << arr[i] << " "; \
cout << endl;
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define debug(x) cout << "#debug " << x << endl;
#define print2D(arr, n) \
cout << "\n_____________________\n"; \
for (int i = 1; i <= n; i++) { \
for (int j = 1; j <= n; j++) { \
cout << arr[i][j] << " "; \
} \
cout << endl; \
} \
cout << "\n_____________________\n";
#define mii map<int, int>
#define printmap(mm) \
for (map<int, int>::iterator itr = mm.begin(); itr != mm.end(); itr++) \
cout << itr->first << "->" << itr->second << " "; \
cout << endl;
#define iterm(mm) \
for (map<int, int>::iterator itr = mm.begin(); itr != mm.end(); itr++)
#define NO \
cout << "NO"; \
return 0;
#define MO 1000000007
#define N 101
#define MX 2000000000
void preprocess() {}
signed main() {
FAST_IO;
#ifndef ONLINE_JUDGE
// freopen("/home/divakar/programs/input.txt","r",stdin);
// freopen("/home/divakar/programs/output.txt","w",stdout);
#endif
clock_t clk = clock();
preprocess();
int t = 1;
// cout << " dsf ";
// cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int w[n], v[n];
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
int dp[N];
memset(dp, INT_MAX, sizeof(dp));
for (int i = 0; i < N; ++i) {
dp[i] = INT_MAX;
}
dp[0] = 0;
// printarr(dp, N);
for (int i = 0; i < n; ++i) {
for (int j = N - 1; j >= v[i]; --j) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
for (int i = N - 1; i >= 0; --i) {
if (dp[i] <= k) {
cout << i << endl;
break;
}
}
// cout << "ENDOFTEST "<< t << "\n";
}
#ifndef ONLINE_JUDGE
clk = clock() - clk;
// cout << "Time Elapsed: " << fixed << setprecision(10) << ((long
// double)clk)/CLOCKS_PER_SEC << "\n";
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FAST_IO \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define endl "\n"
#define printarr(arr, n) \
for (int i = 0; i < n; i++) \
cout << arr[i] << " "; \
cout << endl;
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define debug(x) cout << "#debug " << x << endl;
#define print2D(arr, n) \
cout << "\n_____________________\n"; \
for (int i = 1; i <= n; i++) { \
for (int j = 1; j <= n; j++) { \
cout << arr[i][j] << " "; \
} \
cout << endl; \
} \
cout << "\n_____________________\n";
#define mii map<int, int>
#define printmap(mm) \
for (map<int, int>::iterator itr = mm.begin(); itr != mm.end(); itr++) \
cout << itr->first << "->" << itr->second << " "; \
cout << endl;
#define iterm(mm) \
for (map<int, int>::iterator itr = mm.begin(); itr != mm.end(); itr++)
#define NO \
cout << "NO"; \
return 0;
#define MO 1000000007
#define N 100100
#define MX 2000000000
void preprocess() {}
signed main() {
FAST_IO;
#ifndef ONLINE_JUDGE
// freopen("/home/divakar/programs/input.txt","r",stdin);
// freopen("/home/divakar/programs/output.txt","w",stdout);
#endif
clock_t clk = clock();
preprocess();
int t = 1;
// cout << " dsf ";
// cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int w[n], v[n];
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
int dp[N];
memset(dp, INT_MAX, sizeof(dp));
for (int i = 0; i < N; ++i) {
dp[i] = INT_MAX;
}
dp[0] = 0;
// printarr(dp, N);
for (int i = 0; i < n; ++i) {
for (int j = N - 1; j >= v[i]; --j) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
for (int i = N - 1; i >= 0; --i) {
if (dp[i] <= k) {
cout << i << endl;
break;
}
}
// cout << "ENDOFTEST "<< t << "\n";
}
#ifndef ONLINE_JUDGE
clk = clock() - clk;
// cout << "Time Elapsed: " << fixed << setprecision(10) << ((long
// double)clk)/CLOCKS_PER_SEC << "\n";
#endif
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 973,514 | 973,515 | u563511494 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define MAX 105
ll dp[MAX][100005];
ll W[MAX], V[MAX];
ll n, w;
ll INF = 1e14;
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> W[i] >> V[i];
}
for (int i = 1; i < 100005; i++) {
dp[0][i] = INF;
}
ll ans = 0;
for (int i = 1; i < n; i++) {
for (ll j = 1; j < 100005; j++) {
if (j - V[i] >= 0) {
dp[i][j] = min(dp[i - 1][j - V[i]] + W[i], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
if (dp[i][j] != INF && dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define MAX 105
ll dp[MAX][100005];
ll W[MAX], V[MAX];
ll n, w;
ll INF = 1e14;
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> W[i] >> V[i];
}
for (int i = 1; i < 100005; i++) {
dp[0][i] = INF;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (ll j = 1; j < 100005; j++) {
if (j - V[i] >= 0) {
dp[i][j] = min(dp[i - 1][j - V[i]] + W[i], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
if (dp[i][j] != INF && dp[i][j] <= w)
ans = max(ans, j);
}
}
cout << ans << '\n';
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 973,518 | 973,519 | u389854459 | cpp |
p03164 | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
int tc;
#define MAXV 100500
#define INF 1000000000
ll f[MAXV];
int n, v, w, W;
int main() {
scanf("%i%i", &n, &W);
fill(f + 1, f + MAXV, INF);
for (int i = 0; i < n; ++i) {
scanf("%i%i", &w, &v);
for (int j = MAXV - 1; j >= v; --j)
if (f[j] > f[j - v] + w)
f[j] = f[j - v] + w;
}
for (int j = MAXV - 1; j >= 0; --j)
if (f[j] <= W) {
printf("%i\n", j);
break;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
int tc;
#define MAXV 100500
#define INF 2000000000
ll f[MAXV];
int n, v, w, W;
int main() {
scanf("%i%i", &n, &W);
fill(f + 1, f + MAXV, INF);
for (int i = 0; i < n; ++i) {
scanf("%i%i", &w, &v);
for (int j = MAXV - 1; j >= v; --j)
if (f[j] > f[j - v] + w)
f[j] = f[j - v] + w;
}
for (int j = MAXV - 1; j >= 0; --j)
if (f[j] <= W) {
printf("%i\n", j);
break;
}
return 0;
} | [
"preprocessor.define.value.change",
"literal.integer.change"
] | 973,526 | 973,527 | u936599352 | cpp |
p03164 | #include <bits/stdc++.h>
#define MAX_N 100
#define MAX_V 1000
#define INF 1 << 60
typedef long long int ll;
ll dp[MAX_N + 1][MAX_V + 1];
int main() {
int n, v[MAX_N + 1];
ll W, w[MAX_N + 1];
std::cin >> n >> W;
for (int i = 0; i < n; ++i) {
std::cin >> w[i] >> v[i];
}
for (int j = 1; j <= MAX_V; ++j) {
dp[0][j] = (v[0] >= j) ? w[0] : INF;
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j <= MAX_V; ++j) {
dp[i][j] = dp[i - 1][j];
if (j - v[i] >= 0) {
dp[i][j] = std::min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
}
int ans = 0;
for (int j = 1; j <= MAX_V; ++j) {
if (dp[n - 1][j] <= W) {
ans = j;
}
}
std::cout << ans << std::endl;
} | #include <bits/stdc++.h>
#define MAX_N 100
#define MAX_V 100000
#define INF 1 << 30
typedef long long int ll;
ll dp[MAX_N + 1][MAX_V + 1];
int main() {
int n, v[MAX_N + 1];
ll W, w[MAX_N + 1];
std::cin >> n >> W;
for (int i = 0; i < n; ++i) {
std::cin >> w[i] >> v[i];
}
for (int j = 1; j <= MAX_V; ++j) {
dp[0][j] = (v[0] >= j) ? w[0] : INF;
}
for (int i = 1; i < n; ++i) {
for (int j = 1; j <= MAX_V; ++j) {
dp[i][j] = dp[i - 1][j];
if (j - v[i] >= 0) {
dp[i][j] = std::min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
}
int ans = 0;
for (int j = 1; j <= MAX_V; ++j) {
if (dp[n - 1][j] <= W) {
ans = j;
}
}
std::cout << ans << std::endl;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 973,535 | 973,534 | u600759947 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
typedef pair<int, int> pii;
vector<int> v;
map<int, int> op;
#define MAX 200005
bool visited[MAX];
vector<int> adj[MAX];
const int M = 1e9 + 7;
int n, m;
const ll INF = 1LL << 60;
ll solve(int n, int w, int wt[], int val[]) {
vector<ll> dp(100001, LLONG_MAX);
dp[0] = 0;
for (int i = 0; i <= n; i++) {
int w = wt[i], v = val[i];
for (int j = 100000; j >= v; j--) {
if (dp[j - v] == LLONG_MAX)
continue;
dp[j] = min(dp[j], dp[j - v] + w);
}
}
for (int i = 100000; i >= 0; i--)
if (dp[i] <= w)
return i;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << solve(n, w, wt, val) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
typedef pair<int, int> pii;
vector<int> v;
map<int, int> op;
#define MAX 200005
bool visited[MAX];
vector<int> adj[MAX];
const int M = 1e9 + 7;
int n, m;
const ll INF = 1LL << 60;
ll solve(int n, int w, int wt[], int val[]) {
vector<ll> dp(100001, LLONG_MAX);
dp[0] = 0;
for (int i = 0; i < n; i++) {
int w = wt[i], v = val[i];
for (int j = 100000; j >= v; j--) {
if (dp[j - v] == LLONG_MAX)
continue;
dp[j] = min(dp[j], dp[j - v] + w);
}
}
for (int i = 100000; i >= 0; i--)
if (dp[i] <= w)
return i;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << solve(n, w, wt, val) << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 973,546 | 973,547 | u486889274 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 105;
const int maxw = 1e5 + 5;
int w[maxn], v[maxn];
int n, W;
ll dp[maxw];
int main() {
scanf("%d %d", &n, &W);
int sum = 0;
for (int i = 1; i <= n; i++)
scanf("%d %d", &w[i], &v[i]);
for (int i = 1; i <= n; i++)
sum += v[i];
for (int i = 1; i <= n; i++)
dp[i] = sum;
for (int i = 1; i <= n; i++) {
for (int j = sum; j >= v[i]; j--) {
dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
}
}
for (int i = sum; i >= 0; i--) {
if (dp[i] <= W) {
printf("%d\n", i);
return 0;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxn = 105;
const int maxw = 1e5 + 5;
int w[maxn], v[maxn];
int n, W;
ll dp[maxw];
int main() {
scanf("%d %d", &n, &W);
int sum = 0;
for (int i = 1; i <= n; i++)
scanf("%d %d", &w[i], &v[i]);
for (int i = 1; i <= n; i++)
sum += v[i];
for (int i = 1; i <= sum; i++)
dp[i] = 1e9;
for (int i = 1; i <= n; i++) {
for (int j = sum; j >= v[i]; j--) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
for (int i = sum; i >= 0; i--) {
if (dp[i] <= W) {
printf("%d\n", i);
return 0;
}
}
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"misc.opposites",
"call.function.change"
] | 973,561 | 973,562 | u905710781 | cpp |
p03164 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int N = 0;
int W = 0;
int main() {
//ナップサック問題 荷物の価値を最大化
cin >> N;
cin >> W;
vector<pair<ll, ll>> T;
ll value = 0;
ll weight = 0;
ll max_value = 0;
//入力
for (int i = 0; i < N; i++) {
cin >> weight >> value;
max_value += value;
T.push_back(make_pair(value, weight));
}
//価値が大きい順にソート
sort(T.rbegin(), T.rend());
//余白
T.insert(T.begin(), make_pair(0, 0));
// dp Value 価値を基準に表を作る
vector<vector<ll>> dp;
dp = vector<vector<ll>>(N + 1, vector<ll>(max_value + 1, -1));
dp[0][0] = 0;
//答え
ll ans = 0;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= max_value; j++) {
if (dp[i - 1][j] > -1) {
//直下を更新
if (dp[i][j] <= dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
}
//荷物を足し合わせたところを更新
if (dp[i][j + T[i].first] >= dp[i - 1][j] + T[i].second &&
dp[i - 1][j] + T[i].second <= W) {
dp[i][j + T[i].first] = dp[i - 1][j] + T[i].second;
// ans確認
if (ans < j + T[i].first)
ans = j + T[i].first;
}
}
}
}
cout << ans << endl;
//確認
/*
for(int i = 0; i <= N; i++){
for(int j = 0; j <= max_value; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}
*/
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int N = 0;
int W = 0;
int main() {
//ナップサック問題 荷物の価値を最大化
cin >> N;
cin >> W;
vector<pair<ll, ll>> T;
ll value = 0;
ll weight = 0;
ll max_value = 0;
//入力
for (int i = 0; i < N; i++) {
cin >> weight >> value;
max_value += value;
T.push_back(make_pair(value, weight));
}
//価値が大きい順にソート
sort(T.rbegin(), T.rend());
//前に余白
T.insert(T.begin(), make_pair(0, 0));
// dp Value 価値を基準に表を作る
vector<vector<ll>> dp;
dp = vector<vector<ll>>(N + 1, vector<ll>(max_value + 1, 1145141919));
dp[0][0] = 0;
//答え
ll ans = 0;
//縦:個数 横:価値 価値を達成する最小の重さで更新していく
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= max_value; j++) {
if (dp[i - 1][j] < 1145141919) {
//直下を更新
if (dp[i][j] >= dp[i - 1][j]) {
dp[i][j] = dp[i - 1][j];
}
//荷物を足し合わせたところを更新
if (dp[i][j + T[i].first] >= dp[i - 1][j] + T[i].second &&
dp[i - 1][j] + T[i].second <= W) {
dp[i][j + T[i].first] = dp[i - 1][j] + T[i].second;
// ans確認
if (ans < j + T[i].first)
ans = j + T[i].first;
}
}
}
}
cout << ans << endl;
//確認
/*
for(int i = 0; i <= N; i++){
for(int j = 0; j <= max_value; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}
*/
} | [
"literal.number.change",
"assignment.value.change",
"call.arguments.change",
"control_flow.loop.for.condition.change",
"control_flow.branch.if.condition.change",
"misc.opposites",
"expression.operator.compare.change"
] | 973,563 | 973,564 | u048791623 | cpp |
p03164 | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define f first
#define se second
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef long double ld;
typedef long long int lli;
using namespace std;
// reference: geeks
ll mult(ll a, ll b, ll p = mod) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = mod) { return (a % p + b % p) % p; }
ll sub(ll a, ll b, ll p = mod) { return (a % p - b % p + p) % p; }
ll fpow(ll n, ll k, ll p = mod) {
ll r = 1;
for (; k; k >>= 1) {
if (k & 1)
r = mult(r, n, p);
n = mult(n, n, p);
}
return r;
}
ll inv(ll a, ll p = mod) { return fpow(a, p - 2, p); }
#define INF 10000000000
ll dp[105][100005] = {{0}};
int main() {
ll n, w;
cin >> n >> w;
ll p[n], W[n];
for (int i = 0; i < n; i++)
cin >> W[i] >> p[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < 100005; j++)
dp[i][j] = INF;
if (W[0] <= w)
dp[0][p[0]] = W[0];
dp[0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 1; j < 100005; j++) {
if (j < p[i])
dp[i][j] = dp[i - 1][j];
else {
if (dp[i - 1][j - p[i]] + W[i] <= w)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - p[i]] + W[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
ll ans = 0;
for (int j = 100004; j >= 0; j--) {
if (dp[n - 1][j] <= w) {
ans = j;
break;
}
}
cout << ans;
}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define f first
#define se second
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef long double ld;
typedef long long int lli;
using namespace std;
// reference: geeks
ll mult(ll a, ll b, ll p = mod) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = mod) { return (a % p + b % p) % p; }
ll sub(ll a, ll b, ll p = mod) { return (a % p - b % p + p) % p; }
ll fpow(ll n, ll k, ll p = mod) {
ll r = 1;
for (; k; k >>= 1) {
if (k & 1)
r = mult(r, n, p);
n = mult(n, n, p);
}
return r;
}
ll inv(ll a, ll p = mod) { return fpow(a, p - 2, p); }
#define INF 10000000000
ll dp[105][100005] = {{0}};
int main() {
ll n, w;
cin >> n >> w;
ll p[n], W[n];
for (int i = 0; i < n; i++)
cin >> W[i] >> p[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < 100005; j++)
dp[i][j] = INF;
if (W[0] <= w)
dp[0][p[0]] = W[0];
dp[0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 100005; j++) {
if (j < p[i])
dp[i][j] = dp[i - 1][j];
else {
if (dp[i - 1][j - p[i]] + W[i] <= w)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - p[i]] + W[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
ll ans = 0;
for (int j = 100004; j >= 0; j--) {
if (dp[n - 1][j] <= w) {
ans = j;
break;
}
}
cout << ans;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 973,573 | 973,574 | u697012152 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for (int i = (l); i < (r); i++)
#define incII(i, l, r) for (int i = (l); i <= (r); i++)
#define decID(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define decII(i, l, r) for (int i = (r); i >= (l); i--)
#define inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define FOR(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define RFOR(it, v) for (auto it = v.rbegin(); it != v.rend(); ++it)
template <typename T> bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmineq(T &a, T b) {
if (b <= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmaxeq(T &a, T b) {
if (b >= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
const int V = 100000;
LL n, W, w[100], v[100], dp[V + 1], INF = 1e12;
int main() {
cin >> n >> W;
inc(i, n) { cin >> w[i] >> v[i]; }
incII(j, 0, V) { dp[j] = INF; }
dp[0] = 0;
inc(i, n) {
decII(j, 0, V) { setmin(dp[j + v[i]], dp[j] + w[i]); }
}
LL ans = 0;
incII(j, 0, V) {
if (dp[j] <= W) {
ans = j;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for (int i = (l); i < (r); i++)
#define incII(i, l, r) for (int i = (l); i <= (r); i++)
#define decID(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define decII(i, l, r) for (int i = (r); i >= (l); i--)
#define inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define FOR(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define RFOR(it, v) for (auto it = v.rbegin(); it != v.rend(); ++it)
template <typename T> bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmineq(T &a, T b) {
if (b <= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> bool setmaxeq(T &a, T b) {
if (b >= a) {
a = b;
return true;
} else {
return false;
}
}
template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
const int V = 100000;
LL n, W, w[100], v[100], dp[V + 1001], INF = 1e12;
int main() {
cin >> n >> W;
inc(i, n) { cin >> w[i] >> v[i]; }
incII(j, 0, V) { dp[j] = INF; }
dp[0] = 0;
inc(i, n) {
decII(j, 0, V) { setmin(dp[j + v[i]], dp[j] + w[i]); }
}
LL ans = 0;
incII(j, 0, V) {
if (dp[j] <= W) {
ans = j;
}
}
cout << ans << endl;
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 973,589 | 973,590 | u568652083 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n, dp[105][100005], v[105], w[105], m, ans;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", w + i, v + i);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100000; j++)
dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (ll j = 100000; j >= 0; j--) {
if (j - v[i] >= 0)
dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
else
dp[i][j] = dp[i][j - 1];
if (dp[i][j] <= m)
ans = max(ans, j);
}
}
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n, dp[105][100005], v[105], w[105], m, ans;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", w + i, v + i);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100000; j++)
dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (ll j = 100000; j >= 0; j--) {
if (j - v[i] >= 0)
dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
if (dp[i][j] <= m)
ans = max(ans, j);
}
}
printf("%lld\n", ans);
}
| [] | 973,615 | 973,616 | u743900647 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n, dp[100][100005], v[105], w[105], m, ans;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", w + i, v + i);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100000; j++)
dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (ll j = 100000; j >= 0; j--) {
if (j - v[i] >= 0)
dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
else
dp[i][j] = dp[i][j - 1];
if (dp[i][j] <= m)
ans = max(ans, j);
}
}
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll, ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n, dp[105][100005], v[105], w[105], m, ans;
int main(void) {
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld%lld", w + i, v + i);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100000; j++)
dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (ll j = 100000; j >= 0; j--) {
if (j - v[i] >= 0)
dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
if (dp[i][j] <= m)
ans = max(ans, j);
}
}
printf("%lld\n", ans);
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 973,617 | 973,616 | u743900647 | cpp |
p03165 | #pragma GCC optimize("O2")
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast \
ios::sync_with_stdio(false); \
cin.tie(NULL);
/////////////////////////////////////////////
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
///////////////////////////////
#define int long long
void solve() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
int dp[n + 1][m + 1];
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
int len = dp[n][m];
string ans = "";
int i = n, j = m;
while (len) {
while (i >= 0 && dp[i][j] == len)
--i;
while (j >= 0 && dp[i][j] == len)
--j;
ans.push_back(s[i]);
--len;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
signed main() {
fast;
int t = 1;
// cin>>t;
while (t--)
solve();
} | #pragma GCC optimize("O2")
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast \
ios::sync_with_stdio(false); \
cin.tie(NULL);
/////////////////////////////////////////////
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
///////////////////////////////
#define int long long
void solve() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
int dp[n + 1][m + 1];
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (s[i - 1] == t[j - 1])
dp[i][j] = 1 + dp[i - 1][j - 1];
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
int len = dp[n][m];
string ans = "";
int i = n, j = m;
while (len) {
while (i >= 0 && dp[i][j] == len)
--i;
while (j >= 0 && dp[i + 1][j] == len)
--j;
ans.push_back(s[i]);
--len;
}
reverse(ans.begin(), ans.end());
// for(int i = 1 ; i <= n ;++i)
// for(int j = 1 ; j <= m ; ++j)
// cout<<dp[i][j]<<" \n"[j==m];
cout << ans << endl;
}
signed main() {
fast;
int t = 1;
// cin>>t;
while (t--)
solve();
} | [
"control_flow.loop.condition.change"
] | 973,682 | 973,683 | u487128874 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
EACH(it, P) { s << "<" << *it << "> "; }
return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
return s << endl;
}
template <class T> void show(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << " ";
}
cerr << "\n";
}
typedef long long ll;
int dp[3010][3010];
signed main() {
string s, t;
cin >> s >> t;
dp[0][0] = 0;
string ans = "";
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans += s[i - 1] + ans;
i--, j--;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
EACH(it, P) { s << "<" << *it << "> "; }
return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
return s << endl;
}
template <class T> void show(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << " ";
}
cerr << "\n";
}
typedef long long ll;
int dp[3010][3010];
signed main() {
string s, t;
cin >> s >> t;
dp[0][0] = 0;
string ans = "";
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int i = s.size(), j = t.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j - 1])
j--;
else {
ans = s[i - 1] + ans;
i--, j--;
}
}
cout << ans << endl;
return 0;
} | [
"assignment.value.change"
] | 973,697 | 973,702 | u074445770 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
string lcs(string s, string t) {
int n = s.size();
int m = t.size();
int arr[n][m];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i == 0 || j == 0) {
arr[i][j] = 0;
continue;
}
if (s[i - 1] == t[j - 1]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int l = n;
int r = m;
string ans;
while (l > 0 and r > 0) {
if (arr[l][r] == arr[l - 1][r]) {
l--;
} else if (arr[l][r] == arr[l][r - 1]) {
r--;
} else if (arr[l][r] == (arr[l - 1][r - 1] + 1)) {
ans += s[l - 1];
l--;
r--;
}
}
reverse(ans.begin(), ans.end());
return ans;
}
int main() {
string s, t;
cin >> s >> t;
cout << lcs(s, t) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
string lcs(string s, string t) {
int n = s.size();
int m = t.size();
int arr[n + 1][m + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (i == 0 || j == 0) {
arr[i][j] = 0;
continue;
}
if (s[i - 1] == t[j - 1]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
}
int l = n;
int r = m;
string ans;
while (l > 0 and r > 0) {
if (arr[l][r] == arr[l - 1][r]) {
l--;
} else if (arr[l][r] == arr[l][r - 1]) {
r--;
} else if (arr[l][r] == (arr[l - 1][r - 1] + 1)) {
ans += s[l - 1];
l--;
r--;
}
}
reverse(ans.begin(), ans.end());
return ans;
}
int main() {
string s, t;
cin >> s >> t;
cout << lcs(s, t) << "\n";
}
| [
"variable_declaration.array_dimensions.change",
"expression.operation.binary.add"
] | 973,722 | 973,723 | u100071032 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 3010
#define rep(i, n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9 + 7;
int n, m;
int dp[MAXN][MAXN];
string s, t;
int main() {
cin >> s >> t;
n = s.size();
m = t.size();
string ans = "";
rep(i, n) {
for (int k = i; k < m; ++k) {
if (s[i] == t[k]) {
dp[i + 1][k + 1] = dp[i][k] + 1;
} else {
dp[i + 1][k + 1] = max(dp[i][k + 1], dp[i + 1][k]);
}
}
}
int a = n, b = m;
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 {
--a;
--b;
ans = s[a] + ans;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 3010
#define rep(i, n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9 + 7;
int n, m;
int dp[MAXN][MAXN];
string s, t;
int main() {
cin >> s >> t;
n = s.size();
m = t.size();
string ans = "";
rep(i, n) {
for (int k = 0; k < m; ++k) {
if (s[i] == t[k]) {
dp[i + 1][k + 1] = dp[i][k] + 1;
} else {
dp[i + 1][k + 1] = max(dp[i][k + 1], dp[i + 1][k]);
}
}
}
int a = n, b = m;
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 {
--a;
--b;
ans = s[a] + ans;
}
}
// cout << dp[n][m] << endl;
cout << ans << endl;
} | [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.initializer.change"
] | 973,747 | 973,748 | u558720836 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
#define debug(var) std::cout << #var " = " << var << std::endl
#else
#define debug(var)
#endif
#define p(var) std::cout << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0, i##_length = (n); i < i##_length; ++i)
#define repeq(i, n) for (int i = 1, i##_length = (n); i <= i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a >= 0 && ceil(a) == floor(a); }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
for (int i = 0, len = v.size(); i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
for (int i = 0, len = vv.size(); i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
/*-----8<-----8<-----*/
// sとtの最長共通部分列を求める
//戻り値:最長共通部分列の長さ
// dp配列を格納して返す
ll lcs(string s, string t, vector<vector<ll>> &dp) {
dp.assign(s.size() + 1, vector<ll>(t.size() + 1, 0));
for (ll i = 0, slen = s.size(); i < slen; i++) {
for (ll j = 0, tlen = t.size(); j < tlen; j++) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
return dp[s.size()][t.size()];
}
// sとtの最長共通部分列を求める
//戻り値:最長共通部分列の文字列
string buildlcs(string s, string t, vector<vector<ll>> &dp) {
string lcsstr = "";
ll i = s.size();
ll j = t.size();
if (dp[i][j] == 0)
return 0;
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
i--;
j--;
lcsstr = s[i] + lcsstr;
}
}
return lcsstr;
}
signed main() {
// Longest Common Subsequence
string s, t;
cin >> s >> t;
vector<vector<ll>> dp;
ll lcsnum = lcs(s, t, dp);
debug(lcsnum);
string lcsstr = buildlcs(s, t, dp);
p(lcsstr);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 29;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
#define debug(var) std::cout << #var " = " << var << std::endl
#else
#define debug(var)
#endif
#define p(var) std::cout << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0, i##_length = (n); i < i##_length; ++i)
#define repeq(i, n) for (int i = 1, i##_length = (n); i <= i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a >= 0 && ceil(a) == floor(a); }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
for (int i = 0, len = v.size(); i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
for (int i = 0, len = vv.size(); i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
/*-----8<-----8<-----*/
// sとtの最長共通部分列を求める
//戻り値:最長共通部分列の長さ
// dp配列を格納して返す
ll lcs(string s, string t, vector<vector<ll>> &dp) {
dp.assign(s.size() + 1, vector<ll>(t.size() + 1, 0));
for (ll i = 0, slen = s.size(); i < slen; i++) {
for (ll j = 0, tlen = t.size(); j < tlen; j++) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
return dp[s.size()][t.size()];
}
// sとtの最長共通部分列を求める
//戻り値:最長共通部分列の文字列
string buildlcs(string s, string t, vector<vector<ll>> &dp) {
string lcsstr = "";
ll i = s.size();
ll j = t.size();
if (dp[i][j] == 0)
return "";
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
i--;
j--;
lcsstr = s[i] + lcsstr;
}
}
return lcsstr;
}
signed main() {
// Longest Common Subsequence
string s, t;
cin >> s >> t;
vector<vector<ll>> dp;
ll lcsnum = lcs(s, t, dp);
debug(lcsnum);
string lcsstr = buildlcs(s, t, dp);
p(lcsstr);
return 0;
}
| [
"function.return_value.change"
] | 973,778 | 973,779 | u061071198 | cpp |
p03165 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#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>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MAX_N = 100000;
const int MAX_W = 1000000000;
static const int INF = 1 << 29;
string s, t, ans;
int dp[3001][3001];
int main() {
cin.tie(0);
ios::sync_with_stdio(0); //この2行はより速度を向上させる
// 追加2, 以降 cin の入力元が 'input.txt' になる
//提出時に消す!!
cin >> s >> t;
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); 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]);
}
}
}
// LCSの対応は後ろから遡る
int i = s.size(), j = t.size();
int a = dp[i][j];
while (a != 0) {
if (a > dp[i - 1][j] && a > dp[i][j - 1]) {
ans += s[i - 1];
i--;
j--;
a = dp[i][j]; //対角線移動
continue;
} else {
if (a == dp[i - 1][j]) {
i--;
a = dp[i][j];
continue;
} else {
j--;
a = dp[i][j];
continue;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#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>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MAX_N = 100000;
const int MAX_W = 1000000000;
static const int INF = 1 << 29;
string s, t, ans;
int dp[3001][3001];
int main() {
cin.tie(0);
ios::sync_with_stdio(0); //この2行はより速度を向上させる
// 追加2, 以降 cin の入力元が 'input.txt' になる
//提出時に消す!!
cin >> s >> t;
for (int i = 1; i <= s.size(); i++) {
for (int j = 1; j <= t.size(); j++) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// LCSの対応は後ろから遡る
int i = s.size(), j = t.size();
int a = dp[i][j];
while (a != 0) {
if (a > dp[i - 1][j] && a > dp[i][j - 1]) {
ans += s[i - 1];
i--;
j--;
a = dp[i][j]; //対角線移動
continue;
} else {
if (a == dp[i - 1][j]) {
i--;
a = dp[i][j];
continue;
} else {
j--;
a = dp[i][j];
continue;
}
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 973,786 | 973,787 | u904131314 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;
using ll = long long;
using ull = unsigned long long;
using dbl = double;
using str = string;
using vll = V<ll>;
using vvll = V<vll>;
using vvvll = V<vvll>;
using pl = P<ll, ll>;
using tl = TP<ll, ll, ll>;
using vpl = V<pl>;
using vvpl = V<vpl>;
using vtl = V<tl>;
using vvtl = V<vtl>;
using vs = V<str>;
using vvs = V<vs>;
using vd = V<dbl>;
using vvd = V<vd>;
using qll = queue<ll>;
using qpl = queue<pl>;
using stll = stack<ll>;
using stpl = stack<pl>;
using mapll = map<ll, ll>;
using setll = set<ll>;
using pqll = priority_queue<ll>;
//#define int ll
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define sz size()
#define bgn begin()
#define en end()
#define asn assign
#define emp empty()
#define fr front()
#define bk back()
#define clr clear()
#define ins insert
#define ers erase
#define res resize
#define tp top()
#define p_q priority_queue
#define inv inverse()
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--)
#define REP(i, a) FOR((i), 0, (ll)(a)-1)
#define REP0(i, a) FOR((i), 0, (ll)(a))
#define REP1(i, a) FOR((i), 1, (ll)(a))
#define rREP(i, a) rFOR((i), 0, (ll)(a)-1)
#define rREP0(i, a) rFOR((i), 0, (ll)(a))
#define rREP1(i, a) rFOR((i), 1, (ll)(a))
#define ROR(v, i) for (auto &(i) : (v))
#define IOTA(a, n) iota((a).bgn, (a).en, (n))
#define SORT(a) sort((a).bgn, (a).en)
#define rSORT(a) sort((a).rbegin(), (a).rend())
#define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en)
#define PREVP(a) prev_permutation((a).bgn, (a).en)
#define NEXTP(a) next_permutation((a).bgn, (a).en)
#define BINS(a, b) binary_search((a).bgn, (a).en, (b))
#define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define CNT(a, b) count((a).bgn, (a).en, b)
#define SUM(a) accumulate((a).bgn, (a).en, 0)
#define REV(a) reverse((a).bgn, (a).en)
#define REGS(a, b) regex_search((a), regex(b))
#define REGM(a, b) regex_match((a), regex(b))
#define yn(a) cout << ((a) ? "yes" : "no") << "\n";
#define Yn(a) cout << ((a) ? "Yes" : "No") << "\n";
#define YN(a) cout << ((a) ? "YES" : "NO") << "\n";
#define imp(a) cout << ((a) ? "possible" : "impossible") << "\n";
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n";
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
#define fs(a) cout << ((a) ? "second" : "first") << "\n";
#define Fs(a) cout << ((a) ? "Second" : "First") << "\n";
#define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n";
//#define say(a) cout <<(a);
//#define sal(a) cout <<(a)<<"\n";
#define sak cout << "\n";
#define sas cout << " ";
#define sat cout << "\t";
#define dbg(a) cerr << (#a) << ": " << (a) << "\n";
#define dbgs(...) \
dal(#__VA_ARGS__); \
dal(__VA_ARGS__);
#define c2l(a) ((ll)(a - 48))
#define a2l(a) ((ll)(a - 97))
#define A2l(a) ((ll)(a - 65))
#define l2c(a) ((char)(a + 48))
#define l2a(a) ((char)(a + 97))
#define l2A(a) ((char)(a + 65))
#define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1))
#define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1))
#define Dig2(a, b) (((a) >> (b)) & 1)
#define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10)
#define Pow2(a) ((ll)(1) << (a))
#define Pow10(a) ((ll)(pow(10.0, double(a))))
#define LSB(a) ((a) & (-(a)))
/*#define llin(a) ll (a);cin >>(a);
#define llin2(a,b) ll (a),(b);cin >>(a)>>(b);
#define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c);
#define stin(a) string (a);cin >>(a);*/
#define vin(v) \
ROR((v), (i)) { cin >> (i); };
#define vllin(N, v) \
vll(v)((N)); \
vin(v);
#define vllin2(N, a, b) \
vll(a)(N), (b)(N); \
REP(i, N) { cin >> (a)[i] >> (b)[i]; };
#define vsin(N, v) \
vs(v)((N)); \
vin(v);
#define rdn(a, b) ((a) / (b))
#define rou(a, b) \
((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \
: (((a) / (b)) + 1))
#define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1))
#define powll(a, b) (ll)(pow((double)(a), (double)(b)))
#define Triangle(x1, y1, x2, y2, x3, y3) \
(((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2)))
#define tg(t, i) get<i>(t)
#define Id(x) get<0>(x)
#define Act(x) get<1>(x)
#define InvAct(x) get<2>(x)
#define mg(id, act) mt(id, act, lam(l))
//#define MonoidSet(T) TP<T, function<T(T, T)>>
#define GroupSet(T) TP<T, function<T(T, T)>, function<T(T, T)>>
#define CompareSet(T) TP<T, function<bool(T, T)>>
#define lam(lr) ([](auto l, auto r) { return (lr); })
#define elam(lr) ([=](auto l, auto r) { return (lr); })
#define clam(lr) ([&](auto l, auto r) { return (lr); })
#define lamr(lr) ([](auto l, auto r) { lr })
#define elamr(lr) ([=](auto l, auto r) { lr })
#define clamr(lr) ([&](auto l, auto r) { lr })
#define min(...) Operation(MIN, __VA_ARGS__)
#define max(...) Operation(MAX, __VA_ARGS__)
#define gcd(...) Operation(GCD, __VA_ARGS__)
#define lcm(...) Operation(LCM, __VA_ARGS__)
#define vmin(...) VOperation(MIN, __VA_ARGS__)
#define vmax(...) VOperation(MAX, __VA_ARGS__)
#define vgcd(...) VOperation(GCD, __VA_ARGS__)
#define vlcm(...) VOperation(LCM, __VA_ARGS__)
#define vsum(...) VOperation(ADD, __VA_ARGS__)
#define vpro(...) VOperation(MUL, __VA_ARGS__)
#define emin(a, ...) ((a) = min((a), __VA_ARGS__))
#define emax(a, ...) ((a) = max((a), __VA_ARGS__))
#define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__))
#define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__))
#define ope Operation
#define vope VOperation
#define svll SumV<ll>
#define svvll SumV2<ll>
#define li(...) \
ll __VA_ARGS__; \
Input(__VA_ARGS__);
#define si(...) \
str __VA_ARGS__; \
Input(__VA_ARGS__);
//#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__);
#define vlr(size, ...) \
vll __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vlc(size, ...) \
vll __VA_ARGS__; \
vInitInputC(size, __VA_ARGS__);
#define vli(size, ...) \
vll __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vsr(size, ...) \
vs __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vsc(size, ...) \
vs __VA_ARGS__; \
vInitInputC(size, __VA_ARGS__);
#define vsi(size, ...) \
vs __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vli2(rowSize, columnSize, ...) \
vvll __VA_ARGS__; \
vInitInput2(rowSize, columnSize, __VA_ARGS__);
#define vplr(size, ...) \
vpl __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vplc(size, ...) \
vpl __VA_ARGS__; \
vInitInputC(size, __VA_ARGS__);
#define vpli(size, ...) \
vpl __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = 924844033;
// const ll MOD = 9007199254740881;
const ll INF = 1LL << 60; // 1.15e18
const double PI = acos(-1.0);
const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1};
const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1};
const str alp = "abcdefghijklmnopqrstuvwxyz";
const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template <class T> auto GetVectorValueType(T v) { return v; }
template <class T> auto GetVectorValueType(V<T> v) {
return GetVectorValueType(T());
}
template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) {
return in >> p.fi >> p.se;
}
template <class T> istream &operator>>(istream &in, V<T> &v) {
REP(i, v.sz) in >> v[i];
return in;
}
void Input() {}
template <class Var, class... Args> void Input(Var &var, Args &...args) {
cin >> var;
Input(args...);
}
void vInit(ll size) {}
template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) {
v.res(size);
vInit(size, args...);
}
void vInput(ll size) {}
template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) {
REP(i, size) cin >> v[i];
vInput(size, args...);
}
void vInputR(ll size) {}
template <class T, class... Args>
void vInputR(ll size, V<T> &v, Args &...args) {
REP(i, size) cin >> v[i];
vInputR(size, args...);
}
void vInputNumC(ll num) {}
template <class T, class... Args>
void vInputNumC(ll num, V<T> &v, Args &...args) {
cin >> v[num];
vInputNumC(num, args...);
}
void vInputC(ll size) {}
template <class... Args> void vInputC(ll size, Args &...args) {
REP(i, size) vInputNumC(i, args...);
}
void vInitInputR(ll size) {}
template <class... Args> void vInitInputR(ll size, Args &...args) {
vInit(size, args...);
vInputR(size, args...);
}
void vInitInputC(ll size) {}
template <class... Args> void vInitInputC(ll size, Args &...args) {
vInit(size, args...);
vInputC(size, args...);
}
void vInit2(ll rowSize, ll columnSize) {}
template <class T, class... Args>
void vInit2(ll rowSize, ll columnSize, VV<T> &v, Args &...args) {
v.asn(rowSize, V<T>(columnSize));
vInit2(rowSize, columnSize, args...);
}
void vInput2(ll rowSize, ll columnSize) {}
template <class T, class... Args>
void vInput2(ll rowSize, ll columnSize, VV<T> &v, Args &...args) {
REP(r, rowSize) {
REP(c, columnSize) { cin >> v[r][c]; }
}
vInput2(rowSize, columnSize, args...);
}
void vInitInput2(ll rowSize, ll columnSize) {}
template <class... Args>
void vInitInput2(ll rowSize, ll columnSize, Args &...args) {
vInit2(rowSize, columnSize, args...);
vInput2(rowSize, columnSize, args...);
}
template <class S, class T>
ostream &operator<<(ostream &out, const P<S, T> &p) {
return out << "[" << p.fi << ", " << p.se << "]";
}
template <class T> ostream &operator<<(ostream &out, V<T> &v) {
if (v.emp)
return out << "{}";
else {
auto itr = v.bgn;
out << "{" << *itr;
itr++;
while (itr != v.en) {
out << ", " << *itr;
itr++;
}
out << "}";
return out;
}
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> &m) {
if (m.emp)
return out << "<[]>";
else {
auto itr = m.bgn;
out << "< [" << (itr->fi) << ": " << (itr->se);
itr++;
while (itr != m.en) {
out << "], [" << (itr->fi) << ": " << (itr->se);
itr++;
}
out << "] >";
return out;
}
}
template <class T> ostream &operator<<(ostream &out, const set<T> &s) {
if (s.emp)
return out << "<>";
else {
auto itr = s.bgn;
out << "<" << *itr;
itr++;
while (itr != s.en) {
out << ", " << *itr;
itr++;
}
out << ">";
return out;
}
}
void say() {}
template <class T> void say(T t) { cout << t; }
template <class Head, class... Body> void say(Head head, Body... body) {
cout << head << " ";
say(body...);
}
void sal() { cout << "\n"; }
template <class... Args> void sal(Args... args) {
say(args...);
cout << "\n";
}
void day() {}
template <class T> void day(T t) { cerr << t; }
template <class Head, class... Body> void day(Head head, Body... body) {
cerr << head << " ";
day(body...);
}
void dal() { cerr << "\n"; }
template <class... Args> void dal(Args... args) {
day(args...);
cerr << "\n";
}
void salv() {}
template <class T> void salv(V<T> v) {
if (v.emp)
sal();
else {
auto itr = v.bgn;
say(*itr);
itr++;
while (itr != v.en) {
sas;
say(*itr);
itr++;
}
sak;
}
}
template <class T> void salv(VV<T> v) {
if (v.emp)
sal();
else {
ROR(v, i) salv(i);
}
}
template <class T, class... Args> void salv(T v, Args... args) {
salv(v);
salv(args...);
}
template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) {
if (l < r)
swap(l, r);
return r ? Gcd(r, l % r) : l;
}
template <class L, class R> auto Lcm(L l, R r) {
if (!l || !r)
return 0;
return l / Gcd(l, r) * r;
}
/*
auto LES = mp(INF, lam(return l < r;));
auto GRT = mp(-INF, lam(return l > r;));
auto EQ = mp(0, lam(return l == r;));
auto ADD = mp(0, lam(return l + r;));
auto SUB = mp(0, lam(return l - r;));
auto MUL = mp(1, lam(return l * r;));
auto DIV = mp(1, lam(return l / r;));
auto MDL = mp(1, lam(return l % r;));
auto XOR = mp(0, lam(return l ^ r;));
auto OR = mp(0, lam(return l | r;));
auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;));
auto MIN = mp(INF, lam(return (l < r) ? l : r;));
auto MAX = mp(-INF, lam(return (l > r) ? l : r;));
auto GCD = mp(0, lam(return Gcd(l, r);));
auto LCM = mp(1, lam(return Lcm(l, r);));
*/
auto LES = mp(INF, lam(l < r));
auto GRT = mp(-INF, lam(l > r));
auto EQ = mp(0, lam(l == r));
auto ADD = mt(0, lam(l + r), lam(l - r));
auto MUL = mt(1, lam(l *r), lam(l / r));
auto XOR = mt(0, lam(l ^ r), lam(l ^ r));
auto OR = mg(0, lam(l | r));
auto AND = mg(((ll)(1) << 63) - 1, lam(l &r));
auto MIN = mg(0, lam((l < r) ? l : r));
auto MAX = mg(0, lam((l > r) ? l : r));
auto GCD = mg(0, lam(Gcd(l, r)));
auto LCM = mg(0, lam(Lcm(l, r)));
template <class OperationType> auto Operation(OperationType A) { return Id(A); }
template <class OperationType, class T> auto Operation(OperationType A, T x) {
return x;
}
template <class OperationType, class T, class... Args>
auto Operation(OperationType A, T x, Args... args) {
auto tmp = Operation(A, args...);
return Act(A)(x, tmp);
}
template <class OperationType> auto VOperation(OperationType A) {
return Id(A);
}
template <class OperationType, class T> auto VOperation(OperationType A, T x) {
return x;
}
template <class OperationType, class T>
auto VOperation(OperationType A, V<T> v) {
if (v.emp) {
decltype(GetVectorValueType(T())) tmp = Id(A);
return tmp;
}
auto tmp = VOperation(A, v[0]);
FOR(i, 1, v.sz - 1) tmp = Act(A)(tmp, VOperation(A, v[i]));
return tmp;
}
template <class OperationType, class T, class... Args>
auto VOperation(OperationType A, T x, Args... args) {
auto xResult = VOperation(A, x);
auto tmp = VOperation(A, args...);
return Act(A)(xResult, tmp);
}
ll Bset(ll a, ll b, ll c) {
if (c)
a |= b;
else
a &= ~b;
return a;
}
struct UFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
UFT(ll tsizeget, ll modeget = 0) {
tsize = tsizeget;
mode = modeget;
par.asn(tsize, -1);
if (!mode)
rank.res(tsize, 0);
}
ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
par[x] += par[y];
par[y] = x;
} else {
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = y;
} else {
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
}
ll size(ll x) { return -par[root(x)]; }
};
template <class T> struct pUFT {
public:
ll tsize;
ll now;
vll par;
vll rank;
vll mtime;
vvll sizepi;
VV<T> sizepv;
V<T> elm;
GroupSet(T) Add;
pUFT(ll tsize, GroupSet(T) Add = ADD) : tsize(tsize), Add(Add) { init(); }
void init() {
now = 0;
par.asn(tsize, -1);
rank.asn(tsize, 0);
mtime.asn(tsize, INF);
sizepi.asn(tsize, {0});
sizepv.asn(tsize, {});
}
void set(ll x, T s) {
elm[x] = s;
sizepv[x] = {s};
}
ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); }
bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); }
ll merge(ll x, ll y) {
now++;
x = root(x, now);
y = root(y, now);
if (x != y) {
if (rank[x] < rank[y]) {
elm[y] = Act(Add)(elm[x], elm[y]);
sizepi[y].pb(now);
sizepv[y].pb(elm[y]);
par[x] = y;
mtime[x] = now;
} else {
elm[x] = Act(Add)(elm[x], elm[y]);
sizepi[x].pb(now);
sizepv[x].pb(elm[x]);
par[y] = x;
mtime[y] = now;
if (rank[x] == rank[y])
rank[x]++;
}
}
return now;
}
T size(ll x, ll t) {
x = root(x, t);
return sizepv[x][UPB(sizepi[x], t) - 1];
}
};
struct wUFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
vll dweight;
wUFT(ll tsizeget, ll modeget = 0) {
tsize = tsizeget;
mode = modeget;
par.asn(tsize, -1);
if (!mode)
rank.res(tsize, 0);
dweight.asn(tsize, 0);
}
ll root(ll x) {
if (par[x] < 0)
return x;
else {
ll r = root(par[x]);
dweight[x] += dweight[par[x]];
return par[x] = r;
}
}
ll weight(ll x) {
root(x);
return dweight[x];
}
ll diff(ll x, ll y) { return weight(y) - weight(x); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y, ll w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
par[x] += par[y];
par[y] = x;
} else {
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = y;
dweight[x] = -w;
} else {
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
dweight[y] = w;
}
}
}
ll size(ll x) { return -par[root(x)]; }
};
template <class T> struct sUFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
GroupSet(T) Add;
V<T> elm;
sUFT(ll tsize, GroupSet(T) Add = ADD, ll mode = 0)
: tsize(tsize), Add(Add), mode(mode) {
init();
}
void init() {
par.asn(tsize, -1);
if (!mode)
rank.res(tsize, 0);
elm.asn(tsize, Id(Add));
}
ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
elm[x] = Act(Add)(elm[x], elm[y]);
par[y] = x;
} else {
if (rank[x] < rank[y]) {
elm[y] = Act(Add)(elm[x], elm[y]);
par[x] = y;
} else {
elm[x] = Act(Add)(elm[x], elm[y]);
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
}
T size(ll x) { return elm[root(x)]; }
T &operator[](ll x) { return elm[x]; }
};
template <typename valtype> class SegT {
public:
ll size;
vector<valtype> v;
valtype initv;
function<valtype(valtype x, valtype y)> calc;
SegT() {}
SegT(const SegT &segt) {}
SegT(ll sizeget, ll modeget = 0) {
sizeset(sizeget);
modeset(modeget);
init();
}
SegT(vector<valtype> cpyvec, ll modeget = 0) {
sizeset(cpyvec.sz);
modeset(modeget);
init();
copy(cpyvec);
}
SegT(ll sizeget, valtype initvget,
function<valtype(valtype x, valtype y)> calcget) {
sizeset(sizeget);
initv = initvget;
calc = calcget;
init();
}
SegT(vector<valtype> cpyvec, valtype initvget,
function<valtype(valtype x, valtype y)> calcget) {
sizeset(cpyvec.sz);
initv = initvget;
calc = calcget;
init();
copy(cpyvec);
}
void sizeset(ll rsize) {
size = DigN2(rsize);
if (rsize == Pow2(size - 1))
size--;
return;
}
void modeset(ll mode) {
switch (mode) {
case 0:
initv = 0;
calc = [](valtype x, valtype y) { return x + y; };
break;
case 1:
initv = INF;
calc = [](valtype x, valtype y) { return min(x, y); };
break;
case 2:
initv = -INF;
calc = [](valtype x, valtype y) { return max(x, y); };
break;
}
return;
}
void init() { v.asn(Pow2(size + 1) - 1, initv); }
void copy(vector<valtype> cpyvec) {
REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]);
}
ll i2v(ll i) const {
if (i < 0 || i >= Pow2(size))
return -1;
return Pow2(size) + i - 1;
}
ll top(ll i) const {
if (i == 0)
return -1;
return (i - 1) / 2;
}
pl bot(ll i) const {
if (i + 1 >= Pow2(size))
return mp(-1, -1);
return mp(2 * i + 1, 2 * i + 2);
}
void set(ll i, valtype x) {
i = i2v(i);
v[i] = x;
while (i > 0) {
i = top(i);
v[i] = calc(v[bot(i).fi], v[bot(i).se]);
}
return;
}
void add(ll i, valtype x) {
set(i, v[i2v(i)] + x);
return;
}
valtype operator[](const ll &i) const { return v[i2v(i)]; }
// valtype que(ll a = 0, ll b = Pow2(size) - 1) {
valtype que(ll a, ll b) {
if (a == b)
return v[i2v(a)];
if (a > b)
return initv; // swap(a, b);
valtype ans = initv;
ll ai = i2v(a);
ll bi = i2v(b);
FOR(i, 1, size + 1) {
if (a > b)
break;
if (a % Pow2(i)) {
ans = calc(ans, v[ai]);
a += Pow2(i - 1);
ai = top(ai) + 1;
} else {
ai = top(ai);
}
if (a > b)
break;
if ((b + 1) % Pow2(i)) {
ans = calc(ans, v[bi]);
b -= Pow2(i - 1);
bi = top(bi) - 1;
} else {
bi = top(bi);
}
if (a > b)
break;
}
return ans;
}
valtype que(ll b) { return que(0, b); }
valtype que() { return que(0, Pow2(size) - 1); }
};
/*template <class Type> class DP {
public:
vector<Type> v;
Type initv;
vll size, block;
DP() {}
DP(const DP &dp) {}
template<class... Args> DP(Args... args) {
block.asn(1, 1);
Initialize(args...);
}
void Initialize(Type initv_) {
initv = initv_;
v.asn(block.bk, initv);
}
template<class... Args> void Initialize(ll val, Args... args) {
size.pb(val);
block.pb(block.bk*val);
Initialize(args...);
}
};*/
pl Bezout(ll a, ll b) {
if (b != 0) {
pl xy;
xy = Bezout(b, a % b);
return mp(xy.se, xy.fi - ((a / b) * xy.se));
} else {
return mp(1, 0);
}
}
pl Bez(ll a, ll b, ll c) {
pl xy;
ll x, y, z, gc;
xy = Bezout(a, b);
gc = gcd(a, b);
if (c % gc != 0)
return mp(-1, -1);
x = xy.fi * (c / gc);
y = xy.se * (c / gc);
if (x < 0)
z = rup(-x, (b / gc));
if (x >= 0)
z = -x / (b / gc);
x += z * (b / gc);
y -= z * (a / gc);
return mp(x, y);
}
ll DigS10(ll n) {
ll ans = 0;
while (1) {
ans += n % 10;
n /= 10;
if (!n)
break;
}
return ans;
}
ll isP(ll n) {
if (n <= 1)
return 0;
FOR(i, 2, (ll)sqrt(n) + 1) {
if (n % i == 0)
return 0;
}
return 1;
}
ll Tot(ll n) {
if (n <= 0)
return 0;
ll ans = n, x = 2;
while (x * x <= n) {
if (n % x == 0) {
ans -= ans / x;
while (n % x == 0)
n /= x;
}
x++;
}
if (n > 1)
ans -= ans / n;
return ans;
}
template <class T> struct Graph {
public:
ll vSize;
ll eMode;
ll mapMode;
GroupSet(T) Add;
CompareSet(T) Less;
CompareSet(T) Equal;
VV<P<T, ll>> adj;
map<pl, T> len;
Graph(ll vSize, ll eMode = 0, ll mapMode = 0, GroupSet(T) Add = ADD,
CompareSet(T) Less = LES, CompareSet(T) Equal = EQ)
: vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Less(Less),
Equal(Equal) {}
void Init() { adj.asn(vSize, V<P<T, ll>>()); }
void AddE(ll x, ll y, T cost) {
iAddE(x, y, cost);
if (!eMode)
iAddE(y, x, cost);
}
void iAddE(ll x, ll y, T cost) {
adj[x].pb(mp(cost, y));
if (mapMode)
len[mp(x, y)] = cost;
}
P<bool, T> getE(ll x, ll y) {
if (!len.count(mp(x, y)))
return mp(false, Id(Less));
return mp(true, len[mp(x, y)]);
}
V<T> Dijk(ll x) {
V<T> ans(vSize, Id(Less));
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans[now.se] = segt[now.se].fi;
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, mp(Act(Add)(ans[now.se], i.fi), i.se));
continue;
}
if (Act(Less)(Act(Add)(ans[now.se], i.fi), segt[i.se].fi)) {
segt.set(i.se, mp(Act(Add)(ans[now.se], i.fi), i.se));
continue;
}
}
}
return ans;
}
V<P<T, vll>> rDijk(ll x) {
V<P<T, vll>> ans(vSize, mp(Id(Less), vll()));
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans[now.se].fi = segt[now.se].fi;
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, mp(Act(Add)(ans[now.se].fi, i.fi), i.se));
ans[i.se].se = {now.se};
continue;
}
if (Act(Less)(Act(Add)(ans[now.se].fi, i.fi), segt[i.se].fi)) {
segt.set(i.se, mp(Act(Add)(ans[now.se].fi, i.fi), i.se));
ans[i.se].se = {now.se};
continue;
}
if (Act(Equal)(Act(Add)(ans[now.se].fi, i.fi), segt[i.se].fi)) {
ans[i.se].se.pb(now.se);
continue;
}
}
}
return ans;
}
T Prim(ll x = 0) {
T ans = Id(Add);
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans = Act(Add)(ans, segt[now.se].fi);
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, i);
continue;
}
if (Act(Less)(i.fi, segt[i.se].fi)) {
segt.set(i.se, i);
continue;
}
}
}
return ans;
}
P<T, V<P<T, vll>>> rPrim(ll x = 0) {
P<T, V<P<T, vll>>> ans =
mp(Id(Add), V<P<T, vll>>(vSize, mp(Id(Less), vll())));
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans.se[now.se].fi = segt[now.se].fi;
ans.fi = Act(Add)(ans.fi, ans.se[now.se].fi);
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, i);
ans.se[i.se].se = {now.se};
continue;
}
if (Act(Less)(i.fi, segt[i.se].fi)) {
segt.set(i.se, i);
ans.se[i.se].se = {now.se};
continue;
}
if (Act(Equal)(i.fi, segt[i.se].fi)) {
ans.se[i.se].se.pb(now.se);
continue;
}
}
}
return ans;
}
};
template <class T> struct Sum {
public:
V<T> v, s;
ll size;
GroupSet(T) Add;
Sum(V<T> v, GroupSet(T) Add = ADD) : v(v), size(v.sz), Add(Add) {
Init();
Calc();
}
void Init() { s.asn(size + 1, Id(Add)); }
void Calc() { REP(i, size) s[i + 1] = Act(Add)(s[i], v[i]); }
T operator()(ll x) {
if (x < -1)
x = -1;
if (x > size - 1)
x = size - 1;
return s[x + 1];
}
T operator()(ll l, ll r) {
if (l < 0)
l = 0;
if (r >= size)
r = size - 1;
if (l > r)
return Id(Add);
return InvAct(Add)(s[r + 1], s[l]);
}
};
using sumll = Sum<ll>;
template <class T> struct Sum2 {
public:
VV<T> v, s;
ll RowSize, ColumnSize;
GroupSet(T) Add;
Sum2(VV<T> v, GroupSet(T) Add = ADD)
: v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add) {
Init();
Calc();
}
void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Id(Add))); }
void Calc() {
REP1(r, RowSize) {
REP1(c, ColumnSize) {
// s[r][c] = InvAct(Add)(Act(Add)(Act(Add)(v[r -
//1][c - 1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)),
//operator()(r - 2, c - 2));
s[r][c] = Act(Add)(s[r][c - 1], v[r - 1][c - 1]);
}
}
REP1(r, RowSize) {
REP1(c, ColumnSize) { s[r][c] = Act(Add)(s[r - 1][c], s[r][c]); }
}
}
T operator()(ll r, ll c) {
if (r < -1)
r = -1;
if (c < -1)
c = -1;
if (r > RowSize - 1)
r = RowSize - 1;
if (c > ColumnSize - 1)
c = ColumnSize - 1;
return s[r + 1][c + 1];
}
T operator()(ll r1, ll c1, ll r2, ll c2) {
if (r1 < 0)
r1 = 0;
if (c1 < 0)
c1 = 0;
if (r2 >= RowSize)
r2 = RowSize - 1;
if (c2 >= ColumnSize)
c2 = ColumnSize - 1;
if (r1 > r2)
return Id(Add);
if (c1 > c2)
return Id(Add);
return InvAct(Add)(Act(Add)(s[r2 + 1][c2 + 1], s[r1][c1]),
Act(Add)(s[r2 + 1][c1], s[r1][c2 + 1]));
}
};
using sumll2 = Sum2<ll>;
template <class T> struct Point2 {
public:
VV<T> v;
ll h, w;
Point2() : h(0), w(0) {}
Point2(ll h, ll w) : h(h), w(w) { asn(h, w); }
Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); }
Point2(VV<T> cv) : h(cv.sz), w(cv.sz ? cv[0].sz : 0) {
asn(h, w);
copy(cv);
}
void assign(ll h, ll w) { v.asn(h, V<T>(w)); }
void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); }
void copy(VV<T> cv) { REP(_h, h) REP(_w, w) v[_h][_w] = cv[_h][_w]; }
T &operator()(ll h, ll w) { return v[h][w]; }
T &operator()(pl p) { return v[p.fi][p.se]; }
T &operator[](pl p) { return v[p.fi][p.se]; }
};
template <class T> using P2 = Point2<T>;
template <ll Mod> struct Modll {
public:
ll v;
Modll() : v(0) {}
Modll(ll _v) { set(_v % Mod + Mod); }
Modll &set(ll _v) {
v = (_v < Mod) ? _v : (_v - Mod);
return *this;
}
Modll pow(ll n) const {
Modll x = *this, ans = 1;
while (n) {
if (n & 1)
ans *= x;
x *= x;
n >>= 1;
}
return ans;
}
Modll inverse() const { return (*this).pow(Mod - 2); }
Modll operator+(const Modll &m) const { return Modll().set(v + m.v); }
Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); }
Modll operator*(const Modll &m) const {
return Modll().set((ull(v) * m.v) % Mod);
}
Modll operator/(const Modll &m) const { return *this * m.inv; }
Modll &operator+=(const Modll &m) { return *this = *this + m; }
Modll &operator-=(const Modll &m) { return *this = *this - m; }
Modll &operator*=(const Modll &m) { return *this = *this * m; }
Modll &operator/=(const Modll &m) { return *this = *this / m; }
Modll operator-() const { return Modll(0) - *this; }
explicit operator bool() const { return v != 0; }
friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; }
friend ostream &operator<<(ostream &out, const Modll &m) {
return out << m.v;
}
};
using mll = Modll<MOD>;
using vmll = V<mll>;
using vvmll = V<vmll>;
using vvvmll = V<vvmll>;
vmll MFactMemo(2, 1);
vmll MIFactMemo(2, 1);
mll mFact(ll n) {
if (MFactMemo.sz <= n) {
ll oldsize = MFactMemo.sz;
MFactMemo.res(n + 1, 1);
FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i;
}
return MFactMemo[n];
}
mll miFact(ll n) {
if (MIFactMemo.sz <= n) {
ll oldsize = MIFactMemo.sz;
MIFactMemo.res(n + 1, 1);
MIFactMemo.bk = mFact(n).inv;
rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i;
}
return MIFactMemo[n];
}
mll mComb(ll n, ll k) {
if (n < 0 || k < 0 || n < k)
return 0;
return mFact(n) * miFact(k) * miFact(n - k);
}
ll LIS(vll v, ll m = 0) {
if (v.sz > 0) {
ll ans = 0;
vll dp(v.sz, INF);
FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; }
FOR(i, 0, v.sz - 1) {
if (dp[i] == INF)
break;
ans++;
}
return ans;
} else {
return 0;
}
}
ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) {
ll ng = mi - 1, ok = ma, mid;
while (ok - ng > 1) {
mid = (ng + ok) / 2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
template <class T, class M = decltype(MUL), class S = decltype(ADD)>
VV<T> MultiMatrix(VV<T> A, VV<T> B, M Mul = MUL, S Add = ADD) {
VV<T> ans;
ll ii = A.sz;
if (!ii)
return ans;
ll jj = A[0].sz;
if (!jj)
return ans;
ll jj2 = B.sz;
if (!jj2)
return ans;
if (jj != jj2)
return ans;
ll kk = B[0].sz;
if (!kk)
return ans;
ans.asn(ii, V<T>(kk, 0));
REP(i, ii) {
REP(k, kk) {
REP(j, jj) {
ans[i][k] = Act(Add)(ans[i][k], Act(Mul)(A[i][j], B[j][k]));
}
}
}
return ans;
}
vvll CombMemo(1000, vll(1000, -1));
ll Comb(ll n, ll k) {
if ((n < 0) || (k < 0))
return 0;
if (CombMemo[n][k] == -1) {
if (n < k)
CombMemo[n][k] = 0;
else {
if (n == 0)
CombMemo[n][k] = 1;
else if (k == 0)
CombMemo[n][k] = 1;
else if (n == k)
CombMemo[n][k] = 1;
else
CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k);
}
}
return CombMemo[n][k];
}
template <class T> map<T, ll> Dict(V<T> v) {
map<T, ll> m;
if (!v.sz)
return m;
SORT(v);
UNIQUE(v);
REP(i, v.sz) { m[v[i]] = i; }
return m;
}
template <class T> vll Cmprs(V<T> v) {
auto m = Dict(v);
vll ans(v.sz);
REP(i, v.sz) { ans[i] = m[v[i]]; }
return ans;
}
template <class T> vll PCmprs(V<T> v) {
if (v.sz == 0)
return V<T>();
vll tmp(v.sz);
vll ans(v.sz);
IOTA(tmp, 0);
IOTA(ans, 0);
sort(tmp.bgn, tmp.en, clam(v[l] < v[r]));
sort(ans.bgn, ans.en, clam(tmp[l] < tmp[r]));
return ans;
}
ll BblCnt(vll rv) {
vll v = PCmprs(rv);
SegT<ll> b(v.sz, 0);
ll ans = 0;
REP(i, v.sz) {
ans += (i - b.que(0, v[i]));
b.add(v[i], 1);
}
return ans;
}
pl NGrid(pl p, ll i, ll H, ll W) {
p = mp(p.fi + DX[i], p.se + DY[i]);
if (p.fi < 0 || p.fi >= H || p.se < 0 || p.se >= W)
return mp(INF, INF);
return p;
}
vvll llGrid(vs v) {
vvll r(v.sz, vll(v.sz ? v[0].sz : 0, 0));
REP(h, v.sz) REP(w, v.sz ? v[0].sz : 0) r[h][w] = (v[h][w] == '#');
return r;
}
template <class T> auto ven(T val) { return val; }
template <> auto ven<int>(int val) { return (ll)val; }
template <class T, class... Args> auto ven(T val, Args... args) {
auto tmp = ven(args...);
return V<decltype(tmp)>(val, tmp);
}
template <class T> void zind(T &v) { v--; }
template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); }
template <class T, class... Args> void zind(T &v, Args &...args) {
zind(v);
zind(args...);
}
void Solve();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
void Solve() {
si(s, t);
vvll dp(3010, vll(3010, 0));
REP1(i, s.sz) {
REP1(j, t.sz) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else if (dp[i][j - 1] > dp[i - 1][j]) {
dp[i][j] = dp[i][j - 1];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
ll k = s.sz, l = t.sz;
string r = "";
while (k + l) {
if (dp[k][l] == dp[k - 1][l]) {
k--;
} else if (dp[k][l] == dp[k][l - 1]) {
l--;
} else {
k--;
l--;
r = s[k] + r;
}
}
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;
using ll = long long;
using ull = unsigned long long;
using dbl = double;
using str = string;
using vll = V<ll>;
using vvll = V<vll>;
using vvvll = V<vvll>;
using pl = P<ll, ll>;
using tl = TP<ll, ll, ll>;
using vpl = V<pl>;
using vvpl = V<vpl>;
using vtl = V<tl>;
using vvtl = V<vtl>;
using vs = V<str>;
using vvs = V<vs>;
using vd = V<dbl>;
using vvd = V<vd>;
using qll = queue<ll>;
using qpl = queue<pl>;
using stll = stack<ll>;
using stpl = stack<pl>;
using mapll = map<ll, ll>;
using setll = set<ll>;
using pqll = priority_queue<ll>;
//#define int ll
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define sz size()
#define bgn begin()
#define en end()
#define asn assign
#define emp empty()
#define fr front()
#define bk back()
#define clr clear()
#define ins insert
#define ers erase
#define res resize
#define tp top()
#define p_q priority_queue
#define inv inverse()
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--)
#define REP(i, a) FOR((i), 0, (ll)(a)-1)
#define REP0(i, a) FOR((i), 0, (ll)(a))
#define REP1(i, a) FOR((i), 1, (ll)(a))
#define rREP(i, a) rFOR((i), 0, (ll)(a)-1)
#define rREP0(i, a) rFOR((i), 0, (ll)(a))
#define rREP1(i, a) rFOR((i), 1, (ll)(a))
#define ROR(v, i) for (auto &(i) : (v))
#define IOTA(a, n) iota((a).bgn, (a).en, (n))
#define SORT(a) sort((a).bgn, (a).en)
#define rSORT(a) sort((a).rbegin(), (a).rend())
#define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en)
#define PREVP(a) prev_permutation((a).bgn, (a).en)
#define NEXTP(a) next_permutation((a).bgn, (a).en)
#define BINS(a, b) binary_search((a).bgn, (a).en, (b))
#define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn)
#define CNT(a, b) count((a).bgn, (a).en, b)
#define SUM(a) accumulate((a).bgn, (a).en, 0)
#define REV(a) reverse((a).bgn, (a).en)
#define REGS(a, b) regex_search((a), regex(b))
#define REGM(a, b) regex_match((a), regex(b))
#define yn(a) cout << ((a) ? "yes" : "no") << "\n";
#define Yn(a) cout << ((a) ? "Yes" : "No") << "\n";
#define YN(a) cout << ((a) ? "YES" : "NO") << "\n";
#define imp(a) cout << ((a) ? "possible" : "impossible") << "\n";
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n";
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
#define fs(a) cout << ((a) ? "second" : "first") << "\n";
#define Fs(a) cout << ((a) ? "Second" : "First") << "\n";
#define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n";
//#define say(a) cout <<(a);
//#define sal(a) cout <<(a)<<"\n";
#define sak cout << "\n";
#define sas cout << " ";
#define sat cout << "\t";
#define dbg(a) cerr << (#a) << ": " << (a) << "\n";
#define dbgs(...) \
dal(#__VA_ARGS__); \
dal(__VA_ARGS__);
#define c2l(a) ((ll)(a - 48))
#define a2l(a) ((ll)(a - 97))
#define A2l(a) ((ll)(a - 65))
#define l2c(a) ((char)(a + 48))
#define l2a(a) ((char)(a + 97))
#define l2A(a) ((char)(a + 65))
#define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1))
#define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1))
#define Dig2(a, b) (((a) >> (b)) & 1)
#define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10)
#define Pow2(a) ((ll)(1) << (a))
#define Pow10(a) ((ll)(pow(10.0, double(a))))
#define LSB(a) ((a) & (-(a)))
/*#define llin(a) ll (a);cin >>(a);
#define llin2(a,b) ll (a),(b);cin >>(a)>>(b);
#define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c);
#define stin(a) string (a);cin >>(a);*/
#define vin(v) \
ROR((v), (i)) { cin >> (i); };
#define vllin(N, v) \
vll(v)((N)); \
vin(v);
#define vllin2(N, a, b) \
vll(a)(N), (b)(N); \
REP(i, N) { cin >> (a)[i] >> (b)[i]; };
#define vsin(N, v) \
vs(v)((N)); \
vin(v);
#define rdn(a, b) ((a) / (b))
#define rou(a, b) \
((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \
: (((a) / (b)) + 1))
#define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1))
#define powll(a, b) (ll)(pow((double)(a), (double)(b)))
#define Triangle(x1, y1, x2, y2, x3, y3) \
(((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2)))
#define tg(t, i) get<i>(t)
#define Id(x) get<0>(x)
#define Act(x) get<1>(x)
#define InvAct(x) get<2>(x)
#define mg(id, act) mt(id, act, lam(l))
//#define MonoidSet(T) TP<T, function<T(T, T)>>
#define GroupSet(T) TP<T, function<T(T, T)>, function<T(T, T)>>
#define CompareSet(T) TP<T, function<bool(T, T)>>
#define lam(lr) ([](auto l, auto r) { return (lr); })
#define elam(lr) ([=](auto l, auto r) { return (lr); })
#define clam(lr) ([&](auto l, auto r) { return (lr); })
#define lamr(lr) ([](auto l, auto r) { lr })
#define elamr(lr) ([=](auto l, auto r) { lr })
#define clamr(lr) ([&](auto l, auto r) { lr })
#define min(...) Operation(MIN, __VA_ARGS__)
#define max(...) Operation(MAX, __VA_ARGS__)
#define gcd(...) Operation(GCD, __VA_ARGS__)
#define lcm(...) Operation(LCM, __VA_ARGS__)
#define vmin(...) VOperation(MIN, __VA_ARGS__)
#define vmax(...) VOperation(MAX, __VA_ARGS__)
#define vgcd(...) VOperation(GCD, __VA_ARGS__)
#define vlcm(...) VOperation(LCM, __VA_ARGS__)
#define vsum(...) VOperation(ADD, __VA_ARGS__)
#define vpro(...) VOperation(MUL, __VA_ARGS__)
#define emin(a, ...) ((a) = min((a), __VA_ARGS__))
#define emax(a, ...) ((a) = max((a), __VA_ARGS__))
#define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__))
#define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__))
#define ope Operation
#define vope VOperation
#define svll SumV<ll>
#define svvll SumV2<ll>
#define li(...) \
ll __VA_ARGS__; \
Input(__VA_ARGS__);
#define si(...) \
str __VA_ARGS__; \
Input(__VA_ARGS__);
//#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__);
#define vlr(size, ...) \
vll __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vlc(size, ...) \
vll __VA_ARGS__; \
vInitInputC(size, __VA_ARGS__);
#define vli(size, ...) \
vll __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vsr(size, ...) \
vs __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vsc(size, ...) \
vs __VA_ARGS__; \
vInitInputC(size, __VA_ARGS__);
#define vsi(size, ...) \
vs __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vli2(rowSize, columnSize, ...) \
vvll __VA_ARGS__; \
vInitInput2(rowSize, columnSize, __VA_ARGS__);
#define vplr(size, ...) \
vpl __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
#define vplc(size, ...) \
vpl __VA_ARGS__; \
vInitInputC(size, __VA_ARGS__);
#define vpli(size, ...) \
vpl __VA_ARGS__; \
vInitInputR(size, __VA_ARGS__);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = 924844033;
// const ll MOD = 9007199254740881;
const ll INF = 1LL << 60; // 1.15e18
const double PI = acos(-1.0);
const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1};
const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1};
const str alp = "abcdefghijklmnopqrstuvwxyz";
const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template <class T> auto GetVectorValueType(T v) { return v; }
template <class T> auto GetVectorValueType(V<T> v) {
return GetVectorValueType(T());
}
template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) {
return in >> p.fi >> p.se;
}
template <class T> istream &operator>>(istream &in, V<T> &v) {
REP(i, v.sz) in >> v[i];
return in;
}
void Input() {}
template <class Var, class... Args> void Input(Var &var, Args &...args) {
cin >> var;
Input(args...);
}
void vInit(ll size) {}
template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) {
v.res(size);
vInit(size, args...);
}
void vInput(ll size) {}
template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) {
REP(i, size) cin >> v[i];
vInput(size, args...);
}
void vInputR(ll size) {}
template <class T, class... Args>
void vInputR(ll size, V<T> &v, Args &...args) {
REP(i, size) cin >> v[i];
vInputR(size, args...);
}
void vInputNumC(ll num) {}
template <class T, class... Args>
void vInputNumC(ll num, V<T> &v, Args &...args) {
cin >> v[num];
vInputNumC(num, args...);
}
void vInputC(ll size) {}
template <class... Args> void vInputC(ll size, Args &...args) {
REP(i, size) vInputNumC(i, args...);
}
void vInitInputR(ll size) {}
template <class... Args> void vInitInputR(ll size, Args &...args) {
vInit(size, args...);
vInputR(size, args...);
}
void vInitInputC(ll size) {}
template <class... Args> void vInitInputC(ll size, Args &...args) {
vInit(size, args...);
vInputC(size, args...);
}
void vInit2(ll rowSize, ll columnSize) {}
template <class T, class... Args>
void vInit2(ll rowSize, ll columnSize, VV<T> &v, Args &...args) {
v.asn(rowSize, V<T>(columnSize));
vInit2(rowSize, columnSize, args...);
}
void vInput2(ll rowSize, ll columnSize) {}
template <class T, class... Args>
void vInput2(ll rowSize, ll columnSize, VV<T> &v, Args &...args) {
REP(r, rowSize) {
REP(c, columnSize) { cin >> v[r][c]; }
}
vInput2(rowSize, columnSize, args...);
}
void vInitInput2(ll rowSize, ll columnSize) {}
template <class... Args>
void vInitInput2(ll rowSize, ll columnSize, Args &...args) {
vInit2(rowSize, columnSize, args...);
vInput2(rowSize, columnSize, args...);
}
template <class S, class T>
ostream &operator<<(ostream &out, const P<S, T> &p) {
return out << "[" << p.fi << ", " << p.se << "]";
}
template <class T> ostream &operator<<(ostream &out, V<T> &v) {
if (v.emp)
return out << "{}";
else {
auto itr = v.bgn;
out << "{" << *itr;
itr++;
while (itr != v.en) {
out << ", " << *itr;
itr++;
}
out << "}";
return out;
}
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> &m) {
if (m.emp)
return out << "<[]>";
else {
auto itr = m.bgn;
out << "< [" << (itr->fi) << ": " << (itr->se);
itr++;
while (itr != m.en) {
out << "], [" << (itr->fi) << ": " << (itr->se);
itr++;
}
out << "] >";
return out;
}
}
template <class T> ostream &operator<<(ostream &out, const set<T> &s) {
if (s.emp)
return out << "<>";
else {
auto itr = s.bgn;
out << "<" << *itr;
itr++;
while (itr != s.en) {
out << ", " << *itr;
itr++;
}
out << ">";
return out;
}
}
void say() {}
template <class T> void say(T t) { cout << t; }
template <class Head, class... Body> void say(Head head, Body... body) {
cout << head << " ";
say(body...);
}
void sal() { cout << "\n"; }
template <class... Args> void sal(Args... args) {
say(args...);
cout << "\n";
}
void day() {}
template <class T> void day(T t) { cerr << t; }
template <class Head, class... Body> void day(Head head, Body... body) {
cerr << head << " ";
day(body...);
}
void dal() { cerr << "\n"; }
template <class... Args> void dal(Args... args) {
day(args...);
cerr << "\n";
}
void salv() {}
template <class T> void salv(V<T> v) {
if (v.emp)
sal();
else {
auto itr = v.bgn;
say(*itr);
itr++;
while (itr != v.en) {
sas;
say(*itr);
itr++;
}
sak;
}
}
template <class T> void salv(VV<T> v) {
if (v.emp)
sal();
else {
ROR(v, i) salv(i);
}
}
template <class T, class... Args> void salv(T v, Args... args) {
salv(v);
salv(args...);
}
template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) {
if (l < r)
swap(l, r);
return r ? Gcd(r, l % r) : l;
}
template <class L, class R> auto Lcm(L l, R r) {
if (!l || !r)
return 0;
return l / Gcd(l, r) * r;
}
/*
auto LES = mp(INF, lam(return l < r;));
auto GRT = mp(-INF, lam(return l > r;));
auto EQ = mp(0, lam(return l == r;));
auto ADD = mp(0, lam(return l + r;));
auto SUB = mp(0, lam(return l - r;));
auto MUL = mp(1, lam(return l * r;));
auto DIV = mp(1, lam(return l / r;));
auto MDL = mp(1, lam(return l % r;));
auto XOR = mp(0, lam(return l ^ r;));
auto OR = mp(0, lam(return l | r;));
auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;));
auto MIN = mp(INF, lam(return (l < r) ? l : r;));
auto MAX = mp(-INF, lam(return (l > r) ? l : r;));
auto GCD = mp(0, lam(return Gcd(l, r);));
auto LCM = mp(1, lam(return Lcm(l, r);));
*/
auto LES = mp(INF, lam(l < r));
auto GRT = mp(-INF, lam(l > r));
auto EQ = mp(0, lam(l == r));
auto ADD = mt(0, lam(l + r), lam(l - r));
auto MUL = mt(1, lam(l *r), lam(l / r));
auto XOR = mt(0, lam(l ^ r), lam(l ^ r));
auto OR = mg(0, lam(l | r));
auto AND = mg(((ll)(1) << 63) - 1, lam(l &r));
auto MIN = mg(0, lam((l < r) ? l : r));
auto MAX = mg(0, lam((l > r) ? l : r));
auto GCD = mg(0, lam(Gcd(l, r)));
auto LCM = mg(0, lam(Lcm(l, r)));
template <class OperationType> auto Operation(OperationType A) { return Id(A); }
template <class OperationType, class T> auto Operation(OperationType A, T x) {
return x;
}
template <class OperationType, class T, class... Args>
auto Operation(OperationType A, T x, Args... args) {
auto tmp = Operation(A, args...);
return Act(A)(x, tmp);
}
template <class OperationType> auto VOperation(OperationType A) {
return Id(A);
}
template <class OperationType, class T> auto VOperation(OperationType A, T x) {
return x;
}
template <class OperationType, class T>
auto VOperation(OperationType A, V<T> v) {
if (v.emp) {
decltype(GetVectorValueType(T())) tmp = Id(A);
return tmp;
}
auto tmp = VOperation(A, v[0]);
FOR(i, 1, v.sz - 1) tmp = Act(A)(tmp, VOperation(A, v[i]));
return tmp;
}
template <class OperationType, class T, class... Args>
auto VOperation(OperationType A, T x, Args... args) {
auto xResult = VOperation(A, x);
auto tmp = VOperation(A, args...);
return Act(A)(xResult, tmp);
}
ll Bset(ll a, ll b, ll c) {
if (c)
a |= b;
else
a &= ~b;
return a;
}
struct UFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
UFT(ll tsizeget, ll modeget = 0) {
tsize = tsizeget;
mode = modeget;
par.asn(tsize, -1);
if (!mode)
rank.res(tsize, 0);
}
ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
par[x] += par[y];
par[y] = x;
} else {
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = y;
} else {
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
}
ll size(ll x) { return -par[root(x)]; }
};
template <class T> struct pUFT {
public:
ll tsize;
ll now;
vll par;
vll rank;
vll mtime;
vvll sizepi;
VV<T> sizepv;
V<T> elm;
GroupSet(T) Add;
pUFT(ll tsize, GroupSet(T) Add = ADD) : tsize(tsize), Add(Add) { init(); }
void init() {
now = 0;
par.asn(tsize, -1);
rank.asn(tsize, 0);
mtime.asn(tsize, INF);
sizepi.asn(tsize, {0});
sizepv.asn(tsize, {});
}
void set(ll x, T s) {
elm[x] = s;
sizepv[x] = {s};
}
ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); }
bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); }
ll merge(ll x, ll y) {
now++;
x = root(x, now);
y = root(y, now);
if (x != y) {
if (rank[x] < rank[y]) {
elm[y] = Act(Add)(elm[x], elm[y]);
sizepi[y].pb(now);
sizepv[y].pb(elm[y]);
par[x] = y;
mtime[x] = now;
} else {
elm[x] = Act(Add)(elm[x], elm[y]);
sizepi[x].pb(now);
sizepv[x].pb(elm[x]);
par[y] = x;
mtime[y] = now;
if (rank[x] == rank[y])
rank[x]++;
}
}
return now;
}
T size(ll x, ll t) {
x = root(x, t);
return sizepv[x][UPB(sizepi[x], t) - 1];
}
};
struct wUFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
vll dweight;
wUFT(ll tsizeget, ll modeget = 0) {
tsize = tsizeget;
mode = modeget;
par.asn(tsize, -1);
if (!mode)
rank.res(tsize, 0);
dweight.asn(tsize, 0);
}
ll root(ll x) {
if (par[x] < 0)
return x;
else {
ll r = root(par[x]);
dweight[x] += dweight[par[x]];
return par[x] = r;
}
}
ll weight(ll x) {
root(x);
return dweight[x];
}
ll diff(ll x, ll y) { return weight(y) - weight(x); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y, ll w) {
w += weight(x);
w -= weight(y);
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
par[x] += par[y];
par[y] = x;
} else {
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = y;
dweight[x] = -w;
} else {
par[x] += par[y];
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
dweight[y] = w;
}
}
}
ll size(ll x) { return -par[root(x)]; }
};
template <class T> struct sUFT {
public:
ll tsize;
ll mode;
vll par;
vll rank;
GroupSet(T) Add;
V<T> elm;
sUFT(ll tsize, GroupSet(T) Add = ADD, ll mode = 0)
: tsize(tsize), Add(Add), mode(mode) {
init();
}
void init() {
par.asn(tsize, -1);
if (!mode)
rank.res(tsize, 0);
elm.asn(tsize, Id(Add));
}
ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
bool isRoot(ll x) { return x == root(x); }
bool same(ll x, ll y) { return root(x) == root(y); }
void merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (mode) {
elm[x] = Act(Add)(elm[x], elm[y]);
par[y] = x;
} else {
if (rank[x] < rank[y]) {
elm[y] = Act(Add)(elm[x], elm[y]);
par[x] = y;
} else {
elm[x] = Act(Add)(elm[x], elm[y]);
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
}
T size(ll x) { return elm[root(x)]; }
T &operator[](ll x) { return elm[x]; }
};
template <typename valtype> class SegT {
public:
ll size;
vector<valtype> v;
valtype initv;
function<valtype(valtype x, valtype y)> calc;
SegT() {}
SegT(const SegT &segt) {}
SegT(ll sizeget, ll modeget = 0) {
sizeset(sizeget);
modeset(modeget);
init();
}
SegT(vector<valtype> cpyvec, ll modeget = 0) {
sizeset(cpyvec.sz);
modeset(modeget);
init();
copy(cpyvec);
}
SegT(ll sizeget, valtype initvget,
function<valtype(valtype x, valtype y)> calcget) {
sizeset(sizeget);
initv = initvget;
calc = calcget;
init();
}
SegT(vector<valtype> cpyvec, valtype initvget,
function<valtype(valtype x, valtype y)> calcget) {
sizeset(cpyvec.sz);
initv = initvget;
calc = calcget;
init();
copy(cpyvec);
}
void sizeset(ll rsize) {
size = DigN2(rsize);
if (rsize == Pow2(size - 1))
size--;
return;
}
void modeset(ll mode) {
switch (mode) {
case 0:
initv = 0;
calc = [](valtype x, valtype y) { return x + y; };
break;
case 1:
initv = INF;
calc = [](valtype x, valtype y) { return min(x, y); };
break;
case 2:
initv = -INF;
calc = [](valtype x, valtype y) { return max(x, y); };
break;
}
return;
}
void init() { v.asn(Pow2(size + 1) - 1, initv); }
void copy(vector<valtype> cpyvec) {
REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]);
}
ll i2v(ll i) const {
if (i < 0 || i >= Pow2(size))
return -1;
return Pow2(size) + i - 1;
}
ll top(ll i) const {
if (i == 0)
return -1;
return (i - 1) / 2;
}
pl bot(ll i) const {
if (i + 1 >= Pow2(size))
return mp(-1, -1);
return mp(2 * i + 1, 2 * i + 2);
}
void set(ll i, valtype x) {
i = i2v(i);
v[i] = x;
while (i > 0) {
i = top(i);
v[i] = calc(v[bot(i).fi], v[bot(i).se]);
}
return;
}
void add(ll i, valtype x) {
set(i, v[i2v(i)] + x);
return;
}
valtype operator[](const ll &i) const { return v[i2v(i)]; }
// valtype que(ll a = 0, ll b = Pow2(size) - 1) {
valtype que(ll a, ll b) {
if (a == b)
return v[i2v(a)];
if (a > b)
return initv; // swap(a, b);
valtype ans = initv;
ll ai = i2v(a);
ll bi = i2v(b);
FOR(i, 1, size + 1) {
if (a > b)
break;
if (a % Pow2(i)) {
ans = calc(ans, v[ai]);
a += Pow2(i - 1);
ai = top(ai) + 1;
} else {
ai = top(ai);
}
if (a > b)
break;
if ((b + 1) % Pow2(i)) {
ans = calc(ans, v[bi]);
b -= Pow2(i - 1);
bi = top(bi) - 1;
} else {
bi = top(bi);
}
if (a > b)
break;
}
return ans;
}
valtype que(ll b) { return que(0, b); }
valtype que() { return que(0, Pow2(size) - 1); }
};
/*template <class Type> class DP {
public:
vector<Type> v;
Type initv;
vll size, block;
DP() {}
DP(const DP &dp) {}
template<class... Args> DP(Args... args) {
block.asn(1, 1);
Initialize(args...);
}
void Initialize(Type initv_) {
initv = initv_;
v.asn(block.bk, initv);
}
template<class... Args> void Initialize(ll val, Args... args) {
size.pb(val);
block.pb(block.bk*val);
Initialize(args...);
}
};*/
pl Bezout(ll a, ll b) {
if (b != 0) {
pl xy;
xy = Bezout(b, a % b);
return mp(xy.se, xy.fi - ((a / b) * xy.se));
} else {
return mp(1, 0);
}
}
pl Bez(ll a, ll b, ll c) {
pl xy;
ll x, y, z, gc;
xy = Bezout(a, b);
gc = gcd(a, b);
if (c % gc != 0)
return mp(-1, -1);
x = xy.fi * (c / gc);
y = xy.se * (c / gc);
if (x < 0)
z = rup(-x, (b / gc));
if (x >= 0)
z = -x / (b / gc);
x += z * (b / gc);
y -= z * (a / gc);
return mp(x, y);
}
ll DigS10(ll n) {
ll ans = 0;
while (1) {
ans += n % 10;
n /= 10;
if (!n)
break;
}
return ans;
}
ll isP(ll n) {
if (n <= 1)
return 0;
FOR(i, 2, (ll)sqrt(n) + 1) {
if (n % i == 0)
return 0;
}
return 1;
}
ll Tot(ll n) {
if (n <= 0)
return 0;
ll ans = n, x = 2;
while (x * x <= n) {
if (n % x == 0) {
ans -= ans / x;
while (n % x == 0)
n /= x;
}
x++;
}
if (n > 1)
ans -= ans / n;
return ans;
}
template <class T> struct Graph {
public:
ll vSize;
ll eMode;
ll mapMode;
GroupSet(T) Add;
CompareSet(T) Less;
CompareSet(T) Equal;
VV<P<T, ll>> adj;
map<pl, T> len;
Graph(ll vSize, ll eMode = 0, ll mapMode = 0, GroupSet(T) Add = ADD,
CompareSet(T) Less = LES, CompareSet(T) Equal = EQ)
: vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Less(Less),
Equal(Equal) {}
void Init() { adj.asn(vSize, V<P<T, ll>>()); }
void AddE(ll x, ll y, T cost) {
iAddE(x, y, cost);
if (!eMode)
iAddE(y, x, cost);
}
void iAddE(ll x, ll y, T cost) {
adj[x].pb(mp(cost, y));
if (mapMode)
len[mp(x, y)] = cost;
}
P<bool, T> getE(ll x, ll y) {
if (!len.count(mp(x, y)))
return mp(false, Id(Less));
return mp(true, len[mp(x, y)]);
}
V<T> Dijk(ll x) {
V<T> ans(vSize, Id(Less));
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans[now.se] = segt[now.se].fi;
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, mp(Act(Add)(ans[now.se], i.fi), i.se));
continue;
}
if (Act(Less)(Act(Add)(ans[now.se], i.fi), segt[i.se].fi)) {
segt.set(i.se, mp(Act(Add)(ans[now.se], i.fi), i.se));
continue;
}
}
}
return ans;
}
V<P<T, vll>> rDijk(ll x) {
V<P<T, vll>> ans(vSize, mp(Id(Less), vll()));
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans[now.se].fi = segt[now.se].fi;
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, mp(Act(Add)(ans[now.se].fi, i.fi), i.se));
ans[i.se].se = {now.se};
continue;
}
if (Act(Less)(Act(Add)(ans[now.se].fi, i.fi), segt[i.se].fi)) {
segt.set(i.se, mp(Act(Add)(ans[now.se].fi, i.fi), i.se));
ans[i.se].se = {now.se};
continue;
}
if (Act(Equal)(Act(Add)(ans[now.se].fi, i.fi), segt[i.se].fi)) {
ans[i.se].se.pb(now.se);
continue;
}
}
}
return ans;
}
T Prim(ll x = 0) {
T ans = Id(Add);
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans = Act(Add)(ans, segt[now.se].fi);
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, i);
continue;
}
if (Act(Less)(i.fi, segt[i.se].fi)) {
segt.set(i.se, i);
continue;
}
}
}
return ans;
}
P<T, V<P<T, vll>>> rPrim(ll x = 0) {
P<T, V<P<T, vll>>> ans =
mp(Id(Add), V<P<T, vll>>(vSize, mp(Id(Less), vll())));
if (x < 0 || x >= vSize)
return ans;
SegT<P<T, ll>> segt(vSize, mp(Id(Less), -1),
clamr(if (l.se < 0) return r; if (r.se < 0) return l;
return Act(Less)(l.fi, r.fi) ? l : r;));
segt.set(x, mp(Id(Add), x));
P<T, ll> now;
while ((now = segt.que(0, vSize - 1)).se >= 0) {
ans.se[now.se].fi = segt[now.se].fi;
ans.fi = Act(Add)(ans.fi, ans.se[now.se].fi);
segt.set(now.se, mp(Id(Less), -2));
ROR(adj[now.se], i) {
if (segt[i.se].se == -2)
continue;
if (segt[i.se].se == -1) {
segt.set(i.se, i);
ans.se[i.se].se = {now.se};
continue;
}
if (Act(Less)(i.fi, segt[i.se].fi)) {
segt.set(i.se, i);
ans.se[i.se].se = {now.se};
continue;
}
if (Act(Equal)(i.fi, segt[i.se].fi)) {
ans.se[i.se].se.pb(now.se);
continue;
}
}
}
return ans;
}
};
template <class T> struct Sum {
public:
V<T> v, s;
ll size;
GroupSet(T) Add;
Sum(V<T> v, GroupSet(T) Add = ADD) : v(v), size(v.sz), Add(Add) {
Init();
Calc();
}
void Init() { s.asn(size + 1, Id(Add)); }
void Calc() { REP(i, size) s[i + 1] = Act(Add)(s[i], v[i]); }
T operator()(ll x) {
if (x < -1)
x = -1;
if (x > size - 1)
x = size - 1;
return s[x + 1];
}
T operator()(ll l, ll r) {
if (l < 0)
l = 0;
if (r >= size)
r = size - 1;
if (l > r)
return Id(Add);
return InvAct(Add)(s[r + 1], s[l]);
}
};
using sumll = Sum<ll>;
template <class T> struct Sum2 {
public:
VV<T> v, s;
ll RowSize, ColumnSize;
GroupSet(T) Add;
Sum2(VV<T> v, GroupSet(T) Add = ADD)
: v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add) {
Init();
Calc();
}
void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Id(Add))); }
void Calc() {
REP1(r, RowSize) {
REP1(c, ColumnSize) {
// s[r][c] = InvAct(Add)(Act(Add)(Act(Add)(v[r -
//1][c - 1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)),
//operator()(r - 2, c - 2));
s[r][c] = Act(Add)(s[r][c - 1], v[r - 1][c - 1]);
}
}
REP1(r, RowSize) {
REP1(c, ColumnSize) { s[r][c] = Act(Add)(s[r - 1][c], s[r][c]); }
}
}
T operator()(ll r, ll c) {
if (r < -1)
r = -1;
if (c < -1)
c = -1;
if (r > RowSize - 1)
r = RowSize - 1;
if (c > ColumnSize - 1)
c = ColumnSize - 1;
return s[r + 1][c + 1];
}
T operator()(ll r1, ll c1, ll r2, ll c2) {
if (r1 < 0)
r1 = 0;
if (c1 < 0)
c1 = 0;
if (r2 >= RowSize)
r2 = RowSize - 1;
if (c2 >= ColumnSize)
c2 = ColumnSize - 1;
if (r1 > r2)
return Id(Add);
if (c1 > c2)
return Id(Add);
return InvAct(Add)(Act(Add)(s[r2 + 1][c2 + 1], s[r1][c1]),
Act(Add)(s[r2 + 1][c1], s[r1][c2 + 1]));
}
};
using sumll2 = Sum2<ll>;
template <class T> struct Point2 {
public:
VV<T> v;
ll h, w;
Point2() : h(0), w(0) {}
Point2(ll h, ll w) : h(h), w(w) { asn(h, w); }
Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); }
Point2(VV<T> cv) : h(cv.sz), w(cv.sz ? cv[0].sz : 0) {
asn(h, w);
copy(cv);
}
void assign(ll h, ll w) { v.asn(h, V<T>(w)); }
void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); }
void copy(VV<T> cv) { REP(_h, h) REP(_w, w) v[_h][_w] = cv[_h][_w]; }
T &operator()(ll h, ll w) { return v[h][w]; }
T &operator()(pl p) { return v[p.fi][p.se]; }
T &operator[](pl p) { return v[p.fi][p.se]; }
};
template <class T> using P2 = Point2<T>;
template <ll Mod> struct Modll {
public:
ll v;
Modll() : v(0) {}
Modll(ll _v) { set(_v % Mod + Mod); }
Modll &set(ll _v) {
v = (_v < Mod) ? _v : (_v - Mod);
return *this;
}
Modll pow(ll n) const {
Modll x = *this, ans = 1;
while (n) {
if (n & 1)
ans *= x;
x *= x;
n >>= 1;
}
return ans;
}
Modll inverse() const { return (*this).pow(Mod - 2); }
Modll operator+(const Modll &m) const { return Modll().set(v + m.v); }
Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); }
Modll operator*(const Modll &m) const {
return Modll().set((ull(v) * m.v) % Mod);
}
Modll operator/(const Modll &m) const { return *this * m.inv; }
Modll &operator+=(const Modll &m) { return *this = *this + m; }
Modll &operator-=(const Modll &m) { return *this = *this - m; }
Modll &operator*=(const Modll &m) { return *this = *this * m; }
Modll &operator/=(const Modll &m) { return *this = *this / m; }
Modll operator-() const { return Modll(0) - *this; }
explicit operator bool() const { return v != 0; }
friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; }
friend ostream &operator<<(ostream &out, const Modll &m) {
return out << m.v;
}
};
using mll = Modll<MOD>;
using vmll = V<mll>;
using vvmll = V<vmll>;
using vvvmll = V<vvmll>;
vmll MFactMemo(2, 1);
vmll MIFactMemo(2, 1);
mll mFact(ll n) {
if (MFactMemo.sz <= n) {
ll oldsize = MFactMemo.sz;
MFactMemo.res(n + 1, 1);
FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i;
}
return MFactMemo[n];
}
mll miFact(ll n) {
if (MIFactMemo.sz <= n) {
ll oldsize = MIFactMemo.sz;
MIFactMemo.res(n + 1, 1);
MIFactMemo.bk = mFact(n).inv;
rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i;
}
return MIFactMemo[n];
}
mll mComb(ll n, ll k) {
if (n < 0 || k < 0 || n < k)
return 0;
return mFact(n) * miFact(k) * miFact(n - k);
}
ll LIS(vll v, ll m = 0) {
if (v.sz > 0) {
ll ans = 0;
vll dp(v.sz, INF);
FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; }
FOR(i, 0, v.sz - 1) {
if (dp[i] == INF)
break;
ans++;
}
return ans;
} else {
return 0;
}
}
ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) {
ll ng = mi - 1, ok = ma, mid;
while (ok - ng > 1) {
mid = (ng + ok) / 2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
template <class T, class M = decltype(MUL), class S = decltype(ADD)>
VV<T> MultiMatrix(VV<T> A, VV<T> B, M Mul = MUL, S Add = ADD) {
VV<T> ans;
ll ii = A.sz;
if (!ii)
return ans;
ll jj = A[0].sz;
if (!jj)
return ans;
ll jj2 = B.sz;
if (!jj2)
return ans;
if (jj != jj2)
return ans;
ll kk = B[0].sz;
if (!kk)
return ans;
ans.asn(ii, V<T>(kk, 0));
REP(i, ii) {
REP(k, kk) {
REP(j, jj) {
ans[i][k] = Act(Add)(ans[i][k], Act(Mul)(A[i][j], B[j][k]));
}
}
}
return ans;
}
vvll CombMemo(1000, vll(1000, -1));
ll Comb(ll n, ll k) {
if ((n < 0) || (k < 0))
return 0;
if (CombMemo[n][k] == -1) {
if (n < k)
CombMemo[n][k] = 0;
else {
if (n == 0)
CombMemo[n][k] = 1;
else if (k == 0)
CombMemo[n][k] = 1;
else if (n == k)
CombMemo[n][k] = 1;
else
CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k);
}
}
return CombMemo[n][k];
}
template <class T> map<T, ll> Dict(V<T> v) {
map<T, ll> m;
if (!v.sz)
return m;
SORT(v);
UNIQUE(v);
REP(i, v.sz) { m[v[i]] = i; }
return m;
}
template <class T> vll Cmprs(V<T> v) {
auto m = Dict(v);
vll ans(v.sz);
REP(i, v.sz) { ans[i] = m[v[i]]; }
return ans;
}
template <class T> vll PCmprs(V<T> v) {
if (v.sz == 0)
return V<T>();
vll tmp(v.sz);
vll ans(v.sz);
IOTA(tmp, 0);
IOTA(ans, 0);
sort(tmp.bgn, tmp.en, clam(v[l] < v[r]));
sort(ans.bgn, ans.en, clam(tmp[l] < tmp[r]));
return ans;
}
ll BblCnt(vll rv) {
vll v = PCmprs(rv);
SegT<ll> b(v.sz, 0);
ll ans = 0;
REP(i, v.sz) {
ans += (i - b.que(0, v[i]));
b.add(v[i], 1);
}
return ans;
}
pl NGrid(pl p, ll i, ll H, ll W) {
p = mp(p.fi + DX[i], p.se + DY[i]);
if (p.fi < 0 || p.fi >= H || p.se < 0 || p.se >= W)
return mp(INF, INF);
return p;
}
vvll llGrid(vs v) {
vvll r(v.sz, vll(v.sz ? v[0].sz : 0, 0));
REP(h, v.sz) REP(w, v.sz ? v[0].sz : 0) r[h][w] = (v[h][w] == '#');
return r;
}
template <class T> auto ven(T val) { return val; }
template <> auto ven<int>(int val) { return (ll)val; }
template <class T, class... Args> auto ven(T val, Args... args) {
auto tmp = ven(args...);
return V<decltype(tmp)>(val, tmp);
}
template <class T> void zind(T &v) { v--; }
template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); }
template <class T, class... Args> void zind(T &v, Args &...args) {
zind(v);
zind(args...);
}
void Solve();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
void Solve() {
si(s, t);
vvll dp(3010, vll(3010, 0));
REP1(i, s.sz) {
REP1(j, t.sz) {
if (s[i - 1] == t[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else if (dp[i][j - 1] > dp[i - 1][j]) {
dp[i][j] = dp[i][j - 1];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
ll k = s.sz, l = t.sz;
string r = "";
while (k + l) {
if (k && dp[k][l] == dp[k - 1][l]) {
k--;
} else if (l && dp[k][l] == dp[k][l - 1]) {
l--;
} else {
k--;
l--;
r = s[k] + r;
}
}
cout << r << endl;
} | [
"control_flow.branch.if.condition.change"
] | 973,788 | 973,789 | u172929647 | cpp |
p03165 | #define rep(i, n) REP(i, 0, n)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
template <class T> inline void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
const ll MAXN = (ll)3e3 + 10;
const long long INF = 1LL << 60;
ll dp[MAXN][MAXN];
int main(void) {
string s, t;
cin >> s;
cin >> t;
rep(i, MAXN) rep(j, MAXN) dp[i][j] = 0;
rep(i, s.size()) rep(j, t.size()) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
else {
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
// cout<<dp[s.size()][t.size()]<<endl;
int i = s.size();
int j = t.size();
stack<char> ans;
while (1) {
if (i == 0 && j == 0)
break;
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j - 1] == dp[i][j])
j--;
else {
i--;
j--;
// cout<<s[i]<<endl;
ans.push(s[i]);
}
}
while (ans.size()) {
cout << ans.top();
ans.pop();
}
cout << endl;
return 0;
} | #define rep(i, n) REP(i, 0, n)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
template <class T> inline void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
const ll MAXN = (ll)3e3 + 10;
const long long INF = 1LL << 60;
ll dp[MAXN][MAXN];
int main(void) {
string s, t;
cin >> s;
cin >> t;
rep(i, MAXN) rep(j, MAXN) dp[i][j] = 0;
rep(i, s.size()) rep(j, t.size()) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
else {
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
// cout<<dp[s.size()][t.size()]<<endl;
int i = s.size();
int j = t.size();
stack<char> ans;
while (1) {
if (i == 0 || j == 0)
break;
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j - 1] == dp[i][j])
j--;
else {
i--;
j--;
// cout<<s[i]<<endl;
ans.push(s[i]);
}
}
while (ans.size()) {
cout << ans.top();
ans.pop();
}
cout << endl;
return 0;
} | [
"misc.opposites",
"control_flow.branch.if.condition.change"
] | 973,863 | 973,864 | u381755004 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
const int NMAX = 3100;
int dp[NMAX][NMAX] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
for (int i = 0; i < (int)s.size(); ++i) {
for (int j = 0; j < (int)t.size(); ++j) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
string res = "";
int i = (int)s.size(), j = (int)t.size();
while (0 < i && 0 < 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 の遷移を遡る
}
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
const int NMAX = 3100;
int dp[NMAX][NMAX] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
for (int i = 0; i < (int)s.size(); ++i) {
for (int j = 0; j < (int)t.size(); ++j) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
string res = "";
int i = (int)s.size(), j = (int)t.size();
while (0 < i && 0 < 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];
; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
--i, --j; // DP の遷移を遡る
}
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
| [
"assignment.value.change"
] | 973,865 | 973,866 | u052332717 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
const int NMAX = 3100;
int dp[NMAX][NMAX] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
for (int j = 0; j < s.size(); ++j) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
string res = "";
int i = (int)s.size(), j = (int)t.size();
while (0 < i && 0 < j) {
// (i-1, j) -> (i, j)と更新されていた場合
if (dp[i][j] == dp[i - 1][j])
--i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else {
res += s[i - 1];
--i;
--j;
}
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
const int NMAX = 3100;
int dp[NMAX][NMAX] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
for (int j = 0; j < t.size(); ++j) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
string res = "";
int i = (int)s.size(), j = (int)t.size();
while (0 < i && 0 < j) {
// (i-1, j) -> (i, j)と更新されていた場合
if (dp[i][j] == dp[i - 1][j])
--i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else {
res += s[i - 1];
--i;
--j;
}
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 973,867 | 973,868 | u052332717 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
const int NMAX = 3100;
int dp[NMAX][NMAX] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
for (int j = 0; j < s.size(); ++j) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
string res = "";
int i = (int)s.size(), j = (int)t.size();
while (0 < i && 0 < j) {
// (i-1, j) -> (i, j)と更新されていた場合
if (dp[i][j] == dp[i - 1][j])
--i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else {
res += s[i - 1];
--i;
--j;
}
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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;
}
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
const int NMAX = 3100;
int dp[NMAX][NMAX] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
for (int j = 0; j < t.size(); ++j) {
if (s[i] == t[j])
chmax(dp[i + 1][j + 1], dp[i][j] + 1);
chmax(dp[i + 1][j + 1], dp[i][j + 1]);
chmax(dp[i + 1][j + 1], dp[i + 1][j]);
}
}
string res = "";
int i = (int)s.size(), j = (int)t.size();
while (0 < i && 0 < j) {
// (i-1, j) -> (i, j)と更新されていた場合
if (dp[i][j] == dp[i - 1][j])
--i;
else if (dp[i][j] == dp[i][j - 1])
--j;
else {
res += s[i - 1];
--i;
--j;
}
}
reverse(res.begin(), res.end());
cout << res << endl;
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"call.arguments.change"
] | 973,869 | 973,868 | u052332717 | cpp |
p03165 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define chmin(mi, value) mi = min(mi, value)
#define chmax(ma, value) ma = max(ma, value)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFR INT_MAX
#define INFL (long long)(4e18)
#define INFLR LLONG_MAX
#define EPS (1e-10)
#define MOD 1000000007
//#define MOD 998244353
#define PI 3.141592653589793238
#define RMAX 4294967295
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
using Pi = pair<int, int>;
using vPi = vector<Pi>;
using vvPi = vector<vector<Pi>>;
using vvvPi = vector<vector<vector<Pi>>>;
using vvvvPi = vector<vector<vector<vector<Pi>>>>;
using Pll = pair<ll, ll>;
using vPll = vector<Pll>;
using Pd = pair<double, double>;
using vPd = vector<Pd>;
template <class T> using vec = vector<T>;
template <class T> using pql = priority_queue<T, vector<T>, greater<T>>;
using Comp = complex<double>;
// vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv
// vector input
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// deque
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// multiset
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
// ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^
string YN(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "YES" : "NO");
}
string yn(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "Yes" : "No");
}
string ON(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "OK" : "NG");
}
int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}};
int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0},
{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
char dirchar[4] = {'<', '^', '>', 'v'};
// [a,b)
int irand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_int_distribution<int> dist(a, b - 1);
return dist(Rand);
}
// [a,b)
double drand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_real_distribution<double> dist(a, b);
return dist(Rand);
}
// https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c
template <typename A, typename F> inline auto transform(const A &v, F &&f) {
using result_type =
decltype(std::declval<F>()(std::declval<typename A::value_type>()));
vector<result_type> y(v.size());
std::transform(std::cbegin(v), std::cend(v), std::begin(y), f);
return y;
}
// generate vector which has multiple dimension
template <class T> vector<T> make_v(size_t size, const T &init) {
return vector<T>(size, init);
}
template <class... Ts> auto make_v(size_t size, Ts... rest) {
return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}
template <typename T> T Max(vector<T> a) { return *max_element(all(a)); }
template <typename T> T Min(vector<T> a) { return *min_element(all(a)); }
template <typename T> T Sum(vector<T> a) { return accumulate(all(a), (T)0); }
// for counting using map
template <typename T> void Add(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
m[item] = 1;
} else {
m[item]++;
}
}
// for counting using map
template <typename T> void Erase(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
} else {
if (m[item] == 1) {
m.erase(item);
} else {
m[item]--;
}
}
}
// get method for map with default value
template <typename T, typename U> U Get(map<T, U> m, T key, U def) {
if (m.find(key) == m.end()) {
return def;
} else {
return m[key];
}
}
template <typename T> inline bool Contains(const set<T> &t, const T &key) {
return t.find(key) != t.end();
}
template <typename T, typename U>
inline bool Contains(const map<T, U> &t, const T &key) {
return t.find(key) != t.end();
}
template <class T> struct Edge {
int from, to;
T cost;
Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
};
template <class T> bool operator<(const Edge<T> e1, const Edge<T> e2) {
return e1.cost < e2.cost || (e1.cost == e2.cost && e1.from < e2.from) ||
(e1.cost == e2.cost && e1.from == e2.from && e1.to < e2.to);
}
template <class T> ostream &operator<<(ostream &os, const Edge<T> &edge) {
os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")";
return os;
}
template <class T = int> class Graph {
int n;
bool directed;
vector<vector<Edge<T>>> edges;
public:
Graph(int n, bool directed)
: n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {}
void add_edge(int s, int t, T cost) {
edges[s].emplace_back(s, t, cost);
if (!directed) {
edges[t].emplace_back(t, s, cost);
}
}
Graph() {}
vector<Edge<T>> &operator[](size_t i) { return edges[i]; }
int size() const { return n; }
};
//======================================================
int main() {
string S, T;
cin >> S >> T;
int NS = S.size(), NT = T.size();
vvi dp(NS + 1, vi(NT + 1, 0));
repr(i, 1, NS + 1) {
repr(j, 1, NT + 1) {
if (S[i - 1] == T[j - 1]) {
dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + 1});
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int pi = NS, pj = NT;
string ans = "";
while (pi != 0 && pj != 0) {
if (dp[pi][pj] == dp[pi - 1][pj])
pi--;
if (dp[pi][pj] == dp[pi][pj - 1])
pj--;
else {
pi--, pj--;
ans += S[pi];
}
}
reverse(all(ans));
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define chmin(mi, value) mi = min(mi, value)
#define chmax(ma, value) ma = max(ma, value)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFR INT_MAX
#define INFL (long long)(4e18)
#define INFLR LLONG_MAX
#define EPS (1e-10)
#define MOD 1000000007
//#define MOD 998244353
#define PI 3.141592653589793238
#define RMAX 4294967295
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
using Pi = pair<int, int>;
using vPi = vector<Pi>;
using vvPi = vector<vector<Pi>>;
using vvvPi = vector<vector<vector<Pi>>>;
using vvvvPi = vector<vector<vector<vector<Pi>>>>;
using Pll = pair<ll, ll>;
using vPll = vector<Pll>;
using Pd = pair<double, double>;
using vPd = vector<Pd>;
template <class T> using vec = vector<T>;
template <class T> using pql = priority_queue<T, vector<T>, greater<T>>;
using Comp = complex<double>;
// vvvvvvvvvvvvvvvvvvvvvvv debug output vvvvvvvvvvvvvvvvvvvvvvv
// vector input
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// deque
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
os << "{";
repi(itr, map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// multiset
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set_var) {
os << "{";
repi(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
// ^^^^^^^^^^^^^^^^^^^^^^^ debug output ^^^^^^^^^^^^^^^^^^^^^^^
string YN(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "YES" : "NO");
}
string yn(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "Yes" : "No");
}
string ON(bool y, int id = 0) {
if (id)
cout << id;
return (y ? "OK" : "NG");
}
int dir4[4][2] = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}};
int dir8[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0},
{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
char dirchar[4] = {'<', '^', '>', 'v'};
// [a,b)
int irand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_int_distribution<int> dist(a, b - 1);
return dist(Rand);
}
// [a,b)
double drand(int a, int b) {
static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
uniform_real_distribution<double> dist(a, b);
return dist(Rand);
}
// https://qiita.com/IgnorantCoder/items/3101d6276e9bdddf872c
template <typename A, typename F> inline auto transform(const A &v, F &&f) {
using result_type =
decltype(std::declval<F>()(std::declval<typename A::value_type>()));
vector<result_type> y(v.size());
std::transform(std::cbegin(v), std::cend(v), std::begin(y), f);
return y;
}
// generate vector which has multiple dimension
template <class T> vector<T> make_v(size_t size, const T &init) {
return vector<T>(size, init);
}
template <class... Ts> auto make_v(size_t size, Ts... rest) {
return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}
template <typename T> T Max(vector<T> a) { return *max_element(all(a)); }
template <typename T> T Min(vector<T> a) { return *min_element(all(a)); }
template <typename T> T Sum(vector<T> a) { return accumulate(all(a), (T)0); }
// for counting using map
template <typename T> void Add(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
m[item] = 1;
} else {
m[item]++;
}
}
// for counting using map
template <typename T> void Erase(map<T, int> &m, T item) {
if (m.find(item) == m.end()) {
} else {
if (m[item] == 1) {
m.erase(item);
} else {
m[item]--;
}
}
}
// get method for map with default value
template <typename T, typename U> U Get(map<T, U> m, T key, U def) {
if (m.find(key) == m.end()) {
return def;
} else {
return m[key];
}
}
template <typename T> inline bool Contains(const set<T> &t, const T &key) {
return t.find(key) != t.end();
}
template <typename T, typename U>
inline bool Contains(const map<T, U> &t, const T &key) {
return t.find(key) != t.end();
}
template <class T> struct Edge {
int from, to;
T cost;
Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
};
template <class T> bool operator<(const Edge<T> e1, const Edge<T> e2) {
return e1.cost < e2.cost || (e1.cost == e2.cost && e1.from < e2.from) ||
(e1.cost == e2.cost && e1.from == e2.from && e1.to < e2.to);
}
template <class T> ostream &operator<<(ostream &os, const Edge<T> &edge) {
os << "(" << edge.from << "->" << edge.to << ":" << edge.cost << ")";
return os;
}
template <class T = int> class Graph {
int n;
bool directed;
vector<vector<Edge<T>>> edges;
public:
Graph(int n, bool directed)
: n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {}
void add_edge(int s, int t, T cost) {
edges[s].emplace_back(s, t, cost);
if (!directed) {
edges[t].emplace_back(t, s, cost);
}
}
Graph() {}
vector<Edge<T>> &operator[](size_t i) { return edges[i]; }
int size() const { return n; }
};
//======================================================
int main() {
string S, T;
cin >> S >> T;
int NS = S.size(), NT = T.size();
vvi dp(NS + 1, vi(NT + 1, 0));
repr(i, 1, NS + 1) {
repr(j, 1, NT + 1) {
if (S[i - 1] == T[j - 1]) {
dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + 1});
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
int pi = NS, pj = NT;
string ans = "";
while (pi != 0 && pj != 0) {
if (dp[pi][pj] == dp[pi - 1][pj])
pi--;
else if (dp[pi][pj] == dp[pi][pj - 1])
pj--;
else {
pi--, pj--;
ans += S[pi];
}
}
reverse(all(ans));
cout << ans << endl;
return 0;
}
| [
"control_flow.branch.else_if.replace.add",
"control_flow.branch.if.replace.remove"
] | 973,872 | 973,873 | u366676780 | cpp |
p03165 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int dp[3001][3001];
int main(void) {
string str1, str2;
cin >> str1 >> str2;
for (int i = 1; i <= str1.length(); i++) {
for (int j = 1; j <= str2.length(); j++) {
if (str1[i] == str2[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[str1.length()][str1.length()] << endl;
string res = "";
int i = (int)str1.size(), j = (int)str2.size();
while (i > 1 && j > 1) {
if (dp[i][j] == dp[i - 1][j]) {
--i;
} else if (dp[i][j] ==
dp[i][j - 1]) { // (i-1, j-1) -> (i, j) と更新されていた場合
--j;
} else {
res = str1[i - 1] +
res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
--i, --j;
}
}
cout << res << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int dp[3001][3001];
int main(void) {
string str1, str2;
cin >> str1 >> str2;
for (int i = 1; i <= str1.length(); i++) {
for (int j = 1; j <= str2.length(); j++) {
if (str1[i - 1] == str2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[str1.length()][str2.length()] << endl;
//復元操作
string res = "";
int i = (int)str1.size(), j = (int)str2.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 = str1[i - 1] + res;
--i, --j;
}
}
cout << res << endl;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"literal.number.change",
"control_flow.loop.condition.change"
] | 973,911 | 973,912 | u117734686 | cpp |
p03165 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int dp[3001][3001];
int main(void) {
string str1, str2;
cin >> str1 >> str2;
for (int i = 1; i <= str1.length(); i++) {
for (int j = 1; j <= str2.length(); j++) {
if (str1[i] == str2[j]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[str1.length()][str1.length()] << endl;
string res = "";
int i = (int)str1.size(), j = (int)str2.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 = str1[i - 1] +
res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
--i, --j; // DP の遷移を遡る
}
}
cout << res << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int dp[3001][3001];
int main(void) {
string str1, str2;
cin >> str1 >> str2;
for (int i = 1; i <= str1.length(); i++) {
for (int j = 1; j <= str2.length(); j++) {
if (str1[i - 1] == str2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
// cout << dp[str1.length()][str2.length()] << endl;
//復元操作
string res = "";
int i = (int)str1.size(), j = (int)str2.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 = str1[i - 1] + res;
--i, --j;
}
}
cout << res << endl;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 973,913 | 973,912 | u117734686 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
#define MAX 3100
int dp[MAX][MAX];
int main() {
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
dp[i][j] = 0;
}
}
string s, t;
cin >> s >> t;
for (int i = 0; i < s.length(); i++) {
for (int j = i; 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 + 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 ans = "";
int i = s.length(), j = t.length();
while (i > 0 && j > 0) {
// 1. (i-1, j) -> (i, j) と更新されていた場合
if (dp[i][j] == dp[i - 1][j]) {
--i;
}
// 2. (i, j-1) -> (i, j) と更新されていた場合
else if (dp[i][j] == dp[i][j - 1]) {
--j;
}
// 3.
else {
// この時、s[i-1] == t[j-1]
ans = s[i - 1] + ans;
--i;
--j;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MAX 3100
int dp[MAX][MAX];
int main() {
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
dp[i][j] = 0;
}
}
string s, t;
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] = 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 ans = "";
int i = s.length(), j = t.length();
while (i > 0 && j > 0) {
// 1. (i-1, j) -> (i, j) と更新されていた場合
if (dp[i][j] == dp[i - 1][j]) {
--i;
}
// 2. (i, j-1) -> (i, j) と更新されていた場合
else if (dp[i][j] == dp[i][j - 1]) {
--j;
}
// 3.
else {
// この時、s[i-1] == t[j-1]
ans = s[i - 1] + ans;
--i;
--j;
}
}
cout << ans << endl;
return 0;
}
| [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.initializer.change"
] | 973,919 | 973,920 | u055447809 | cpp |
p03165 | #include <algorithm>
#include <assert.h>
#include <climits>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
template <typename T> T gcd(T a, T b) {
if (a < b)
gcd(b, a);
if (b == 1)
return 1;
T r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
#define MOD (1000000000 + 7)
int dp[3001][3001];
int main() {
string s, t;
cin >> s >> t;
REP(i, s.size()) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
int i = s.size();
int j = t.size();
string ans = "";
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j])
i--;
else if (dp[i][j] == dp[i][j--])
j--;
else {
ans = s[i - 1] + ans;
i--;
j--;
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <assert.h>
#include <climits>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
template <typename T> T gcd(T a, T b) {
if (a < b)
gcd(b, a);
if (b == 1)
return 1;
T r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
#define MOD (1000000000 + 7)
int dp[3001][3001];
int main() {
string s, t;
cin >> s >> t;
REP(i, s.size()) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
int i = s.size();
int j = t.size();
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] + ans;
i--;
j--;
}
}
cout << ans << endl;
}
| [
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 973,943 | 973,944 | u535347736 | cpp |
p03165 | #include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
string s, t;
std::cin >> s >> t;
int Ns = s.size();
int Nt = t.size();
int dp[Ns + 2][Nt + 2] = {};
REP(i, Ns) {
REP(j, Nt) {
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 x = Ns;
int y = Nt;
while (x > 0 || y > 0) {
if (dp[x][y] == dp[x - 1][y]) {
x--;
} else if (dp[x][y] == dp[x][y - 1]) {
y--;
} else {
x--;
y--;
ans = s[x] + ans;
}
}
std::cout << ans << '\n';
// REP(i, Ns + 1) {
// REP(j, Nt + 1) { std::cout << dp[i][j] << ' '; }
// std::cout << '\n';
// }
}
ll div_ceil(ll a, ll b) {
ll quotient = a / b;
ll remainder = a % b;
if (remainder == 0) {
return quotient;
} else {
return quotient + 1;
}
}
| #include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int main() {
string s, t;
std::cin >> s >> t;
int Ns = s.size();
int Nt = t.size();
int dp[Ns + 1][Nt + 1] = {};
REP(i, Ns) {
REP(j, Nt) {
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 x = Ns;
int y = Nt;
while (x > 0 && y > 0) {
if (dp[x][y] == dp[x - 1][y]) {
x--;
} else if (dp[x][y] == dp[x][y - 1]) {
y--;
} else {
x--;
y--;
ans = s[x] + ans;
}
}
std::cout << ans << '\n';
// REP(i, Ns + 1) {
// REP(j, Nt + 1) { std::cout << dp[i][j] << ' '; }
// std::cout << '\n';
// }
}
ll div_ceil(ll a, ll b) {
ll quotient = a / b;
ll remainder = a % b;
if (remainder == 0) {
return quotient;
} else {
return quotient + 1;
}
}
| [
"literal.number.change",
"expression.operation.binary.change",
"misc.opposites",
"control_flow.loop.condition.change"
] | 973,974 | 973,973 | u408053343 | cpp |
p03165 | #include <iostream>
using namespace std;
const int MAX_S = 3100;
const int MAX_T = 3100;
long long dp[MAX_S][MAX_T] = {
0}; // N-1番目までで入れた容量の価値を最大にするもの
const long long INF = 1LL << 60;
int main() {
string S, T;
cin >> S >> T;
dp[0][0] = 0;
for (int i = 0; i < S.size(); ++i) {
for (int j = 0; j < T.size(); ++j) {
if (S[i] == S[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 = S.size(), j = T.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
--i;
} else if (dp[i][j] == dp[i][j - 1]) {
--j;
} else {
res = S[i - 1] + res;
--i, --j;
}
}
cout << res << endl;
return 0;
} | #include <iostream>
using namespace std;
const int MAX_S = 3100;
const int MAX_T = 3100;
long long dp[MAX_S][MAX_T] = {
0}; // N-1番目までで入れた容量の価値を最大にするもの
const long long INF = 1LL << 60;
int main() {
string S, T;
cin >> S >> T;
dp[0][0] = 0;
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], 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 = S.size(), j = T.size();
while (i > 0 && j > 0) {
if (dp[i][j] == dp[i - 1][j]) {
--i;
} else if (dp[i][j] == dp[i][j - 1]) {
--j;
} else {
res = S[i - 1] + res;
--i, --j;
}
}
cout << res << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 974,012 | 974,013 | u894555185 | cpp |
p03165 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, i0, n) for (int i = (i0); i < (n); i++)
#define COUT(val) cout << (val) << "\n";
using namespace std;
using ll = long long int;
int main(void) {
string s, t;
cin >> s >> t;
int ns = s.size(), nt = t.size();
vector<vector<int>> dp(ns + 1, vector<int>(nt + 1, -1));
FOR(i, 0, ns + 1) dp[i][0] = 0;
FOR(j, 0, nt + 1) dp[0][j] = 0;
FOR(i, 1, ns + 1) FOR(j, 1, nt + 1) {
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);
}
string ans = "";
while (ns > 0 || nt > 0) {
while (dp[ns][nt] == dp[ns - 1][nt])
ns--;
while (dp[ns][nt] == dp[ns][nt - 1])
nt--;
ans.push_back(s[ns - 1]);
ns--;
nt--;
}
reverse(ans.begin(), ans.end());
COUT(ans);
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, i0, n) for (int i = (i0); i < (n); i++)
#define COUT(val) cout << (val) << "\n";
using namespace std;
using ll = long long int;
int main(void) {
string s, t;
cin >> s >> t;
int ns = s.size(), nt = t.size();
vector<vector<int>> dp(ns + 1, vector<int>(nt + 1, -1));
FOR(i, 0, ns + 1) dp[i][0] = 0;
FOR(j, 0, nt + 1) dp[0][j] = 0;
FOR(i, 1, ns + 1) FOR(j, 1, nt + 1) {
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);
}
string ans = "";
while (dp[ns][nt] > 0) {
while (dp[ns][nt] == dp[ns - 1][nt])
ns--;
while (dp[ns][nt] == dp[ns][nt - 1])
nt--;
ans.push_back(s[ns - 1]);
ns--;
nt--;
}
reverse(ans.begin(), ans.end());
COUT(ans);
} | [
"control_flow.loop.condition.change"
] | 974,066 | 974,067 | u375405838 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
const ull MOD = 998244353;
#ifdef LOCAL
#include "../../pp.hpp"
#define debug pp::debug
#else
#define debug(args...)
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
vvi dp(n, vi(m, 0));
dp[0][0] = (s[0] == t[0]);
for (int i = 1; i < n; ++i)
dp[i][0] = max(dp[i - 1][0], (int)(s[i] == t[0]));
for (int j = 1; j < m; ++j)
dp[0][j] = max(dp[0][j - 1], (int)(s[0] == t[j]));
for (int i = 1; i < n; ++i) {
for (int j = 1; j < m; ++j) {
dp[i][j] = dp[i - 1][j - 1] + (s[i] == t[j]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
}
}
string ans;
int i = n - 1;
int j = m - 1;
while (true) {
if (i == 0) {
if (dp[i][j] == 1)
ans.push_back(s[i]);
break;
} else if (j == 0) {
if (dp[i][j] == 1)
ans.push_back(s[j]);
break;
} else if (dp[i - 1][j] == dp[i][j]) {
--i;
} else if (dp[i][j - 1] == dp[i][j]) {
--j;
} else if (dp[i - 1][j - 1] == dp[i][j]) {
--i;
--j;
} else {
ans.push_back(s[i]);
--i;
--j;
}
}
debug("dp", dp);
debug("len lcs", dp[n - 1][m - 1]);
reverse(ans.begin(), ans.end());
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
const ull MOD = 998244353;
#ifdef LOCAL
#include "../../pp.hpp"
#define debug pp::debug
#else
#define debug(args...)
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
vvi dp(n, vi(m, 0));
dp[0][0] = (s[0] == t[0]);
for (int i = 1; i < n; ++i)
dp[i][0] = max(dp[i - 1][0], (int)(s[i] == t[0]));
for (int j = 1; j < m; ++j)
dp[0][j] = max(dp[0][j - 1], (int)(s[0] == t[j]));
for (int i = 1; i < n; ++i) {
for (int j = 1; j < m; ++j) {
dp[i][j] = dp[i - 1][j - 1] + (s[i] == t[j]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
dp[i][j] = max(dp[i][j], dp[i][j - 1]);
}
}
string ans;
int i = n - 1;
int j = m - 1;
while (true) {
if (i == 0) {
if (dp[i][j] == 1)
ans.push_back(s[i]);
break;
} else if (j == 0) {
if (dp[i][j] == 1)
ans.push_back(t[j]);
break;
} else if (dp[i - 1][j] == dp[i][j]) {
--i;
} else if (dp[i][j - 1] == dp[i][j]) {
--j;
} else if (dp[i - 1][j - 1] == dp[i][j]) {
--i;
--j;
} else {
ans.push_back(s[i]);
--i;
--j;
}
}
debug("dp", dp);
debug("len lcs", dp[n - 1][m - 1]);
reverse(ans.begin(), ans.end());
cout << ans << '\n';
}
| [
"identifier.change",
"call.arguments.change"
] | 974,092 | 974,093 | u286163941 | cpp |
p03165 | // https://atcoder.jp/contests/dp/tasks/dp_f
// shauryakr
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[3005][3005];
void solve() {
for (int i = 1; i <= a.length(); i++) {
for (int j = 1; j <= b.length(); j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
}
// for(int i=0; i<=b.length(); i++)
// {
// for(int j=0; j<=a.length(); j++)
// {
// cout << dp[j][i] << " ";
// }
// cout << endl;
// }
int i = a.length(), j = b.length();
string subseq = "";
while (i != 0 || j != 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
subseq = subseq + a[i - 1];
i--;
j--;
}
}
reverse(subseq.begin(), subseq.end());
cout << subseq << endl;
}
int main() {
cin >> a >> b;
solve();
return 0;
} | // https://atcoder.jp/contests/dp/tasks/dp_f
// shauryakr
#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[3005][3005];
void solve() {
for (int i = 1; i <= a.length(); i++) {
for (int j = 1; j <= b.length(); j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
}
// for(int i=0; i<=b.length(); i++)
// {
// for(int j=0; j<=a.length(); j++)
// {
// cout << dp[j][i] << " ";
// }
// cout << endl;
// }
int i = a.length(), j = b.length();
string subseq = "";
while (i != 0 && j != 0) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
} else if (dp[i][j] == dp[i][j - 1]) {
j--;
} else {
subseq = subseq + a[i - 1];
i--;
j--;
}
}
reverse(subseq.begin(), subseq.end());
cout << subseq << endl;
}
int main() {
cin >> a >> b;
solve();
return 0;
} | [
"misc.opposites",
"control_flow.loop.condition.change"
] | 974,114 | 974,115 | u009824133 | cpp |
p03165 | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 3010
string s, t;
string ans;
int dp[MAXN][MAXN];
void dfs(int i, int j) {
int val = dp[i][j];
if (val == 0)
return;
if (i == 0 && j == 0) {
ans += s[0];
return;
}
if (i == 0) {
ans += s[0];
return;
}
if (j == 0) {
ans += t[0];
}
if (val == dp[i - 1][j]) {
dfs(i - 1, j);
} else if (val == dp[i][j - 1]) {
dfs(i, j - 1);
} else {
ans += s[i];
dfs(i - 1, j - 1);
}
}
int main() {
cin >> s >> t;
int n = (int)s.length(), m = (int)t.length();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = -1;
}
}
if (s[0] == t[0]) {
dp[0][0] = 1;
} else {
dp[0][0] = 0;
}
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][0], (s[i] == t[0] ? 1 : 0));
}
for (int i = 1; i < m; i++) {
dp[0][i] = max(dp[0][i - 1], (s[0] == t[i] ? 1 : 0));
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
}
}
dfs(n - 1, m - 1);
for (int i = ans.length() - 1; i >= 0; i--) {
cout << ans[i];
}
cout << endl;
} | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 3010
string s, t;
string ans;
int dp[MAXN][MAXN];
void dfs(int i, int j) {
int val = dp[i][j];
if (val == 0)
return;
if (i == 0 && j == 0) {
ans += s[0];
return;
}
if (i == 0) {
ans += s[0];
return;
}
if (j == 0) {
ans += t[0];
return;
}
if (val == dp[i - 1][j]) {
dfs(i - 1, j);
} else if (val == dp[i][j - 1]) {
dfs(i, j - 1);
} else {
ans += s[i];
dfs(i - 1, j - 1);
}
}
int main() {
cin >> s >> t;
int n = (int)s.length(), m = (int)t.length();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = -1;
}
}
if (s[0] == t[0]) {
dp[0][0] = 1;
} else {
dp[0][0] = 0;
}
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][0], (s[i] == t[0] ? 1 : 0));
}
for (int i = 1; i < m; i++) {
dp[0][i] = max(dp[0][i - 1], (s[0] == t[i] ? 1 : 0));
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
}
}
dfs(n - 1, m - 1);
for (int i = ans.length() - 1; i >= 0; i--) {
cout << ans[i];
}
cout << endl;
} | [
"control_flow.return.add"
] | 974,137 | 974,138 | u719290158 | cpp |
p03165 | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 3010
string s, t;
string ans;
int dp[MAXN][MAXN];
void dfs(int i, int j) {
int val = dp[i][j];
if (val == 0)
return;
if (i == 0 && j == 0) {
ans += s[0];
return;
}
if (i == 0) {
ans += s[0];
return;
}
if (j == 0) {
ans += t[j];
}
if (val == dp[i - 1][j]) {
dfs(i - 1, j);
} else if (val == dp[i][j - 1]) {
dfs(i, j - 1);
} else {
ans += s[i];
dfs(i - 1, j - 1);
}
}
int main() {
cin >> s >> t;
int n = (int)s.length(), m = (int)t.length();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = -1;
}
}
if (s[0] == t[0]) {
dp[0][0] = 1;
} else {
dp[0][0] = 0;
}
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][0], (s[i] == t[0] ? 1 : 0));
}
for (int i = 1; i < m; i++) {
dp[0][i] = max(dp[0][i - 1], (s[0] == t[i] ? 1 : 0));
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
}
}
dfs(n - 1, m - 1);
for (int i = ans.length() - 1; i >= 0; i--) {
cout << ans[i];
}
cout << endl;
}
| #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 3010
string s, t;
string ans;
int dp[MAXN][MAXN];
void dfs(int i, int j) {
int val = dp[i][j];
if (val == 0)
return;
if (i == 0 && j == 0) {
ans += s[0];
return;
}
if (i == 0) {
ans += s[0];
return;
}
if (j == 0) {
ans += t[0];
return;
}
if (val == dp[i - 1][j]) {
dfs(i - 1, j);
} else if (val == dp[i][j - 1]) {
dfs(i, j - 1);
} else {
ans += s[i];
dfs(i - 1, j - 1);
}
}
int main() {
cin >> s >> t;
int n = (int)s.length(), m = (int)t.length();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i][j] = -1;
}
}
if (s[0] == t[0]) {
dp[0][0] = 1;
} else {
dp[0][0] = 0;
}
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][0], (s[i] == t[0] ? 1 : 0));
}
for (int i = 1; i < m; i++) {
dp[0][i] = max(dp[0][i - 1], (s[0] == t[i] ? 1 : 0));
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s[i] == t[j])
dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j - 1]);
}
}
dfs(n - 1, m - 1);
for (int i = ans.length() - 1; i >= 0; i--) {
cout << ans[i];
}
cout << endl;
} | [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"variable_access.subscript.index.change",
"control_flow.return.add"
] | 974,139 | 974,138 | u719290158 | cpp |
p03165 | #include <iostream>
#include <string>
#include <vector>
using namespace std;
const long long INF = 1e18;
int main() {
string s, t;
cin >> s >> t;
int ls = s.size(), lt = t.size();
auto dp = vector<vector<int>>(3010, vector<int>(3010, 0));
dp[0][0] = (s[0] == t[0]) ? 1 : 0;
for (int i = 1; i < ls; i++) {
if (s[i] == t[0])
dp[i][0] = 1;
else
dp[i][0] = dp[i - 1][0];
}
for (int i = 1; i < lt; i++) {
if (s[0] == t[i])
dp[0][i] = 1;
else
dp[0][i] = dp[0][i - 1];
}
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;
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
string ans = "";
int i = ls - 1, j = lt - 1;
while (i >= 0 && j >= 0) {
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 (s[i] == t[i])
ans = s[i] + ans;
i--;
j--;
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
const long long INF = 1e18;
int main() {
string s, t;
cin >> s >> t;
int ls = s.size(), lt = t.size();
auto dp = vector<vector<int>>(3010, vector<int>(3010, 0));
dp[0][0] = (s[0] == t[0]) ? 1 : 0;
for (int i = 1; i < ls; i++) {
if (s[i] == t[0])
dp[i][0] = 1;
else
dp[i][0] = dp[i - 1][0];
}
for (int i = 1; i < lt; i++) {
if (s[0] == t[i])
dp[0][i] = 1;
else
dp[0][i] = dp[0][i - 1];
}
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;
else
dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
}
}
string ans = "";
int i = ls - 1, j = lt - 1;
while (i >= 0 && j >= 0) {
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 (s[i] == t[j])
ans = s[i] + ans;
i--;
j--;
}
}
cout << ans << endl;
return 0;
} | [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 974,159 | 974,160 | u808916291 | cpp |
p03165 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
#define debug(x) cerr << #x << " = " << x << endl;
const int MAX = 3e3 + 100;
int dp[MAX][MAX];
pair<int, ii> p[MAX][MAX];
string s, t;
int dp_solve(int idxs, int idxt) {
if (idxs < 0 || idxt < 0)
return 0;
int &ans = dp[idxs][idxt];
if (~ans)
return ans;
auto &parent = p[idxs][idxt];
parent = {-1, {-1, -1}};
ans = 0;
int tmp = dp_solve(idxs - 1, idxt);
if (tmp > ans && idxs - 1 >= 0) {
ans = tmp;
parent = {0, {idxs - 1, idxt}};
}
tmp = dp_solve(idxs, idxt - 1);
if (tmp > ans && idxt - 1 >= 0) {
ans = tmp;
parent = {0, {idxs, idxt - 1}};
}
tmp = dp_solve(idxs - 1, idxt - 1) + 1;
if (s[idxs] == t[idxt] && tmp > ans) {
ans = tmp;
parent = {1, {idxs - 1, idxt - 1}};
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> s >> t;
memset(dp, -1, sizeof dp);
for (int i = 0; i < MAX; i++)
for (int j = 0; j < MAX; j++)
p[i][j] = {-1, {0, 0}};
int ss = (int)s.size() - 1, st = (int)t.size() - 1;
dp_solve(ss, st);
auto cur = p[ss][st];
string ans = "";
while (cur.first != -1) {
if (cur.first == 1)
if (cur.second.first + 1 >= ss)
ans += s[cur.second.first + 1];
if (cur.second.first >= 0 && cur.second.second >= 0)
cur = p[cur.second.first][cur.second.second];
else
break;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
#define debug(x) cerr << #x << " = " << x << endl;
const int MAX = 3e3 + 100;
int dp[MAX][MAX];
pair<int, ii> p[MAX][MAX];
string s, t;
int dp_solve(int idxs, int idxt) {
if (idxs < 0 || idxt < 0)
return 0;
int &ans = dp[idxs][idxt];
if (~ans)
return ans;
auto &parent = p[idxs][idxt];
parent = {-1, {-1, -1}};
ans = 0;
int tmp = dp_solve(idxs - 1, idxt);
if (tmp > ans && idxs - 1 >= 0) {
ans = tmp;
parent = {0, {idxs - 1, idxt}};
}
tmp = dp_solve(idxs, idxt - 1);
if (tmp > ans && idxt - 1 >= 0) {
ans = tmp;
parent = {0, {idxs, idxt - 1}};
}
tmp = dp_solve(idxs - 1, idxt - 1) + 1;
if (s[idxs] == t[idxt] && tmp > ans) {
ans = tmp;
parent = {1, {idxs - 1, idxt - 1}};
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> s >> t;
memset(dp, -1, sizeof dp);
for (int i = 0; i < MAX; i++)
for (int j = 0; j < MAX; j++)
p[i][j] = {-1, {0, 0}};
int ss = (int)s.size() - 1, st = (int)t.size() - 1;
dp_solve(ss, st);
auto cur = p[ss][st];
string ans = "";
while (cur.first != -1) {
if (cur.first == 1)
if (cur.second.first + 1 <= ss)
ans += s[cur.second.first + 1];
if (cur.second.first >= 0 && cur.second.second >= 0)
cur = p[cur.second.first][cur.second.second];
else
break;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 974,208 | 974,209 | u364803514 | cpp |
p03165 | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int dp[3000][3000];
int main() {
string s;
string t;
cin >> s;
cin >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (i == 0) {
if (t.substr(0, j).find(s[i]) != string::npos) {
dp[i][j] = 1;
}
} else if (j == 0) {
if (s.substr(0, i).find(t[j]) != string::npos) {
dp[i][j] = 1;
}
} else {
dp[i][j] = 0;
}
}
}
for (int i = 1; i < s.size(); i++) {
for (int j = 1; j < t.size(); 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);
}
}
}
// cout << dp[s.size() - 1][t.size() - 1] << endl;
string ans = "";
if (dp[s.size() - 1][t.size() - 1] == 0) {
cout << "" << endl;
return 0;
}
int cur_i = s.size() - 1;
int cur_j = t.size() - 1;
int prev_max;
while (true) {
if (cur_i <= 0 || cur_j <= 0) {
break;
}
prev_max = max(dp[cur_i - 1][cur_j], dp[cur_i][cur_j - 1]);
if (s[cur_i] == t[cur_j]) {
prev_max = max(prev_max, dp[cur_i - 1][cur_j - 1] + 1);
}
if (prev_max == dp[cur_i - 1][cur_j]) {
cur_i--;
} else if (prev_max == dp[cur_i][cur_j - 1]) {
cur_j--;
} else if (prev_max == dp[cur_i - 1][cur_j - 1] + 1) {
ans.push_back(s[cur_i]);
cur_i--;
cur_j--;
}
}
if (dp[cur_i][cur_j] == 1) {
if (cur_i == 0) {
ans.push_back(s[0]);
} else {
ans.push_back(t[0]);
}
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int dp[3000][3000];
int main() {
string s;
string t;
cin >> s;
cin >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (i == 0) {
if (t.substr(0, j + 1).find(s[0]) != string::npos) {
dp[i][j] = 1;
}
} else if (j == 0) {
if (s.substr(0, i + 1).find(t[0]) != string::npos) {
dp[i][j] = 1;
}
} else {
dp[i][j] = 0;
}
}
}
for (int i = 1; i < s.size(); i++) {
for (int j = 1; j < t.size(); 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);
}
}
}
// cout << dp[s.size() - 1][t.size() - 1] << endl;
string ans = "";
if (dp[s.size() - 1][t.size() - 1] == 0) {
cout << "" << endl;
return 0;
}
int cur_i = s.size() - 1;
int cur_j = t.size() - 1;
int prev_max;
while (true) {
if (cur_i <= 0 || cur_j <= 0) {
break;
}
prev_max = max(dp[cur_i - 1][cur_j], dp[cur_i][cur_j - 1]);
if (s[cur_i] == t[cur_j]) {
prev_max = max(prev_max, dp[cur_i - 1][cur_j - 1] + 1);
}
if (prev_max == dp[cur_i - 1][cur_j]) {
cur_i--;
} else if (prev_max == dp[cur_i][cur_j - 1]) {
cur_j--;
} else if (prev_max == dp[cur_i - 1][cur_j - 1] + 1) {
ans.push_back(s[cur_i]);
cur_i--;
cur_j--;
}
}
if (dp[cur_i][cur_j] == 1) {
if (cur_i == 0) {
ans.push_back(s[0]);
} else {
ans.push_back(t[0]);
}
}
/*for(int i = 0; i < s.size(); i++){
for(int j = 0; j < t.size(); j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"call.arguments.add",
"identifier.replace.remove",
"literal.replace.add",
"variable_access.subscript.index.change"
] | 974,215 | 974,216 | u623349537 | cpp |
p03166 | #include <bits/stdc++.h>
#include <string.h>
#define ll long long
#include <vector>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;
int n, m;
vector<int> adj[100005];
int dp[100005];
int longpath(int node) {
if (dp[node] != -1)
return dp[node];
int ans = 0;
for (auto i : adj[node]) {
ans = max(ans, 1 + longpath(node));
}
return dp[node] = ans;
}
int main() {
IOS;
cin >> n >> m;
for (int i = 0, x, y; i < m; i++) {
cin >> x >> y;
adj[x].push_back(y);
}
for (int i = 1; i <= n; i++)
adj[0].push_back(i);
memset(dp, -1, sizeof(dp));
cout << longpath(0) - 1;
} | #include <bits/stdc++.h>
#include <string.h>
#define ll long long
#include <vector>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;
int n, m;
vector<int> adj[100005];
int dp[100005];
int longpath(int node) {
if (dp[node] != -1)
return dp[node];
int ans = 0;
for (auto i : adj[node]) {
ans = max(ans, 1 + longpath(i));
}
return dp[node] = ans;
}
int main() {
IOS;
cin >> n >> m;
for (int i = 0, x, y; i < m; i++) {
cin >> x >> y;
adj[x].push_back(y);
}
for (int i = 1; i <= n; i++)
adj[0].push_back(i);
memset(dp, -1, sizeof(dp));
cout << longpath(0) - 1;
} | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 974,270 | 974,271 | u375055372 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> x;
int n, m;
bool visited[100009];
int dp[100009];
int solve(int curr) {
if (dp[curr] != -1)
return dp[curr];
int temp = -1;
for (auto i : x[curr]) {
if (dp[i] != -1) {
temp = 1 + dp[i];
dp[curr] = max(dp[curr], temp);
} else
dp[curr] = max(dp[curr], 1 + solve(i));
}
if (dp[curr] == -1) {
return dp[curr] = 0;
}
return dp[curr];
}
int main() {
scanf("%d%d", &n, &m);
x.resize(m + 5);
int from, to;
for (int i = 0; i < m; ++i) {
scanf("%d%d", &from, &to);
x[from].push_back(to);
}
memset(visited, false, sizeof visited);
memset(dp, -1, sizeof dp);
int ans = -1;
for (int i = 1; i <= n; ++i)
ans = max(ans, solve(i));
printf("%d", ans);
} | #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> x;
int n, m;
bool visited[100009];
int dp[100009];
int solve(int curr) {
if (dp[curr] != -1)
return dp[curr];
int temp = -1;
for (auto i : x[curr]) {
if (dp[i] != -1) {
temp = 1 + dp[i];
dp[curr] = max(dp[curr], temp);
} else
dp[curr] = max(dp[curr], 1 + solve(i));
}
if (dp[curr] == -1) {
return dp[curr] = 0;
}
return dp[curr];
}
int main() {
scanf("%d%d", &n, &m);
x.resize(n + 5);
int from, to;
for (int i = 0; i < m; ++i) {
scanf("%d%d", &from, &to);
x[from].push_back(to);
}
memset(visited, false, sizeof visited);
memset(dp, -1, sizeof dp);
int ans = -1;
for (int i = 1; i <= n; ++i)
ans = max(ans, solve(i));
printf("%d", ans);
} | [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 974,311 | 974,312 | u059216660 | cpp |
p03166 | using namespace std;
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll, ll>
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll, ll>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
typedef long long int ll;
// stringstream convert;
// convert << number;
// string s = convert.str();
ll fact[500005], invfact[500005];
ll power(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2 == 1)
z = (z * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return z;
}
ll inv(ll x) { return power(x, MOD - 2); }
ll divide(ll x, ll y) { return (x * inv(y)) % MOD; }
ll C(ll n, ll k) {
if (k > n)
return 0;
return divide(fact[n], (fact[n - k] * fact[k]) % MOD);
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
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;
}
void init() {
ll p = MOD;
fact[0] = 1;
ll i;
for (i = 1; i < 500005; i++) {
fact[i] = (i * fact[i - 1]) % p;
}
i--;
invfact[i] = power(fact[i], p - 2);
for (i--; i >= 0; i--) {
invfact[i] = (invfact[i + 1] * (i + 1)) % p;
}
}
ll s;
ll fun(ll a) {
if (a == 0)
return 0;
return a + fun(a - 1);
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> gq;
#define MAXN 10000001
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
set<ll> getFactorization(ll x) {
set<ll> ret;
while (x != 1) {
ret.insert(spf[x]);
x = x / spf[x];
}
return ret;
}
ll sm(ll n) {
ll i;
ll k = 0;
while (n > 0) {
k = k + n % 10;
n = n / 10;
}
return k;
}
vector<ll> v[100001];
ll dp[100001];
ll vis[100001];
void dfs(ll k) {
vis[k] = 1;
for (ll i = 0; i < v[k].size(); i++) {
if (!vis[v[k][i]]) {
dfs(v[k][i]);
dp[k] = max(dp[k], 1 + dp[v[k][i]]);
}
}
}
void ghost() {
ll i = 0, j = 0, k = 0, l = 0, n, r = 0, q = 0, y = 100000000000, m, w;
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> k >> l;
v[k].pb(l);
}
for (i = 1; i <= n; i++) {
if (!vis[i])
dfs(i);
}
ll ans = 0;
for (i = 1; i <= n; i++)
ans = max(ans, dp[i]);
cout << ans << endl;
}
signed main() {
int test = 1;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
fast
// cin>>test;
while (test--) ghost();
return 0;
}
| using namespace std;
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll, ll>
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll, ll>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
typedef long long int ll;
// stringstream convert;
// convert << number;
// string s = convert.str();
ll fact[500005], invfact[500005];
ll power(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2 == 1)
z = (z * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return z;
}
ll inv(ll x) { return power(x, MOD - 2); }
ll divide(ll x, ll y) { return (x * inv(y)) % MOD; }
ll C(ll n, ll k) {
if (k > n)
return 0;
return divide(fact[n], (fact[n - k] * fact[k]) % MOD);
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
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;
}
void init() {
ll p = MOD;
fact[0] = 1;
ll i;
for (i = 1; i < 500005; i++) {
fact[i] = (i * fact[i - 1]) % p;
}
i--;
invfact[i] = power(fact[i], p - 2);
for (i--; i >= 0; i--) {
invfact[i] = (invfact[i + 1] * (i + 1)) % p;
}
}
ll s;
ll fun(ll a) {
if (a == 0)
return 0;
return a + fun(a - 1);
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> gq;
#define MAXN 10000001
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
set<ll> getFactorization(ll x) {
set<ll> ret;
while (x != 1) {
ret.insert(spf[x]);
x = x / spf[x];
}
return ret;
}
ll sm(ll n) {
ll i;
ll k = 0;
while (n > 0) {
k = k + n % 10;
n = n / 10;
}
return k;
}
vector<ll> v[100001];
ll dp[100001];
ll vis[100001];
void dfs(ll k) {
vis[k] = 1;
for (ll i = 0; i < v[k].size(); i++) {
if (!vis[v[k][i]])
dfs(v[k][i]);
dp[k] = max(dp[k], 1 + dp[v[k][i]]);
}
}
void ghost() {
ll i = 0, j = 0, k = 0, l = 0, n, r = 0, q = 0, y = 100000000000, m, w;
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> k >> l;
v[k].pb(l);
}
for (i = 1; i <= n; i++) {
if (!vis[i])
dfs(i);
}
ll ans = 0;
for (i = 1; i <= n; i++)
ans = max(ans, dp[i]);
cout << ans << endl;
}
signed main() {
int test = 1;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
fast
// cin>>test;
while (test--) ghost();
return 0;
}
| [] | 974,315 | 974,316 | u379844185 | cpp |
p03166 | #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> vertices;
vector<int> dp;
int longestPath(int root) {
if (dp[root] != -1)
return dp[root];
int max = 0;
for (int vertex : vertices[root]) {
dp[vertex] = longestPath(vertex);
if (dp[vertex] > max) {
max = dp[vertex];
}
}
dp[root] = max;
// cout<<root<<"->"<<max<<endl;
return 1 + dp[root];
}
int main() {
int N, M;
cin >> N >> M;
int maximum = 0;
vertices = vector<vector<int>>(N + 1);
dp = vector<int>(N + 1, -1);
for (int i = 0; i < M; i++) {
int from, to;
cin >> from >> to;
vertices[from].push_back(to);
}
for (int i = 1; i <= N; i++) {
if (dp[i] == -1) {
int res = longestPath(i);
if (res > maximum) {
maximum = res;
}
}
}
// cout<<endl;
cout << maximum - 1;
// cout<<endl;
// for(int i = 1; i <= N;i++){
// cout<<dp[i]<<" ";
// }
} | #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> vertices;
vector<int> dp;
int longestPath(int root) {
if (dp[root] != -1)
return dp[root];
int max = 0;
for (int vertex : vertices[root]) {
dp[vertex] = longestPath(vertex);
if (dp[vertex] > max) {
max = dp[vertex];
}
}
dp[root] = 1 + max;
// cout<<root<<"->"<<max<<endl;
return dp[root];
}
int main() {
int N, M;
cin >> N >> M;
int maximum = 0;
vertices = vector<vector<int>>(N + 1);
dp = vector<int>(N + 1, -1);
for (int i = 0; i < M; i++) {
int from, to;
cin >> from >> to;
vertices[from].push_back(to);
}
for (int i = 1; i <= N; i++) {
if (dp[i] == -1) {
int res = longestPath(i);
if (res > maximum) {
maximum = res;
}
}
}
// cout<<endl;
cout << maximum - 1;
// cout<<endl;
// for(int i = 1; i <= N;i++){
// cout<<dp[i]<<" ";
// }
} | [
"assignment.change",
"expression.operation.binary.remove"
] | 974,328 | 974,329 | u446995216 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define test \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define f0(i, n) for (ll i = 0; i < (n); i++)
#define f1(i, n) for (i = 1; i <= (n); i++)
#define f(i, m, n) for (auto i = (m); i <= (n); i++)
#define nl cout << "\n"
#define mod 1000000007
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(x) ((ll)x.size())
#define mem(a, b) memset(a, b, sizeof(a));
#define make_graph(k) \
int x, y; \
f0(i, k) { \
cin >> x >> y; \
adj[x].pb(y); /*adj[y].pb(x);*/ \
}
#define dekh cout << "dekh"
#define o_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setpll \
tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, \
tree_order_statistics_node_update>
typedef vector<ll> vl;
/*ll Pow(ll a, ll b, ll m){
if(b==0)return 1;
if(b%2==0){
ll x = a*a;
x%=m;
return Pow(x,b/2,m);
}
return (a*Pow(a,b-1,m))%m;
}
*/
vector<ll> adj[200005];
ll vis[200005] = {0};
ll depth[200005] = {0};
// ll p;ll arr[200005];
void dfs(ll x) {
vis[x] = 1;
for (auto child : adj[x]) {
if (!vis[child]) {
dfs(child);
}
depth[x] = max(depth[x], depth[child] + 1);
}
}
int main() {
fast ll n, m, i;
cin >> n >> m;
make_graph(m);
f1(i, n) {
if (!vis[i]) {
dfs(i);
}
}
auto maxi = max_element(depth, depth + n);
cout << *maxi;
}
| #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define test \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define f0(i, n) for (ll i = 0; i < (n); i++)
#define f1(i, n) for (i = 1; i <= (n); i++)
#define f(i, m, n) for (auto i = (m); i <= (n); i++)
#define nl cout << "\n"
#define mod 1000000007
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(x) ((ll)x.size())
#define mem(a, b) memset(a, b, sizeof(a));
#define make_graph(k) \
int x, y; \
f0(i, k) { \
cin >> x >> y; \
adj[x].pb(y); /*adj[y].pb(x);*/ \
}
#define dekh cout << "dekh"
#define o_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setpll \
tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, \
tree_order_statistics_node_update>
typedef vector<ll> vl;
/*ll Pow(ll a, ll b, ll m){
if(b==0)return 1;
if(b%2==0){
ll x = a*a;
x%=m;
return Pow(x,b/2,m);
}
return (a*Pow(a,b-1,m))%m;
}
*/
vector<ll> adj[200005];
ll vis[200005] = {0};
ll depth[200005] = {0};
// ll p;ll arr[200005];
void dfs(ll x) {
vis[x] = 1;
for (auto child : adj[x]) {
if (!vis[child]) {
dfs(child);
}
depth[x] = max(depth[x], depth[child] + 1);
}
}
int main() {
fast ll n, m, i;
cin >> n >> m;
make_graph(m);
f1(i, n) {
if (!vis[i]) {
dfs(i);
}
}
auto maxi = max_element(depth, depth + n + 1);
cout << *maxi;
}
| [
"assignment.change"
] | 974,331 | 974,332 | u806085844 | cpp |
p03166 | /*
https://atcoder.jp/contests/dp/tasks/dp_g
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
const int oo = 1e9 + 7;
vector<vector<int>> adj;
int n, m;
int f[N], ans = 0;
bool Visited[N];
void Init() {
cin >> n >> m;
for (int i = 0; i <= n; ++i) {
adj.push_back(vector<int>());
}
int u, v;
for (int i = 0; i < m; ++i) {
cin >> u >> v;
adj[u].push_back(v);
}
}
void DFS(int pos) {
Visited[pos] = true;
for (int i = 0; i < adj[pos].size(); ++i) {
if (!Visited[adj[pos][i]])
DFS(adj[pos][i]);
f[pos] = max(f[pos], f[adj[pos][i]] + 1);
}
}
int main() {
Init();
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (Visited[i])
continue;
DFS(i);
}
for (int i = 1; i <= n; ++i) {
ans = max(ans, f[i]);
}
cout << ans;
return 0;
} | /*
https://atcoder.jp/contests/dp/tasks/dp_g
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int oo = 1e9 + 7;
vector<vector<int>> adj;
int n, m;
int f[N], ans = 0;
bool Visited[N];
void Init() {
cin >> n >> m;
for (int i = 0; i <= n; ++i) {
adj.push_back(vector<int>());
}
int u, v;
for (int i = 0; i < m; ++i) {
cin >> u >> v;
adj[u].push_back(v);
}
}
void DFS(int pos) {
Visited[pos] = true;
for (int i = 0; i < adj[pos].size(); ++i) {
if (!Visited[adj[pos][i]])
DFS(adj[pos][i]);
f[pos] = max(f[pos], f[adj[pos][i]] + 1);
}
}
int main() {
Init();
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (Visited[i])
continue;
DFS(i);
}
for (int i = 1; i <= n; ++i) {
ans = max(ans, f[i]);
}
cout << ans;
return 0;
} | [
"literal.number.change"
] | 974,335 | 974,336 | u130511458 | cpp |
p03166 | #include <bits/stdc++.h>
#define pi pair<int, int>
#define mk make_pair
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i, a, n) for (int i = a; i < n; i++)
#define fr(i, a, n) for (int i = a; i >= n; i--)
#define ll long long
#define N 1000000
using namespace std;
vector<int> adj[100005];
vector<int> dp(100005, -1);
void addedge(int x, int y) { adj[x].push_back(y); }
int dfs(int ind) {
if (dp[ind] == -1) {
int ans = 0;
for (auto i : adj[ind]) {
ans = max(ans, dfs(i) + 1);
}
ans = dp[ind];
}
return dp[ind];
}
int longestpath(int n) {
int answer = INT_MIN;
fo(i, 1, n + 1) { answer = max(answer, dfs(i)); }
return answer;
}
int main() {
int n, m;
cin >> n >> m;
int x, y;
f(i, m) {
cin >> x >> y;
addedge(x, y);
}
cout << longestpath(n);
}
| #include <bits/stdc++.h>
#define pi pair<int, int>
#define mk make_pair
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i, a, n) for (int i = a; i < n; i++)
#define fr(i, a, n) for (int i = a; i >= n; i--)
#define ll long long
#define N 1000000
using namespace std;
vector<int> adj[100005];
vector<int> dp(100005, -1);
void addedge(int x, int y) { adj[x].push_back(y); }
int dfs(int ind) {
if (dp[ind] == -1) {
int ans = 0;
for (auto i : adj[ind]) {
ans = max(ans, dfs(i) + 1);
}
dp[ind] = ans;
}
return dp[ind];
}
int longestpath(int n) {
int answer = INT_MIN;
fo(i, 1, n + 1) { answer = max(answer, dfs(i)); }
return answer;
}
int main() {
int n, m;
cin >> n >> m;
int x, y;
f(i, m) {
cin >> x >> y;
addedge(x, y);
}
cout << longestpath(n);
}
| [
"assignment.change"
] | 974,337 | 974,338 | u765828490 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define c(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define ffor(n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef unordered_map<string, int> umsi;
int32_t main() {
fast_io;
int n, m;
cin >> n >> m;
vii g(n + 1);
int x, y;
vi lgp(n + 1, 0);
vi ind(n + 1, 0);
for (int i = 0; i < m; i++) {
cin >> x >> y;
g[x].push_back(y);
ind[y]++;
}
queue<int> q;
for (int i = 0; i < n; i++)
if (!ind[i])
q.push(i);
while (!q.empty()) {
int t = q.front();
q.pop();
for (auto j : g[t]) {
lgp[j] = max(lgp[j], lgp[t] + 1);
ind[j]--;
if (!ind[j])
q.push(j);
}
}
int ans = *max_element(lgp.begin(), lgp.end());
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define c(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define ffor(n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef unordered_map<string, int> umsi;
int32_t main() {
fast_io;
int n, m;
cin >> n >> m;
vii g(n + 1);
int x, y;
vi lgp(n + 1, 0);
vi ind(n + 1, 0);
for (int i = 0; i < m; i++) {
cin >> x >> y;
g[x].push_back(y);
ind[y]++;
}
queue<int> q;
for (int i = 1; i <= n; i++)
if (!ind[i])
q.push(i);
while (!q.empty()) {
int t = q.front();
q.pop();
for (auto j : g[t]) {
lgp[j] = max(lgp[j], lgp[t] + 1);
ind[j]--;
if (!ind[j])
q.push(j);
}
}
int ans = *max_element(lgp.begin(), lgp.end());
cout << ans;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 974,339 | 974,340 | u900229905 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a, n) \
for (size_t i = 0; i < n; i++) \
cin >> a[i];
#define ffor(n) for (size_t i = 0; i < n; i++)
#define asort(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.begin(), a.end(), greater<int>())
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef unordered_map<string, int> umsi;
int32_t main() {
fast_io;
int n, m, u, v;
cin >> n >> m;
vi graph[100005], in_deg(n + 1), ans(n + 1);
for (int i = 0; i < n; i++) {
cin >> u >> v;
graph[u].pb(v);
in_deg[v]++;
}
queue<int> que;
for (int i = 1; i <= n; i++)
if (in_deg[i] == 0)
que.push(i);
while (!que.empty()) {
u = que.front();
que.pop();
for (auto &i : graph[u]) {
ans[i] = max(ans[i], ans[u] + 1);
in_deg[i]--;
if (in_deg[i] == 0)
que.push(i);
}
}
cout << *max_element(ans.begin(), ans.end());
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a, n) \
for (size_t i = 0; i < n; i++) \
cin >> a[i];
#define ffor(n) for (size_t i = 0; i < n; i++)
#define asort(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.begin(), a.end(), greater<int>())
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef unordered_map<string, int> umsi;
int32_t main() {
fast_io;
int n, m, u, v;
cin >> n >> m;
vi graph[100005], in_deg(n + 1), ans(n + 1);
for (int i = 0; i < m; i++) {
cin >> u >> v;
graph[u].pb(v);
in_deg[v]++;
}
queue<int> que;
for (int i = 1; i <= n; i++)
if (in_deg[i] == 0)
que.push(i);
while (!que.empty()) {
u = que.front();
que.pop();
for (auto &i : graph[u]) {
ans[i] = max(ans[i], ans[u] + 1);
in_deg[i]--;
if (in_deg[i] == 0)
que.push(i);
}
}
cout << *max_element(ans.begin(), ans.end());
return 0;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 974,343 | 974,344 | u688146320 | cpp |
p03166 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<int> arr[100001];
bool vis[100001];
int dist[100001];
void dfs(int node) {
vis[node] = 1;
for (auto child : arr[node]) {
if (vis[child] == 0) {
dfs(child);
dist[node] = max(dist[node], 1 + dist[child]);
}
}
}
int main() {
// https://atcoder.jp/contests/dp/tasks/dp_g
int n, m;
cin >> n >> m;
int a, b;
for (int i = 0; i <= n; i++) {
vis[i] = 0;
dist[i] = 0;
arr[i].clear();
}
for (int i = 0; i < m; i++) {
cin >> a >> b;
arr[a].push_back(b);
}
for (int i = 1; i <= n; i++) {
if (vis[i] == 0)
dfs(i);
}
int maxi = 0;
for (int i = 1; i <= n; i++) {
maxi = max(maxi, dist[i]);
}
cout << maxi << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
vector<int> arr[100001];
bool vis[100001];
int dist[100001];
void dfs(int node) {
vis[node] = 1;
for (auto child : arr[node]) {
if (vis[child] == 0)
dfs(child);
dist[node] = max(dist[node], 1 + dist[child]);
}
}
int main() {
// https://atcoder.jp/contests/dp/tasks/dp_g
int n, m;
cin >> n >> m;
int a, b;
for (int i = 0; i <= n; i++) {
vis[i] = 0;
dist[i] = 0;
arr[i].clear();
}
for (int i = 0; i < m; i++) {
cin >> a >> b;
arr[a].push_back(b);
}
for (int i = 1; i <= n; i++) {
if (vis[i] == 0)
dfs(i);
}
int maxi = 0;
for (int i = 1; i <= n; i++) {
maxi = max(maxi, dist[i]);
}
cout << maxi << endl;
return 0;
} | [] | 974,349 | 974,350 | u780643980 | cpp |
p03166 | #include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>
#define pb push_back
// #define pop pop_back
#define ll long long int
#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#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, a, b) for (ll i = a; i >= b; i--)
#define I long_max
#define pii pair<int, int>
#define pll pair<long, long>
#define vpair vector<pair<int, int>>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fir first
#define sec second
#define d (int)1e9 + 7
#define INF (int)2e9 + 1
#define el "\n"
#define fs fastscan
#define vrep(vec) for (const auto &value : vec)
#define arep(arrat) for (const auto &value : array)
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
void swap(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
}
// over
bool isPrime(int n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
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;
}
ll dfs(ll n, vector<vector<ll>> &adj, vector<ll> &dp) {
for (ll j = 0; j < adj[n].size(); j++) {
if (dp[adj[n][j]] == -1) {
if (dp[n] == -1) {
dp[n] = 0;
}
dp[n] = max(dp[n], 1 + dfs(adj[n][j], adj, dp));
} else {
if (dp[n] == -1) {
dp[n] = 0;
}
dp[n] = max(dp[n], 1 + dp[adj[n][j]]);
}
}
if (dp[n] == -1) {
return dp[n] = 0;
}
return dp[n];
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
// use auto instead of data types
{
ll n, m;
cin >> n >> m;
vector<vector<ll>> adj(n + 1);
rep(i, m) {
int t1, t2;
cin >> t1 >> t2;
adj[t1].push_back(t2);
}
vector<ll> dp(n + 1, -1);
rep2(i, 1, n) {
if (dp[n] == -1)
dfs(i, adj, dp);
}
cout << *max_element(dp.begin(), dp.end()) << el;
}
return 0;
}
| #include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>
#define pb push_back
// #define pop pop_back
#define ll long long int
#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#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, a, b) for (ll i = a; i >= b; i--)
#define I long_max
#define pii pair<int, int>
#define pll pair<long, long>
#define vpair vector<pair<int, int>>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define fir first
#define sec second
#define d (int)1e9 + 7
#define INF (int)2e9 + 1
#define el "\n"
#define fs fastscan
#define vrep(vec) for (const auto &value : vec)
#define arep(arrat) for (const auto &value : array)
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
void swap(int *a, int *b) {
int temp;
temp = *a;
*a = *b;
*b = temp;
}
// over
bool isPrime(int n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
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;
}
ll dfs(ll n, vector<vector<ll>> &adj, vector<ll> &dp) {
for (ll j = 0; j < adj[n].size(); j++) {
if (dp[adj[n][j]] == -1) {
if (dp[n] == -1) {
dp[n] = 0;
}
dp[n] = max(dp[n], 1 + dfs(adj[n][j], adj, dp));
} else {
if (dp[n] == -1) {
dp[n] = 0;
}
dp[n] = max(dp[n], 1 + dp[adj[n][j]]);
}
}
if (dp[n] == -1) {
return dp[n] = 0;
}
return dp[n];
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
// use auto instead of data types
{
ll n, m;
cin >> n >> m;
vector<vector<ll>> adj(n + 1);
rep(i, m) {
int t1, t2;
cin >> t1 >> t2;
adj[t1].push_back(t2);
}
vector<ll> dp(n + 1, -1);
rep2(i, 1, n) {
if (dp[i] == -1)
dfs(i, adj, dp);
}
cout << *max_element(dp.begin(), dp.end()) << el;
}
return 0;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 974,354 | 974,355 | u016294888 | cpp |
p03166 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> V[200005];
int indegree[200005];
int bio[200005];
int dp[200005];
void dfs(int a) {
bio[a] = 1;
for (auto b : V[a]) {
dp[b] = max(dp[b], dp[a] + 1);
indegree[b]--;
if (!indegree[b]) {
dfs(b);
}
}
}
int main() {
int n, m, sol, a, b;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
V[a].push_back(b);
indegree[b]++;
}
for (int i = 1; i <= n; i++) {
if (indegree[i] == 0 && bio[i] == 0) {
dfs(i);
}
}
for (int i = 1; i <= n; i++) {
sol = max(sol, dp[i]);
}
cout << sol << endl;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> V[200005];
int indegree[200005];
int bio[200005];
int dp[200005];
void dfs(int a) {
bio[a] = 1;
for (auto b : V[a]) {
dp[b] = max(dp[b], dp[a] + 1);
indegree[b]--;
if (!indegree[b]) {
dfs(b);
}
}
}
int main() {
int n, m, sol = 0, a, b;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
V[a].push_back(b);
indegree[b]++;
}
for (int i = 1; i <= n; i++) {
if (indegree[i] == 0 && bio[i] == 0) {
dfs(i);
}
}
for (int i = 1; i <= n; i++) {
sol = max(sol, dp[i]);
}
cout << sol << endl;
}
| [
"variable_declaration.value.change"
] | 974,400 | 974,401 | u787597250 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool visited[100005];
int dp[100005];
void visit(int vertex) {
visited[vertex] = 1;
dp[vertex] = 0;
for (int child : adj[vertex]) {
if (!visited[child]) {
visit(child);
}
dp[vertex] = max(dp[vertex], 1 + dp[child]);
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
visit(i);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
cout << "Hello world!" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool visited[100005];
int dp[100005];
void visit(int vertex) {
visited[vertex] = 1;
dp[vertex] = 0;
for (int child : adj[vertex]) {
if (!visited[child]) {
visit(child);
}
dp[vertex] = max(dp[vertex], 1 + dp[child]);
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
visit(i);
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
| [
"io.output.change"
] | 974,402 | 974,403 | u397680283 | cpp |
p03166 | #define _CRT_SECURE_NO_WARNINGS
/* وتزودوا فإن خير الزاد التقوى */
/* وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت */
#include <bits/stdc++.h>
#include <fstream>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout << #x << " = " << x << " \n"
#define sz(n) n.size()
#define M_Sayed fast()
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define RT(v) return cout << v, 0
#define MP make_pair
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
const double EPS = (1e-7);
const ll mod = (1e9 + 7), OO = 1e9;
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
// freopen("input", "r", stdin);
// freopen("output", "w", stdout);
#endif
}
void fast() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
// BFS (lenth && all path from an start node
vector<vector<ll>> adjList;
ll vis[100001];
ll y;
ll ca = 0, x;
ll dfs(int u) {
if (vis[u])
return vis[u];
for (auto e : adjList[u])
vis[u] = max(vis[u], 1 + dfs(e));
return vis[u];
}
int main() {
M_Sayed;
run();
int n, e, k;
cin >> n >> e;
adjList.resize(n + 1);
for (int i = 0; i < e; i++) {
int from, to;
cin >> from >> to;
adjList[from].push_back(to);
}
for (int i = 1; i <= n; i++) {
y = max(y, dfs(i));
}
RT(y);
} | #define _CRT_SECURE_NO_WARNINGS
/* وتزودوا فإن خير الزاد التقوى */
/* وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت */
#include <bits/stdc++.h>
#include <fstream>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout << #x << " = " << x << " \n"
#define sz(n) n.size()
#define M_Sayed fast()
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define RT(v) return cout << v, 0
#define MP make_pair
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
const double EPS = (1e-7);
const ll mod = (1e9 + 7), OO = 1e9;
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
// freopen("input", "r", stdin);
// freopen("output", "w", stdout);
#endif
}
void fast() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
// BFS (lenth && all path from an start node
vector<vector<ll>> adjList;
ll vis[100005];
ll y;
ll ca = 0, x;
ll dfs(int u) {
if (vis[u])
return vis[u];
for (auto e : adjList[u])
vis[u] = max(vis[u], 1 + dfs(e));
return vis[u];
}
int main() {
M_Sayed;
// run();
int n, e, k;
cin >> n >> e;
adjList.resize(n + 1);
for (int i = 0; i < e; i++) {
int from, to;
cin >> from >> to;
adjList[from].push_back(to);
}
for (int i = 1; i <= n; i++) {
y = max(y, dfs(i));
}
// cout << round(12.3);
RT(y);
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"call.remove"
] | 974,443 | 974,444 | u018679195 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
const int mx = 1000009;
vector<ll> edg[mx];
int visited[mx];
ll dp[mx];
void dfs(int node) {
visited[node] = 1;
for (auto i : edg[node]) {
if (!visited[i]) {
dfs(i);
}
dp[node] = max(dp[node], dp[i] + 1);
}
}
int main() {
cin >> n >> m;
ll x, y;
for (int i = 0; i < m; i++) {
cin >> x >> y;
edg[x].push_back(y);
}
for (int i = 1; i <= m; i++) {
if (!visited[i]) {
dfs(i);
}
}
ll ans = 0;
for (int i = 1; i <= m; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
const int mx = 1000009;
vector<ll> edg[mx];
int visited[mx];
ll dp[mx];
void dfs(int node) {
visited[node] = 1;
for (auto i : edg[node]) {
if (!visited[i]) {
dfs(i);
}
dp[node] = max(dp[node], dp[i] + 1);
}
}
int main() {
cin >> n >> m;
ll x, y;
for (int i = 0; i < m; i++) {
cin >> x >> y;
edg[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
if (!visited[i]) {
dfs(i);
}
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 974,445 | 974,446 | u474448122 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
#include <map>
#include <string.h>
#define MEM(var, val) memset(var, (val), sizeof(var))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define nitro \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
//*max_element(a.begin(), a.end())
vector<vll> adj;
vll vis;
vll d;
void dfs(int v) {
if (vis[v])
return;
vis[v] = 1;
for (int i : adj[v]) {
if (!vis[i]) {
dfs(i);
d[v] = MAX(d[v], 1 + d[i]);
}
}
}
int main() {
ll n, m;
cin >> n >> m;
adj.clear();
adj.resize(n + 1);
vis.clear();
vis.resize(n + 1, 0);
d.clear();
d.resize(n + 1, 0);
for (int i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
adj[a].pb(b);
}
for (int i = 1; i <= n; i++) {
if (!vis[i])
dfs(i);
}
cout << *max_element(d.begin(), d.end());
} | #include <bits/stdc++.h>
using namespace std;
#include <map>
#include <string.h>
#define MEM(var, val) memset(var, (val), sizeof(var))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define nitro \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
//*max_element(a.begin(), a.end())
vector<vll> adj;
vll vis;
vll d;
void dfs(int v) {
if (vis[v])
return;
vis[v] = 1;
for (int i : adj[v]) {
if (!vis[i])
dfs(i);
d[v] = MAX(d[v], 1 + d[i]);
}
}
int main() {
ll n, m;
cin >> n >> m;
adj.clear();
adj.resize(n + 1);
vis.clear();
vis.resize(n + 1, 0);
d.clear();
d.resize(n + 1, 0);
for (int i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
adj[a].pb(b);
}
for (int i = 1; i <= n; i++) {
if (!vis[i])
dfs(i);
}
cout << *max_element(d.begin(), d.end());
} | [] | 974,459 | 974,460 | u116264984 | cpp |
p03166 |
//#include "stdc++.h"
#include <bits/stdc++.h>
#include <iostream>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p * p) % m;
if (n % 2)
return (p * a) % m;
else
return p;
}
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
int main() {
IOS; // ifstream fin("input.txt");ofstream fout("output.txt");
int n, m;
cin >> n >> m;
vector<int> adj[n + 1];
int u, v;
int in[n + 1];
memset(in, 0, sizeof(in));
for (int i = 0; i < m; i++) {
cin >> u >> v;
adj[u].pb(v);
in[v]++;
}
set<pair<int, int>> s;
set<pair<int, int>>::iterator it;
vector<int> topo;
for (int i = 1; i <= n; i++)
s.insert(m1(in[i], i));
pair<int, int> p;
while (!s.empty()) {
p = (*s.begin());
s.erase(s.begin());
u = p.second;
topo.pb(u);
for (int i = 0; i < adj[u].size(); i++) {
v = adj[u][i];
it = s.find(m1(in[v], v));
if (it != s.end()) {
in[v]--;
s.erase(it);
s.insert(m1(in[v], v));
}
}
}
int d[n + 1];
memset(d, 0, sizeof(d));
int ans = 0;
for (int i = 0; i < topo.size(); i++) {
u = topo[i];
for (int j = 0; j < adj[u].size(); j++) {
v = adj[u][j];
d[v] = max(d[j], 1 + d[u]);
}
}
for (int i = 1; i <= n; i++)
ans = max(ans, d[i]);
cout << ans << endl;
return 0;
}
|
//#include "stdc++.h"
#include <bits/stdc++.h>
#include <iostream>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p * p) % m;
if (n % 2)
return (p * a) % m;
else
return p;
}
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
int main() {
IOS; // ifstream fin("input.txt");ofstream fout("output.txt");
int n, m;
cin >> n >> m;
vector<int> adj[n + 1];
int u, v;
int in[n + 1];
memset(in, 0, sizeof(in));
for (int i = 0; i < m; i++) {
cin >> u >> v;
adj[u].pb(v);
in[v]++;
}
set<pair<int, int>> s;
set<pair<int, int>>::iterator it;
vector<int> topo;
for (int i = 1; i <= n; i++)
s.insert(m1(in[i], i));
pair<int, int> p;
while (!s.empty()) {
p = (*s.begin());
s.erase(s.begin());
u = p.second;
topo.pb(u);
for (int i = 0; i < adj[u].size(); i++) {
v = adj[u][i];
it = s.find(m1(in[v], v));
if (it != s.end()) {
in[v]--;
s.erase(it);
s.insert(m1(in[v], v));
}
}
}
int d[n + 1];
memset(d, 0, sizeof(d));
int ans = 0;
for (int i = 0; i < topo.size(); i++) {
u = topo[i];
for (int j = 0; j < adj[u].size(); j++) {
v = adj[u][j];
d[v] = max(d[v], 1 + d[u]);
}
}
for (int i = 1; i <= n; i++)
ans = max(ans, d[i]);
cout << ans << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 974,471 | 974,472 | u314476982 | cpp |
p03166 | #include <bits/stdc++.h>
#define N 500003
#define MOD 1000000007
#define int long long
using namespace std;
int vis[100006];
vector<int> v[100006];
int dp[100006];
void dfs(int root) {
if (vis[root])
return;
vis[root] = 1;
for (auto it : v[root]) {
if (!vis[root])
dfs(it);
dp[root] = max(dp[root], dp[it] + 1);
}
}
signed main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].push_back(y);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
dfs(i);
ans = max(ans, dp[i]);
}
cout << ans + 1 << endl;
}
| #include <bits/stdc++.h>
#define N 500003
#define MOD 1000000007
#define int long long
using namespace std;
int vis[100006];
vector<int> v[100006];
int dp[100006];
void dfs(int root) {
if (vis[root])
return;
vis[root] = 1;
for (auto it : v[root]) {
if (!vis[it])
dfs(it);
dp[root] = max(dp[root], dp[it] + 1);
}
}
signed main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].push_back(y);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
dfs(i);
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 974,511 | 974,512 | u360668137 | cpp |
p03166 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define PII pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define dec(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
// if(x<0 || x>=r || y<0 || y>=c)
inline ll read() {
ll x = 0;
bool f = true;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = false;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? x : -x;
}
ll gcd(ll m, ll n) { return n == 0 ? m : gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }
bool prime(int x) {
if (x < 2)
return false;
for (int i = 2; i * i <= x; ++i) {
if (x % i == 0)
return false;
}
return true;
}
ll qpow(ll m, ll k, ll mod) {
ll res = 1, t = m;
while (k) {
if (k & 1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> a(n + 1);
vector<int> in(n + 1), dp(n + 1);
rep(i, 1, n) {
int u, v;
cin >> u >> v;
a[u].push_back(v);
in[v]++;
}
queue<int> q;
rep(i, 1, n) {
if (!in[i])
q.push(i);
}
while (!q.empty()) {
int f = q.front();
q.pop();
for (int i = 0; i < a[f].size(); i++) {
int to = a[f][i];
in[to]--;
if (!in[to]) {
dp[to] = dp[f] + 1;
q.push(to);
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, dp[i]);
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define PII pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define dec(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
// if(x<0 || x>=r || y<0 || y>=c)
inline ll read() {
ll x = 0;
bool f = true;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = false;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? x : -x;
}
ll gcd(ll m, ll n) { return n == 0 ? m : gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }
bool prime(int x) {
if (x < 2)
return false;
for (int i = 2; i * i <= x; ++i) {
if (x % i == 0)
return false;
}
return true;
}
ll qpow(ll m, ll k, ll mod) {
ll res = 1, t = m;
while (k) {
if (k & 1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> a(n + 1);
vector<int> in(n + 1), dp(n + 1);
rep(i, 1, m) {
int u, v;
cin >> u >> v;
a[u].push_back(v);
in[v]++;
}
queue<int> q;
rep(i, 1, n) {
if (!in[i])
q.push(i);
}
while (!q.empty()) {
int f = q.front();
q.pop();
for (int i = 0; i < a[f].size(); i++) {
int to = a[f][i];
in[to]--;
if (!in[to]) {
dp[to] = dp[f] + 1;
q.push(to);
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, dp[i]);
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"call.arguments.change"
] | 974,513 | 974,514 | u258553417 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
// void d_m_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
// }
int solve(int src) {
if (dp[src] != -1)
return dp[src];
int leaf = 1;
int bestChild = 0;
for (int nbr : graph[src]) {
leaf = 0;
bestChild = max(bestChild, solve(nbr));
}
if (leaf)
return dp[src] = 1;
else
return dp[src] = 1 + bestChild;
}
int32_t main() {
// d_m_c();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
}
memset(dp, -1, sizeof dp);
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, solve(i));
}
cout << best;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
// void d_m_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
// }
int solve(int src) {
if (dp[src] != -1)
return dp[src];
int leaf = 1;
int bestChild = 0;
for (int nbr : graph[src]) {
leaf = 0;
bestChild = max(bestChild, solve(nbr));
}
if (leaf)
return dp[src] = 0;
else
return dp[src] = 1 + bestChild;
}
int32_t main() {
// d_m_c();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
}
memset(dp, -1, sizeof dp);
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, solve(i));
}
cout << best;
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"function.return_value.change"
] | 974,526 | 974,527 | u337524871 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
// void d_m_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
// }
int solve(int src) {
if (dp[src] != -1)
return dp[src];
int leaf = 1;
int bestChild = 0;
for (int nbr : graph[src]) {
leaf = 0;
bestChild = max(bestChild, solve(nbr));
}
if (leaf)
return dp[src] = 1;
else
dp[src] = 1 + bestChild;
}
int32_t main() {
// d_m_c();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
}
memset(dp, -1, sizeof dp);
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, solve(i));
}
cout << best;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
// void d_m_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
// }
int solve(int src) {
if (dp[src] != -1)
return dp[src];
int leaf = 1;
int bestChild = 0;
for (int nbr : graph[src]) {
leaf = 0;
bestChild = max(bestChild, solve(nbr));
}
if (leaf)
return dp[src] = 0;
else
return dp[src] = 1 + bestChild;
}
int32_t main() {
// d_m_c();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
}
memset(dp, -1, sizeof dp);
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, solve(i));
}
cout << best;
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"function.return_value.change",
"control_flow.return.add"
] | 974,528 | 974,527 | u337524871 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
// void d_m_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
// }
int solve(int src) {
if (dp[src] != -1)
return dp[src];
int leaf = 1;
int bestChild = 0;
for (int nbr : graph[src]) {
leaf = 0;
bestChild = max(bestChild, solve(nbr));
}
if (leaf)
return dp[src] = 0;
else
dp[src] = 1 + bestChild;
}
int main() {
// d_m_c();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
}
memset(dp, -1, sizeof dp);
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, solve(i));
}
cout << best;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
int dp[100001];
// void d_m_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
// }
int solve(int src) {
if (dp[src] != -1)
return dp[src];
int leaf = 1;
int bestChild = 0;
for (int nbr : graph[src]) {
leaf = 0;
bestChild = max(bestChild, solve(nbr));
}
if (leaf)
return dp[src] = 0;
else
return dp[src] = 1 + bestChild;
}
int32_t main() {
// d_m_c();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
}
memset(dp, -1, sizeof dp);
int best = 0;
for (int i = 1; i <= n; i++) {
best = max(best, solve(i));
}
cout << best;
return 0;
} | [
"control_flow.return.add",
"function.return_type.change"
] | 974,529 | 974,527 | u337524871 | cpp |
p03166 | #include <bits/stdc++.h>
#define ll long long int
#define loop(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rloop(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define loopl(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i)
#define loopr(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define count_1(n) __builtin_popcountll(n)
#define pb push_back
#define eb emplace_back
#define ab(a) (a < 0) ? (-1 * a) : a
#define pc putchar_unlocked
#define gc getchar_unlocked
#define mset(a, b, c) loop(i, 0, b) a[i] = c
#define F first
#define S second
#define mp make_pair
#define clr(x) x.clear()
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define itoc(c) ((char)(((int)'0') + c))
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(p) p.begin(), p.end()
#define mid(s, e) (s + (e - s) / 2)
#define mini INT_MIN
#define vloop(i, v) for (auto i : v)
const int MX = 10010896;
const int lmt = 3164;
const int N = 10000001;
int flag[MX >> 6];
#define ifc(i) (flag[i >> 6] & (1 << ((i >> 1) & 31)))
#define isc(i) (flag[i >> 6] |= (1 << ((i >> 1) & 31)))
#define chk(n) (n == 2 || (n > 2 && (n & 1) && !ifc(n)))
#define sv() \
int t; \
scanf("%d", &t); \
while (t--)
using namespace std;
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
ll modpow(ll a, ll b) {
ll res = 1;
a %= MOD;
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
void sieve() {
int i, j, k;
for (i = 3; i < lmt; i += 2)
if (!ifc(i))
for (j = i * i, k = i << 1; j < MX; j += k)
isc(j);
}
int n, m, vis[100009], dis[100009];
vi adj[100009];
vi tt(100005);
void init() { memset(vis, 0, sizeof(vis)); }
int dfs(int s) {
if (vis[s])
return dis[s];
vis[s] = 1;
int ret = 0;
for (auto u : adj[s])
ret = max(ret, dfs(u) + 1);
dis[s] = ret;
return dis[s];
}
int main() {
int n, m;
cin >> n >> m;
loop(i, 0, n) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
}
int ans = 0;
loop(i, 1, n + 1) {
if (!vis[i])
ans = max(ans, dfs(i));
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ll long long int
#define loop(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rloop(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define loopl(i, a, b) for (ll i = (ll)a; i < (ll)b; ++i)
#define loopr(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define count_1(n) __builtin_popcountll(n)
#define pb push_back
#define eb emplace_back
#define ab(a) (a < 0) ? (-1 * a) : a
#define pc putchar_unlocked
#define gc getchar_unlocked
#define mset(a, b, c) loop(i, 0, b) a[i] = c
#define F first
#define S second
#define mp make_pair
#define clr(x) x.clear()
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9
#define itoc(c) ((char)(((int)'0') + c))
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(p) p.begin(), p.end()
#define mid(s, e) (s + (e - s) / 2)
#define mini INT_MIN
#define vloop(i, v) for (auto i : v)
const int MX = 10010896;
const int lmt = 3164;
const int N = 10000001;
int flag[MX >> 6];
#define ifc(i) (flag[i >> 6] & (1 << ((i >> 1) & 31)))
#define isc(i) (flag[i >> 6] |= (1 << ((i >> 1) & 31)))
#define chk(n) (n == 2 || (n > 2 && (n & 1) && !ifc(n)))
#define sv() \
int t; \
scanf("%d", &t); \
while (t--)
using namespace std;
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
}
ll modpow(ll a, ll b) {
ll res = 1;
a %= MOD;
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
void sieve() {
int i, j, k;
for (i = 3; i < lmt; i += 2)
if (!ifc(i))
for (j = i * i, k = i << 1; j < MX; j += k)
isc(j);
}
int n, m, vis[100009], dis[100009];
vi adj[100009];
vi tt(100005);
void init() { memset(vis, 0, sizeof(vis)); }
int dfs(int s) {
if (vis[s])
return dis[s];
vis[s] = 1;
int ret = 0;
for (auto u : adj[s])
ret = max(ret, dfs(u) + 1);
dis[s] = ret;
return dis[s];
}
int main() {
int n, m;
cin >> n >> m;
loop(i, 0, m) {
int a, b;
cin >> a >> b;
adj[a].pb(b);
}
int ans = 0;
loop(i, 1, n + 1) {
if (!vis[i])
ans = max(ans, dfs(i));
}
cout << ans << endl;
} | [
"identifier.change",
"call.arguments.change"
] | 974,534 | 974,535 | u202379883 | cpp |
p03166 | // Harjot Singh Student NIT JALANDHAR
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long int ll;
int longestpath(int s, vector<int> *adj, int *dp) {
if (dp[s] != -1)
return dp[s];
bool child = false;
int len = 0;
for (auto it : adj[s]) {
child = true;
len = max(len, longestpath(it, adj, dp));
}
return dp[s] = child ? 1 + len : 0;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> adj[n + 1];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
int dp[m + 1];
memset(dp, -1, sizeof(dp));
int res = 0;
for (int i = 1; i <= m; i++) {
res = max(res, longestpath(i, adj, dp));
}
cout << res << endl;
return 0;
}
| // Harjot Singh Student NIT JALANDHAR
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef long long int ll;
int longestpath(int s, vector<int> *adj, int *dp) {
if (dp[s] != -1)
return dp[s];
bool child = false;
int len = 0;
for (auto it : adj[s]) {
child = true;
len = max(len, longestpath(it, adj, dp));
}
return dp[s] = child ? 1 + len : 0;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> adj[n + 1];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
}
int dp[n + 1];
memset(dp, -1, sizeof(dp));
int res = 0;
for (int i = 1; i <= n; i++) {
res = max(res, longestpath(i, adj, dp));
}
cout << res << endl;
return 0;
}
| [
"identifier.change",
"expression.operation.binary.change",
"control_flow.loop.for.condition.change"
] | 974,546 | 974,547 | u487912105 | cpp |
p03166 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mod 1000000007
#define check exit(0)
#define nl cout << endl;
#define inp 10
#define ordered_set \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define deb(v) \
for (int i = 0; i < v.size(); i++) { \
cout << v[i]; \
(i == v.size() - 1) ? cout << "\n" : cout << " "; \
}
#define jaldi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
// Pick yourself up, 'cause...
vector<int> g[100005];
vector<bool> visited(100005, false);
vector<int> start(inp, 0);
void dfs(int n) {
if (visited[n])
return;
visited[n] = true;
for (int c : g[n]) {
dfs(c);
start[n] = max(start[n], 1 + start[c]);
}
}
int main() {
jaldi
int n,
m;
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].push_back(v);
}
for (int i = 1; i <= n; i++) {
if (!visited[i])
dfs(i);
}
for (int i = 1; i <= n; i++)
visited[i] = false;
// deb(start);
// for(int i=1;i<=n;i++)
// {
// if(!visited[i]) dfs(i);
// }
// deb(start);
int ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, start[i]);
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mod 1000000007
#define check exit(0)
#define nl cout << endl;
#define inp 200005
#define ordered_set \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define deb(v) \
for (int i = 0; i < v.size(); i++) { \
cout << v[i]; \
(i == v.size() - 1) ? cout << "\n" : cout << " "; \
}
#define jaldi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
// Pick yourself up, 'cause...
vector<int> g[100005];
vector<bool> visited(100005, false);
vector<int> start(inp, 0);
void dfs(int n) {
if (visited[n])
return;
visited[n] = true;
for (int c : g[n]) {
dfs(c);
start[n] = max(start[n], 1 + start[c]);
}
}
int main() {
jaldi
int n,
m;
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++) {
cin >> u >> v;
g[u].push_back(v);
}
for (int i = 1; i <= n; i++) {
if (!visited[i])
dfs(i);
}
for (int i = 1; i <= n; i++)
visited[i] = false;
// deb(start);
// for(int i=1;i<=n;i++)
// {
// if(!visited[i]) dfs(i);
// }
// deb(start);
int ans = 0;
for (int i = 1; i <= n; i++)
ans = max(ans, start[i]);
cout << ans;
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 974,548 | 974,549 | u319910051 | cpp |
p03166 | #include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MAX 100005
vector<int> v[MAX];
int dp[MAX], vis[MAX], indeg[MAX];
void dfs(int x) {
vis[x] = 1;
dp[x] = 0;
if (v[x].size() == 0)
return;
int val = 0;
for (auto i : v[x]) {
if (vis[i] == 0) {
dfs(i);
if (val < dp[i])
val = dp[i];
}
}
dp[x] = val + 1;
}
signed main() {
int n, m, i;
cin >> n >> m;
for (i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
indeg[b]++;
v[a].push_back(b);
}
int m1 = 0;
for (i = 1; i <= n; i++)
if (indeg[i] == 0) {
dfs(i);
if (dp[i] > m1)
m1 = dp[i];
}
cout << m1 << "\n";
} | #include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MAX 100005
vector<int> v[MAX];
int dp[MAX], vis[MAX], indeg[MAX];
void dfs(int x) {
vis[x] = 1;
dp[x] = 0;
if (v[x].size() == 0)
return;
int val = 0;
for (auto i : v[x]) {
if (vis[i] == 0)
dfs(i);
if (val < dp[i])
val = dp[i];
}
dp[x] = val + 1;
}
signed main() {
int n, m, i;
cin >> n >> m;
for (i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
indeg[b]++;
v[a].push_back(b);
}
int m1 = 0;
for (i = 1; i <= n; i++)
if (indeg[i] == 0) {
dfs(i);
if (dp[i] > m1)
m1 = dp[i];
}
cout << m1 << "\n";
} | [] | 974,563 | 974,564 | u474688099 | cpp |
p03165 | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))
// container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
sort(ALL(c)); \
for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))
// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
// constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 1, 0, 0};
constexpr int dy[] = {0, 0, -1, 1};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
//
struct Accelerate_Cin {
Accelerate_Cin() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
};
signed main() {
string s, t;
cin >> s >> t;
static int dp[3030][3030];
m0(dp);
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i + 1] == t[j + 1]) {
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.size(), j = t.size();
while (i >= 1 && j >= 1) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
continue;
}
if (dp[i][j] == dp[i][j - 1]) {
j--;
continue;
}
ans = s[i - 1] + ans;
i--, j--;
}
cout << ans << endl;
return 0;
}
| #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))
// container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
sort(ALL(c)); \
for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))
// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
// constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 1, 0, 0};
constexpr int dy[] = {0, 0, -1, 1};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
//
struct Accelerate_Cin {
Accelerate_Cin() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
};
signed main() {
string s, t;
cin >> s >> t;
static int dp[3030][3030];
m0(dp);
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
string ans = "";
int i = s.size(), j = t.size();
while (i >= 1 && j >= 1) {
if (dp[i][j] == dp[i - 1][j]) {
i--;
continue;
}
if (dp[i][j] == dp[i][j - 1]) {
j--;
continue;
}
ans = s[i - 1] + ans;
i--, j--;
}
cout << ans << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 974,579 | 974,580 | u876978301 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.