Datasets:

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
p03164
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> ii; const int N = 1e2 + 5; const int M = 1e3 + 5; const ll INF = 1e15; int n, W, h[N], v[N], w[N]; ll dp[N][N * M]; ll f(int cur, int rem) { if (rem < 0) return INF; if (cur == n + 1) { if (rem == 0) return 0; return INF; } ll &res = dp[cur][rem]; if (res != -1) return res; res = f(cur + 1, rem); res = min(res, f(cur + 1, rem - v[cur]) + w[cur]); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> W; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; memset(dp, -1, sizeof dp); for (int i = N * M - 5; i >= 17; i--) { if (f(1, i) <= W) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> ii; const int N = 1e2 + 5; const int M = 1e3 + 5; const ll INF = 1e15; int n, W, h[N], v[N], w[N]; ll dp[N][N * M]; ll f(int cur, int rem) { if (rem < 0) return INF; if (cur == n + 1) { if (rem == 0) return 0; return INF; } ll &res = dp[cur][rem]; if (res != -1) return res; res = f(cur + 1, rem); res = min(res, f(cur + 1, rem - v[cur]) + w[cur]); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> W; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; memset(dp, -1, sizeof dp); for (int i = N * M - 5; i >= 0; i--) { if (f(1, i) <= W) { cout << i << endl; return 0; } } }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,767
971,768
u445860050
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) // const ll mod = 1000000007; int dp[105][100005]; int main() { // cout.precision(10); for (int i = 0; i <= 100000; i++) { dp[0][i] = INF; } dp[0][0] = 0; int N, W; cin >> N >> W; for (int i = 1; i <= N; i++) { int w, v; cin >> w >> v; for (int j = 0; j <= 100000; j++) { dp[i][j] = dp[i - 1][j]; if (j - v >= 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v] + w); } } } for (int i = 100000; i >= 0; i--) { if (dp[N][i] <= W) { cout << i << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9 + 2) #define PI (acos(-1)) // const ll mod = 1000000007; int dp[105][100005]; int main() { // cout.precision(10); for (int i = 0; i <= 100000; i++) { dp[0][i] = INF; } dp[0][0] = 0; int N, W; cin >> N >> W; for (int i = 1; i <= N; i++) { int w, v; cin >> w >> v; for (int j = 0; j <= 100000; j++) { dp[i][j] = dp[i - 1][j]; if (j - v >= 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v] + w); } } } for (int i = 100000; i >= 0; i--) { if (dp[N][i] <= W) { cout << i << endl; return 0; } } return 0; }
[]
971,776
971,777
u980655160
cpp
p03164
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { int N, W; cin >> N >> W; vector<LL> w(N + 1), v(N + 1); for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; vector<LL> dp(100 * 1000 + 1, 1000000000L); dp[0] = 0; int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 100 * 1000; j >= v[i]; j--) { dp[j] = min(dp[j - v[i]] + w[i], dp[j]); if (dp[j] <= W) ans = max(ans, j); } } for (int j = 0; j <= 100 * 1000; j++) { if (dp[j] <= W) ans = max(ans, j); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using LL = long long; int main() { int N, W; cin >> N >> W; vector<LL> w(N + 1), v(N + 1); for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; vector<LL> dp(100 * 1000 + 1, 10000000000L); dp[0] = 0; int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 100 * 1000; j >= v[i]; j--) { dp[j] = min(dp[j - v[i]] + w[i], dp[j]); if (dp[j] <= W) ans = max(ans, j); } } for (int j = 0; j <= 100 * 1000; j++) { if (dp[j] <= W) ans = max(ans, j); } cout << ans << endl; }
[ "literal.number.change", "call.arguments.change" ]
971,786
971,787
u296096665
cpp
p03164
#include <bits/stdc++.h> #define fore(x, a, b) for (int x = a, qwerty = b; x < qwerty; x++) #define ALL(a) (a).begin(), (a).end() #define SZ(a) ((int)(a).size()) #define pb push_back #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fst first #define snd second #define mset(a, v) memset((a), (v), sizeof(a)) //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") using namespace std; typedef long long ll; const int N = 200500; int n, K, W; int w[N]; int v[N]; int dp[101][100100]; int f(int i, int s) { if (s >= K) return 0; if (i == n) return 2e9; int &r = dp[i][s]; if (r != -1) return r; r = f(i + 1, s); r = min(r, f(i + 1, s + v[i]) + w[i]); return r; } int main() { FIN; cin >> n >> W; fore(i, 0, n) cin >> w[i] >> v[i]; int l = 0, r = 1e5 + 10; while (r - l > 1) { K = (l + r) / 2; memset(dp, -1, sizeof dp); if (f(0, 0) <= W) l = K; else r = K; } cout << l << "\n"; }
#include <bits/stdc++.h> #define fore(x, a, b) for (int x = a, qwerty = b; x < qwerty; x++) #define ALL(a) (a).begin(), (a).end() #define SZ(a) ((int)(a).size()) #define pb push_back #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fst first #define snd second #define mset(a, v) memset((a), (v), sizeof(a)) //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") using namespace std; typedef long long ll; const int N = 200500; int n, K, W; int w[N]; int v[N]; int dp[101][100100]; int f(int i, int s) { if (s >= K) return 0; if (i == n) return 1e9 + 10; int &r = dp[i][s]; if (r != -1) return r; r = f(i + 1, s); r = min(r, f(i + 1, s + v[i]) + w[i]); return r; } int main() { FIN; cin >> n >> W; fore(i, 0, n) cin >> w[i] >> v[i]; int l = 0, r = 1e5 + 10; while (r - l > 1) { K = (l + r) / 2; memset(dp, -1, sizeof dp); if (f(0, 0) <= W) l = K; else r = K; } cout << l << "\n"; }
[ "literal.number.change", "function.return_value.change" ]
971,798
971,799
u780156982
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 5; const ll INF = 2e11; ll n, w[N], v[N], W, dp[N][105]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; for (int i = 0; i < N; ++i) for (int j = 0; j < 105; ++j) dp[i][j] = INF; dp[0][0] = 0; for (int i = 1; i <= n; ++i) for (int j = 0; j < 200; ++j) { dp[j][i] = dp[j][i - 1]; if (j - v[i] >= 0) dp[j][i] = min(dp[j][i], dp[j - v[i]][i - 1] + w[i]); } for (int j = N - 1; j >= 0; --j) if (dp[j][n] <= W) { cout << j << "\n"; return 0; } }
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 5; const ll INF = 2e11; ll n, w[N], v[N], W, dp[N][105]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; for (int i = 0; i < N; ++i) for (int j = 0; j < 105; ++j) dp[i][j] = INF; dp[0][0] = 0; for (int i = 1; i <= n; ++i) for (int j = 0; j < N; ++j) { dp[j][i] = dp[j][i - 1]; if (j - v[i] >= 0) dp[j][i] = min(dp[j][i], dp[j - v[i]][i - 1] + w[i]); } for (int j = N - 1; j >= 0; --j) if (dp[j][n] <= W) { cout << j << "\n"; return 0; } }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,800
971,801
u270946680
cpp
p03164
#include <iostream> using namespace std; long long dp[110][100010] = {}, a[110], b[110], ans; int main() { int i, j, n, w; cin >> n >> w; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (i = 0; i <= n; i++) { for (j = 0; j <= 10000; j++) { dp[i][j] = 1000000000000000; } } dp[0][0] = 0; for (i = 1; i <= n; i++) { for (j = 0; j <= 100000; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); dp[i][b[i] + j] = min(dp[i][b[i] + j], dp[i - 1][j] + a[i]); } } for (i = 100000; i >= 0; i--) { if (dp[n][i] <= w) { cout << i << endl; return 0; } } }
#include <iostream> using namespace std; long long dp[110][100010] = {}, a[110], b[110], ans; int main() { int i, j, n, w; cin >> n >> w; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (i = 0; i <= n; i++) { for (j = 0; j <= 100000; j++) { dp[i][j] = 1000000000000000; } } dp[0][0] = 0; for (i = 1; i <= n; i++) { for (j = 0; j <= 100000; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); dp[i][b[i] + j] = min(dp[i][b[i] + j], dp[i - 1][j] + a[i]); } } for (i = 100000; i >= 0; i--) { if (dp[n][i] <= w) { cout << i << endl; return 0; } } }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,806
971,807
u621509943
cpp
p03164
/*==========================================================================================*\ ** _ _ _ _ _ _ _ ** ** | |__ _ _/ | |_| |__ | || | _ __ | |__ ** ** | '_ \| | | | | __| '_ \| || |_| '_ \| '_ \ ** ** | |_) | |_| | | |_| | | |__ _| | | | | | | ** ** |_.__/ \__,_|_|\__|_| |_| |_| |_| |_|_| |_| ** \*==========================================================================================*/ //===================================== // Solution Briefing - Foreword //===================================== // Libraries and namespaces //#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #if __cplusplus >= 201103L #include <chrono> #include <random> #include <unordered_map> #include <unordered_set> #endif // __cplusplus using namespace std; //#define DEBUG #define OPTIONAL_FEATURE //===================================== // Macroes #define sp ' ' #define el '\n' #define task "" #define maxinp () #define fi first #define se second #define pb push_back #define whole(x) x.begin(), x.end() #define whole_1(x) x.begin() + 1, x.end() #define r_whole(x) x.rbegin(), x.rend() #define FOR(i, x, y) for (auto i = x; i <= y; ++i) #define FORl(i, x, y) for (auto i = x; i < y; ++i) #define FORb(i, x, y) for (auto i = x; i >= y; --i) #define FORlb(i, x, y) for (auto i = x; i > y; --i) #define MEMS(x, val) memset(x, val, sizeof(x)) #define what_is(x) cerr << #x << " is " << x << endl; #define FILEOP() \ { \ freopen(task ".inp", "r", stdin); \ freopen(task ".out", "w", stdout); \ } #define FILEOP_DEBUG() \ { \ freopen(task ".inp", "r", stdin); \ freopen(task ".out", "w", stdout); \ freopen(task ".err", "w", stderr); \ } // Macroes - Optional #ifdef OPTIONAL_FEATURE #define pc(x) putchar(x) #define gc() getchar() #endif //===================================== // Auxilary Functions and Fast I/O #ifdef OPTIONAL_FEATURE template <class T, class R> T max(const T &__X, const R &__Y) { return __X > __Y ? __X : __Y; } template <class T, class R> T min(const T &__X, const R &__Y) { return __X < __Y ? __X : __Y; } template <class T, class R> void maximize(T &__X, R __Y) { __X = __X > __Y ? __X : __Y; } template <class T, class R> void minimize(T &__X, R __Y) { __X = __X < __Y ? __X : __Y; } template <class T> int getBit(T &__X, int __i) { return ((__X >> __i) & 1) == 1; } template <class T> bool inRange(T __L, T __R, T __X) { return __L <= __X && __X <= __R; } template <class T> T __abs(T __X) { return (__X < 0) ? -__X : __X; } #endif // Fast I/O template <class T> inline void scan(T &__ret) { __ret = T(); char c = 0; bool neg = 0; while (isdigit(c) == 0 && c != '-') c = getchar(); if (c == '-') { neg = 1; c = getchar(); } for (; isdigit(c) != 0; c = getchar()) __ret = __ret * 10 + c - '0'; __ret = (neg) ? -__ret : __ret; } template <class T> void print(T __X) { if (__X < 0) { putchar('-'); __X *= -1; } if (__X > 9) print(__X / 10); putchar(__X % 10 + '0'); } //===================================== // Constants const long long inf = 100000000007; //===================================== // Typedefs typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<bool> vb; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vii> vvii; vi dp, sdp, a, b; int n, s, v; //===================================== // Functions and procedures // File I/O and utilities void FileInit() { FILEOP() } void FileDebug() { #ifdef DEBUG FILEOP_DEBUG() #else FILEOP() #endif } void FileClose() { fclose(stdin); fclose(stdout); } // Main Procedure int main() { v = 0; scan(n); scan(s); a = b = vi(n + 1, 0LL); FOR(i, 1, n) scan(a[i]), scan(b[i]), v += b[i]; dp = sdp = vi(v + 1, inf); dp[0] = sdp[0] = 0; FOR(i, 1, n) { FOR(j, 0, b[i]) dp[j] = sdp[j]; FOR(j, b[i], v) minimize(dp[j], dp[j - b[i]] + a[i]); sdp = dp; } FORb(i, v, 0) if (dp[i] <= s) { print(i); break; } return 0; } //=============================================================================// /** CTB, you are always in my heart and in my code <3 #30yearsCTB **/ //=============================================================================//
/*==========================================================================================*\ ** _ _ _ _ _ _ _ ** ** | |__ _ _/ | |_| |__ | || | _ __ | |__ ** ** | '_ \| | | | | __| '_ \| || |_| '_ \| '_ \ ** ** | |_) | |_| | | |_| | | |__ _| | | | | | | ** ** |_.__/ \__,_|_|\__|_| |_| |_| |_| |_|_| |_| ** \*==========================================================================================*/ //===================================== // Solution Briefing - Foreword //===================================== // Libraries and namespaces //#include <bits/stdc++.h> #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #if __cplusplus >= 201103L #include <chrono> #include <random> #include <unordered_map> #include <unordered_set> #endif // __cplusplus using namespace std; //#define DEBUG #define OPTIONAL_FEATURE //===================================== // Macroes #define sp ' ' #define el '\n' #define task "" #define maxinp () #define fi first #define se second #define pb push_back #define whole(x) x.begin(), x.end() #define whole_1(x) x.begin() + 1, x.end() #define r_whole(x) x.rbegin(), x.rend() #define FOR(i, x, y) for (auto i = x; i <= y; ++i) #define FORl(i, x, y) for (auto i = x; i < y; ++i) #define FORb(i, x, y) for (auto i = x; i >= y; --i) #define FORlb(i, x, y) for (auto i = x; i > y; --i) #define MEMS(x, val) memset(x, val, sizeof(x)) #define what_is(x) cerr << #x << " is " << x << endl; #define FILEOP() \ { \ freopen(task ".inp", "r", stdin); \ freopen(task ".out", "w", stdout); \ } #define FILEOP_DEBUG() \ { \ freopen(task ".inp", "r", stdin); \ freopen(task ".out", "w", stdout); \ freopen(task ".err", "w", stderr); \ } // Macroes - Optional #ifdef OPTIONAL_FEATURE #define pc(x) putchar(x) #define gc() getchar() #endif //===================================== // Auxilary Functions and Fast I/O #ifdef OPTIONAL_FEATURE template <class T, class R> T max(const T &__X, const R &__Y) { return __X > __Y ? __X : __Y; } template <class T, class R> T min(const T &__X, const R &__Y) { return __X < __Y ? __X : __Y; } template <class T, class R> void maximize(T &__X, R __Y) { __X = __X > __Y ? __X : __Y; } template <class T, class R> void minimize(T &__X, R __Y) { __X = __X < __Y ? __X : __Y; } template <class T> int getBit(T &__X, int __i) { return ((__X >> __i) & 1) == 1; } template <class T> bool inRange(T __L, T __R, T __X) { return __L <= __X && __X <= __R; } template <class T> T __abs(T __X) { return (__X < 0) ? -__X : __X; } #endif // Fast I/O template <class T> inline void scan(T &__ret) { __ret = T(); char c = 0; bool neg = 0; while (isdigit(c) == 0 && c != '-') c = getchar(); if (c == '-') { neg = 1; c = getchar(); } for (; isdigit(c) != 0; c = getchar()) __ret = __ret * 10 + c - '0'; __ret = (neg) ? -__ret : __ret; } template <class T> void print(T __X) { if (__X < 0) { putchar('-'); __X *= -1; } if (__X > 9) print(__X / 10); putchar(__X % 10 + '0'); } //===================================== // Constants const long long inf = 100000000007; //===================================== // Typedefs typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<bool> vb; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vii> vvii; vi dp, sdp, a, b; int n, s, v; //===================================== // Functions and procedures // File I/O and utilities void FileInit() { FILEOP() } void FileDebug() { #ifdef DEBUG FILEOP_DEBUG() #else FILEOP() #endif } void FileClose() { fclose(stdin); fclose(stdout); } // Main Procedure int main() { v = 0; scan(n); scan(s); a = b = vi(n + 1, 0LL); FOR(i, 1, n) scan(a[i]), scan(b[i]), v += b[i]; dp = sdp = vi(v + 1, inf); dp[0] = sdp[0] = 0; FOR(i, 1, n) { FORl(j, 0, b[i]) dp[j] = sdp[j]; FOR(j, b[i], v) minimize(dp[j], sdp[j - b[i]] + a[i]); sdp = dp; } FORb(i, v, 0) if (dp[i] <= s) { print(i); break; } return 0; } //=============================================================================// /** CTB, you are always in my heart and in my code <3 #30yearsCTB **/ //=============================================================================//
[ "assignment.variable.change", "identifier.change", "call.function.change", "call.arguments.change", "expression.operation.binary.change" ]
971,824
971,825
u689136268
cpp
p03164
#include <bits/stdc++.h> using namespace std; int n; long long w[110], v[110]; long long dp[110][100010]; #define INF 10000000000000 #define VMAX 100010 int main() { long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < VMAX; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < VMAX; j++) { if (j < v[j]) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } } } int ans = 0; for (int i = 0; i < VMAX; i++) if (dp[n][i] <= W) ans = i; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; long long w[110], v[110]; long long dp[110][100010]; #define INF 10000000000000 #define VMAX 100010 int main() { long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < VMAX; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < VMAX; j++) { if (j < v[i]) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } } } int ans = 0; for (int i = 0; i < VMAX; i++) if (dp[n][i] <= W) ans = i; cout << ans << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
971,830
971,831
u221119670
cpp
p03164
#include <algorithm> #include <bitset> #include <cctype> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <string> #include <vector> using namespace std; #define REP(i, b, e) for (ll i = (ll)b; i < (ll)e; i++) #define rep0(i, n) REP(i, 0ll, n) #define rep1(i, n) REP(i, 1ll, n + 1) #define shosu setprecision(17) typedef long long ll; typedef pair<ll, ll> P; typedef pair<char, P> Q; // ll longinf=1ll<<60; int inf = 1 << 29; ll longinf = (1ll << 60); int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; signed main() { ll N, W; cin >> N >> W; ll w[N + 1], v[N + 1]; rep1(i, N) { cin >> w[i] >> v[i]; } ll V = N * 1000; ll dp[N + 1][V + 1]; ll ans = 0; ll accum[N + 1]; accum[0] = 0; rep0(i, N) { accum[i] = accum[i - 1] + v[i]; } rep0(i, N + 1) rep0(j, V + 1) dp[i][j] = longinf; rep0(i, N + 1) dp[i][0] = 0; rep1(i, N) { rep0(j, V + 1) { if (j <= v[i]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][0] + w[i]); } else if (j <= accum[i]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); } else { dp[i][j] = dp[i - 1][j]; } } } rep0(j, V + 1) { if (dp[N][j] <= W) { ans = j; } // cout<<dp[N][j]<<" "; } // cout<<endl; cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <string> #include <vector> using namespace std; #define REP(i, b, e) for (ll i = (ll)b; i < (ll)e; i++) #define rep0(i, n) REP(i, 0ll, n) #define rep1(i, n) REP(i, 1ll, n + 1) #define shosu setprecision(17) typedef long long ll; typedef pair<ll, ll> P; typedef pair<char, P> Q; // ll longinf=1ll<<60; int inf = 1 << 29; ll longinf = (1ll << 60); int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, -1, 1}; signed main() { ll N, W; cin >> N >> W; ll w[N + 1], v[N + 1]; rep1(i, N) { cin >> w[i] >> v[i]; } ll V = N * 1000; ll dp[N + 1][V + 1]; ll ans = 0; ll accum[N + 1]; accum[0] = 0; rep1(i, N) { accum[i] = accum[i - 1] + v[i]; } rep0(i, N + 1) rep0(j, V + 1) dp[i][j] = longinf; rep0(i, N + 1) dp[i][0] = 0; rep1(i, N) { rep0(j, V + 1) { if (j <= v[i]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][0] + w[i]); } else if (j <= accum[i]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); } else { dp[i][j] = dp[i - 1][j]; } } } rep0(j, V + 1) { if (dp[N][j] <= W) { ans = j; } // cout<<dp[N][j]<<" "; } // cout<<endl; cout << ans << endl; return 0; }
[ "identifier.change" ]
971,832
971,833
u297045966
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 100000; const ll INF = 1e18 + 7107; int n, w[100005], v[100005], ans; ll f[100005], T; int main() { scanf("%d%lld", &n, &T); for (int i = 1; i <= n; i++) scanf("%d%d", &w[i], &v[i]); for (int i = 1; i <= MX; i++) f[i] = INF; f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = MX; j >= 1; j--) { if (f[j] >= v[i]) f[j] = min(f[j], f[j - v[i]] + w[i]); } } for (int i = 1; i <= MX; i++) if (f[i] <= T) ans = max(ans, i); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 100000; const ll INF = 1e18 + 7107; int n, w[100005], v[100005], ans; ll f[100005], T; int main() { scanf("%d%lld", &n, &T); for (int i = 1; i <= n; i++) scanf("%d%d", &w[i], &v[i]); for (int i = 1; i <= MX; i++) f[i] = INF; f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = MX; j >= 1; j--) { if (j >= v[i]) f[j] = min(f[j], f[j - v[i]] + w[i]); } } for (int i = 1; i <= MX; i++) if (f[i] <= T) ans = max(ans, i); printf("%d\n", ans); return 0; }
[ "control_flow.loop.for.condition.change", "control_flow.branch.if.condition.change" ]
971,856
971,857
u674236668
cpp
p03164
/* Author: Sagar Gupta E mail: sagar.june97p@gmail.com */ #include <bits/stdc++.h> #define newline ("\n") #define deb(x) cerr << (#x) << " = " << (x) << '\n' #define FOR(x, n) for (int x = 0; x < n; x++) #define PI (3.141592653589) #define MOD 1000000007 using namespace std; long long weight[101], value[101]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // Pikachu, I choose you int n, w; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> weight[i]; cin >> value[i]; } long long dp[100001]; for (int i = 0; i < 100001; i++) { dp[i] = LONG_LONG_MAX; } dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 100000; j >= value[i]; j--) { if (dp[j - value[i]] != INT_MAX) { dp[j] = min(dp[j], dp[j - value[i]] + weight[i]); } } } for (int i = 100000; i >= 0; i--) { if (dp[i] <= w) { cout << i; return 0; } } return 0; }
/* Author: Sagar Gupta E mail: sagar.june97p@gmail.com */ #include <bits/stdc++.h> #define newline ("\n") #define deb(x) cerr << (#x) << " = " << (x) << '\n' #define FOR(x, n) for (int x = 0; x < n; x++) #define PI (3.141592653589) #define MOD 1000000007 using namespace std; long long weight[101], value[101]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // Pikachu, I choose you int n, w; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> weight[i]; cin >> value[i]; } long long dp[100001]; for (int i = 0; i < 100001; i++) { dp[i] = LONG_LONG_MAX; } dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 100000; j >= value[i]; j--) { if (dp[j - value[i]] != LONG_LONG_MAX) { dp[j] = min(dp[j], dp[j - value[i]] + weight[i]); } } } for (int i = 100000; i >= 0; i--) { if (dp[i] <= w) { cout << i; return 0; } } return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
971,858
971,859
u612695892
cpp
p03164
#include <bits/stdc++.h> #ifdef PRAGMA #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #endif #define fst first #define snd second #define fore(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define mp make_pair #define bs binary_search #define ALL(s) s.begin(), s.end() #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define SZ(n) ((int)(n).size()) #define MAXI ((ll)1e16) #define MINI ((ll)-1e16) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } ll n, w, res; ll weight[101]; ll val[101]; ll dp[101][1001]; ll solve(ll i, ll value) { if (value < 0) return MAXI; if (i == -1 && (value < 0 || value > 0)) return MAXI; if (i == -1) return 0; if (dp[i][value] != -1) return dp[i][value]; dp[i][value] = min(weight[i] + solve(i - 1, value - val[i]), solve(i - 1, value)); return dp[i][value]; } int main() { FIN; cin >> n >> w; fore(i, 0, n) { cin >> weight[i] >> val[i]; } memset(dp, -1, sizeof(dp)); for (int i = 100000; i > -1; i--) { if (solve(n - 1, i) <= w) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> #ifdef PRAGMA #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #endif #define fst first #define snd second #define fore(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define mp make_pair #define bs binary_search #define ALL(s) s.begin(), s.end() #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define SZ(n) ((int)(n).size()) #define MAXI ((ll)1e16) #define MINI ((ll)-1e16) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } ll n, w, res; ll weight[101]; ll val[101]; ll dp[101][100001]; ll solve(ll i, ll value) { if (value < 0) return MAXI; if (i == -1 && (value < 0 || value > 0)) return MAXI; if (i == -1) return 0; if (dp[i][value] != -1) return dp[i][value]; dp[i][value] = min(weight[i] + solve(i - 1, value - val[i]), solve(i - 1, value)); return dp[i][value]; } int main() { FIN; cin >> n >> w; fore(i, 0, n) { cin >> weight[i] >> val[i]; } memset(dp, -1, sizeof(dp)); for (int i = 100000; i > -1; i--) { if (solve(n - 1, i) <= w) { cout << i << endl; return 0; } } }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
971,862
971,863
u654921099
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int n, w; ll dp[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> w; for (int i = 0; i <= 100000; i++) dp[i] = 1e9; dp[0] = 0; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; for (int j = 100000 - b; j >= 0; j--) dp[j + b] = min(dp[j + b], dp[j] + a); } int ans = 0; for (int i = 0; i <= 100000; i++) { if (dp[i] <= w) ans = max(ans, i); } cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int n, w; ll dp[100100]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> w; for (int i = 0; i <= 100000; i++) dp[i] = 2e9; dp[0] = 0; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; for (int j = 100000 - b; j >= 0; j--) dp[j + b] = min(dp[j + b], dp[j] + a); } int ans = 0; for (int i = 0; i <= 100000; i++) { if (dp[i] <= w) ans = max(ans, i); } cout << ans; }
[ "literal.number.change", "assignment.value.change" ]
971,865
971,866
u137940828
cpp
p03164
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; #define read freopen("in.c", "r", stdin) #define write freopen("out.c", "w", stdout) #define all(a) a.begin(), a.end() #define bye exit(0) #define mp make_pair #define ff first #define ss second #define L(x) ((x) << 1) #define R(x) ((x) << 1 | 1) #define SZ(a) (ll)(a).size() #define pb push_back #define eb emplace_back #define eps 1e-9 #define inf (1000000000) #define infl (1000000000000000000LL) #define cs(p) printf("Case %d:", (p)++) #define ptc(c) putchar(c) #define gtc() getchar() #define nl puts("") #define sp printf(" ") #define out(a) printf("%lld", (ll)(a)) #define SET(a, x) memset((a), x, sizeof(a)) #define dbg(x) cerr << "--- " << #x << " = " << (x) << '\n' ll bgm(ll a, ll b, ll m) { b = (b == -1) ? (m - 2) : b; a %= m; ll rem = 1; while (b != 0) { if (b & 1) rem = (rem * a) % m; a = (a * a) % m; b >>= 1; } return rem; } inline ll in() { ll a; assert(scanf("%lld", &a) != EOF); return a; } const int MAX = 100000 + 5; const int LEN = 100; const ll MOD = 1000000007; int t; int n, W; int w[MAX], v[MAX]; int vis[LEN][MAX]; int dp[LEN][MAX]; int lo, hi, mid; int ans; int solve(int pos, int now) { if (now <= 0) { return 0; } if (pos == n) { return inf; } if (vis[pos][now] == t) { return dp[pos][now]; } vis[pos][now] = t; dp[pos][now] = min(solve(pos + 1, now), w[pos] + solve(pos + 1, now - v[pos])); return dp[pos][now]; } int main() { n = in(), W = in(); for (int i = 0; i < n; i++) { w[i] = in(), v[i] = in(); } lo = 0, hi = MAX - 1; while (lo <= hi) { mid = (lo + hi) / 2; ++t; if (solve(0, mid) <= W) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } out(ans), nl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; #define read freopen("in.c", "r", stdin) #define write freopen("out.c", "w", stdout) #define all(a) a.begin(), a.end() #define bye exit(0) #define mp make_pair #define ff first #define ss second #define L(x) ((x) << 1) #define R(x) ((x) << 1 | 1) #define SZ(a) (ll)(a).size() #define pb push_back #define eb emplace_back #define eps 1e-9 #define inf (1000000000) #define infl (1000000000000000000LL) #define cs(p) printf("Case %d:", (p)++) #define ptc(c) putchar(c) #define gtc() getchar() #define nl puts("") #define sp printf(" ") #define out(a) printf("%lld", (ll)(a)) #define SET(a, x) memset((a), x, sizeof(a)) #define dbg(x) cerr << "--- " << #x << " = " << (x) << '\n' ll bgm(ll a, ll b, ll m) { b = (b == -1) ? (m - 2) : b; a %= m; ll rem = 1; while (b != 0) { if (b & 1) rem = (rem * a) % m; a = (a * a) % m; b >>= 1; } return rem; } inline ll in() { ll a; assert(scanf("%lld", &a) != EOF); return a; } const int MAX = 100000 + 5; const int LEN = 100; const ll MOD = 1000000007; int t; int n, W; int w[MAX], v[MAX]; int vis[LEN][MAX]; ll dp[LEN][MAX]; int lo, hi, mid; int ans; ll solve(int pos, int now) { if (now <= 0) { return 0; } if (pos == n) { return infl; } if (vis[pos][now] == t) { return dp[pos][now]; } vis[pos][now] = t; dp[pos][now] = min(solve(pos + 1, now), w[pos] + solve(pos + 1, now - v[pos])); return dp[pos][now]; } int main() { n = in(), W = in(); for (int i = 0; i < n; i++) { w[i] = in(), v[i] = in(); } lo = 0, hi = MAX - 1; while (lo <= hi) { mid = (lo + hi) / 2; ++t; if (solve(0, mid) <= W) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } out(ans), nl; return 0; }
[ "variable_declaration.type.change", "identifier.change", "function.return_value.change" ]
971,870
971,871
u222758739
cpp
p03164
// Author:- Yatin Patel // Mail:- yatinpatel.gt@gmail.com #include <bits/stdc++.h> #define FILEIN \ ifstream fin; \ fin.open("input.txt"); #define FILEOUT \ ofstream fout; \ fout.open("output.txt"); using namespace std; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define FAST \ ios::sync_with_stdio(false); \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define ld long double #define pb push_back #define ff first #define ss second #define precision(x, d) cout << fixed << setprecision(d) << x #define minQueue priority_queue<ll, vector<ll>, greater<ll>> #define maxQueue priority_queue<ll, vector<ll>, less<ll>> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define RFOR(i, a, b) for (ll i = a; i > b; i--) #define FILL(a, b) memset((a), (b), sizeof((a))) #define MOD 1000000007 #define INF LONG_MAX #define MINF LONG_MIN ll power(ll x, unsigned ll y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } //#define fin cin //#define fout cout int main() { FAST; ll n, W; cin >> n >> W; vector<ll> v(n); vector<ll> w(n); for (ll i = 0; i < n; i++) { cin >> w[i] >> v[i]; } ll dp[100006]; for (ll j = 100005; j >= 0; j--) { dp[j] = INF; } dp[0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 100005; j >= 0; j--) { if (j + v[i - 1] <= 100005) dp[j + v[i - 1]] = min(dp[j + v[i - 1]], dp[j] + w[i - 1]); } } for (ll j = 100005; j >= 0; j--) { // cout<<dp[j]<<" "; if (dp[j] <= W) { cout << j; return 0; } } cout << 0; return 0; }
// Author:- Yatin Patel // Mail:- yatinpatel.gt@gmail.com #include <bits/stdc++.h> #define FILEIN \ ifstream fin; \ fin.open("input.txt"); #define FILEOUT \ ofstream fout; \ fout.open("output.txt"); using namespace std; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define FAST \ ios::sync_with_stdio(false); \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define ld long double #define pb push_back #define ff first #define ss second #define precision(x, d) cout << fixed << setprecision(d) << x #define minQueue priority_queue<ll, vector<ll>, greater<ll>> #define maxQueue priority_queue<ll, vector<ll>, less<ll>> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define RFOR(i, a, b) for (ll i = a; i > b; i--) #define FILL(a, b) memset((a), (b), sizeof((a))) #define MOD 1000000007 #define INF INT_MAX #define MINF LONG_MIN ll power(ll x, unsigned ll y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } //#define fin cin //#define fout cout int main() { FAST; ll n, W; cin >> n >> W; vector<ll> v(n); vector<ll> w(n); for (ll i = 0; i < n; i++) { cin >> w[i] >> v[i]; } ll dp[100006]; for (ll j = 100005; j >= 0; j--) { dp[j] = INF; } dp[0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 100005; j >= 0; j--) { if (j + v[i - 1] <= 100005) dp[j + v[i - 1]] = min(dp[j + v[i - 1]], dp[j] + w[i - 1]); } } for (ll j = 100005; j >= 0; j--) { // cout<<dp[j]<<" "; if (dp[j] <= W) { cout << j; return 0; } } cout << 0; return 0; }
[ "preprocessor.define.value.change" ]
971,880
971,881
u646513066
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl "\n" #define dbg(x) cout << #x << " = " << (x) << endl; const ll MOD = 1000000007; const ll INF = 1e18; const int maxn = 1000; int n, c; int w[maxn]; int v[maxn]; vector<vector<ll>> dp(105, vector<ll>(100005, INF)); int main() { // #ifndef ONLINE_JUDGE // freopen("F:\\Scripts\\input","r",stdin); // freopen("F:\\Scripts\\output","w",stdout); // #endif ios::sync_with_stdio(false); cin.tie(0); cin >> n >> c; int maxv = 1; for (int i = 0; i < n; i++) cin >> w[i] >> v[i], maxv += v[i]; dp[0][0] = 0; ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < maxv; j++) { dp[i][0] = 0; if (v[i] <= j) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; if (dp[i][j] <= c) ans = max(ans, 1LL * j); } return cout << ans, 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl "\n" #define dbg(x) cout << #x << " = " << (x) << endl; const ll MOD = 1000000007; const ll INF = 1e18; const int maxn = 1000; int n, c; int w[maxn]; int v[maxn]; vector<vector<ll>> dp(105, vector<ll>(100005, INF)); int main() { // #ifndef ONLINE_JUDGE // freopen("F:\\Scripts\\input","r",stdin); // freopen("F:\\Scripts\\output","w",stdout); // #endif ios::sync_with_stdio(false); cin.tie(0); cin >> n >> c; int maxv = 1; for (int i = 0; i < n; i++) cin >> w[i] >> v[i], maxv += v[i]; dp[0][0] = 0; ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < maxv; j++) { dp[i][0] = 0; if (v[i] <= j) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; if (dp[i + 1][j] <= c) ans = max(ans, 1LL * j); } return cout << ans, 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
971,893
971,894
u075489826
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl "\n" #define dbg(x) cout << #x << " = " << (x) << endl; const ll MOD = 1000000007; const ll INF = 1e18; const int maxn = 1000; int n, c; int w[maxn]; int v[maxn]; vector<vector<ll>> dp(105, vector<ll>(100005, 100005)); int main() { // #ifndef ONLINE_JUDGE // freopen("F:\\Scripts\\input","r",stdin); // freopen("F:\\Scripts\\output","w",stdout); // #endif ios::sync_with_stdio(false); cin.tie(0); cin >> n >> c; int maxv = 1; for (int i = 0; i < n; i++) cin >> w[i] >> v[i], maxv += v[i]; dp[0][0] = 0; ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < maxv; j++) { dp[i][0] = 0; if (v[i] <= j) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; if (dp[i][j] <= c) ans = max(ans, 1LL * j); } return cout << ans, 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define endl "\n" #define dbg(x) cout << #x << " = " << (x) << endl; const ll MOD = 1000000007; const ll INF = 1e18; const int maxn = 1000; int n, c; int w[maxn]; int v[maxn]; vector<vector<ll>> dp(105, vector<ll>(100005, INF)); int main() { // #ifndef ONLINE_JUDGE // freopen("F:\\Scripts\\input","r",stdin); // freopen("F:\\Scripts\\output","w",stdout); // #endif ios::sync_with_stdio(false); cin.tie(0); cin >> n >> c; int maxv = 1; for (int i = 0; i < n; i++) cin >> w[i] >> v[i], maxv += v[i]; dp[0][0] = 0; ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < maxv; j++) { dp[i][0] = 0; if (v[i] <= j) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; if (dp[i + 1][j] <= c) ans = max(ans, 1LL * j); } return cout << ans, 0; }
[ "identifier.replace.add", "literal.replace.remove", "call.arguments.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
971,896
971,894
u075489826
cpp
p03164
// // main.cpp // E - Knapsack 2 // // Created by Nishant Dhankhar on 16/01/19. // Copyright © 2019 Nishant Dhankhar. All rights reserved. // #include <bits/stdc++.h> //REMEMBER TO REMOVE '/' #include <iostream> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define int ll #define double long double #define ff first #define ss second #define RE(i, n) for (int i = 1; i <= n; i++) #define RED(i, n) for (int i = n; i > 0; i--) #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define all(v) v.begin(), v.end() #define pii pair<int, int> #define mii map<int, int> #define vi vector<int> #define vvi vector<vi> #define wl(t) while (t--) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define OUT(a) cout << a << endl; int n, W; const int INF = 100000000; int dp[105][100005]; signed main() { cin >> n >> W; // dp on the value; // if the value can be achieved , we int w[n], v[n]; RE(i, n) { cin >> w[i] >> v[i]; } rep(i, 104) { rep(j, 100004) { dp[i][j] = INF; } } dp[0][0] = 0; RE(i, n) { rep(j, 100001) { dp[i][j] = dp[i - 1][j]; if (j >= v[i] && dp[i - 1][j - v[i]] < INF) remin(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } int ans = 0; rep(i, 100001) { if (dp[n][i] <= W) ans = i; } OUT(ans); }
// // main.cpp // E - Knapsack 2 // // Created by Nishant Dhankhar on 16/01/19. // Copyright © 2019 Nishant Dhankhar. All rights reserved. // #include <bits/stdc++.h> //REMEMBER TO REMOVE '/' #include <iostream> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define int ll #define double long double #define ff first #define ss second #define RE(i, n) for (int i = 1; i <= n; i++) #define RED(i, n) for (int i = n; i > 0; i--) #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define all(v) v.begin(), v.end() #define pii pair<int, int> #define mii map<int, int> #define vi vector<int> #define vvi vector<vi> #define wl(t) while (t--) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define OUT(a) cout << a << endl; int n, W; const int INF = 1000000000000; int dp[105][100005]; signed main() { cin >> n >> W; // dp on the value; // if the value can be achieved , we int w[n], v[n]; RE(i, n) { cin >> w[i] >> v[i]; } rep(i, 104) { rep(j, 100004) { dp[i][j] = INF; } } dp[0][0] = 0; RE(i, n) { rep(j, 100001) { dp[i][j] = dp[i - 1][j]; if (j >= v[i] && dp[i - 1][j - v[i]] < INF) remin(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } int ans = 0; rep(i, 100001) { if (dp[n][i] <= W) ans = i; } OUT(ans); }
[ "literal.number.change", "variable_declaration.value.change" ]
971,897
971,898
u114310424
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; const ll oo = 0x3f3f3f3f3f3f3f3f; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n, w; cin >> n >> w; ll N = n * 1000 + 100; vector<ll> dp(N, oo); dp[0] = 0; for (ll i = 0, a, b; i < n; ++i) { cin >> a >> b; for (int j = N; j >= 0; --j) if (dp[j] != oo) dp[j + b] = min(dp[j + b], dp[j] + a); } for (ll i = N - 1; i >= 0; --i) { if (dp[i] <= w) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; const ll oo = 0x3f3f3f3f3f3f3f3f; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n, w; cin >> n >> w; ll N = n * 1000 + 100; vector<ll> dp(N, oo); dp[0] = 0; for (ll i = 0, a, b; i < n; ++i) { cin >> a >> b; for (int j = N - 1; j >= 0; --j) if (dp[j] != oo) dp[j + b] = min(dp[j + b], dp[j] + a); } for (ll i = N - 1; i >= 0; --i) { if (dp[i] <= w) { cout << i << endl; return 0; } } }
[ "control_flow.loop.for.initializer.change" ]
971,899
971,900
u122051363
cpp
p03164
#include <algorithm> #include <bitset> #include <cctype> #include <chrono> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; /*----------------------------------------*/ int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int N, W; cin >> N >> W; vector<int> w(N), v(N); REP(i, N) cin >> w[i] >> v[i]; vector<vector<long long>> dp(N + 1, vector<long long>(10001, LINF)); dp[0][0] = 0; REP(i, N) REP(j, 10001) { if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; } for (int j = 10001; j >= 0; --j) if (dp[N][j] <= W) { cout << j << '\n'; return 0; } }
#include <algorithm> #include <bitset> #include <cctype> #include <chrono> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; /*----------------------------------------*/ int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int N, W; cin >> N >> W; vector<int> w(N), v(N); REP(i, N) cin >> w[i] >> v[i]; vector<vector<long long>> dp(N + 1, vector<long long>(100001, LINF)); dp[0][0] = 0; REP(i, N) REP(j, 100001) { if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; } for (int j = 100000; j >= 0; --j) if (dp[N][j] <= W) { cout << j << '\n'; return 0; } }
[ "literal.number.change", "call.arguments.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
971,904
971,905
u219786796
cpp
p03164
#include <algorithm> #include <bitset> #include <cctype> #include <chrono> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; /*----------------------------------------*/ int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int N, W; cin >> N >> W; vector<int> w(N), v(N); REP(i, N) cin >> w[i] >> v[i]; vector<vector<long long>> dp(N + 1, vector<long long>(10010, LINF)); dp[0][0] = 0; REP(i, N) REP(j, 10010) { if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; } for (int j = 10010; j >= 0; --j) if (dp[N][j] <= W) { cout << j << '\n'; return 0; } }
#include <algorithm> #include <bitset> #include <cctype> #include <chrono> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; /*----------------------------------------*/ int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); int N, W; cin >> N >> W; vector<int> w(N), v(N); REP(i, N) cin >> w[i] >> v[i]; vector<vector<long long>> dp(N + 1, vector<long long>(100001, LINF)); dp[0][0] = 0; REP(i, N) REP(j, 100001) { if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); else dp[i + 1][j] = dp[i][j]; } for (int j = 100000; j >= 0; --j) if (dp[N][j] <= W) { cout << j << '\n'; return 0; } }
[ "literal.number.change", "call.arguments.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
971,906
971,905
u219786796
cpp
p03164
#include <bits/stdc++.h> #define int long long int #define mp make_pair using namespace std; int n, k; vector<int> v(102), w(102); int dp[102][100002]; int fun(int pos, int value) { if (value == 0) { return 0; } if (value < 0) { return 1e15; } if (pos == n) { return 1e15; } if (dp[pos][value] != -1) { return dp[pos][value]; } dp[pos][value] = min(fun(pos + 1, value), w[pos] + fun(pos + 1, value - v[pos])); return dp[pos][value]; } int32_t main() { scanf("%lld", &n); scanf("%lld", &k); for (int i = 0; i < n; ++i) { scanf("%lld", &w[i]); scanf("%lld", &v[i]); } for (int i = 0; i < 102; ++i) { for (int j = 0; j < 100002; ++j) { dp[i][j] = -1; } } int ans = 0; for (int i = 1; i <= 100000; ++i) { int ans1 = fun(0, i); if (ans1 < k) { ans = i; } } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> #define int long long int #define mp make_pair using namespace std; int n, k; vector<int> v(102), w(102); int dp[102][100002]; int fun(int pos, int value) { if (value == 0) { return 0; } if (value < 0) { return 1e15; } if (pos == n) { return 1e15; } if (dp[pos][value] != -1) { return dp[pos][value]; } dp[pos][value] = min(fun(pos + 1, value), w[pos] + fun(pos + 1, value - v[pos])); return dp[pos][value]; } int32_t main() { scanf("%lld", &n); scanf("%lld", &k); for (int i = 0; i < n; ++i) { scanf("%lld", &w[i]); scanf("%lld", &v[i]); } for (int i = 0; i < 102; ++i) { for (int j = 0; j < 100002; ++j) { dp[i][j] = -1; } } int ans = 0; for (int i = 1; i <= 100000; ++i) { int ans1 = fun(0, i); if (ans1 <= k) { ans = i; } } printf("%lld", ans); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
971,909
971,910
u041920892
cpp
p03164
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.cpp * Author: Allen * * Created on January 12, 2019, 5:13 PM */ #include <climits> #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; typedef long long int lli; /* * */ int main(int argc, char **argv) { lli n, w; cin >> n >> w; lli a, b; lli dp[100001]; for (lli i = 1; i <= 100000; i++) { dp[i] = 100000000; } dp[0] = 0; for (lli i = 0; i < n; i++) { cin >> a >> b; for (lli j = 100000; j >= b; j--) { dp[j] = min(dp[j], dp[j - b] + a); } } lli ans = 0; for (lli i = 0; i <= 100000; i++) { if (dp[i] <= w) { ans = i; } } printf("%lli", ans); return 0; }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.cpp * Author: Allen * * Created on January 12, 2019, 5:13 PM */ #include <climits> #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; typedef long long int lli; /* * */ int main(int argc, char **argv) { lli n, w; cin >> n >> w; lli a, b; lli dp[100001]; for (lli i = 1; i <= 100000; i++) { dp[i] = LLONG_MAX - 100000000000; } dp[0] = 0; for (lli i = 0; i < n; i++) { cin >> a >> b; for (lli j = 100000; j >= b; j--) { dp[j] = min(dp[j], dp[j - b] + a); } } lli ans = 0; for (lli i = 0; i <= 100000; i++) { if (dp[i] <= w) { ans = i; } } printf("%lli", ans); return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "assignment.change" ]
971,925
971,926
u381906125
cpp
p03164
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.cpp * Author: Allen * * Created on January 12, 2019, 5:13 PM */ #include <climits> #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; typedef long long int lli; /* * */ int main(int argc, char **argv) { lli n, w; cin >> n >> w; lli a, b; lli dp[100001]; for (lli i = 1; i <= 100000; i++) { dp[i] = LLONG_MAX - 101; } dp[0] = 0; for (lli i = 0; i < n; i++) { cin >> a >> b; for (lli j = 100000; j >= b; j--) { dp[j] = min(dp[j], dp[j - b] + a); } } lli ans = 0; for (lli i = 0; i <= 100000; i++) { if (dp[i] <= w) { ans = i; } } printf("%lli", ans); return 0; }
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.cpp * Author: Allen * * Created on January 12, 2019, 5:13 PM */ #include <climits> #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; typedef long long int lli; /* * */ int main(int argc, char **argv) { lli n, w; cin >> n >> w; lli a, b; lli dp[100001]; for (lli i = 1; i <= 100000; i++) { dp[i] = LLONG_MAX - 100000000000; } dp[0] = 0; for (lli i = 0; i < n; i++) { cin >> a >> b; for (lli j = 100000; j >= b; j--) { dp[j] = min(dp[j], dp[j - b] + a); } } lli ans = 0; for (lli i = 0; i <= 100000; i++) { if (dp[i] <= w) { ans = i; } } printf("%lli", ans); return 0; }
[ "literal.number.change", "assignment.value.change", "expression.operation.binary.change" ]
971,927
971,926
u381906125
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long int dp[100005][105]; pair<int, int> jinis[105]; void init() { memset(dp, -1, sizeof(dp)); } long long solve(int vleft, int cur, int n) { if (cur == n) { if (vleft == 0) return 0; return (long long)2000000000; } if (dp[vleft][cur] != -1) return dp[vleft][cur]; long long ret1 = 0, ret2 = 0; ret1 = (long long)jinis[cur].first + solve(max(0, vleft - jinis[cur].second), cur + 1, n); ret2 = solve(vleft, cur + 1, n); return dp[vleft][cur] = min(ret1, ret2); } int main() { int n, w; cin >> n >> w; int hi = 0; for (int i = 0; i < n; ++i) { cin >> jinis[i].first >> jinis[i].second; hi = hi + jinis[i].second; } int lo = 0; while (lo + 1 < hi) { int mid = (lo + hi) / 2; // init(); if (solve(mid, 0, n) <= w) lo = mid; else hi = mid; } long long lw = solve(hi, 0, n); if (lw <= w) { cout << hi << "\n"; } else { cout << lo << "\n"; } // cout<<solve(w,0,n)<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long int dp[100005][105]; pair<int, int> jinis[105]; void init() { memset(dp, -1, sizeof(dp)); } long long solve(int vleft, int cur, int n) { if (cur == n) { if (vleft == 0) return 0; return (long long)2000000000; } if (dp[vleft][cur] != -1) return dp[vleft][cur]; long long ret1 = 0, ret2 = 0; ret1 = (long long)jinis[cur].first + solve(max(0, vleft - jinis[cur].second), cur + 1, n); ret2 = solve(vleft, cur + 1, n); return dp[vleft][cur] = min(ret1, ret2); } int main() { int n, w; cin >> n >> w; int hi = 0; for (int i = 0; i < n; ++i) { cin >> jinis[i].first >> jinis[i].second; hi = hi + jinis[i].second; } int lo = 0; init(); while (lo + 1 < hi) { int mid = (lo + hi) / 2; // init(); if (solve(mid, 0, n) <= w) lo = mid; else hi = mid; } long long lw = solve(hi, 0, n); if (lw <= w) { cout << hi << "\n"; } else { cout << lo << "\n"; } // cout<<solve(w,0,n)<<"\n"; return 0; }
[ "call.add" ]
971,930
971,931
u860352559
cpp
p03164
#include <bits/stdc++.h> #define ioFix \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); long long madd(long long x, long long y, long long modulo) { return (x + y) % modulo; } long long mmult(long long x, long long y, long long modulo) { return (x * y) % modulo; } long long mpow(long long base, long long exponent, long long modulo) { long long res = 1; for (int i = 0; i < exponent; i++) res = (res * base) % modulo; return res; } long long mfac(long long n, long long modulo) { long long res = 1; for (int i = 2; i <= n; i++) res = (res * i) % modulo; return res; } // Slower, DP approach long long mcombDP(long long n, long long k, long long modulo) { long long C[k + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) for (long long j = std::min(i, k); j > 0; j--) C[j] = (C[j] + C[j - 1]) % modulo; return C[k]; } // Lucas theorem long long mcomb(long long n, long long k, long long modulo) { if (k == 0) return 1; return (mcomb(n / modulo, k / modulo, modulo) * mcombDP(n % modulo, k % modulo, modulo)) % modulo; } #define PI (2.0 * acos(0.0)) #define INF (int)1e9 #define LINF (long long)1e18 #define EPS 1e-9 #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<long long, long long> #define pdd pair<double, double> #define pcc pair<char, char> #define pbb pair<bool, bool> #define vi vector<int> #define vvi vector<vector<int>> #define vd vector<double> #define vvd vector<vector<double>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> #define vs vector<string> #define vvs vector<vector<string>> #define REP(n) for (int xix = 0; xix < (n); xix++) #define FOR(i, from, to) for (int(i) = from; (i) < (to); (i)++) #define RANGE(i, from, to) for (int(i) = from; (i) <= (to); (i)++) #define ALL(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define mt make_tuple #define fillArray(arr, val) std::fill(std::begin(arr), std::end(arr), (val)) #define pow2(x) ((x) * (x)) #define mod(x, m) ((((x) % (m)) + (m)) % (m)) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define watch(x) cout << (#x) << " is " << (x) << endl #define watchVector(v) \ { \ for (int xvx = 0; xvx < (v).size(); xvx++) { \ cout << (v)[xvx] << " "; \ } \ cout << endl; \ } #define watchArray(arr, n) \ { \ for (int xax = 0; xax < (n); xax++) { \ cout << (arr)[xax] << " "; \ } \ cout << endl; \ } #define watchMatrix(x, rows, cols) \ for (int r = 0; r < (rows); r++) { \ for (int c = 0; c < (cols); c++) { \ cout << (x)[r][c] << " "; \ } \ cout << endl; \ } /* Requires GNU C++ */ #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; /* typedef base_name< key, mapped, key_comp_func, tag_specifying_datastructure, updating_node_invariants_policy> my_name; my_name s; s.insert(x); s.find_by_order(i); // index->value s.order_of_key(x); // value->index */ namespace std { typedef trie<std::string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie; typedef tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set; } // namespace std using namespace std; int main() { ioFix; int N, W; cin >> N >> W; vector<pii> items(N); // <weight, value> FOR(i, 0, N) cin >> items[i].first >> items[i].second; int vTot = 0; FOR(i, 0, N) vTot += items[i].second; vector<vector<ll>> dp( N + 1, vector<ll>(vTot + 1, 1e9)); // dp[i][v] = min weight to reach this value tot dp[0][0] = 0; RANGE(i, 1, N) { RANGE(v, 0, vTot) { dp[i][v] = dp[i - 1][v]; if (v < items[i - 1].first) continue; if (dp[i - 1][v - items[i - 1].second] + items[i - 1].first <= W) dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - items[i - 1].second] + items[i - 1].first); } } for (int v = vTot; v >= 0; v--) { if (dp[N][v] != 1e9) { cout << v << endl; break; } } }
#include <bits/stdc++.h> #define ioFix \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); long long madd(long long x, long long y, long long modulo) { return (x + y) % modulo; } long long mmult(long long x, long long y, long long modulo) { return (x * y) % modulo; } long long mpow(long long base, long long exponent, long long modulo) { long long res = 1; for (int i = 0; i < exponent; i++) res = (res * base) % modulo; return res; } long long mfac(long long n, long long modulo) { long long res = 1; for (int i = 2; i <= n; i++) res = (res * i) % modulo; return res; } // Slower, DP approach long long mcombDP(long long n, long long k, long long modulo) { long long C[k + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long i = 1; i <= n; i++) for (long long j = std::min(i, k); j > 0; j--) C[j] = (C[j] + C[j - 1]) % modulo; return C[k]; } // Lucas theorem long long mcomb(long long n, long long k, long long modulo) { if (k == 0) return 1; return (mcomb(n / modulo, k / modulo, modulo) * mcombDP(n % modulo, k % modulo, modulo)) % modulo; } #define PI (2.0 * acos(0.0)) #define INF (int)1e9 #define LINF (long long)1e18 #define EPS 1e-9 #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<long long, long long> #define pdd pair<double, double> #define pcc pair<char, char> #define pbb pair<bool, bool> #define vi vector<int> #define vvi vector<vector<int>> #define vd vector<double> #define vvd vector<vector<double>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> #define vs vector<string> #define vvs vector<vector<string>> #define REP(n) for (int xix = 0; xix < (n); xix++) #define FOR(i, from, to) for (int(i) = from; (i) < (to); (i)++) #define RANGE(i, from, to) for (int(i) = from; (i) <= (to); (i)++) #define ALL(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define mt make_tuple #define fillArray(arr, val) std::fill(std::begin(arr), std::end(arr), (val)) #define pow2(x) ((x) * (x)) #define mod(x, m) ((((x) % (m)) + (m)) % (m)) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define watch(x) cout << (#x) << " is " << (x) << endl #define watchVector(v) \ { \ for (int xvx = 0; xvx < (v).size(); xvx++) { \ cout << (v)[xvx] << " "; \ } \ cout << endl; \ } #define watchArray(arr, n) \ { \ for (int xax = 0; xax < (n); xax++) { \ cout << (arr)[xax] << " "; \ } \ cout << endl; \ } #define watchMatrix(x, rows, cols) \ for (int r = 0; r < (rows); r++) { \ for (int c = 0; c < (cols); c++) { \ cout << (x)[r][c] << " "; \ } \ cout << endl; \ } /* Requires GNU C++ */ #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; /* typedef base_name< key, mapped, key_comp_func, tag_specifying_datastructure, updating_node_invariants_policy> my_name; my_name s; s.insert(x); s.find_by_order(i); // index->value s.order_of_key(x); // value->index */ namespace std { typedef trie<std::string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie; typedef tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set; } // namespace std using namespace std; int main() { ioFix; ll N, W; cin >> N >> W; vector<pii> items(N); // <weight, value> FOR(i, 0, N) cin >> items[i].first >> items[i].second; ll vTot = 0; FOR(i, 0, N) vTot += items[i].second; vector<vector<ll>> dp( N + 1, vector<ll>(vTot + 1, 2e9)); // dp[i][v] = min weight to reach this value tot dp[0][0] = 0; RANGE(i, 1, N) { RANGE(v, 0, vTot) { dp[i][v] = dp[i - 1][v]; if (v < items[i - 1].second) // not enough value continue; if (dp[i - 1][v - items[i - 1].second] + items[i - 1].first <= W) dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - items[i - 1].second] + items[i - 1].first); } } for (int v = vTot; v >= 0; v--) { if (dp[N][v] != 2e9) { cout << v << endl; break; } } }
[ "variable_declaration.type.change", "literal.number.change", "call.arguments.change", "control_flow.branch.if.condition.change" ]
971,947
971,948
u805352368
cpp
p03164
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") #include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define mod 998244353 #define inf (1LL << 61) #define int long long typedef long long ll; int dp[2][100001]; int32_t main() { IOS; int n; cin >> n; int w; cin >> w; int v[n], wt[n]; for (int i = 0; i < n; i++) cin >> wt[i] >> v[i]; dp[1][0] = 0; for (int j = 1; j < 100001; j++) { dp[0][j] = inf; dp[1][j] = inf; } dp[0][0] = 0; int ans = 0; for (int i = 0; i < n; i++) { int cur = i & 1; int prev = cur ^ 1; for (int j = 1; j < 34; ++j) { dp[cur][j] = dp[prev][j]; if (j >= v[i]) dp[cur][j] = min(dp[cur][j], dp[prev][j - v[i]] + wt[i]); else dp[cur][j] = min(dp[cur][j], dp[prev][0] + wt[i]); if (i == n - 1 and dp[cur][j] <= w) ans = j; } } cout << ans; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") #include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define mod 998244353 #define inf (1LL << 61) #define int long long typedef long long ll; int dp[2][100001]; int32_t main() { IOS; int n; cin >> n; int w; cin >> w; int v[n], wt[n]; for (int i = 0; i < n; i++) cin >> wt[i] >> v[i]; dp[1][0] = 0; for (int j = 1; j < 100001; j++) { dp[0][j] = inf; dp[1][j] = inf; } dp[0][0] = 0; int ans = 0; for (int i = 0; i < n; i++) { int cur = i & 1; int prev = cur ^ 1; for (int j = 1; j < 100001; ++j) { dp[cur][j] = dp[prev][j]; if (j >= v[i]) dp[cur][j] = min(dp[cur][j], dp[prev][j - v[i]] + wt[i]); else dp[cur][j] = min(dp[cur][j], dp[prev][0] + wt[i]); if (i == n - 1 and dp[cur][j] <= w) ans = j; } } cout << ans; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,980
971,981
u811982971
cpp
p03164
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } // #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) 1 #endif typedef long long ll; typedef double ld; #define pll pair<ll, ll> #define pii pair<int, int> #define pb push_back #define mp(x, y) make_pair((x), (y)) #define F first #define S second #define I insert #define vi vector<int> #define vll vector<ll> #define vpll vector<pll> #define all(x) (x).begin(), (x).end() #define sz(x) (ll)(x).size() const ll INF = 1e15; const int V = 1e5 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, W; cin >> n >> W; // w , v; ll A[2][n + 1]; for (int i = 1; i <= n; i++) cin >> A[0][i] >> A[1][i]; ll dp[2][V]; for (int i = 0; i < V; i++) { dp[0][i] = INF; dp[1][i] = INF; } dp[0][0] = 0; dp[1][0] = 0; for (int i = 1; i <= n; i++) { for (int j = V - A[1][i] - 1; j >= 0; j--) dp[1][j + A[1][i]] = min(dp[0][j + A[1][i]], dp[0][j] + A[0][i]); for (int j = 0; j < 20; j++) dp[0][j] = dp[1][j]; } for (int i = V - 1; i >= 0; i--) { if (dp[0][i] <= W) { cout << i << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } // #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) 1 #endif typedef long long ll; typedef double ld; #define pll pair<ll, ll> #define pii pair<int, int> #define pb push_back #define mp(x, y) make_pair((x), (y)) #define F first #define S second #define I insert #define vi vector<int> #define vll vector<ll> #define vpll vector<pll> #define all(x) (x).begin(), (x).end() #define sz(x) (ll)(x).size() const ll INF = 1e15; const int V = 1e5 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, W; cin >> n >> W; // w , v; ll A[2][n + 1]; for (int i = 1; i <= n; i++) cin >> A[0][i] >> A[1][i]; ll dp[2][V]; for (int i = 0; i < V; i++) { dp[0][i] = INF; dp[1][i] = INF; } dp[0][0] = 0; dp[1][0] = 0; for (int i = 1; i <= n; i++) { for (int j = V - A[1][i] - 1; j >= 0; j--) dp[1][j + A[1][i]] = min(dp[0][j + A[1][i]], dp[0][j] + A[0][i]); for (int j = 0; j < V; j++) dp[0][j] = dp[1][j]; } for (int i = V - 1; i >= 0; i--) { if (dp[0][i] <= W) { cout << i << endl; return 0; } } return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,997
971,998
u293764826
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long dp[200][200000]; int c[200], w[200]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); int n, we; cin >> n >> we; for (int i = 1; i <= n; i++) cin >> w[i] >> c[i]; for (int i = 0; i <= n; i++) for (int j = 0; j <= 100000; j++) dp[i][j] = (long long)1e18; dp[0][0] = 0; for (int i = 0; i <= n; i++) for (int j = 0; j + c[i] <= 100000; j++) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); dp[i + 1][j + c[i]] = min(dp[i + 1][j + c[i]], dp[i][j] + w[i]); } int ans = 0; for (int i = 0; i <= 100000; i++) if (dp[n][i] <= we) ans = i; cout << ans; }
#include <bits/stdc++.h> using namespace std; long long dp[200][200000]; long long c[200], w[200]; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); int n, we; cin >> n >> we; for (int i = 0; i < n; i++) cin >> w[i] >> c[i]; for (int i = 0; i <= n; i++) for (int j = 0; j <= 100000; j++) dp[i][j] = (long long)1e18; dp[0][0] = 0; for (int i = 0; i < n; i++) for (int j = 0; j + c[i] <= 100000; j++) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); dp[i + 1][j + c[i]] = min(dp[i + 1][j + c[i]], dp[i][j] + w[i]); } int ans = 0; for (int i = 0; i <= 100000; i++) if (dp[n][i] <= we) ans = i; cout << ans; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "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", "...
972,005
972,006
u933786880
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define LEN(x) (int)x.size() #define ALL(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; const int MOD = 1000'000'007; const double EPS = 0.000'000'001; inline int fcmp(double x, double y) { return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1); } const ll INF = MOD; const int N = 105, V = 100005; int n, ww; ll dp[V], v[N], w[N]; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false); cout.precision(10); cin >> n >> ww; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; for (int i = 0; i < V; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = V - 1; j >= v[i]; j--) dp[j] = min(dp[j - v[i]] + w[i], dp[j]); } int ans = 0; for (int i = 0; i < 150; i++) if (dp[i] <= ww) ans = i; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define LEN(x) (int)x.size() #define ALL(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; const int MOD = 1000'000'007; const double EPS = 0.000'000'001; inline int fcmp(double x, double y) { return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1); } const ll INF = MOD; const int N = 105, V = 100005; int n, ww; ll dp[V], v[N], w[N]; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false); cout.precision(10); cin >> n >> ww; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; for (int i = 0; i < V; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = V - 1; j >= v[i]; j--) dp[j] = min(dp[j - v[i]] + w[i], dp[j]); } int ans = 0; for (int i = 0; i < V; i++) if (dp[i] <= ww) ans = i; cout << ans << endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,011
972,012
u932730369
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define LEN(x) (int)x.size() #define ALL(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; const int MOD = 1000'000'007; const double EPS = 0.000'000'001; inline int fcmp(double x, double y) { return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1); } const ll INF = 1e18; const int N = 105, V = 100005; int n, ww; ll dp[V], v[N], w[N]; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false); cout.precision(10); cin >> n >> ww; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; for (int i = 0; i < V; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = V - 1; j >= v[i]; j--) dp[j] = min(dp[j - v[i]] + w[i], dp[j]); } int ans = 0; for (int i = 0; i < 150; i++) if (dp[i] <= ww) ans = i; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define LEN(x) (int)x.size() #define ALL(x) x.begin(), x.end() typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; const int MOD = 1000'000'007; const double EPS = 0.000'000'001; inline int fcmp(double x, double y) { return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1); } const ll INF = MOD; const int N = 105, V = 100005; int n, ww; ll dp[V], v[N], w[N]; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false); cout.precision(10); cin >> n >> ww; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; for (int i = 0; i < V; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = V - 1; j >= v[i]; j--) dp[j] = min(dp[j - v[i]] + w[i], dp[j]); } int ans = 0; for (int i = 0; i < V; i++) if (dp[i] <= ww) ans = i; cout << ans << endl; return 0; }
[ "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,013
972,012
u932730369
cpp
p03164
#include <iostream> using namespace std; int w[110], v[110]; long long int dp[1100]; int INF = 1000000009; int N, W; int main() { for (int i = 0; i < 100001; i++) dp[i] = INF; cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 100000; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } int ans = 0; for (int i = 0; i < 100001; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int w[110], v[110]; long long int dp[110000]; int INF = 1000000009; int N, W; int main() { for (int i = 0; i < 100001; i++) dp[i] = INF; cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 100000; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } int ans = 0; for (int i = 0; i < 100001; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
972,068
972,069
u090967649
cpp
p03164
#include <bits/stdc++.h> using namespace std; void min_self(long long &x, long long y) { x = min(x, y); } long long inf = 1e18 + 1; int main() { int n; int w; scanf("%d %d", &n, &w); vector<int> weight(n + 1), value(n + 1); for (int i = 0; i < n; i++) { scanf("%d%d", &weight[i], &value[i]); } int sum_value = 0; for (int x : value) { sum_value += x; } vector<long long> dp(sum_value + 1, inf); dp[0] = 0; for (int item = 0; item < n; item++) { for (int value_already = sum_value - value[item]; value_already >= 0; value_already--) { min_self(dp[value_already + value[item]], dp[value_already] + weight[item]); } } long long answer = 0; for (int long long i = 0; i < sum_value; i++) { if (dp[i] <= w) { answer = max(answer, i); } } cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void min_self(long long &x, long long y) { x = min(x, y); } long long inf = 1e18 + 1; int main() { int n; int w; scanf("%d %d", &n, &w); vector<int> weight(n + 1), value(n + 1); for (int i = 0; i < n; i++) { scanf("%d%d", &weight[i], &value[i]); } int sum_value = 0; for (int x : value) { sum_value += x; } vector<long long> dp(sum_value + 1, inf); dp[0] = 0; for (int item = 0; item < n; item++) { for (int value_already = sum_value - value[item]; value_already >= 0; value_already--) { min_self(dp[value_already + value[item]], dp[value_already] + weight[item]); } } long long answer = 0; for (int long long i = 0; i <= sum_value; i++) { if (dp[i] <= w) { answer = max(answer, i); } } cout << answer << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
972,092
972,093
u713008740
cpp
p03164
#include <bits/stdc++.h> using namespace std; void min_self(long long &x, long long y) { x = min(x, y); } long long inf = 1e18 + 1; int main() { int n; int w; scanf("%d %d", &n, &w); vector<int> weight(n + 1), value(n + 1); for (int i = 0; i < n; i++) { scanf("%d%d", &weight[i], &value[i]); } int sum_value = 0; for (int x : value) { sum_value += x; } vector<long long> dp(sum_value + 1, inf); dp[0] = 0; for (int item = 0; item < n; item++) { for (int value_already = sum_value - value[item]; value_already >= 0; value_already--) { min_self(dp[value_already + value[item]], dp[value_already] + weight[item]); } } long long answer = 0; for (int i = 0; i < sum_value; i++) { if (dp[i] <= w) { answer = max(answer, dp[i]); } } cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void min_self(long long &x, long long y) { x = min(x, y); } long long inf = 1e18 + 1; int main() { int n; int w; scanf("%d %d", &n, &w); vector<int> weight(n + 1), value(n + 1); for (int i = 0; i < n; i++) { scanf("%d%d", &weight[i], &value[i]); } int sum_value = 0; for (int x : value) { sum_value += x; } vector<long long> dp(sum_value + 1, inf); dp[0] = 0; for (int item = 0; item < n; item++) { for (int value_already = sum_value - value[item]; value_already >= 0; value_already--) { min_self(dp[value_already + value[item]], dp[value_already] + weight[item]); } } long long answer = 0; for (int long long i = 0; i <= sum_value; i++) { if (dp[i] <= w) { answer = max(answer, i); } } cout << answer << endl; return 0; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.value.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "call.arguments.change" ]
972,094
972,093
u713008740
cpp
p03164
#include <algorithm> #include <iostream> #include <numeric> #include <stdio.h> #include <vector> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long inf = 1LL << 60; const long long maxN = 110; const long long maxV = 100010; long long N, W; vector<long long> w, v; long long dp[maxN][maxV]; int main() { scanf("%Ld %Ld", &N, &W); w.resize(N); v.resize(N); rep(i, N) scanf("%Ld %Ld", &w[i], &v[i]); rep(i, maxN) rep(j, maxV) dp[i][j] = inf; dp[0][0] = 0; long long V = accumulate(v.begin(), v.end(), 0); rep(i, N) { rep(v_sum, V) { if (v_sum >= v[i]) chmin(dp[i + 1][v_sum], dp[i][v_sum - v[i]] + w[i]); chmin(dp[i + 1][v_sum], dp[i][v_sum]); } } long long ans = 0; rep(sum_v, V) if (dp[N][sum_v] <= W) ans = sum_v; printf("%Ld\n", ans); return 0; }
// dp[i][v_sum] = w_sum // v_sum以上になるiまでのwiの和の最小値 // dp[N][v_sum] W以下なるv_sum最大値が答え // dp[0][any] = 0 ほんまか? ほんまじゃない… //むり~~~~~~~~~~~~~~ //配るDP #include <algorithm> #include <iostream> #include <numeric> #include <stdio.h> #include <vector> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long inf = 1LL << 60; const long long maxN = 110; const long long maxV = 100010; long long N, W; vector<long long> w, v; long long dp[maxN][maxV]; int main() { scanf("%Ld %Ld", &N, &W); w.resize(N); v.resize(N); rep(i, N) scanf("%Ld %Ld", &w[i], &v[i]); rep(i, maxN) rep(j, maxV) dp[i][j] = inf; dp[0][0] = 0; long long V = accumulate(v.begin(), v.end(), 0); rep(i, N) { rep(v_sum, maxV) { if (v_sum >= v[i]) chmin(dp[i + 1][v_sum], dp[i][v_sum - v[i]] + w[i]); chmin(dp[i + 1][v_sum], dp[i][v_sum]); // cout << i << " " << v_sum << " " << dp[i+1][v_sum] << endl; } } long long ans = 0; rep(sum_v, maxV) if (dp[N][sum_v] <= W) ans = sum_v; printf("%Ld\n", ans); return 0; }
[ "identifier.change", "call.arguments.change" ]
972,097
972,098
u877476774
cpp
p03164
#include <algorithm> #include <iostream> #include <numeric> #include <stdio.h> #include <vector> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long inf = 1LL << 60; const long long maxN = 110; const long long maxV = 100010; long long N, W; vector<long long> w, v; long long dp[maxN][maxV]; int main() { scanf("%Ld %Ld", &N, &W); w.resize(N); v.resize(N); rep(i, N) scanf("%Ld %Ld", &w[i], &v[i]); rep(i, N + 1) rep(j, maxV) dp[i][j] = inf; dp[0][0] = 0; long long V = accumulate(v.begin(), v.end(), 0); rep(i, N) { rep(v_sum, V) { if (v_sum >= v[i]) chmin(dp[i + 1][v_sum], dp[i][v_sum - v[i]] + w[i]); chmin(dp[i + 1][v_sum], dp[i][v_sum]); } } long long ans = 0; rep(sum_v, V) if (dp[N][sum_v] <= W) ans = sum_v; printf("%Ld\n", ans); return 0; }
// dp[i][v_sum] = w_sum // v_sum以上になるiまでのwiの和の最小値 // dp[N][v_sum] W以下なるv_sum最大値が答え // dp[0][any] = 0 ほんまか? ほんまじゃない… //むり~~~~~~~~~~~~~~ //配るDP #include <algorithm> #include <iostream> #include <numeric> #include <stdio.h> #include <vector> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long inf = 1LL << 60; const long long maxN = 110; const long long maxV = 100010; long long N, W; vector<long long> w, v; long long dp[maxN][maxV]; int main() { scanf("%Ld %Ld", &N, &W); w.resize(N); v.resize(N); rep(i, N) scanf("%Ld %Ld", &w[i], &v[i]); rep(i, maxN) rep(j, maxV) dp[i][j] = inf; dp[0][0] = 0; long long V = accumulate(v.begin(), v.end(), 0); rep(i, N) { rep(v_sum, maxV) { if (v_sum >= v[i]) chmin(dp[i + 1][v_sum], dp[i][v_sum - v[i]] + w[i]); chmin(dp[i + 1][v_sum], dp[i][v_sum]); // cout << i << " " << v_sum << " " << dp[i+1][v_sum] << endl; } } long long ans = 0; rep(sum_v, maxV) if (dp[N][sum_v] <= W) ans = sum_v; printf("%Ld\n", ans); return 0; }
[ "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove", "identifier.change" ]
972,099
972,098
u877476774
cpp
p03164
#include <climits> #include <cmath> #include <iostream> #include <numeric> #include <vector> using namespace std; template <typename T> void mymin(T &a, T b) { if (a > b) a = b; } int main() { int N, W; cin >> N >> W; vector<int> w(N, 0); vector<int> v(N, 0); for (int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i); int Vmax = accumulate(v.begin(), v.end(), 0); vector<vector<long long>> dp(N + 1, vector<long long>(Vmax + 1, LLONG_MAX)); dp.at(0).at(0) = 0; for (int i = 0; i < N; i++) { for (int sum_v = 0; sum_v <= Vmax; sum_v++) { dp.at(i + 1).at(sum_v) = dp.at(i).at(sum_v); if (sum_v - v.at(i) >= 0) { mymin(dp.at(i + 1).at(sum_v), dp.at(i).at(sum_v - v.at(i)) + w.at(i)); } } } long long ans = 0; for (int i = 0; i <= Vmax; i++) { if (dp.at(N).at(i) <= W) { ans = i; } } cout << ans << endl; }
#include <climits> #include <cmath> #include <iostream> #include <numeric> #include <vector> using namespace std; template <typename T> void mymin(T &a, T b) { if (a > b) a = b; } int main() { int N, W; cin >> N >> W; vector<int> w(N, 0); vector<int> v(N, 0); for (int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i); int Vmax = accumulate(v.begin(), v.end(), 0); vector<vector<long long>> dp(N + 1, vector<long long>(Vmax + 1, INT_MAX)); dp.at(0).at(0) = 0; for (int i = 0; i < N; i++) { for (int sum_v = 0; sum_v <= Vmax; sum_v++) { dp.at(i + 1).at(sum_v) = dp.at(i).at(sum_v); if (sum_v - v.at(i) >= 0) { mymin(dp.at(i + 1).at(sum_v), dp.at(i).at(sum_v - v.at(i)) + w.at(i)); } } } long long ans = 0; for (int i = 0; i <= Vmax; i++) { if (dp.at(N).at(i) <= W) { ans = i; } } cout << ans << endl; }
[ "identifier.change", "call.arguments.change" ]
972,123
972,124
u634208461
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define repn(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, a) for (int i = 0; i < (a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define fi first #define se second #define endl '\n' ll dp[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); int n, w; cin >> n >> w; rep(i, 100000) dp[i] = 1e18; dp[0] = 0; int a, b; repn(i, 1, n + 1) { cin >> a >> b; for (int j = 1000 * i; j >= b; j--) { dp[j] = min(dp[j], dp[j - b] + a); } } ll ans = 0; rep(i, 100001) if (dp[i] <= w) ans = i; cout << ans << endl; return 0; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; #define repn(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, a) for (int i = 0; i < (a); i++) #define all(v) v.begin(), v.end() #define mp make_pair #define pb push_back #define fi first #define se second #define endl '\n' ll dp[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); int n, w; cin >> n >> w; rep(i, 100001) dp[i] = 1e18; dp[0] = 0; int a, b; repn(i, 1, n + 1) { cin >> a >> b; for (int j = 1000 * i; j >= b; j--) { dp[j] = min(dp[j], dp[j - b] + a); } } ll ans = 0; rep(i, 100001) if (dp[i] <= w) ans = i; cout << ans << endl; return 0; } /* Things to look out for: - Integer overflows - Array bounds - Special cases Be careful! */
[ "literal.number.change", "assignment.variable.change", "call.arguments.change" ]
972,127
972,128
u626595726
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, w; cin >> n >> w; ll a[2][n], dp[n * 1000 + 1]; for (int i = 0; i < n; i++) cin >> a[0][i] >> a[1][i]; for (int i = 0; i <= n * 100; i++) dp[i] = INT_MAX; ll mx = 0; for (int i = 0; i < n; i++) { for (ll j = n * 1000; j >= 1; j--) { if (j > a[1][i] && dp[j - a[1][i]] != INT_MAX) { dp[j] = min(dp[j], dp[j - a[1][i]] + a[0][i]); } else if (j == a[1][i]) dp[j] = min(dp[j], a[0][i]); if (dp[j] != INT_MAX && dp[j] <= w) mx = max(j, mx); } } cout << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, w; cin >> n >> w; ll a[2][n], dp[n * 1000 + 1]; for (int i = 0; i < n; i++) cin >> a[0][i] >> a[1][i]; for (int i = 0; i <= n * 1000; i++) dp[i] = INT_MAX; ll mx = 0; for (int i = 0; i < n; i++) { for (ll j = n * 1000; j >= 1; j--) { if (j > a[1][i] && dp[j - a[1][i]] != INT_MAX) { dp[j] = min(dp[j], dp[j - a[1][i]] + a[0][i]); } else if (j == a[1][i]) dp[j] = min(dp[j], a[0][i]); if (dp[j] != INT_MAX && dp[j] <= w) mx = max(j, mx); } } cout << mx << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,134
972,135
u025287064
cpp
p03164
#include <iostream> using namespace std; constexpr long long INF = 10000000007LL; int N, W; long long dp[100005]; int main() { cin >> N >> W; dp[0] = 0LL; for (int x = 1; x <= 100 * 1000; ++x) dp[x] = INF; int w, v; for (int i = 1; i <= N; ++i) { cin >> w >> v; for (int x = 100 * 1000; x >= 0; --x) { if (x - v >= 0) dp[x] = min(dp[x], dp[x - v] + w); } } long long ans = 0LL; for (int x = 100 * 1000; x >= 0; ++x) { if (dp[x] <= W) { ans = x; break; } } cout << ans << endl; }
#include <iostream> using namespace std; constexpr long long INF = 10000000007LL; int N, W; long long dp[100005]; int main() { cin >> N >> W; dp[0] = 0LL; for (int x = 1; x <= 100 * 1000; ++x) dp[x] = INF; int w, v; for (int i = 1; i <= N; ++i) { cin >> w >> v; for (int x = 100 * 1000; x >= 0; --x) { if (x - v >= 0) dp[x] = min(dp[x], dp[x - v] + w); } } long long ans = 0LL; for (int x = 100 * 1000; x >= 0; --x) { if (dp[x] <= W) { ans = x; break; } } cout << ans << endl; }
[]
972,150
972,151
u605853117
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define endl '\n' #define fcin \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define inf 0x3f3f3f3f const int W = 1e9 + 9; const int N = 101; int w[N], v[N]; int n; ll maxw; int main() { fcin; cin >> n >> maxw; int tot = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; tot += v[i]; } // dp[i]: min weight for total value exactly i vector<ll> dp((int)1e5 + 5, 1e18L + 8); dp[0] = 0; for (int i = 0; i < n; i++) { for (int vi = tot - v[i]; vi >= 0; vi--) { dp[vi + v[i]] = min(dp[vi + v[i]], dp[vi] + w[i]); } } int ans = 0; for (int i = 0; i < tot; i++) if (dp[i] <= maxw) ans = max(ans, i); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define endl '\n' #define fcin \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define inf 0x3f3f3f3f const int W = 1e9 + 9; const int N = 101; int w[N], v[N]; int n; ll maxw; int main() { fcin; cin >> n >> maxw; int tot = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; tot += v[i]; } // dp[i]: min weight for total value exactly i vector<ll> dp((int)1e5 + 5, 1e18L + 8); dp[0] = 0; for (int i = 0; i < n; i++) { for (int vi = tot - v[i]; vi >= 0; vi--) { dp[vi + v[i]] = min(dp[vi + v[i]], dp[vi] + w[i]); } } int ans = 0; for (int i = 0; i <= tot; i++) if (dp[i] <= maxw) ans = max(ans, i); cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
972,162
972,163
u189873906
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define endl '\n' #define fcin \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define inf 0x3f3f3f3f const int W = 1e9 + 9; const int N = 101; int w[N], v[N]; int n, maxw; int main() { fcin; cin >> n >> maxw; int tot = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; tot += v[i]; } // dp[i]: min weight for total value exactly i vector<ll> dp((int)1e5 + 5, 1e18L + 8); dp[0] = 0; for (int i = 0; i < n; i++) { for (int vi = tot - v[i]; vi >= 0; vi--) { dp[vi + v[i]] = min(dp[vi + v[i]], dp[vi] + w[i]); } } int ans = 0; for (int i = 0; i < tot; i++) if (dp[i] <= maxw) ans = max(ans, i); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define endl '\n' #define fcin \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define inf 0x3f3f3f3f const int W = 1e9 + 9; const int N = 101; int w[N], v[N]; int n; ll maxw; int main() { fcin; cin >> n >> maxw; int tot = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; tot += v[i]; } // dp[i]: min weight for total value exactly i vector<ll> dp((int)1e5 + 5, 1e18L + 8); dp[0] = 0; for (int i = 0; i < n; i++) { for (int vi = tot - v[i]; vi >= 0; vi--) { dp[vi + v[i]] = min(dp[vi + v[i]], dp[vi] + w[i]); } } int ans = 0; for (int i = 0; i <= tot; i++) if (dp[i] <= maxw) ans = max(ans, i); cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
972,164
972,163
u189873906
cpp
p03164
#include <stdio.h> const int N = 1e5 + 10; const long long int INF = 1e16 + 10; int max(int a, int b) { return a > b ? a : b; } int min(int a, int b) { return a > b ? b : a; } int main() { int n, w, p, v, ans = 0; long long int a[N]; scanf("%d%d", &n, &w); for (int i = 1; i < N; i++) a[i] = INF; a[0] = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &p, &v); for (int j = N - 1; j >= v; j--) a[j] = min(a[j], a[j - v] + p); } for (int i = N - 1; i >= 0; i--) if (a[i] <= w) { ans = i; break; } printf("%d\n", ans); }
#include <stdio.h> const int N = 1e5 + 10; const long long int INF = 1e16 + 10; int max(int a, int b) { return a > b ? a : b; } long long int min(long long int a, long long int b) { return a > b ? b : a; } int main() { int n, w, p, v, ans = 0; long long int a[N]; scanf("%d%d", &n, &w); for (int i = 1; i < N; i++) a[i] = INF; a[0] = 0; for (int i = 0; i < n; i++) { scanf("%d%d", &p, &v); for (int j = N - 1; j >= v; j--) a[j] = min(a[j], a[j - v] + p); } for (int i = N - 1; i >= 0; i--) if (a[i] <= w) { ans = i; break; } printf("%d\n", ans); }
[ "variable_declaration.type.widen.change" ]
972,167
972,168
u241347678
cpp
p03164
#include "bits/stdc++.h" using namespace std; using ll = long long; const double pi = acos(-1); #define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++) #define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { REP(i, v.size()) { if (i) os << " "; os << v[i]; } return os; } template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { REP(i, v.size()) { if (i) os << endl; os << v[i]; } return os; } const ll INF = 1LL << 60; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; #define int long long inline void my_io() { std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(16); } signed main() { ll n, w; cin >> n >> w; vector<ll> wei(n + 1, 0); vector<ll> val(n + 1, 0); vector<vector<ll>> dp(n + 1, vector<ll>(100001, 1LL << 20)); REP(i, n) { cin >> wei[i + 1] >> val[i + 1]; } dp[0][0] = 0; FOR(i, 1, n + 1) { FOR(j, val[i], 100001) { dp[i][j] = min(dp[i][j], dp[i - 1][j - val[i]] + wei[i]); } REP(j, 100001) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } ll ans = 0; RREP(i, 100001) { if (dp[n][i] < w + 1) { ans = i; break; } } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; using ll = long long; const double pi = acos(-1); #define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++) #define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { REP(i, v.size()) { if (i) os << " "; os << v[i]; } return os; } template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { REP(i, v.size()) { if (i) os << endl; os << v[i]; } return os; } const ll INF = 1LL << 60; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; #define int long long inline void my_io() { std::ios::sync_with_stdio(false); std::cin.tie(0); cout << fixed << setprecision(16); } signed main() { ll n, w; cin >> n >> w; vector<ll> wei(n + 1, 0); vector<ll> val(n + 1, 0); vector<vector<ll>> dp(n + 1, vector<ll>(100001, INF / 2)); REP(i, n) { cin >> wei[i + 1] >> val[i + 1]; } dp[0][0] = 0; FOR(i, 1, n + 1) { FOR(j, val[i], 100001) { dp[i][j] = min(dp[i][j], dp[i - 1][j - val[i]] + wei[i]); } REP(j, 100001) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } ll ans = 0; RREP(i, 100001) { if (dp[n][i] < w + 1) { ans = i; break; } } cout << ans << endl; }
[ "call.arguments.change" ]
972,171
972,172
u800551451
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i >= b; i--) typedef long long int ll; typedef vector<ll> vi; int main() { ll n, wt; cin >> n >> wt; ll w[n + 5], v[n + 5]; rep(i, 0, n) cin >> w[i] >> v[i]; ll tot = 0; for (ll &i : v) tot += i; vi dp(tot + 5, 1e18 + 5); dp[0] = 0; rep(i, 0, n) rrep(val, (tot - v[i]), 0) dp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]); ll ans = 0; rep(val, 0, (tot + 1)) if (dp[val] <= wt) ans = val; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i >= b; i--) typedef long long int ll; typedef vector<ll> vi; int main() { ll n, wt; cin >> n >> wt; ll w[n], v[n]; rep(i, 0, n) cin >> w[i] >> v[i]; ll tot = 0; for (ll &i : v) tot += i; vi dp(tot + 5, 1e18 + 5); dp[0] = 0; rep(i, 0, n) rrep(val, (tot - v[i]), 0) dp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]); ll ans = 0; rep(val, 0, (tot + 1)) if (dp[val] <= wt) ans = val; cout << ans << endl; }
[ "expression.operation.binary.remove" ]
972,173
972,174
u633475329
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define MAX_N 101 #define MAX_VALUE 100001 // 10^3 * 100 is max value that sum of values can be #define MAX 1000000000 typedef long long ll; ll n, w; ll V[MAX_N], W[MAX_N]; ll dp[MAX_N][MAX_VALUE]; // holds the minimum weight needed to get that value int main() { cin >> n >> w; for (int j = 0; j < n; j++) { cin >> W[j] >> V[j]; } for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_VALUE; j++) { dp[i][j] = MAX; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < MAX_VALUE; j++) { if (j - V[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j - V[i - 1]] + W[i - 1], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; for (int i = MAX_VALUE - 1; i >= 0; i--) { if (dp[n][i] <= w) { ans = i; break; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define MAX_N 101 #define MAX_VALUE 100001 // 10^3 * 100 is max value that sum of values can be #define MAX 1000000001 typedef long long ll; ll n, w; ll V[MAX_N], W[MAX_N]; ll dp[MAX_N][MAX_VALUE]; // holds the minimum weight needed to get that value int main() { cin >> n >> w; for (int j = 0; j < n; j++) { cin >> W[j] >> V[j]; } for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_VALUE; j++) { dp[i][j] = MAX; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < MAX_VALUE; j++) { if (j - V[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j - V[i - 1]] + W[i - 1], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; for (int i = MAX_VALUE - 1; i >= 0; i--) { if (dp[n][i] <= w) { ans = i; break; } } cout << ans << "\n"; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
972,178
972,179
u760218205
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define MAX_N 101 #define MAX_VALUE 100001 // 10^3 * 100 is max value that sum of values can be #define MAX 99999999 typedef long long ll; ll n, w; ll V[MAX_N], W[MAX_N]; ll dp[MAX_N][MAX_VALUE]; // holds the minimum weight needed to get that value int main() { cin >> n >> w; for (int j = 0; j < n; j++) { cin >> W[j] >> V[j]; } for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_VALUE; j++) { dp[i][j] = MAX; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < MAX_VALUE; j++) { if (j - V[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j - V[i - 1]] + W[i - 1], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; for (int i = MAX_VALUE - 1; i >= 0; i--) { if (dp[n][i] <= w) { ans = i; break; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define MAX_N 101 #define MAX_VALUE 100001 // 10^3 * 100 is max value that sum of values can be #define MAX 1000000001 typedef long long ll; ll n, w; ll V[MAX_N], W[MAX_N]; ll dp[MAX_N][MAX_VALUE]; // holds the minimum weight needed to get that value int main() { cin >> n >> w; for (int j = 0; j < n; j++) { cin >> W[j] >> V[j]; } for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_VALUE; j++) { dp[i][j] = MAX; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < MAX_VALUE; j++) { if (j - V[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j - V[i - 1]] + W[i - 1], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; for (int i = MAX_VALUE - 1; i >= 0; i--) { if (dp[n][i] <= w) { ans = i; break; } } cout << ans << "\n"; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
972,180
972,179
u760218205
cpp
p03164
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stdbool.h> #include <string> #include <utility> #include <vector> typedef long long ll; #define N (1000000000 + 7) #define INF 1e17 using namespace std; typedef pair<ll, ll> P; ll dp[110][100010]; int main(void) { ll n, W; cin >> n >> W; vector<ll> v(n), w(n); fill(dp[0], dp[110], INF); dp[0][0] = 0; for (ll i = 0; i < n; i++) cin >> w[i] >> v[i]; for (ll i = 0; i < n; i++) { for (ll j = 0; j <= 100; j++) { if (j >= v[i]) dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (ll i = 1; i <= 100000; i++) { if (dp[n][i] <= W) ans = max(ans, i); } cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stdbool.h> #include <string> #include <utility> #include <vector> typedef long long ll; #define N (1000000000 + 7) #define INF 1e17 using namespace std; typedef pair<ll, ll> P; ll dp[110][100010]; int main(void) { ll n, W; cin >> n >> W; vector<ll> v(n), w(n); fill(dp[0], dp[110], INF); dp[0][0] = 0; for (ll i = 0; i < n; i++) cin >> w[i] >> v[i]; for (ll i = 0; i < n; i++) { for (ll j = 0; j <= 100000; j++) { if (j >= v[i]) dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (ll i = 0; i <= 100000; i++) { if (dp[n][i] <= W) ans = max(ans, i); } cout << ans << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
972,183
972,184
u240303506
cpp
p03164
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); ++i) typedef long long llong; using namespace std; int main() { int n, lim; cin >> n >> lim; vector<int> w(n), v(n); llong sumw = 0; int sumv = 0; REP(i, n) { cin >> w[i] >> v[i]; sumw += w[i]; sumv += v[i]; } vector<llong> dp(sumv + 1, sumw); //価値iに必要な最小重さdp[i]. dp[0] = 0; REP(i, n) { for (int j = sumv; j >= 0; --j) { if (j >= v[i]) dp[j] = min(dp[j], dp[j - v[i]] + w[i]); else break; } } for (int i = sumv; i >= 0; --i) { if (dp[i] >= lim) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); ++i) typedef long long llong; using namespace std; int main() { int n, lim; cin >> n >> lim; vector<int> w(n), v(n); llong sumw = 0; int sumv = 0; REP(i, n) { cin >> w[i] >> v[i]; sumw += w[i]; sumv += v[i]; } vector<llong> dp(sumv + 1, sumw); //価値iに必要な最小重さdp[i]. dp[0] = 0; REP(i, n) { for (int j = sumv; j >= 0; --j) { if (j >= v[i]) dp[j] = min(dp[j], dp[j - v[i]] + w[i]); else break; } } for (int i = sumv; i >= 0; --i) { if (dp[i] <= lim) { cout << i << endl; return 0; } } }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
972,187
972,188
u209767598
cpp
p03164
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) ll N, W; ll w[110], v[110]; ll dp[110][100100]; ll ans = 0; ll V = 100010; int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } // dp[i][j]にはi個品物を選んだ時に総和の価値がjのときの最小の重さを記録する // 0個選んだ時は価値0のときだけ0、あとINF dp[0][0] = 0; for (int j = 1; j <= V; j++) { dp[0][j] = INF; } for (int i = 1; i <= N; i++) { for (int j = 0; j <= V; j++) { if (j - v[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } } } for (ll j = 0; j <= V; j++) { if (dp[N][j] <= W) { ans = max(ans, j); } } cout << ans << endl; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-7) #define INF (1e10) #define PI (acos(-1)) ll N, W; ll w[110], v[110]; ll dp[110][100100]; ll ans = 0; ll V = 100010; int main() { cin >> N >> W; for (ll i = 0; i < N; i++) { cin >> w[i] >> v[i]; } // dp[i][j]にはi個品物を選んだ時に総和の価値がjのときの最小の重さを記録する // 0個選んだ時は価値0のときだけ0、あとINF dp[0][0] = 0; for (ll j = 1; j <= V; j++) { dp[0][j] = INF; } for (ll i = 1; i <= N; i++) { for (ll j = 0; j <= V; j++) { if (j - v[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } } } for (ll j = 0; j <= V; j++) { if (dp[N][j] <= W) { ans = max(ans, j); } } cout << ans << endl; }
[ "preprocessor.define.value.change", "literal.float.change", "control_flow.loop.for.initializer.change", "variable_declaration.type.change" ]
972,195
972,196
u815863697
cpp
p03164
#include <algorithm> #include <array> #include <assert.h> #include <bits/stdc++.h> #include <bitset> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <sstream> // istringstream buffer(myString); #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> // #include <boost/functional/hash.hpp> using namespace std; #define endl "\n"; #define bit(x, i) (x & (1 << i)) // select the bit of position i of x #define lowbit(x) \ ((x) & \ ((x) ^ \ ((x)-1))) // get the lowest bit of x; example: x=12; 1100 => 100 => 4 #define LL long long #define ULL unsigned long long #define inf 1000000007 #define mod 1000000007 #define PII pair<int, int> #define V vector #define VI vector<int> #define VS vector<string> #define ALL(x) x.begin(), x.end() // handy for function like "sort()" #define pi 3.14159265358979323846 const ULL INF = 1e18L + 5; // set a to the maximum of a and b #define REMAX(a, b) (a) = max((a), (b)); #define REMIN(a, b) (a) = min((a), (b)); // conversion string removeZeros(string str) { return str.erase(0, min(str.find_first_not_of('0'), str.size() - 1)); } // remove leading zeros #define char2int(c) (c - '0') #define int2char(i) (static_cast<char>(i)) #define bin2int(bin) (bitset<1001>(bin).to_ulong()) #define int2bin(i) removeZeros(bitset<1001>(i).to_string()) // str.erase(0, min(str.find_first_not_of('0'), str.size()-1)); // remove // leading zeros // works for unordered_set, unordered_map.. #define HMAP unordered_map #define SET unordered_set #define HAS(umap, key) (umap.find(key) != umap.end()) #define COUNTER(m, j) \ if (HAS(m, j)) { \ m[j]++; \ } else { \ m[j] = 1; \ } // loop #define FOREACH(vec, i) for (auto i = vec.begin(); i != vec.end(); i++) // read line #define READ_INTS(vec, n) \ vector<LL> vec(n); \ for (LL i = 0; i < n; i++) { \ cin >> vec[i]; \ }; \ cin.ignore(); #define READ_DOUBLES(vec, n) \ vector<double> vec(n); \ FOREACH(vec, i) { cin >> *i; }; \ cin.ignore(); #define READ_STRING(vec) \ string vec; \ getline(cin, vec); #define READ_INT(i) \ LL i; \ cin >> i; \ cin.ignore(); // #define SPLIT_STRINGS(vec, str) istringstream iss(str); vector<string> // vec((istream_iterator<string>(iss)), istream_iterator<string>()); debug #define dd(var) cerr << #var << "=" << (var) << " | " #define ddv(vec) \ FOREACH(vec, i) { cout << *i << " "; } \ cout << endl; #define ddvv(vec) \ for (auto &i : vec) { \ for (auto &j : i) { \ cout << j << " "; \ }; \ cout << endl \ }; void solve() { READ_INT(N); READ_INT(W); vector<LL> w(N); vector<LL> v(N); LL sum_values = 0; for (LL i = 0; i < N; i++) { cin >> w[i] >> v[i]; sum_values += v[i]; } vector<LL> dp(sum_values + 1, INF); dp[0] = 0; for (LL i = 0; i < N; i++) { for (LL j = sum_values - v[i]; j >= 0; --j) { REMIN(dp[j + v[i]], w[i] + dp[j]) } } LL res = 0; for (LL i = 0; i < sum_values; i++) { if (dp[i] <= W) { REMAX(res, i); } } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // READ_INT(t); // for (LL i = 0; i < t; i++) { solve(); // } return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bits/stdc++.h> #include <bitset> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <sstream> // istringstream buffer(myString); #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> // #include <boost/functional/hash.hpp> using namespace std; #define endl "\n"; #define bit(x, i) (x & (1 << i)) // select the bit of position i of x #define lowbit(x) \ ((x) & \ ((x) ^ \ ((x)-1))) // get the lowest bit of x; example: x=12; 1100 => 100 => 4 #define LL long long #define ULL unsigned long long #define inf 1000000007 #define mod 1000000007 #define PII pair<int, int> #define V vector #define VI vector<int> #define VS vector<string> #define ALL(x) x.begin(), x.end() // handy for function like "sort()" #define pi 3.14159265358979323846 const ULL INF = 1e18L + 5; // set a to the maximum of a and b #define REMAX(a, b) (a) = max((a), (b)); #define REMIN(a, b) (a) = min((a), (b)); // conversion string removeZeros(string str) { return str.erase(0, min(str.find_first_not_of('0'), str.size() - 1)); } // remove leading zeros #define char2int(c) (c - '0') #define int2char(i) (static_cast<char>(i)) #define bin2int(bin) (bitset<1001>(bin).to_ulong()) #define int2bin(i) removeZeros(bitset<1001>(i).to_string()) // str.erase(0, min(str.find_first_not_of('0'), str.size()-1)); // remove // leading zeros // works for unordered_set, unordered_map.. #define HMAP unordered_map #define SET unordered_set #define HAS(umap, key) (umap.find(key) != umap.end()) #define COUNTER(m, j) \ if (HAS(m, j)) { \ m[j]++; \ } else { \ m[j] = 1; \ } // loop #define FOREACH(vec, i) for (auto i = vec.begin(); i != vec.end(); i++) // read line #define READ_INTS(vec, n) \ vector<LL> vec(n); \ for (LL i = 0; i < n; i++) { \ cin >> vec[i]; \ }; \ cin.ignore(); #define READ_DOUBLES(vec, n) \ vector<double> vec(n); \ FOREACH(vec, i) { cin >> *i; }; \ cin.ignore(); #define READ_STRING(vec) \ string vec; \ getline(cin, vec); #define READ_INT(i) \ LL i; \ cin >> i; \ cin.ignore(); // #define SPLIT_STRINGS(vec, str) istringstream iss(str); vector<string> // vec((istream_iterator<string>(iss)), istream_iterator<string>()); debug #define dd(var) cerr << #var << "=" << (var) << " | " #define ddv(vec) \ FOREACH(vec, i) { cout << *i << " "; } \ cout << endl; #define ddvv(vec) \ for (auto &i : vec) { \ for (auto &j : i) { \ cout << j << " "; \ }; \ cout << endl \ }; void solve() { READ_INT(N); READ_INT(W); vector<LL> w(N); vector<LL> v(N); LL sum_values = 0; for (LL i = 0; i < N; i++) { cin >> w[i] >> v[i]; sum_values += v[i]; } vector<LL> dp(sum_values + 1, INF); dp[0] = 0; for (LL i = 0; i < N; i++) { for (LL j = sum_values - v[i]; j >= 0; --j) { REMIN(dp[j + v[i]], w[i] + dp[j]) } } LL res = 0; for (LL i = 0; i <= sum_values; i++) { if (dp[i] <= W) { REMAX(res, i); } } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // READ_INT(t); // for (LL i = 0; i < t; i++) { solve(); // } return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
972,204
972,205
u831038161
cpp
p03164
#include <algorithm> #include <iostream> #include <utility> using namespace std; #define maxW 100010 #define maxN 102 #define maxV 1000 #define INFINITY 99999999999999 typedef long long ll; int n; ll s; ll cache[maxN][maxW], v[maxN], w[maxN]; ll rec(int i, int V) { if (V == 90) { int a = 0; } if (V == 0) { return 0; } if (i == 0 && V == v[i]) { return w[i]; } if (i <= 0 || V < 0) return INFINITY; if (cache[i][V] != -1) return cache[i][V]; if (v[i] > V) return cache[i][V] = rec(i - 1, V); return cache[i][V] = min(rec(i - 1, V), w[i] + rec(i - 1, V - v[i])); } int main() { cin >> n >> s; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; for (int j = 0; j < maxW; j++) { cache[i][j] = -1; } } for (int i = maxV * maxN; i >= 0; i--) { ll w = rec(n - 1, i); if (w <= s) { cout << i << endl; return 0; } } return 0; }
#include <algorithm> #include <iostream> #include <utility> using namespace std; #define maxW 100010 #define maxN 102 #define maxV 100000 #define INFINITY 99999999999999 typedef long long ll; int n; ll s; ll cache[maxN][maxW], v[maxN], w[maxN]; ll rec(int i, int V) { if (V == 90) { int a = 0; } if (V == 0) { return 0; } if (i == 0 && V == v[i]) { return w[i]; } if (i <= 0 || V < 0) return INFINITY; if (cache[i][V] != -1) return cache[i][V]; if (v[i] > V) return cache[i][V] = rec(i - 1, V); return cache[i][V] = min(rec(i - 1, V), w[i] + rec(i - 1, V - v[i])); } int main() { cin >> n >> s; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; for (int j = 0; j < maxW; j++) { cache[i][j] = -1; } } for (int i = maxV; i >= 0; i--) { ll w = rec(n - 1, i); if (w <= s) { cout << i << endl; return 0; } } return 0; }
[ "preprocessor.define.value.change", "literal.integer.change", "control_flow.loop.for.initializer.change", "expression.operation.binary.remove" ]
972,210
972,211
u304052848
cpp
p03164
// https://atcoder.jp/contests/dp/tasks/dp_e #include <algorithm> #include <bits/stdc++.h> #include <limits.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; const int precision = 16; const int modulo = 1000000007; // 10^9 + 7 using ll = long long; const double EPS = 1e-9; const ll INF = 1e18L + 5; template <class T> void print(vector<T> v) { for (auto it : v) { cout << it << " "; } cout << endl; } ll solveSK2() { int n, C; cin >> n >> C; vector<ll> weight(n), value(n); for (int i = 0; i < n; ++i) { cin >> weight[i] >> value[i]; } int sum_value = accumulate(value.begin(), value.end(), 0); vector<ll> dp(sum_value + 1, INF), dp0(sum_value + 1, INF); dp[0] = 0; dp0[0] = 0; for (auto i = 0; i <= n; ++i) { for (int v = sum_value - value[i]; v >= 0; --v) { dp[v + value[i]] = min(dp0[v + value[i]], dp0[v] + weight[i]); } dp0 = dp; } ll ans = 0; for (ll i = 0; i < sum_value; ++i) { if (dp[i] <= C) { ans = max(ans, i); } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.precision(precision); cout.setf(ios_base::fixed); auto ret = solveSK2(); cout << ret; return 0; }
// https://atcoder.jp/contests/dp/tasks/dp_e #include <algorithm> #include <bits/stdc++.h> #include <limits.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; const int precision = 16; const int modulo = 1000000007; // 10^9 + 7 using ll = long long; const double EPS = 1e-9; const ll INF = 1e18L + 5; template <class T> void print(vector<T> v) { for (auto it : v) { cout << it << " "; } cout << endl; } ll solveSK2() { int n, C; cin >> n >> C; vector<int> weight(n), value(n); for (int i = 0; i < n; ++i) { cin >> weight[i] >> value[i]; } int sum_value = accumulate(value.begin(), value.end(), 0); vector<ll> dp(sum_value + 1, INF), dp0(sum_value + 1, INF); dp[0] = 0; dp0[0] = 0; for (int i = 0; i < n; ++i) { for (int v = sum_value - value[i]; v >= 0; --v) { dp[v + value[i]] = min(dp0[v + value[i]], dp0[v] + weight[i]); } dp0 = dp; } ll ans = 0; for (ll i = 0; i <= sum_value; ++i) { if (dp[i] <= C) { ans = max(ans, i); } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.precision(precision); cout.setf(ios_base::fixed); auto ret = solveSK2(); cout << ret; return 0; }
[ "control_flow.loop.for.initializer.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
972,222
972,220
u476450778
cpp
p03164
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <stack> #include <string> #include <vector> //#include<bits/stdc++.h> using namespace std; #define ok1 printf("ok1\n"); #define ok2 printf("ok2\n"); #define M 1000000000000000000LL #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, s, n) for (int i = (s); i < (n); i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define REPR(i, s, n) for (int i = (s); i >= (n); (i)--) #define all(a) (a).begin(), (a).end() #define reall(a) (a).rbegin(), (a).rend() #define pb push_back #define pf push_front #define MIN(a, b) a = min((a), (b)) #define MAX(a, b) a = max((a), (b)) #define SIZE(v) (int)v.size() const double pi = acos(-1.0); typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef deque<ll> dll; typedef pair<ll, ll> P; const ll mod = 1e9 + 7; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, w, m, k, ans = 0; cin >> n >> w; vll W(n), V(n); rep(i, n) cin >> W[i] >> V[i]; vvll dp(n + 1, vll(110, M)); dp[0][0] = 0; rep(i, n) { rep(j, 110) { if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - V[i]] + W[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } /*rep(i, n + 1) { rep(j, w + 1) { cout << dp[i][j] << " "; } cout << endl; }*/ rep(i, 110) if (dp[n][i] <= w) ans = i; cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <stack> #include <string> #include <vector> //#include<bits/stdc++.h> using namespace std; #define ok1 printf("ok1\n"); #define ok2 printf("ok2\n"); #define M 1000000000000000000LL #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, s, n) for (int i = (s); i < (n); i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define REPR(i, s, n) for (int i = (s); i >= (n); (i)--) #define all(a) (a).begin(), (a).end() #define reall(a) (a).rbegin(), (a).rend() #define pb push_back #define pf push_front #define MIN(a, b) a = min((a), (b)) #define MAX(a, b) a = max((a), (b)) #define SIZE(v) (int)v.size() const double pi = acos(-1.0); typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef deque<ll> dll; typedef pair<ll, ll> P; const ll mod = 1e9 + 7; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, w, m, k, ans = 0; cin >> n >> w; vll W(n), V(n); rep(i, n) cin >> W[i] >> V[i]; vvll dp(n + 1, vll(100010, M)); dp[0][0] = 0; rep(i, n) { rep(j, 100010) { if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - V[i]] + W[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } /*rep(i, n + 1) { rep(j, w + 1) { cout << dp[i][j] << " "; } cout << endl; }*/ rep(i, 100010) if (dp[n][i] <= w) ans = i; cout << ans << endl; return 0; }
[ "literal.number.change", "call.arguments.change" ]
972,235
972,234
u373958718
cpp
p03164
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, w, a[N], b[N], dp[N], ans; int main() { cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (int i = 1; i < N; i++) dp[i] = 2e9; for (int i = 1; i <= n; i++) { for (int j = N - 1; j >= b[i]; j--) { dp[j] = min(dp[j], dp[j - b[i]] + a[i]); } } for (int i = 1; i < N; i++) { if (dp[i] <= w) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; long long n, w, a[N], b[N], dp[N], ans; int main() { cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (int i = 1; i < N; i++) dp[i] = 2e9; for (int i = 1; i <= n; i++) { for (int j = N - 1; j >= b[i]; j--) { dp[j] = min(dp[j], dp[j - b[i]] + a[i]); } } for (int i = 1; i < N; i++) { if (dp[i] <= w) ans = i; } cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
972,244
972,245
u644994661
cpp
p03164
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int n, w, a[N], b[N], dp[N]; int main() { cin >> n >> w; for (int i = 1; i < N; i++) { dp[i] = 1e9; } for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; for (int j = N - 1; j >= b[i]; j--) { dp[j] = min(dp[j - b[i]] + a[i], dp[j]); } } for (int i = N - 1; i >= 0; i--) { if (dp[i] <= w) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 2; int n, w, a[N], b[N]; long long dp[N]; int main() { cin >> n >> w; for (int i = 1; i < N; i++) { dp[i] = 1e18; } for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; for (int j = N - 1; j >= b[i]; j--) { dp[j] = min(dp[j - b[i]] + a[i], dp[j]); } } for (int i = N - 1; i >= 0; i--) { if (dp[i] <= w) { cout << i << endl; return 0; } } }
[ "literal.number.change", "assignment.value.change" ]
972,246
972,247
u644994661
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__() \ for (long blockTime = NULL; \ (blockTime == NULL ? (blockTime = clock()) != NULL : false); \ debug("Time:%.4fs\n", (double)(clock() - blockTime) / CLOCKS_PER_SEC)) #define setp(x) cout << fixed << setprecision(x) #define forn(i, a, b) for (int i = a; i < b; i++) #define fore(i, a, b) for (int i = a; i <= b; i++) #define pb push_back #define mp make_pair #define F first #define S second #define PI 3.14159265358979323846264338327 #define INF 2000000000 #define MOD 998244353 #define MAXN 100005 typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef unsigned long long ull; void mins(int &x, int v) { x = min(x, v); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, W, MAXV = 0; cin >> n >> W; int w[n], v[n]; // min weight with value = j forn(i, 0, n) { cin >> w[i] >> v[i]; MAXV += v[i]; } int dp[MAXV + 1]; forn(i, 0, MAXV) dp[i] = INF; dp[0] = 0; forn(j, 0, n) { for (int i = MAXV; i >= v[j]; i--) { mins(dp[i], dp[i - v[j]] + w[j]); } } for (int i = MAXV; i >= 0; i--) { if (dp[i] <= W) { cout << i; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__() \ for (long blockTime = NULL; \ (blockTime == NULL ? (blockTime = clock()) != NULL : false); \ debug("Time:%.4fs\n", (double)(clock() - blockTime) / CLOCKS_PER_SEC)) #define setp(x) cout << fixed << setprecision(x) #define forn(i, a, b) for (int i = a; i < b; i++) #define fore(i, a, b) for (int i = a; i <= b; i++) #define pb push_back #define mp make_pair #define F first #define S second #define PI 3.14159265358979323846264338327 #define INF 2000000000 #define MOD 998244353 #define MAXN 100005 typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef unsigned long long ull; void mins(ll &x, ll v) { x = min(x, v); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, W, MAXV = 0; cin >> n >> W; ll w[n], v[n]; // min weight with value = j forn(i, 0, n) { cin >> w[i] >> v[i]; MAXV += v[i]; } ll dp[MAXV + 1]; fore(i, 0, MAXV) dp[i] = INF; dp[0] = 0; forn(j, 0, n) { for (int i = MAXV; i >= v[j]; i--) { mins(dp[i], dp[i - v[j]] + w[j]); } } for (int i = MAXV; i >= 0; i--) { if (dp[i] <= W) { cout << i; return 0; } } return 0; }
[ "variable_declaration.type.change", "assignment.variable.change", "identifier.change", "call.function.change" ]
972,252
972,251
u603846802
cpp
p03164
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } #ifndef ONLINE_JUDGE #define TRACE #endif #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) 1 #endif #define mp make_pair #define pb push_back #define endl '\n' #define F first #define S second #define I insert typedef long double ld; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pll> vpll; typedef vector<pii> vpii; const int N = 1e2 + 5; const int M = 1e5 + 2; const ll INF = 1e15; ll w[N], v[N], dp[N][M]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(25); ll n, W; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (int i = 0; i <= n; i++) for (int j = 0; j < M; j++) dp[i][j] = INF; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j < M; j++) { dp[i][j] = dp[i - 1][j]; if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } for (int i = M - 1; i >= 0; i--) { if (dp[n][i] <= W) { cout << i; exit(0); } } }
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } #ifndef ONLINE_JUDGE #define TRACE #endif #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) 1 #endif #define mp make_pair #define pb push_back #define endl '\n' #define F first #define S second #define I insert typedef long double ld; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pll> vpll; typedef vector<pii> vpii; const int N = 1e2 + 5; const int M = 1e5 + 2; const ll INF = 1e15; ll w[N], v[N], dp[N][M]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(25); ll n, W; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (int i = 0; i <= n; i++) for (int j = 0; j < M; j++) dp[i][j] = INF; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < M; j++) { dp[i][j] = dp[i - 1][j]; if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } for (int i = M - 1; i >= 0; i--) { if (dp[n][i] <= W) { cout << i; exit(0); } } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
972,262
972,263
u127449133
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; #define fi first #define se second #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(v) s.size() #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) #define fill(a, v) memset(a, v, sizeof(a)) #define tc \ int T; \ cin >> T; \ while (T--) #define nl printf("\n") #define aya printf("yaha aya\n") #define debug(x, y) printf("%d %d\n", x, y) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define grt greater<int>() const int mod = 1e9 + 7; const int mod2 = 1e9 + 9; inline int pow_(ll a, int n, int p = mod) { int r = 1; while (n) { if (n & 1) r = r * a % p; n >>= 1; a = a * a % p; } return r; } const int mx = 1e2 + 1; int w[mx], v[mx]; int N, W; const int inf = 1e9; int main(void) { cin >> N >> W; int V = 1e5; int dp[V + 1]; // fill(dp,inf); rep(i, 0, V) dp[i] = inf; dp[0] = 0; rep(i, 0, N - 1) { cin >> w[i] >> v[i]; per(j, V, v[i]) dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } int ans = 0; rep(i, 0, V) if (dp[i] <= W) ans = i; cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; #define fi first #define se second #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define sz(v) s.size() #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) #define fill(a, v) memset(a, v, sizeof(a)) #define tc \ int T; \ cin >> T; \ while (T--) #define nl printf("\n") #define aya printf("yaha aya\n") #define debug(x, y) printf("%d %d\n", x, y) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define grt greater<int>() const int mod = 1e9 + 7; const int mod2 = 1e9 + 9; inline int pow_(ll a, int n, int p = mod) { int r = 1; while (n) { if (n & 1) r = r * a % p; n >>= 1; a = a * a % p; } return r; } const int mx = 1e2 + 1; ll w[mx], v[mx]; int N, W; const int inf = 1e9 + 1; int main(void) { cin >> N >> W; int V = 1e5; ll dp[V + 1]; // fill(dp,inf); rep(i, 0, V) dp[i] = inf; dp[0] = 0; rep(i, 0, N - 1) { cin >> w[i] >> v[i]; per(j, V, v[i]) dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } int ans = 0; rep(i, 1, V) if (dp[i] <= W) ans = i; cout << ans << "\n"; }
[ "variable_declaration.type.change", "literal.number.change", "call.arguments.change" ]
972,274
972,275
u817703858
cpp
p03164
#include <algorithm> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define modulo 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL << 60 // ナップサック ll N, W; ll w[101], v[101]; ll dp[101][100000]; // dp[i][j] : i番目までの商品で価値j持って帰る際の最小の重さ void input() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j <= 100000; j++) dp[0][j] = LLINF; } void solve() { dp[0][0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= 100000; j++) { if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int j = 0; j <= 100000; j++) { if (dp[N][j] <= W) { // 持って帰れる ans = j; } } cout << ans << endl; } int main() { input(); solve(); return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define modulo 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL << 60 // ナップサック // 品物がN個しかなかったら、価値の最大は V_MXAX * N だと思ってたので // jのループを1000*Nまでにしてたがなぜか通らなかった ll N, W; ll w[101], v[101]; ll dp[101][100001]; // dp[i][j] : i番目までの商品で価値j持って帰る際の最小の重さ void input() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j <= 100000; j++) dp[0][j] = LLINF; } void solve() { dp[0][0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= 100000; j++) { if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int j = 0; j <= (1000 * N); j++) { if (dp[N][j] <= W) { // 持って帰れる ans = j; } } cout << ans << endl; } int main() { input(); solve(); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,278
972,279
u774652316
cpp
p03164
#include <algorithm> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define modulo 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL << 60 // ナップサック ll N, W; ll w[101], v[101]; ll dp[101][100000]; // dp[i][j] : i番目までの商品で価値j持って帰る際の最小の重さ void input() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j <= 100000; j++) dp[0][j] = LLINF; } void solve() { dp[0][0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= 100000; j++) { if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int j = 0; j <= 100000; j++) { if (dp[N][j] <= W) { // 持って帰れる ans = j; } } cout << ans << endl; } int main() { input(); solve(); return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define modulo 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL << 60 // ナップサック ll N, W; ll w[101], v[101]; ll dp[101][100001]; // dp[i][j] : i番目までの商品で価値j持って帰る際の最小の重さ void input() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j <= 100000; j++) dp[0][j] = LLINF; } void solve() { dp[0][0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= 100000; j++) { if (j >= v[i]) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int j = 0; j <= 100000; j++) { if (dp[N][j] <= W) { // 持って帰れる ans = j; } } cout << ans << endl; } int main() { input(); solve(); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
972,278
972,280
u774652316
cpp
p03164
#include <stdio.h> #include <vector> using namespace std; const int C = 100001, N = 101, Inf = 1000000000; typedef long long ll; int n, k, a, b, c, v; ll dp[N][C], w, mw; int main() { int j, i; scanf("%d %lld", &n, &mw); for (j = 1; j < C; j++) dp[0][j] = Inf; for (i = 1; i <= n; i++) { scanf("%lld %d", &w, &v); for (j = 0; j < C; j++) { dp[i][j] = Inf; if (j >= v) dp[i][j] = min(dp[i - 1][j - v] + w, dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } for (i = C - 1; i >= 0; i--) if (dp[n][i] <= mw) break; printf("%d", i); return 0; }
#include <stdio.h> #include <vector> using namespace std; const int C = 100001, N = 101, Inf = 1500000000; typedef long long ll; int n, k, a, b, c, v; ll dp[N][C], w, mw; int main() { int j, i; scanf("%d %lld", &n, &mw); for (j = 1; j < C; j++) dp[0][j] = Inf; for (i = 1; i <= n; i++) { scanf("%lld %d", &w, &v); for (j = 0; j < C; j++) { dp[i][j] = Inf; if (j >= v) dp[i][j] = min(dp[i - 1][j - v] + w, dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } for (i = C - 1; i >= 0; i--) if (dp[n][i] <= mw) break; printf("%d", i); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
972,301
972,302
u679729810
cpp
p03164
#include <iostream> using namespace std; 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; } const long long INF = 1LL << 60; const int MAX_N = 110; const int MAX_V = 100100; //入力 int N; long long W, weight[MAX_N], value[MAX_N]; //品物の品質は100個なので少し余裕を持たせてサイズ110 // DPテーブル long long dp[MAX_N][MAX_V]; int main() { cin >> N >> W; for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; //初期化 for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF; //初期条件 dp[0][0] = 0; // DPループ for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_N; ++sum_v) { // i番目の品物を選ぶ場合 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]); } } long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
#include <iostream> using namespace std; 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; } const long long INF = 1LL << 60; const int MAX_N = 110; const int MAX_V = 100100; //入力 int N; long long W, weight[MAX_N], value[MAX_N]; //品物の品質は100個なので少し余裕を持たせてサイズ110 // DPテーブル long long dp[MAX_N][MAX_V]; int main() { cin >> N >> W; for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; //初期化 for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF; //初期条件 dp[0][0] = 0; // DPループ for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i番目の品物を選ぶ場合 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]); } } long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,317
972,318
u794707792
cpp
p03164
#include <iostream> using namespace std; 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; } const long long INF = 1LL << 60; const int MAX_N = 110; const int MAX_V = 100100; //入力 int N; long long W, weight[MAX_N], value[MAX_N]; //品物の品質は100個なので少し余裕を持たせてサイズ110 // DPテーブル long long dp[MAX_N][MAX_V]; int main() { cin >> N >> W; for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; //初期化 for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF; //初期条件 dp[0][0] = 0; // DPループ for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_N; ++sum_v) { // i番目の品物を選ぶ場合 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]); } } long long res = 0; for (int sum_v = 0; sum_v < MAX_N; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
#include <iostream> using namespace std; 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; } const long long INF = 1LL << 60; const int MAX_N = 110; const int MAX_V = 100100; //入力 int N; long long W, weight[MAX_N], value[MAX_N]; //品物の品質は100個なので少し余裕を持たせてサイズ110 // DPテーブル long long dp[MAX_N][MAX_V]; int main() { cin >> N >> W; for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; //初期化 for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF; //初期条件 dp[0][0] = 0; // DPループ for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i番目の品物を選ぶ場合 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]); } } long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,319
972,318
u794707792
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define P pair<int, int> int main() { int N, W; cin >> N >> W; vector<P> w_v(N); int sum = 0; for (int i = 0; i < N; i += 1) { cin >> w_v[i].second >> w_v[i].first; sum += w_v[i].second; } sort(w_v.rbegin(), w_v.rend()); int dp[sum + 1]; for (int i = 0; i <= sum; i += 1) { dp[i] = W + 1; } dp[0] = 0; for (int i = N - 1; i >= 0; i -= 1) { for (int j = sum; j >= w_v[i].second; j -= 1) { dp[j] = min(dp[j], w_v[i].first + dp[j - w_v[i].second]); } } for (int i = sum; i >= 0; i -= 1) { if (dp[i] <= W) { cout << i; break; } } }
#include <bits/stdc++.h> using namespace std; #define P pair<int, int> int main() { int N, W; cin >> N >> W; vector<P> w_v(N); int sum = 0; for (int i = 0; i < N; i += 1) { cin >> w_v[i].second >> w_v[i].first; sum += w_v[i].first; } sort(w_v.rbegin(), w_v.rend()); int dp[sum + 1]; for (int i = 0; i <= sum; i += 1) { dp[i] = W + 1; } dp[0] = 0; for (int i = N - 1; i >= 0; i -= 1) { for (int j = sum; j >= w_v[i].first; j -= 1) { dp[j] = min(dp[j], w_v[i].second + dp[j - w_v[i].first]); } } for (int i = sum; i >= 0; i -= 1) { if (dp[i] <= W) { cout << i; break; } } }
[ "assignment.value.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "call.arguments.change", "variable_access.subscript.index.change" ]
972,322
972,323
u054986947
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long i, j, max_, f[101][100001], w[101], v[101], n, W, x = 0; int main() { memset(f, 0x7f, sizeof(f)); scanf("%lld %lld", &n, &W); for (i = 1; i <= n; i++) { scanf("%lld %lld", &w[i], &v[i]); x += v[i]; } f[0][0] = 0; for (i = 1; i <= n; i++) for (j = 0; j <= x; j++) { f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + w[i]); } for (i = 0; i <= x; i++) if (f[3][i] <= W) max_ = max(max_, i); printf("%lld", max_); return 0; }
#include <bits/stdc++.h> using namespace std; long long i, j, max_, f[101][100001], w[101], v[101], n, W, x = 0; int main() { memset(f, 0x7f, sizeof(f)); scanf("%lld %lld", &n, &W); for (i = 1; i <= n; i++) { scanf("%lld %lld", &w[i], &v[i]); x += v[i]; } f[0][0] = 0; for (i = 1; i <= n; i++) for (j = 0; j <= x; j++) { f[i][j] = f[i - 1][j]; if (j >= v[i]) f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + w[i]); } for (i = 0; i <= x; i++) if (f[n][i] <= W) max_ = max(max_, i); printf("%lld", max_); return 0; }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
972,344
972,345
u386813869
cpp
p03165
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); i++) #define mp(x, y) make_pair(x, y) #define all(x) (x).begin(), (x).end() using ll = long long; using vll = vector<ll>; using P = pair<int, int>; const int inf = 1e9 + 7; const ll INF = 1e18; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } string s, t; int dp[3300][3300]; int main() { cin >> s >> t; int n = s.size(), m = t.size(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i - 1] == t[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1); else { chmax(dp[i][j], dp[i - 1][j]); chmax(dp[i][j], dp[i][j - 1]); } // es } // j } // i string ans = ""; while (n > 0 && m > 0) { if (dp[n][m] == dp[n - 1][m]) n--; else if (dp[n][m] == dp[n][m - 1]) m--; else m--; n--; ans += s[n]; } reverse(all(ans)); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); i++) #define mp(x, y) make_pair(x, y) #define all(x) (x).begin(), (x).end() using ll = long long; using vll = vector<ll>; using P = pair<int, int>; const int inf = 1e9 + 7; const ll INF = 1e18; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } string s, t; int dp[3300][3300]; int main() { cin >> s >> t; int n = s.size(), m = t.size(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (s[i - 1] == t[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1); else { chmax(dp[i][j], dp[i - 1][j]); chmax(dp[i][j], dp[i][j - 1]); } // es } // j } // i string ans = ""; while (n > 0 && m > 0) { if (dp[n][m] == dp[n - 1][m]) n--; else if (dp[n][m] == dp[n][m - 1]) m--; else { m--; n--; ans += s[n]; } } reverse(all(ans)); cout << ans << endl; }
[]
972,356
972,357
u531461815
cpp
p03165
// atcoder.jp/contests/dp/tasks/dp_d #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ll long long #define rep(i, s, n) for (ll i = s; i < n; ++i) #define repm(i, s, n) for (ll i = s; n < i; --i) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define MOD 1000000007 using namespace std; string solve(string s, string t) { int sl = s.length(); int tl = t.length(); int dp[sl + 1][tl + 1]; rep(i, 0, sl) { rep(j, 0, tl) { dp[i][j] = 0; } } rep(i, 0, sl) { rep(j, 0, tl) { if (s[i] == t[j]) { dp[i + 1][j + 1] = max(dp[i + 1][j], max(dp[i][j + 1], dp[i][j] + 1)); } else { dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]); } } } // rep(i, 0, sl) { // rep(j, 0, tl) { cout << dp[i][j] << ' '; } // cout << endl; // } string ans = ""; int p = sl; int q = tl; while (p > 0 && q > 0) { if (dp[p][q] == dp[p - 1][q]) { --p; } else if (dp[p][q] == dp[p][q - 1]) { --q; } else { --p; --q; ans += s[p]; } } reverse(ans.begin(), ans.end()); return ans; } int main() { string s, t; ios::sync_with_stdio(false); cin.tie(nullptr); cin >> s; cin >> t; string ans = solve(s, t); cout << ans << endl; }
// atcoder.jp/contests/dp/tasks/dp_d #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ll long long #define rep(i, s, n) for (ll i = s; i < n; ++i) #define repm(i, s, n) for (ll i = s; n < i; --i) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define MOD 1000000007 using namespace std; string solve(string s, string t) { int sl = s.length(); int tl = t.length(); int dp[sl + 1][tl + 1]{}; rep(i, 0, sl) { rep(j, 0, tl) { dp[i][j] = 0; } } rep(i, 0, sl) { rep(j, 0, tl) { if (s[i] == t[j]) { dp[i + 1][j + 1] = max(dp[i + 1][j], max(dp[i][j + 1], dp[i][j] + 1)); } else { dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]); } } } // rep(i, 0, sl) { // rep(j, 0, tl) { cout << dp[i][j] << ' '; } // cout << endl; // } string ans = ""; int p = sl; int q = tl; while (p > 0 && q > 0) { if (dp[p][q] == dp[p - 1][q]) { --p; } else if (dp[p][q] == dp[p][q - 1]) { --q; } else { --p; --q; ans += s[p]; } } reverse(ans.begin(), ans.end()); return ans; } int main() { string s, t; ios::sync_with_stdio(false); cin.tie(nullptr); cin >> s; cin >> t; string ans = solve(s, t); cout << ans << endl; }
[]
972,364
972,365
u483187413
cpp
p03165
#include <bits/stdc++.h> using namespace std; // string max(string p,string q){ // if(p.length() > q.length()){ // return p; // } // return q; // } string solve(string p, string q) { int m = p.length(); int n = q.length(); int dp[m + 1][n + 1] = {0}; for (int i = 0; i < m + 1; i++) { for (int j = 0; j < n + 1; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (p[i - 1] == q[j - 1]) { dp[i][j] = dp[i - 1][j - 1] + p[i - 1]; } else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } } string ans = ""; int i = m; int j = n; while (i >= 1 && j >= 1) { if (dp[i][j] != max(dp[i - 1][j], dp[i][j - 1])) { ans = ans + p[i - 1]; i--; j--; } else if (dp[i][j] == dp[i - 1][j]) i--; else j--; } reverse(ans.begin(), ans.end()); return ans; // return dp[m][n]; } int main() { string p, q; cin >> p >> q; cout << solve(p, q) << endl; }
#include <bits/stdc++.h> using namespace std; // string max(string p,string q){ // if(p.length() > q.length()){ // return p; // } // return q; // } string solve(string p, string q) { int m = p.length(); int n = q.length(); int dp[m + 1][n + 1] = {0}; for (int i = 0; i < m + 1; i++) { for (int j = 0; j < n + 1; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (p[i - 1] == q[j - 1]) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } } string ans = ""; int i = m; int j = n; while (i >= 1 && j >= 1) { if (dp[i][j] != max(dp[i - 1][j], dp[i][j - 1])) { ans = ans + p[i - 1]; i--; j--; } else if (dp[i][j] == dp[i - 1][j]) i--; else j--; } reverse(ans.begin(), ans.end()); return ans; // return dp[m][n]; } int main() { string p, q; cin >> p >> q; cout << solve(p, q) << endl; }
[]
972,397
972,398
u086313715
cpp
p03165
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using namespace std; template <typename T> using vec = std::vector<T>; int main() { string s; string t; cin >> s >> t; vec<vec<int>> dp(s.size() + 1, vec<int>(t.size() + 1, 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 - 1], dp[i][j - 1], dp[i - 1][j]}); if (s[i - 1] == t[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1); } string ans = ""; int i = s.size(); int j = t.size(); while (i >= 1 && j >= 1) { char a = dp[i - 1][j - 1]; char b = dp[i][j - 1]; char c = dp[i - 1][j]; if (a == b && a == c && a == dp[i][j] - 1) { ans = ans + s[i - 1]; --i, --j; } else if (a == b && a == c) { --i, --j; } else if (b >= c) { --j; } else { --i; } } reverse(all(ans)); cout << ans << '\n'; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using namespace std; template <typename T> using vec = std::vector<T>; int main() { string s; string t; cin >> s >> t; vec<vec<int>> dp(s.size() + 1, vec<int>(t.size() + 1, 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 - 1], dp[i][j - 1], dp[i - 1][j]}); if (s[i - 1] == t[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1); } string ans = ""; int i = s.size(); int j = t.size(); while (i >= 1 && j >= 1) { int a = dp[i - 1][j - 1]; int b = dp[i][j - 1]; int c = dp[i - 1][j]; if (a == b && a == c && a == dp[i][j] - 1) { ans = ans + s[i - 1]; --i, --j; } else if (a == b && a == c) { --i, --j; } else if (b > c) { --j; } else { --i; } } reverse(all(ans)); cout << ans << '\n'; }
[ "variable_declaration.type.primitive.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
972,406
972,407
u945359338
cpp
p03165
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define optimize \ ios::sync_with_stdio(0); \ cin.tie(0); #define PI acos(-1.0) #define pb push_back #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define RESET(a, b) memset(a, b, sizeof(a)) #define pii pair<int, int> #define gcd(a, b) __gcd(a, b) #define min3(a, b, c) min(c, min(a, b)) #define max3(a, b, c) max(c, max(a, b)) #define MX 3005 string str1, str2; int ara[MX][MX]; string LCS() { int n1 = str1.size(), n2 = str2.size(); for (int i = 1; i < n1; i++) { for (int j = 1; j < n2; j++) { if (str1[i] == str2[j]) { ara[i][j] = (ara[i - 1][j - 1] + 1); } else { ara[i][j] = max(ara[i - 1][j], ara[i][j - 1]); } } } int i = n1 - 1, j = n2 - 1; string ans; while (ara[i][j]) { if (ara[i][j] == ara[i - 1][j]) i--; if (ara[i][j] == ara[i][j - 1]) j--; else { ans += str1[i]; i--, j--; } } reverse(ans.begin(), ans.end()); return ans; } int main() { str1 += '?'; str2 += '#'; string temp; cin >> temp; str1 += temp; cin >> temp; str2 += temp; cout << LCS() << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define optimize \ ios::sync_with_stdio(0); \ cin.tie(0); #define PI acos(-1.0) #define pb push_back #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define RESET(a, b) memset(a, b, sizeof(a)) #define pii pair<int, int> #define gcd(a, b) __gcd(a, b) #define min3(a, b, c) min(c, min(a, b)) #define max3(a, b, c) max(c, max(a, b)) #define MX 3005 string str1, str2; int ara[MX][MX]; string LCS() { int n1 = str1.size(), n2 = str2.size(); for (int i = 1; i < n1; i++) { for (int j = 1; j < n2; j++) { if (str1[i] == str2[j]) { ara[i][j] = (ara[i - 1][j - 1] + 1); } else { ara[i][j] = max(ara[i - 1][j], ara[i][j - 1]); } } } int i = n1 - 1, j = n2 - 1; string ans; while (ara[i][j]) { if (ara[i][j] == ara[i - 1][j]) i--; else if (ara[i][j] == ara[i][j - 1]) j--; else { ans += str1[i]; i--, j--; } } reverse(ans.begin(), ans.end()); return ans; } int main() { str1 += '?'; str2 += '#'; string temp; cin >> temp; str1 += temp; cin >> temp; str2 += temp; cout << LCS() << endl; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
972,470
972,471
u325622555
cpp
p03165
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define optimize \ ios::sync_with_stdio(0); \ cin.tie(0); #define PI acos(-1.0) #define pb push_back #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define RESET(a, b) memset(a, b, sizeof(a)) #define pii pair<int, int> #define gcd(a, b) __gcd(a, b) #define min3(a, b, c) min(c, min(a, b)) #define max3(a, b, c) max(c, max(a, b)) #define MX 3005 string str1, str2; int ara[MX][MX]; string LCS() { int n1 = str1.size(), n2 = str2.size(); for (int i = 1; i < n1; i++) { for (int j = 1; j < n2; j++) { if (str1[i] == str2[j]) { ara[i][j] = (ara[i - 1][j - 1] + 1); } else { ara[i][j] = max(ara[i - 1][j], ara[i][j - 1]); } } } int i = n1 - 1, j = n2 - 1; string ans; while (ara[i][j]) { if (ara[i][j] == ara[i - 1][j]) i--; if (ara[i][j] == ara[i][j - 1]) j--; else { ans += str1[i]; i--, j--; } } reverse(ans.begin(), ans.end()); return ans; } int main() { str1 += '0'; str2 += '0'; string temp; cin >> temp; str1 += temp; cin >> temp; str2 += temp; cout << LCS() << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define optimize \ ios::sync_with_stdio(0); \ cin.tie(0); #define PI acos(-1.0) #define pb push_back #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define RESET(a, b) memset(a, b, sizeof(a)) #define pii pair<int, int> #define gcd(a, b) __gcd(a, b) #define min3(a, b, c) min(c, min(a, b)) #define max3(a, b, c) max(c, max(a, b)) #define MX 3005 string str1, str2; int ara[MX][MX]; string LCS() { int n1 = str1.size(), n2 = str2.size(); for (int i = 1; i < n1; i++) { for (int j = 1; j < n2; j++) { if (str1[i] == str2[j]) { ara[i][j] = (ara[i - 1][j - 1] + 1); } else { ara[i][j] = max(ara[i - 1][j], ara[i][j - 1]); } } } int i = n1 - 1, j = n2 - 1; string ans; while (ara[i][j]) { if (ara[i][j] == ara[i - 1][j]) i--; else if (ara[i][j] == ara[i][j - 1]) j--; else { ans += str1[i]; i--, j--; } } reverse(ans.begin(), ans.end()); return ans; } int main() { str1 += '?'; str2 += '#'; string temp; cin >> temp; str1 += temp; cin >> temp; str2 += temp; cout << LCS() << endl; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove", "literal.string.change", "assignment.value.change" ]
972,472
972,471
u325622555
cpp
p03165
#include <bits/stdc++.h> using namespace std; // DEFINE and // TYPEDEF-------------------------------------------------------------- // For actual content check from line 85 #define FORG(i, a, n) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? ++i : --i) // for - general #define FORZ(i, n) for (lld i = 0; i < (lld)n; ++i) // for - zero #define FORGI(i, a, n, inc) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? i += inc : i -= inc) // for - general incremental #define FORZI(i, n, inc) \ for (lld i = 0; i < (lld)n; i += inc) // for - zero incremental #define SPEEDUP \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define MEM(a, val) memset(a, val, sizeof(a)); #define all(m) m.begin(), m.end() #define sz(m) (lld) m.size() #define st first #define nd second #define pb push_back #define DEC(x) fixed << setprecision(x) typedef long long int lld; typedef unsigned long long int ulld; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.st >> a.nd; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.st << " " << a.nd; return out; } template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } // DEBUGGER------------------------------------------------------------------------ // #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables #define DEBUGON #define ZINDA \ cerr << "\nIdhar-ich hai apun!!\n"; // to debug if code reached that point #ifdef DEBUGON vector<string> vec_splitter(string s) { for (char &c : s) c = c == ',' ? ' ' : c; stringstream ss; ss << s; vector<string> res; for (string z; ss >> z; res.push_back(z)) ; return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << "): "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #define DEBUG(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #else #define debug(...) 320; #define DEBUG(...) 320; #endif lld power(lld b, lld e) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(b * b, (e - 1) / 2); else return power(b * b, e / 2); } lld power(lld b, lld e, lld m) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m; else return power(((b % m) * (b % m)) % m, e / 2, m) % m; } #define endl '\n' const long double pi = acos(-1); constexpr int mod = 1e9 + 7; // 1000000007 // endl : changed to '\n', to flush comment that definition //-------------------------------------------------------------------------------- lld dp[3007][3007]; pair<lld, lld> path[3007][3007]; void swagWaalaFunction() { lld n, m; string a, b, ans; cin >> a >> b; n = sz(a); m = sz(b); MEM(dp, 0); FORZ(i, 3007) FORZ(j, 3007) path[i][j] = {-1, -1}; if (a[0] == b[0]) { dp[0][0] = 1; path[0][0] = {-1, -1}; } FORZ(i, n) FORZ(j, m) { if (i) { dp[i][j] = dp[i - 1][j]; path[i][j] = {-1, 0}; } if (j and dp[i][j] < dp[i][j - 1]) { dp[i][j] = dp[i][j - 1]; path[i][j] = {0, -1}; } if (a[i] == b[j]) { lld add = 1; if (i and j) add += dp[i - 1][j - 1]; if (add > dp[i][j]) { dp[i][j] = add; path[i][j] = {-1, -1}; } } assert(!(path[i][j].st == 0 and path[i][j].nd == 0)); } lld i = n - 1, j = m - 1; while (i >= 0 and j >= 0) { pair<lld, lld> temp = path[i][j]; if (temp.st == -1 and temp.nd == -1) ans += a[i]; i += temp.st; j += temp.nd; } reverse(ans.begin(), ans.end()); // DEBUG(dp[n-1][m-1]); cout << ans << endl; return; } int main() { SPEEDUP; lld tc = 1; // cin>>tc; #ifdef PRIMES sieve(); #endif #ifdef CHOOSE nCrModInit(); #endif FORZ(i, tc) { // cout<<"Case #"<<i+1<<": "; swagWaalaFunction(); } // cerr<<"\n"<<timeKyaHorhaH; return 0; }
#include <bits/stdc++.h> using namespace std; // DEFINE and // TYPEDEF-------------------------------------------------------------- // For actual content check from line 85 #define FORG(i, a, n) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? ++i : --i) // for - general #define FORZ(i, n) for (lld i = 0; i < (lld)n; ++i) // for - zero #define FORGI(i, a, n, inc) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? i += inc : i -= inc) // for - general incremental #define FORZI(i, n, inc) \ for (lld i = 0; i < (lld)n; i += inc) // for - zero incremental #define SPEEDUP \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define MEM(a, val) memset(a, val, sizeof(a)); #define all(m) m.begin(), m.end() #define sz(m) (lld) m.size() #define st first #define nd second #define pb push_back #define DEC(x) fixed << setprecision(x) typedef long long int lld; typedef unsigned long long int ulld; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.st >> a.nd; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.st << " " << a.nd; return out; } template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } // DEBUGGER------------------------------------------------------------------------ // #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables #define DEBUGON #define ZINDA \ cerr << "\nIdhar-ich hai apun!!\n"; // to debug if code reached that point #ifdef DEBUGON vector<string> vec_splitter(string s) { for (char &c : s) c = c == ',' ? ' ' : c; stringstream ss; ss << s; vector<string> res; for (string z; ss >> z; res.push_back(z)) ; return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << "): "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #define DEBUG(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #else #define debug(...) 320; #define DEBUG(...) 320; #endif lld power(lld b, lld e) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(b * b, (e - 1) / 2); else return power(b * b, e / 2); } lld power(lld b, lld e, lld m) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m; else return power(((b % m) * (b % m)) % m, e / 2, m) % m; } #define endl '\n' const long double pi = acos(-1); constexpr int mod = 1e9 + 7; // 1000000007 // endl : changed to '\n', to flush comment that definition //-------------------------------------------------------------------------------- lld dp[3007][3007]; pair<lld, lld> path[3007][3007]; void swagWaalaFunction() { lld n, m; string a, b, ans; cin >> a >> b; n = sz(a); m = sz(b); MEM(dp, 0); FORZ(i, 3007) FORZ(j, 3007) path[i][j] = {0, -1}; if (a[0] == b[0]) { dp[0][0] = 1; path[0][0] = {-1, -1}; } FORZ(i, n) FORZ(j, m) { if (i) { dp[i][j] = dp[i - 1][j]; path[i][j] = {-1, 0}; } if (j and dp[i][j] < dp[i][j - 1]) { dp[i][j] = dp[i][j - 1]; path[i][j] = {0, -1}; } if (a[i] == b[j]) { lld add = 1; if (i and j) add += dp[i - 1][j - 1]; if (add > dp[i][j]) { dp[i][j] = add; path[i][j] = {-1, -1}; } } assert(!(path[i][j].st == 0 and path[i][j].nd == 0)); } lld i = n - 1, j = m - 1; while (i >= 0 and j >= 0) { pair<lld, lld> temp = path[i][j]; if (temp.st == -1 and temp.nd == -1) ans += a[i]; i += temp.st; j += temp.nd; } reverse(ans.begin(), ans.end()); // DEBUG(dp[n-1][m-1]); cout << ans << endl; return; } int main() { SPEEDUP; lld tc = 1; // cin>>tc; #ifdef PRIMES sieve(); #endif #ifdef CHOOSE nCrModInit(); #endif FORZ(i, tc) { // cout<<"Case #"<<i+1<<": "; swagWaalaFunction(); } // cerr<<"\n"<<timeKyaHorhaH; return 0; }
[ "literal.number.change" ]
972,491
972,492
u531151228
cpp
p03165
#include <bits/stdc++.h> using namespace std; // DEFINE and // TYPEDEF-------------------------------------------------------------- // For actual content check from line 85 #define FORG(i, a, n) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? ++i : --i) // for - general #define FORZ(i, n) for (lld i = 0; i < (lld)n; ++i) // for - zero #define FORGI(i, a, n, inc) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? i += inc : i -= inc) // for - general incremental #define FORZI(i, n, inc) \ for (lld i = 0; i < (lld)n; i += inc) // for - zero incremental #define SPEEDUP \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define MEM(a, val) memset(a, val, sizeof(a)); #define all(m) m.begin(), m.end() #define sz(m) (lld) m.size() #define st first #define nd second #define pb push_back #define DEC(x) fixed << setprecision(x) typedef long long int lld; typedef unsigned long long int ulld; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.st >> a.nd; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.st << " " << a.nd; return out; } template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } // DEBUGGER------------------------------------------------------------------------ // #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables #define DEBUGON #define ZINDA \ cerr << "\nIdhar-ich hai apun!!\n"; // to debug if code reached that point #ifdef DEBUGON vector<string> vec_splitter(string s) { for (char &c : s) c = c == ',' ? ' ' : c; stringstream ss; ss << s; vector<string> res; for (string z; ss >> z; res.push_back(z)) ; return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << "): "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #define DEBUG(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #else #define debug(...) 320; #define DEBUG(...) 320; #endif lld power(lld b, lld e) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(b * b, (e - 1) / 2); else return power(b * b, e / 2); } lld power(lld b, lld e, lld m) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m; else return power(((b % m) * (b % m)) % m, e / 2, m) % m; } #define endl '\n' const long double pi = acos(-1); constexpr int mod = 1e9 + 7; // 1000000007 // endl : changed to '\n', to flush comment that definition //-------------------------------------------------------------------------------- lld dp[3007][3007]; pair<lld, lld> path[3007][3007]; void swagWaalaFunction() { lld n, m; string a, b, ans; cin >> a >> b; n = sz(a); m = sz(b); MEM(dp, 0); FORZ(i, 3007) FORZ(j, 3007) path[i][j] = {0, 0}; if (a[0] == b[0]) { dp[0][0] = 1; path[0][0] = {-1, -1}; } FORZ(i, n) FORZ(j, m) { if (i) { dp[i][j] = dp[i - 1][j]; path[i][j] = {-1, 0}; } if (j and dp[i][j] < dp[i][j - 1]) { dp[i][j] = dp[i][j - 1]; path[i][j] = {0, -1}; } if (a[i] == b[j]) { lld add = 1; if (i and j) add += dp[i - 1][j - 1]; if (add > dp[i][j]) { dp[i][j] = add; path[i][j] = {-1, -1}; } } assert(!(path[i][j].st == 0 and path[i][j].nd == 0)); } lld i = n - 1, j = m - 1; while (i >= 0 and j >= 0) { pair<lld, lld> temp = path[i][j]; if (temp.st == -1 and temp.nd == -1) ans += a[i]; i += temp.st; j += temp.nd; } reverse(ans.begin(), ans.end()); // DEBUG(dp[n-1][m-1]); cout << ans << endl; return; } int main() { SPEEDUP; lld tc = 1; // cin>>tc; #ifdef PRIMES sieve(); #endif #ifdef CHOOSE nCrModInit(); #endif FORZ(i, tc) { // cout<<"Case #"<<i+1<<": "; swagWaalaFunction(); } // cerr<<"\n"<<timeKyaHorhaH; return 0; }
#include <bits/stdc++.h> using namespace std; // DEFINE and // TYPEDEF-------------------------------------------------------------- // For actual content check from line 85 #define FORG(i, a, n) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? ++i : --i) // for - general #define FORZ(i, n) for (lld i = 0; i < (lld)n; ++i) // for - zero #define FORGI(i, a, n, inc) \ for (lld i = (lld)a; a < n ? i < (lld)n : (lld)n < i; \ a < n ? i += inc : i -= inc) // for - general incremental #define FORZI(i, n, inc) \ for (lld i = 0; i < (lld)n; i += inc) // for - zero incremental #define SPEEDUP \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define MEM(a, val) memset(a, val, sizeof(a)); #define all(m) m.begin(), m.end() #define sz(m) (lld) m.size() #define st first #define nd second #define pb push_back #define DEC(x) fixed << setprecision(x) typedef long long int lld; typedef unsigned long long int ulld; template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &a) { in >> a.st >> a.nd; return in; } template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> a) { out << a.st << " " << a.nd; return out; } template <typename T, typename T1> T amax(T &a, T1 b) { if (b > a) a = b; return a; } template <typename T, typename T1> T amin(T &a, T1 b) { if (b < a) a = b; return a; } // DEBUGGER------------------------------------------------------------------------ // #define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables #define DEBUGON #define ZINDA \ cerr << "\nIdhar-ich hai apun!!\n"; // to debug if code reached that point #ifdef DEBUGON vector<string> vec_splitter(string s) { for (char &c : s) c = c == ',' ? ' ' : c; stringstream ss; ss << s; vector<string> res; for (string z; ss >> z; res.push_back(z)) ; return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << "): "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #define DEBUG(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__); #else #define debug(...) 320; #define DEBUG(...) 320; #endif lld power(lld b, lld e) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(b * b, (e - 1) / 2); else return power(b * b, e / 2); } lld power(lld b, lld e, lld m) { assert(e >= 0); if (e == 0) return 1; if (e % 2 == 1) return b * power(((b % m) * (b % m)) % m, (e - 1) / 2, m) % m; else return power(((b % m) * (b % m)) % m, e / 2, m) % m; } #define endl '\n' const long double pi = acos(-1); constexpr int mod = 1e9 + 7; // 1000000007 // endl : changed to '\n', to flush comment that definition //-------------------------------------------------------------------------------- lld dp[3007][3007]; pair<lld, lld> path[3007][3007]; void swagWaalaFunction() { lld n, m; string a, b, ans; cin >> a >> b; n = sz(a); m = sz(b); MEM(dp, 0); FORZ(i, 3007) FORZ(j, 3007) path[i][j] = {0, -1}; if (a[0] == b[0]) { dp[0][0] = 1; path[0][0] = {-1, -1}; } FORZ(i, n) FORZ(j, m) { if (i) { dp[i][j] = dp[i - 1][j]; path[i][j] = {-1, 0}; } if (j and dp[i][j] < dp[i][j - 1]) { dp[i][j] = dp[i][j - 1]; path[i][j] = {0, -1}; } if (a[i] == b[j]) { lld add = 1; if (i and j) add += dp[i - 1][j - 1]; if (add > dp[i][j]) { dp[i][j] = add; path[i][j] = {-1, -1}; } } assert(!(path[i][j].st == 0 and path[i][j].nd == 0)); } lld i = n - 1, j = m - 1; while (i >= 0 and j >= 0) { pair<lld, lld> temp = path[i][j]; if (temp.st == -1 and temp.nd == -1) ans += a[i]; i += temp.st; j += temp.nd; } reverse(ans.begin(), ans.end()); // DEBUG(dp[n-1][m-1]); cout << ans << endl; return; } int main() { SPEEDUP; lld tc = 1; // cin>>tc; #ifdef PRIMES sieve(); #endif #ifdef CHOOSE nCrModInit(); #endif FORZ(i, tc) { // cout<<"Case #"<<i+1<<": "; swagWaalaFunction(); } // cerr<<"\n"<<timeKyaHorhaH; return 0; }
[ "literal.number.change" ]
972,493
972,492
u531151228
cpp
p03165
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define rep(i, j, n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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; } //(a+b-1)/b signed main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vvl dp(n + 10, vl(m + 10)); rep(i, 0, n) { rep(j, 0, m) { if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; ll i = n, j = m; while (i > 0 && j > 0) { if (dp[i - 1][i] == dp[i][j]) --i; else if (dp[i][j - 1] == dp[i][j]) --j; else { ans = s[i - 1] + ans; --i, --j; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define rep(i, j, n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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; } //(a+b-1)/b signed main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vvl dp(n + 10, vl(m + 10)); rep(i, 0, n) { rep(j, 0, m) { if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; ll i = n, j = m; 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 { ans = s[i - 1] + ans; --i, --j; } } cout << ans << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
972,504
972,505
u164181205
cpp
p03165
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define rep(i, j, n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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; } //(a+b-1)/b signed main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vvl dp(n + 10, vl(m + 10)); rep(i, 0, n) { rep(j, 0, m) { if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans; ll i = n, j = m; while (i > 0 && j > 0) { if (dp[i - 1][i] == dp[i][j]) --i; else if (dp[i][j - 1] == dp[i][j]) --j; else { ans = s[i - 1] + ans; --i, --j; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define rep(i, j, n) for (long long i = j; i < (long long)(n); i++) #define _GLIBCXX_DEBUG #define MOD 1000000007 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; } //(a+b-1)/b signed main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vvl dp(n + 10, vl(m + 10)); rep(i, 0, n) { rep(j, 0, m) { if (s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; ll i = n, j = m; 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 { ans = s[i - 1] + ans; --i, --j; } } cout << ans << endl; return 0; }
[ "variable_declaration.value.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
972,506
972,505
u164181205
cpp
p03165
#include <bits/stdc++.h> using namespace std; #define FOR(i, start, end) for (uint64_t i = start; i < end; i++) #define REP(i, n) FOR(i, 0, n) // 最大公約数gcd // 最小公倍数lcm=m*n/gcd uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); } // vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0)) // v[n][k]に組み合わせ数が入る。 void comb(vector<vector<uint64_t>> &v) { for (uint64_t i = 0; i < v.size(); i++) { v[i][0] = 1; v[i][i] = 1; } for (uint64_t k = 1; k < v.size(); k++) { for (uint64_t j = 1; j < k; j++) { v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); } } } // 掛け算オーバーフロー判定 bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } //素因数分解 void primeFactorization( uint64_t a, list<uint64_t> &factors) { //素因数分解を出力するプログラム long i, sq; if (a % 2 == 0) { //偶数の場合 factors.push_back(2); primeFactorization(a / 2, factors); // 2で割った値で再帰 return; } sq = sqrt(a); for (i = 3; i <= sq; i += 2) { // 3以上√a以下の奇数の場合 if (a % i == 0) { factors.push_back(i); primeFactorization(a / i, factors); //割れた値で再帰 return; } } //偶数でも3以上√a以下の奇数の場合でも割り切れない場合 if (a != 1) { // aが1でないなら、a自身は素数 factors.push_back(a); } } // フェルマーの小定理 // mod. m での a の逆元 a^{-1} を計算する // (a/b)%m = a*movinv(b,m)%m int64_t modinv(int64_t a, int64_t m) { int64_t b = m, u = 1, v = 0; while (b) { int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 円周率 // M_PI // #include <iomanip> // setprecisionを使用するのに必要 // cout << std::fixed << std::setprecision(15) << y << endl; // 昇順 // priority_queue<int, vector<int>, greater<int> > queue; signed main() { string s, t; cin >> s >> t; int m = s.length(); int n = t.length(); int dp[m + 1][n + 1] = {}; for (int i = 0; i < m; i++) { for (int j = 0; j < n; 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]); } } } int i = m; int j = n; 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.push_back(s[i - 1]); i--; j--; } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, start, end) for (uint64_t i = start; i < end; i++) #define REP(i, n) FOR(i, 0, n) // 最大公約数gcd // 最小公倍数lcm=m*n/gcd uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); } // vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0)) // v[n][k]に組み合わせ数が入る。 void comb(vector<vector<uint64_t>> &v) { for (uint64_t i = 0; i < v.size(); i++) { v[i][0] = 1; v[i][i] = 1; } for (uint64_t k = 1; k < v.size(); k++) { for (uint64_t j = 1; j < k; j++) { v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); } } } // 掛け算オーバーフロー判定 bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } //素因数分解 void primeFactorization( uint64_t a, list<uint64_t> &factors) { //素因数分解を出力するプログラム long i, sq; if (a % 2 == 0) { //偶数の場合 factors.push_back(2); primeFactorization(a / 2, factors); // 2で割った値で再帰 return; } sq = sqrt(a); for (i = 3; i <= sq; i += 2) { // 3以上√a以下の奇数の場合 if (a % i == 0) { factors.push_back(i); primeFactorization(a / i, factors); //割れた値で再帰 return; } } //偶数でも3以上√a以下の奇数の場合でも割り切れない場合 if (a != 1) { // aが1でないなら、a自身は素数 factors.push_back(a); } } // フェルマーの小定理 // mod. m での a の逆元 a^{-1} を計算する // (a/b)%m = a*movinv(b,m)%m int64_t modinv(int64_t a, int64_t m) { int64_t b = m, u = 1, v = 0; while (b) { int64_t t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 円周率 // M_PI // #include <iomanip> // setprecisionを使用するのに必要 // cout << std::fixed << std::setprecision(15) << y << endl; // 昇順 // priority_queue<int, vector<int>, greater<int> > queue; signed main() { string s, t; cin >> s >> t; int m = s.length(); int n = t.length(); int dp[m + 1][n + 1] = {}; for (int i = 0; i < m; i++) { for (int j = 0; j < n; 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]); } } } int i = m; int j = n; 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.push_back(s[i - 1]); i--; j--; } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change", "misc.opposites" ]
972,527
972,528
u925478083
cpp
p03165
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; int INF = 1e9 + 7; int mod = 1e9 + 7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int dp[4005][4005]; signed main() { 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]) { 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][j + 1]}); } } string R = ""; 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 { R += S[i - 1]; i--; j--; } } reverse(R.begin(), R.end()); cout << R << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; int INF = 1e9 + 7; int mod = 1e9 + 7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int dp[4005][4005]; signed main() { 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]) { 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][j + 1]}); } } string R = ""; 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 { R += S[i - 1]; i--; j--; } } reverse(R.begin(), R.end()); cout << R << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
972,541
972,542
u237390401
cpp
p03165
#include <bits/stdc++.h> using namespace std; struct edge { int to; // 辺の行き先 int weight; // 辺の重み edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<int>>; using dou = long double; string Yes = "Yes"; string YES = "YES"; string NO = "NO"; string No = "No"; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define brep(n) for (int bit = 0; bit < (1 << n); bit++) #define erep(i, container) for (auto i : container) #define irep(i, n) for (int i = n - 1; i >= (int)0; i--) #define rrep(i, m, n) for (int i = m; i < (int)(n); i++) #define reprep(i, j, h, w) rep(i, h) rep(j, w) #define all(x) (x).begin(), (x).end() #define aall(x, n) (x).begin(), (x).begin() + (n) #define VEC(type, name, n) \ std::vector<type> name(n); \ rep(i, n) std::cin >> name[i]; #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define res resize #define as assign #define fi first #define se second #define itn int #define mp make_pair #define sum(a) accumulate(all(a), 0) #define keta fixed << setprecision #define vvector(name, typ, m, n, a) \ vector<vector<typ>> name(m, vector<typ>(n, a)) #define vvvector(name, t, l, m, n, a) \ vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a))); #define vvvvector(name, t, k, l, m, n, a) \ vector<vector<vector<vector<t>>>> name( \ k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a)))); typedef long long ll; const int INF = 2000000000; const ll INF64 = 922337203685477580ll; const int mod = 1000000007ll; const ll MOD = 1000000007LL; const double pi = 3.1415926535897932384626; int main() { string s, t; std::cin >> s >> t; vvector(dp, int, s.size() + 1, t.size() + 1, 0); rep(i, s.size()) rep(j, t.size()) { if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]); dp[i + 1][j + 1] = max(dp[i + 1][1 + j], dp[i][j + 1]); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]); } // std::cout << dp[s.size()][t.size()] << std::endl; int i = s.size(), j = t.size(); string ans; while (i > 0 && j > 0) { if (dp[i][j] == dp[i - 1][j]) { i--; } if (dp[i][j] == dp[i][j - 1]) { j--; } else { ans = s[i - 1] + ans; i--; j--; } } std::cout << ans << std::endl; }
#include <bits/stdc++.h> using namespace std; struct edge { int to; // 辺の行き先 int weight; // 辺の重み edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<int>>; using dou = long double; string Yes = "Yes"; string YES = "YES"; string NO = "NO"; string No = "No"; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define brep(n) for (int bit = 0; bit < (1 << n); bit++) #define erep(i, container) for (auto i : container) #define irep(i, n) for (int i = n - 1; i >= (int)0; i--) #define rrep(i, m, n) for (int i = m; i < (int)(n); i++) #define reprep(i, j, h, w) rep(i, h) rep(j, w) #define all(x) (x).begin(), (x).end() #define aall(x, n) (x).begin(), (x).begin() + (n) #define VEC(type, name, n) \ std::vector<type> name(n); \ rep(i, n) std::cin >> name[i]; #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define res resize #define as assign #define fi first #define se second #define itn int #define mp make_pair #define sum(a) accumulate(all(a), 0) #define keta fixed << setprecision #define vvector(name, typ, m, n, a) \ vector<vector<typ>> name(m, vector<typ>(n, a)) #define vvvector(name, t, l, m, n, a) \ vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a))); #define vvvvector(name, t, k, l, m, n, a) \ vector<vector<vector<vector<t>>>> name( \ k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a)))); typedef long long ll; const int INF = 2000000000; const ll INF64 = 922337203685477580ll; const int mod = 1000000007ll; const ll MOD = 1000000007LL; const double pi = 3.1415926535897932384626; int main() { string s, t; std::cin >> s >> t; vvector(dp, int, s.size() + 1, t.size() + 1, 0); rep(i, s.size()) rep(j, t.size()) { if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]); dp[i + 1][j + 1] = max(dp[i + 1][1 + j], dp[i][j + 1]); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]); } // std::cout << dp[s.size()][t.size()] << std::endl; int i = s.size(), 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--; } } std::cout << ans << std::endl; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
972,603
972,604
u539011156
cpp
p03165
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int dp[3010][3010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; rep(i, s.size()) { rep(j, t.size()) { 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]); } } string ans; int slen = s.size(); int tlen = t.size(); while (slen > 0 && tlen > 0 && dp[slen][tlen] > 0) { // cout << (dp[slen][tlen] == dp[slen - 1][tlen]) << " " << (dp[slen][tlen] // == dp[tlen - 1][tlen]) << " " << ans << endl; if (dp[slen][tlen] == dp[slen - 1][tlen]) slen--; else if (dp[slen][tlen] == dp[slen - 1][tlen]) tlen--; else { slen--; tlen--; ans = s[slen] + ans; } } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int dp[3010][3010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; rep(i, s.size()) { rep(j, t.size()) { 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]); } } string ans; int slen = s.size(); int tlen = t.size(); while (slen > 0 && tlen > 0 && dp[slen][tlen] > 0) { // cout << (dp[slen][tlen] == dp[slen - 1][tlen]) << " " << (dp[slen][tlen] // == dp[tlen - 1][tlen]) << " " << ans << endl; if (dp[slen][tlen] == dp[slen - 1][tlen]) slen--; else if (dp[slen][tlen] == dp[slen][tlen - 1]) tlen--; else { slen--; tlen--; ans = s[slen] + ans; } } cout << ans << endl; return 0; }
[ "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
972,625
972,626
u965730380
cpp
p03165
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int dp[3010][3010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; rep(i, s.size()) { rep(j, t.size()) { 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]); } } string ans; int slen = s.size(); int tlen = t.size(); while (slen > 0 && tlen > 0 && dp[slen][tlen] > 0) { if (dp[slen][tlen] == dp[slen - 1][tlen]) slen--; else if (dp[slen][tlen] == dp[tlen - 1][tlen]) tlen--; else { slen--; tlen--; ans = s[slen] + ans; } } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int dp[3010][3010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; rep(i, s.size()) { rep(j, t.size()) { 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]); } } string ans; int slen = s.size(); int tlen = t.size(); while (slen > 0 && tlen > 0 && dp[slen][tlen] > 0) { // cout << (dp[slen][tlen] == dp[slen - 1][tlen]) << " " << (dp[slen][tlen] // == dp[tlen - 1][tlen]) << " " << ans << endl; if (dp[slen][tlen] == dp[slen - 1][tlen]) slen--; else if (dp[slen][tlen] == dp[slen][tlen - 1]) tlen--; else { slen--; tlen--; ans = s[slen] + ans; } } cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
972,627
972,626
u965730380
cpp
p03165
#include <bits/stdc++.h> using namespace std; typedef long long int ll; string s, t; ll dp[3007][3007]; int main() { cin >> s >> t; s += ';'; t += '.'; for (ll i = 0; i < s.length(); ++i) { for (ll 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] = max(dp[i + 1][j], dp[i][j]); dp[i][j + 1] = max(dp[i][j], dp[i][j + 1]); } } ll i = s.length() - 1, j = t.length() - 1; string ans = ""; while (i + j) { ll cur = dp[i][j]; if (dp[i - 1][j] == cur) i--; else if (dp[i][j - 1] == cur) j--; else { i--; j--; ans += s[i]; } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; string s, t; ll dp[3007][3007]; int main() { cin >> s >> t; s += ';'; t += '.'; for (ll i = 0; i < s.length(); ++i) { for (ll 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] = max(dp[i + 1][j], dp[i][j]); dp[i][j + 1] = max(dp[i][j], dp[i][j + 1]); } } ll i = s.length() - 1, j = t.length() - 1; string ans = ""; while (i && j) { ll cur = dp[i][j]; if (dp[i - 1][j] == cur) i--; else if (dp[i][j - 1] == cur) j--; else { i--; j--; ans += s[i]; } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
[ "control_flow.loop.condition.change" ]
972,628
972,629
u406910179
cpp
p03165
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1LL << 60; const double EPS = 1e-10; const ll mod = 1000000007; ll dp[3010][3010] = {}; int main(void) { 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]) 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.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 - 1][j]) j--; else { ans = s[i - 1] + ans; i--, j--; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1LL << 60; const double EPS = 1e-10; const ll mod = 1000000007; ll dp[3010][3010] = {}; int main(void) { 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]) 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.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; }
[ "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
972,682
972,683
u675509234
cpp
p03165
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int m = s.size(), n = t.size(); vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0)); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1; dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]); } } string res = ""; int i = m, j = n; 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 <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int m = s.size(), n = t.size(); vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0)); for (int i = 0; i < m; i++) { for (int j = 0; j < n; 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 res = ""; int i = m, j = n; 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; }
[ "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add" ]
972,712
972,713
u315212004
cpp
p03165
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for (int i = 0; i < (n); i++) 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; } ll dp[3100][3100]; int main() { 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]); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string res = ""; int i = (int)s.size(), j = (int)t.size(); while (i > 0 && j > 0) { if (dp[i][j] == dp[i - 1][j]) { --i; } else if (dp[i][j] == dp[i][j - 1]) { --j; } else { res = s[i - 1] + res; --i; --j; } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for (int i = 0; i < (n); i++) 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; } ll dp[3100][3100]; int main() { 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 + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string res = ""; int i = (int)s.size(), j = (int)t.size(); while (i > 0 && j > 0) { if (dp[i][j] == dp[i - 1][j]) { --i; } else if (dp[i][j] == dp[i][j - 1]) { --j; } else { res = s[i - 1] + res; --i; --j; } } cout << res << endl; }
[ "expression.operation.binary.add" ]
972,716
972,717
u436660228
cpp
p03165
#include <bits/stdc++.h> #define smax(a, b) ((a) < (b) ? ((a) = (b), true) : false) #define smin(a, b) ((a) > (b) ? ((a) = (b), true) : false) #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; char a[3001]; char b[3001]; int dp[3001][3001]; int dir[3001][3001]; char add[3001][3001]; stack<char> ans; int main() { cin >> a >> b; int alen = strlen(a); int blen = strlen(b); for (int i = 1; i <= alen; i++) { for (int j = 1; j <= blen; j++) { int x = dp[i - 1][j - 1]; int y = dp[i - 1][j]; int z = dp[i][j - 1]; if (a[i - 1] == b[j - 1]) x++; dp[i][j] = max({x, y, z}); if (dp[i][j] == x) { dir[i][j] = 1; if (a[i - 1] == b[j - 1]) { add[i][j] = a[i - 1]; } } if (dp[i][j] == y) { dir[i][j] = 2; } if (dp[i][j] == z) { dir[i][j] = 3; } } } int dx = alen; int dy = blen; while (dx > 0 && dy > 0) { if (add[dx][dy] != 0) { ans.push(add[dx][dy]); } if (dir[dx][dy] == 1) { dx--; dy--; } else if (dir[dx][dy] == 2) { dx--; } else if (dir[dx][dy] == 3) { dy--; } } while (!ans.empty()) { cout << ans.top(); ans.pop(); } cout << endl; return 0; }
#include <bits/stdc++.h> #define smax(a, b) ((a) < (b) ? ((a) = (b), true) : false) #define smin(a, b) ((a) > (b) ? ((a) = (b), true) : false) #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; char a[3001]; char b[3001]; int dp[3001][3001]; int dir[3001][3001]; char add[3001][3001]; stack<char> ans; int main() { cin >> a >> b; int alen = strlen(a); int blen = strlen(b); for (int i = 1; i <= alen; i++) { for (int j = 1; j <= blen; j++) { int x = dp[i - 1][j - 1]; int y = dp[i - 1][j]; int z = dp[i][j - 1]; if (a[i - 1] == b[j - 1]) x++; dp[i][j] = max({x, y, z}); if (dp[i][j] == x) { dir[i][j] = 1; if (a[i - 1] == b[j - 1]) { add[i][j] = a[i - 1]; } } else if (dp[i][j] == y) { dir[i][j] = 2; } else if (dp[i][j] == z) { dir[i][j] = 3; } } } int dx = alen; int dy = blen; while (dx > 0 && dy > 0) { if (add[dx][dy] != 0) { ans.push(add[dx][dy]); } if (dir[dx][dy] == 1) { dx--; dy--; } else if (dir[dx][dy] == 2) { dx--; } else if (dir[dx][dy] == 3) { dy--; } } while (!ans.empty()) { cout << ans.top(); ans.pop(); } cout << endl; return 0; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
972,757
972,758
u048420094
cpp
p03165
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<vector<int>> dp(n + 1, vector<int>(m + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i] == t[j]) dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1] + dp[i][j] + 1}); else dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1]}); } } cerr << dp[n][m] << endl; 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.push_back(s[i - 1]); i--; j--; } } reverse(ans.begin(), ans.end()); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<vector<int>> dp(n + 1, vector<int>(m + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i] == t[j]) dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1], dp[i][j] + 1}); else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]); } } // dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1], dp[i][j] + 1}); // dp[i + 1][j + 1] = max({dp[i + 1][j], dp[i][j + 1] + dp[i][j] + 1}); cerr << dp[n][m] << endl; 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.push_back(s[i - 1]); i--; j--; } } reverse(ans.begin(), ans.end()); cout << ans << endl; }
[ "control_flow.branch.else.remove", "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add", "assignment.add" ]
972,776
972,777
u543584809
cpp
p03165
#include <iostream> //#include <iomanip> #include <algorithm> #include <string> #include <vector> //#include <utility> //#include <set> //#include <map> //#include <queue> //#include <deque> //#include <bitset> //#include <math.h> using namespace std; using ll = long long; // using ld = long double ; using vll = vector<ll>; using vvll = vector<vll>; // using vc = vector<char> ; // using vvc = vector<vc> ; // using vb = vector<bool> ; // using vvb = vector<vb> ; // using pll = pair<ll,ll> ; #define all(v) v.begin(), v.end() // ll mod = 1000000007 ; // long double pie = acos(-1) ; // ll INF = 1000000000000 ; // void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} // void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} // ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} // ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} // ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;} // void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;} // void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;} // void fix_cout(){cout << fixed << setprecision(20) ;} int main() { string s, t; cin >> s >> t; vvll dp(s.size() + 1, vll(t.size() + 1, 0)); for (int i = 1; i <= s.size(); i++) { for (int j = 1; j <= t.size(); j++) { if (s.at(i - 1) == t.at(j - 1)) { dp.at(i).at(j) = dp.at(i - 1).at(j - 1) + 1; } else { dp.at(i).at(j) = max(dp.at(i - 1).at(j), dp.at(i).at(j - 1)); } } } ll cnt = dp.at(s.size()).at(t.size()); string ans = ""; int posi = s.size(), posj = t.size(); ll sub = posj; while (cnt > 0) { if (dp.at(posi).at(posj) == cnt && dp.at(posi - 1).at(posj) != cnt && dp.at(posi).at(posj - 1) != cnt) { ans += s.at(posi - 1); cnt--; posi--; posj--; sub = posi; } else { posi--; if (posi == 0) { posj--; posi = sub; } } } reverse(all(ans)); /*for(int i=1;i<=s.size();i++){ for(int j=1;j<=t.size();j++){ cout << dp.at(i).at(j) << (j==t.size()?'\n':' ') ; } }*/ cout << ans << endl; }
#include <iostream> //#include <iomanip> #include <algorithm> #include <string> #include <vector> //#include <utility> //#include <set> //#include <map> //#include <queue> //#include <deque> //#include <bitset> //#include <math.h> using namespace std; using ll = long long; // using ld = long double ; using vll = vector<ll>; using vvll = vector<vll>; // using vc = vector<char> ; // using vvc = vector<vc> ; // using vb = vector<bool> ; // using vvb = vector<vb> ; // using pll = pair<ll,ll> ; #define all(v) v.begin(), v.end() // ll mod = 1000000007 ; // long double pie = acos(-1) ; // ll INF = 1000000000000 ; // void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} // void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} // ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} // ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} // ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;} // void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;} // void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;} // void fix_cout(){cout << fixed << setprecision(20) ;} int main() { string s, t; cin >> s >> t; vvll dp(s.size() + 1, vll(t.size() + 1, 0)); for (int i = 1; i <= s.size(); i++) { for (int j = 1; j <= t.size(); j++) { if (s.at(i - 1) == t.at(j - 1)) { dp.at(i).at(j) = dp.at(i - 1).at(j - 1) + 1; } else { dp.at(i).at(j) = max(dp.at(i - 1).at(j), dp.at(i).at(j - 1)); } } } ll cnt = dp.at(s.size()).at(t.size()); string ans = ""; int posi = s.size(), posj = t.size(); ll sub = posi; while (cnt > 0) { // cout << posi << " " << posj << endl ; if (dp.at(posi).at(posj) == cnt && dp.at(posi - 1).at(posj) != cnt && dp.at(posi).at(posj - 1) != cnt) { ans += s.at(posi - 1); cnt--; posi--; posj--; sub = posi; } else { posi--; if (posi == 0) { posj--; posi = sub; } } } reverse(all(ans)); /*for(int i=1;i<=s.size();i++){ for(int j=1;j<=t.size();j++){ cout << dp.at(i).at(j) << (j==t.size()?'\n':' ') ; } }*/ cout << ans << endl; }
[ "variable_declaration.value.change", "identifier.change" ]
972,780
972,781
u993074316
cpp
p03165
#include <iostream> //#include <iomanip> #include <algorithm> #include <string> #include <vector> //#include <utility> //#include <set> //#include <map> //#include <queue> //#include <deque> //#include <bitset> //#include <math.h> using namespace std; using ll = long long; // using ld = long double ; using vll = vector<ll>; using vvll = vector<vll>; // using vc = vector<char> ; // using vvc = vector<vc> ; // using vb = vector<bool> ; // using vvb = vector<vb> ; // using pll = pair<ll,ll> ; #define all(v) v.begin(), v.end() // ll mod = 1000000007 ; // long double pie = acos(-1) ; // ll INF = 1000000000000 ; // void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} // void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} // ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} // ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} // ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;} // void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;} // void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;} // void fix_cout(){cout << fixed << setprecision(20) ;} int main() { string s, t; cin >> s >> t; vvll dp(s.size() + 1, vll(t.size() + 1, 0)); for (int i = 1; i <= s.size(); i++) { for (int j = 1; j <= t.size(); j++) { if (s.at(i - 1) == t.at(j - 1)) { dp.at(i).at(j) = dp.at(i - 1).at(j - 1) + 1; } else { dp.at(i).at(j) = max(dp.at(i - 1).at(j), dp.at(i).at(j - 1)); } } } ll cnt = dp.at(s.size()).at(t.size()); string ans = ""; int posi = s.size(), posj = t.size(); ll sub = posj; while (cnt > 0) { if (dp.at(posi).at(posj) == cnt && dp.at(posi - 1).at(posj) != cnt && dp.at(posi - 1).at(posj) != cnt) { ans += s.at(posi - 1); cnt--; posi--; posj--; sub = posi; } else { posi--; if (posi == 0) { posj--; posi = sub; } } } reverse(all(ans)); /*for(int i=1;i<=s.size();i++){ for(int j=1;j<=t.size();j++){ cout << dp.at(i).at(j) << (j==t.size()?'\n':' ') ; } }*/ cout << ans << endl; }
#include <iostream> //#include <iomanip> #include <algorithm> #include <string> #include <vector> //#include <utility> //#include <set> //#include <map> //#include <queue> //#include <deque> //#include <bitset> //#include <math.h> using namespace std; using ll = long long; // using ld = long double ; using vll = vector<ll>; using vvll = vector<vll>; // using vc = vector<char> ; // using vvc = vector<vc> ; // using vb = vector<bool> ; // using vvb = vector<vb> ; // using pll = pair<ll,ll> ; #define all(v) v.begin(), v.end() // ll mod = 1000000007 ; // long double pie = acos(-1) ; // ll INF = 1000000000000 ; // void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} // void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} // ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} // ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} // ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;} // void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;} // void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;} // void fix_cout(){cout << fixed << setprecision(20) ;} int main() { string s, t; cin >> s >> t; vvll dp(s.size() + 1, vll(t.size() + 1, 0)); for (int i = 1; i <= s.size(); i++) { for (int j = 1; j <= t.size(); j++) { if (s.at(i - 1) == t.at(j - 1)) { dp.at(i).at(j) = dp.at(i - 1).at(j - 1) + 1; } else { dp.at(i).at(j) = max(dp.at(i - 1).at(j), dp.at(i).at(j - 1)); } } } ll cnt = dp.at(s.size()).at(t.size()); string ans = ""; int posi = s.size(), posj = t.size(); ll sub = posi; while (cnt > 0) { // cout << posi << " " << posj << endl ; if (dp.at(posi).at(posj) == cnt && dp.at(posi - 1).at(posj) != cnt && dp.at(posi).at(posj - 1) != cnt) { ans += s.at(posi - 1); cnt--; posi--; posj--; sub = posi; } else { posi--; if (posi == 0) { posj--; posi = sub; } } } reverse(all(ans)); /*for(int i=1;i<=s.size();i++){ for(int j=1;j<=t.size();j++){ cout << dp.at(i).at(j) << (j==t.size()?'\n':' ') ; } }*/ cout << ans << endl; }
[ "variable_declaration.value.change", "identifier.change", "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
972,782
972,781
u993074316
cpp
p03165
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i > 0; i++) using ll = long long; int dp[3010][3010]; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; rep(i, s.size()) { rep(j, t.size()) { if (s[i + 1] == t[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]); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]); } } string res = ""; int i = s.size(); int 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; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i > 0; i++) using ll = long long; int dp[3010][3010]; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; rep(i, s.size()) { rep(j, t.size()) { 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(); int 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; }
[ "expression.operation.binary.remove" ]
972,783
972,784
u297398560
cpp
p03165
#include <bits/stdc++.h> using namespace std; int main() { string x, y; int m, n, i, j; cin >> x >> y; m = x.length(); // use i for x n = y.length(); // use j for y int dp[m + 1][n + 1]; // rows for x and coloumns for y for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (x[i - 1] == y[j - 1]) dp[i][j] = 1 + dp[i - 1][j - 1]; else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } if (dp[m][n] == 0) { cout << " " << endl; return 0; } string res = ""; for (i = m, j = n; i > 0 && j > 0;) { if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) { res.push_back(x[i - 1]); i--; j--; } else if (dp[i][j - 1] > dp[i - 1][j]) j--; else i--; } /*while(!s.empty()) { cout<<s.top(); s.pop(); } return 0;*/ reverse(res.begin(), res.end()); cout << res << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string x, y; int m, n, i, j; cin >> x >> y; m = x.length(); // use i for x n = y.length(); // use j for y int dp[m + 1][n + 1]; // rows for x and coloumns for y for (i = 0; i <= m; i++) { for (j = 0; j <= n; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (x[i - 1] == y[j - 1]) dp[i][j] = 1 + dp[i - 1][j - 1]; else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } if (dp[m][n] == 0) { cout << " " << endl; return 0; } string res = ""; for (i = m, j = n; i > 0 && j > 0;) { if (dp[i][j] != dp[i - 1][j] && dp[i][j] != dp[i][j - 1]) { res.push_back(x[i - 1]); i--; j--; } else if (dp[i][j - 1] > dp[i - 1][j]) j--; else i--; } /*while(!s.empty()) { cout<<s.top(); s.pop(); } return 0;*/ reverse(res.begin(), res.end()); cout << res << "\n"; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
972,804
972,805
u345094009
cpp
p03165
#include <algorithm> #include <iostream> #include <string> using namespace std; string s, t; int dp[3009][3009]; int main() { cin >> s >> t; 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 - 1] == t[i - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1); } } int i = s.size(); int j = t.size(); string res; 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--; res.push_back(s[i]); } } reverse(res.begin(), res.end()); cout << res << endl; }
#include <algorithm> #include <iostream> #include <string> using namespace std; string s, t; int dp[3009][3009]; int main() { cin >> s >> t; 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 - 1] == t[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1); } } int i = s.size(); int j = t.size(); string res = ""; 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--; res.push_back(s[i]); } } reverse(res.begin(), res.end()); cout << res << endl; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change", "variable_declaration.value.change" ]
972,827
972,828
u047554023
cpp
p03165
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; int ls = s.size(); int lt = t.size(); vector<vector<int>> dp(ls + 1, vector<int>(lt + 1)); rep(i, ls) { rep(j, lt) { 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]); } } } int p = ls, q = lt; string ans; while (p > 0 || q > 0) { if (dp[p][q] == dp[p - 1][q]) p--; else if (dp[p][q] == dp[p][q - 1]) q--; else { p--; q--; ans = s[p] + ans; } } 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; int main() { string s, t; cin >> s >> t; int ls = s.size(); int lt = t.size(); vector<vector<int>> dp(ls + 1, vector<int>(lt + 1)); rep(i, ls) { rep(j, lt) { 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]); } } } int p = ls, q = lt; string ans; while (p > 0 && q > 0) { if (dp[p][q] == dp[p - 1][q]) p--; else if (dp[p][q] == dp[p][q - 1]) q--; else { p--; q--; ans = s[p] + ans; } } cout << ans << endl; }
[ "misc.opposites", "control_flow.loop.condition.change" ]
972,839
972,840
u314917898
cpp
p03165
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; using P = pair<ll, ll>; 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; } const ll MOD = 1000000007; const int INF = 1 << 30; // const ll INF = (ll)1e18 + 1; int main() { string S; cin >> S; string T; cin >> T; int N_S = S.size(); int N_T = T.size(); vector<vector<int>> dp(N_S + 10, vector<int>(N_T + 10, -INF)); dp[0][0] = dp[0][1] = dp[1][0] = 0; for (int i = 0; i < N_S; ++i) { for (int j = 0; j < N_T; ++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]); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; while (N_S > 0 && N_T > 0) { // (i, j + 1) -> (i + 1, j + 1) if (dp[N_S][N_T] == dp[N_S - 1][N_T]) --N_S; // (i + 1, j) -> (i + 1, j + 1) else if (dp[N_S][N_T] == dp[N_S][N_T - 1]) --N_T; // (i, j) -> (i + 1, j + 1) else { ans = S[N_S - 1] + ans; --N_S, --N_T; } } // cout << dp[N_S][N_T] << endl; cout << ans << endl; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; using P = pair<ll, ll>; 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; } const ll MOD = 1000000007; const int INF = 1 << 30; // const ll INF = (ll)1e18 + 1; int main() { string S; cin >> S; string T; cin >> T; int N_S = S.size(); int N_T = T.size(); vector<vector<int>> dp(N_S + 10, vector<int>(N_T + 10, 0)); dp[0][0] = dp[0][1] = dp[1][0] = 0; for (int i = 0; i < N_S; ++i) { for (int j = 0; j < N_T; ++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]); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; while (N_S > 0 && N_T > 0) { // (i, j + 1) -> (i + 1, j + 1) if (dp[N_S][N_T] == dp[N_S - 1][N_T]) --N_S; // (i + 1, j) -> (i + 1, j + 1) else if (dp[N_S][N_T] == dp[N_S][N_T - 1]) --N_T; // (i, j) -> (i + 1, j + 1) else { ans = S[N_S - 1] + ans; --N_S, --N_T; } } // cout << dp[N_S][N_T] << endl; cout << ans << endl; }
[ "call.arguments.change", "expression.operation.unary.remove" ]
972,855
972,856
u952081880
cpp
p03165
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; using P = pair<ll, ll>; 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; } const ll MOD = 1000000007; const int INF = 1 << 30; // const ll INF = (ll)1e18 + 1; int main() { string S; cin >> S; string T; cin >> T; int N_S = S.size(); int N_T = T.size(); vector<vector<int>> dp(N_S + 10, vector<int>(N_T + 10, -INF)); dp[0][0] = dp[0][1] = dp[1][0] = 0; for (int i = 0; i < N_S; ++i) { for (int j = 0; j < N_T; ++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]); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; while (N_S > 0 && N_T >> 0) { // (i, j + 1) -> (i + 1, j + 1) if (dp[N_S][N_T] == dp[N_S - 1][N_T]) --N_S; // (i + 1, j) -> (i + 1, j + 1) else if (dp[N_S][N_T] == dp[N_S][N_T - 1]) --N_T; // (i, j) -> (i + 1, j + 1) else { ans = S[N_S - 1] + ans; --N_S, --N_T; } } // cout << dp[N_S][N_T] << endl; cout << ans << endl; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; using P = pair<ll, ll>; 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; } const ll MOD = 1000000007; const int INF = 1 << 30; // const ll INF = (ll)1e18 + 1; int main() { string S; cin >> S; string T; cin >> T; int N_S = S.size(); int N_T = T.size(); vector<vector<int>> dp(N_S + 10, vector<int>(N_T + 10, 0)); dp[0][0] = dp[0][1] = dp[1][0] = 0; for (int i = 0; i < N_S; ++i) { for (int j = 0; j < N_T; ++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]); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } } string ans = ""; while (N_S > 0 && N_T > 0) { // (i, j + 1) -> (i + 1, j + 1) if (dp[N_S][N_T] == dp[N_S - 1][N_T]) --N_S; // (i + 1, j) -> (i + 1, j + 1) else if (dp[N_S][N_T] == dp[N_S][N_T - 1]) --N_T; // (i, j) -> (i + 1, j + 1) else { ans = S[N_S - 1] + ans; --N_S, --N_T; } } // cout << dp[N_S][N_T] << endl; cout << ans << endl; }
[ "call.arguments.change", "expression.operation.unary.remove", "control_flow.loop.condition.change" ]
972,857
972,856
u952081880
cpp
p03165
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); // dp[i][j] := sのi文字目, tのj文字目まで見たときの最長共通部分列(LCS) vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]); if (s[i] == t[j]) { dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]) + 1; } } } int i = n, j = m; 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; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); // dp[i][j] := sのi文字目, tのj文字目まで見たときの最長共通部分列(LCS) vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]); if (s[i] == t[j]) { dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1); } } } int i = n, j = m; 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; return 0; }
[ "call.arguments.change" ]
972,901
972,902
u813098295
cpp
p03165
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define ll long long template <class T> using v = std::vector<T>; template <class T> using vv = v<v<T>>; const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } } 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; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int dp[3005][3005]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t, res; cin >> s >> t; rep(i, s.size()) rep(j, t.size()) 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); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } int i = s.size(), j = t.size(); while (i > 0 && j > 0) { if (dp[i][j] == dp[i - 1][j]) --i; if (dp[i][j] == dp[i][j - 1]) --j; else { res = s[i - 1] + res; --i, --j; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define ll long long template <class T> using v = std::vector<T>; template <class T> using vv = v<v<T>>; const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } } 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; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int dp[3005][3005]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t, res; cin >> s >> t; rep(i, s.size()) rep(j, t.size()) 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); chmax(dp[i + 1][j + 1], dp[i + 1][j]); chmax(dp[i + 1][j + 1], dp[i][j + 1]); } int i = s.size(), j = t.size(); while (i > 0 && j > 0) { if (dp[i][j] == dp[i - 1][j]) --i; else if (dp[i][j] == dp[i][j - 1]) --j; else { res = s[i - 1] + res; --i, --j; } } cout << res << endl; return 0; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
972,903
972,904
u411751515
cpp
p03165
#include <bits/stdc++.h> #include <regex> #ifdef _DEBUG #include "debug.h" #endif #define int ll #define FOR(i, s, e) for (int i = int(s); i < int(e); ++i) #define REP(i, e) FOR(i, 0, e) #define all(v) (v).begin(), (v).end() #define mkpr make_pair #define mktp make_tuple #define tv(tp, i) get<(i)>(tp) #define CLEAR(obj) obj = decltype(obj)() #define var auto #define OUT(type) type & #define IN(type) const type & #define self (*this) #define in : #define True true #define False false using namespace std; using int32 = int32_t; using str = string; using cstr = const str; using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>; using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>; static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7; static const ll LINF = LLONG_MAX / 2; #ifdef int static const int INF = LINF; #else static const int INF = INT_MAX / 2; #endif static double EPS = 1e-9; #define FASTCIN() \ cin.tie(0); \ ios::sync_with_stdio(false); #ifdef IMPORT_SAMPLE #define DEBUG_IMPORT(file) \ vs args(argv, argv + argc); \ str sample = make_sample(args, file); \ ifstream ifs(sample); \ cin.rdbuf(ifs.rdbuf()); #else #define DEBUG_IMPORT(file) #endif static inline bool DBLEQ(double a, double b) { return abs(a - b) < EPS; } static inline void EPR(str msg) { cerr << msg << endl; } static inline void AST(bool exp, str msg) { if (!exp) { EPR(msg); } assert(exp); } static inline void TAST(bool exp, str msg) { if (!exp) { EPR(msg); } while (!exp) { } } int32 main(int32 argc, char *argv[]) { FASTCIN(); DEBUG_IMPORT("sample-2"); string S, T; cin >> S >> T; int N = S.size(), M = T.size(); // var dp = vector<vs>(N+1, vs(M+1, "")); var dp = vvi(N + 1, vi(M + 1, 0)); REP(i, N) { REP(j, M) { if (T[j] == S[i]) { dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]); } } str ans = ""; int i = N, j = M; while (0 < i and 0 < j) { if (dp[i][j] == dp[i - 1][j] + 1 and dp[i][j] == dp[i][j - 1] + 1) { ans += S[i - 1]; i -= 1; j -= 1; } else if (dp[i][j] == dp[i - 1][j]) { i -= 1; } else if (dp[i][j] == dp[i][j - 1]) { j -= 1; } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <regex> #ifdef _DEBUG #include "debug.h" #endif #define int ll #define FOR(i, s, e) for (int i = int(s); i < int(e); ++i) #define REP(i, e) FOR(i, 0, e) #define all(v) (v).begin(), (v).end() #define mkpr make_pair #define mktp make_tuple #define tv(tp, i) get<(i)>(tp) #define CLEAR(obj) obj = decltype(obj)() #define var auto #define OUT(type) type & #define IN(type) const type & #define self (*this) #define in : #define True true #define False false using namespace std; using int32 = int32_t; using str = string; using cstr = const str; using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>; using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>; using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>; static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7; static const ll LINF = LLONG_MAX / 2; #ifdef int static const int INF = LINF; #else static const int INF = INT_MAX / 2; #endif static double EPS = 1e-9; #define FASTCIN() \ cin.tie(0); \ ios::sync_with_stdio(false); #ifdef IMPORT_SAMPLE #define DEBUG_IMPORT(file) \ vs args(argv, argv + argc); \ str sample = make_sample(args, file); \ ifstream ifs(sample); \ cin.rdbuf(ifs.rdbuf()); #else #define DEBUG_IMPORT(file) #endif static inline bool DBLEQ(double a, double b) { return abs(a - b) < EPS; } static inline void EPR(str msg) { cerr << msg << endl; } static inline void AST(bool exp, str msg) { if (!exp) { EPR(msg); } assert(exp); } static inline void TAST(bool exp, str msg) { if (!exp) { EPR(msg); } while (!exp) { } } int32 main(int32 argc, char *argv[]) { FASTCIN(); DEBUG_IMPORT("sample-2"); string S, T; cin >> S >> T; int N = S.size(), M = T.size(); // var dp = vector<vs>(N+1, vs(M+1, "")); var dp = vvi(N + 1, vi(M + 1, 0)); REP(i, N) { REP(j, M) { if (T[j] == S[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][j + 1]); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]); } } str ans = ""; int i = N, j = M; while (0 < i and 0 < j) { if (dp[i][j] == dp[i - 1][j] + 1 and dp[i][j] == dp[i][j - 1] + 1) { ans += S[i - 1]; i -= 1; j -= 1; } else if (dp[i][j] == dp[i - 1][j]) { i -= 1; } else if (dp[i][j] == dp[i][j - 1]) { j -= 1; } } reverse(ans.begin(), ans.end()); cout << ans << endl; return 0; }
[ "assignment.change" ]
972,909
972,910
u404244809
cpp
p03165
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1)); dp.at(0).at(0) = 0; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < t.size(); j++) { dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i).at(j + 1)); dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i + 1).at(j)); if (s.at(i) == t.at(j)) { // cout << i+1 << " " << j+1 << " " << dp.at(i+1).at(j+1) << endl; dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i).at(j) + 1); } } } // cout << dp.at(s.size()).at(t.size()) << endl; string ans = ""; int i = s.size(), j = t.size(); while (i > 0 && j > 0) { if (dp.at(i).at(j) == dp.at(i - 1).at(j)) { i--; } else if (dp.at(i).at(j) == dp.at(i).at(j - 1)) { j--; } else { ans += s.at(i - 1); i--; j--; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1)); dp.at(0).at(0) = 0; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < t.size(); j++) { dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i).at(j + 1)); dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i + 1).at(j)); if (s.at(i) == t.at(j)) { // cout << i+1 << " " << j+1 << " " << dp.at(i+1).at(j+1) << endl; dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i).at(j) + 1); } } } // cout << dp.at(s.size()).at(t.size()) << endl; string ans = ""; int i = s.size(), j = t.size(); while (i > 0 && j > 0) { if (dp.at(i).at(j) == dp.at(i - 1).at(j)) { i--; } else if (dp.at(i).at(j) == dp.at(i).at(j - 1)) { j--; } else { ans = s.at(i - 1) + ans; i--; j--; } } cout << ans << endl; }
[ "assignment.value.change", "assignment.change" ]
972,944
972,945
u718758485
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 + 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 > 0 && cy > 0) { 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; } } // string ans = ""; // 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{ // i--; j--; // ans = s[i] + ans; // } // } // cout << ans << endl; // // 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; }
[ "expression.operation.binary.remove", "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
972,979
972,980
u616547520
cpp