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
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, k, n) for (int i = (k); i < (n); ++i) int main() { int N; cin >> N; vector<ll> a(N); REP(i, N) cin >> a[i]; vector<vector<ll>> dp(N, vector<ll>(N, 0LL)); if (N % 2 == 0) { REP(i, N) dp[i][0] = -a[i]; FOR(j, 1, N) FOR(i, 0, N) { if (i + j >= N) continue; else { if ((j + 1) % 2 == 0) { dp[i][j] = max(a[i] + dp[i + 1][j - 1], a[i + j] + dp[i][j - 1]); } else { dp[i][j] = min(-a[i] + dp[i + 1][j - 1], -a[i + j] + dp[i][j - 1]); } } } } if (N % 2 == 1) { REP(i, N) dp[i][i] = a[i]; FOR(j, 1, N) FOR(i, 0, N) { if (i + j >= N) continue; else { if ((j + 1) % 2 == 0) { dp[i][j] = min(-a[i] + dp[i + 1][j - 1], -a[i + j] + dp[i][j - 1]); } else { dp[i][j] = max(a[i] + dp[i + 1][j - 1], a[i + j] + dp[i][j - 1]); } } } } cout << dp[0][N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, k, n) for (int i = (k); i < (n); ++i) int main() { int N; cin >> N; vector<ll> a(N); REP(i, N) cin >> a[i]; vector<vector<ll>> dp(N, vector<ll>(N, 0LL)); if (N % 2 == 0) { REP(i, N) dp[i][0] = -a[i]; FOR(j, 1, N) FOR(i, 0, N) { if (i + j >= N) continue; else { if ((j + 1) % 2 == 0) { dp[i][j] = max(a[i] + dp[i + 1][j - 1], a[i + j] + dp[i][j - 1]); } else { dp[i][j] = min(-a[i] + dp[i + 1][j - 1], -a[i + j] + dp[i][j - 1]); } } } } if (N % 2 == 1) { REP(i, N) dp[i][0] = a[i]; FOR(j, 1, N) FOR(i, 0, N) { if (i + j >= N) continue; else { if ((j + 1) % 2 == 0) { dp[i][j] = min(-a[i] + dp[i + 1][j - 1], -a[i + j] + dp[i][j - 1]); } else { dp[i][j] = max(a[i] + dp[i + 1][j - 1], a[i + j] + dp[i][j - 1]); } } } } cout << dp[0][N - 1] << endl; return 0; }
[ "assignment.variable.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change" ]
979,867
979,868
u434282696
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define vi vector<ll> #define all(a) (a).begin(), (a).end() #define rep(i, a, b) for (ll i = a; i < b; i++) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define pb push_back #define endl "\n" const ll MAX = 4e3 + 3; const ll mod = 1e2 + 7; vi a(MAX); ll dp[MAX][MAX]; /* ll fun(ll i,ll j) { if(i>j) return 0; if(dp[i][j]!=-1) return dp[i][j]; ll x,y; x=a[i]+min(fun(i+2,j),fun(i+1,j-1)); y=a[j]+min(fun(i+1,j-1),fun(i,j-2)); dp[i][j]=max(x,y); return dp[i][j]; } */ ll fun(ll n) { memset(dp, 0, sizeof(dp)); for (ll i = 0; i < n; i++) { dp[i][i] = a[i]; } ll x, y, z, j; for (ll len = 2; len <= n; len++) { for (ll i = 0; i < n - len; i++) { j = i + len - 1; x = i + 2 <= j ? dp[i + 2][j] : 0; y = i + 1 <= j - 1 ? dp[i + 1][j - 1] : 0; z = i <= j - 2 ? dp[i][j - 2] : 0; dp[i][j] = max(a[i] + min(x, y), a[j] + min(y, z)); } } return dp[0][n - 1]; } int main() { FASTIO int t = 1; // cin>>t; while (t--) { ll n, c; cin >> n; ll sum = 0; rep(i, 0, n) { cin >> a[i]; sum += a[i]; } memset(dp, -1, sizeof(dp)); ll ans = fun(n); ans = 2 * ans - sum; cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define ll long long #define vi vector<ll> #define all(a) (a).begin(), (a).end() #define rep(i, a, b) for (ll i = a; i < b; i++) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define pb push_back #define endl "\n" const ll MAX = 4e3 + 3; const ll mod = 1e2 + 7; vi a(MAX); ll dp[MAX][MAX]; /* ll fun(ll i,ll j) { if(i>j) return 0; if(dp[i][j]!=-1) return dp[i][j]; ll x,y; x=a[i]+min(fun(i+2,j),fun(i+1,j-1)); y=a[j]+min(fun(i+1,j-1),fun(i,j-2)); dp[i][j]=max(x,y); return dp[i][j]; } */ ll fun(ll n) { memset(dp, 0, sizeof(dp)); for (ll i = 0; i < n; i++) { dp[i][i] = a[i]; } ll x, y, z, j; for (ll len = 2; len <= n; len++) { for (ll i = 0; i <= n - len; i++) { j = i + len - 1; x = i + 2 <= j ? dp[i + 2][j] : 0; y = i + 1 <= j - 1 ? dp[i + 1][j - 1] : 0; z = i <= j - 2 ? dp[i][j - 2] : 0; dp[i][j] = max(a[i] + min(x, y), a[j] + min(y, z)); } } return dp[0][n - 1]; } int main() { FASTIO int t = 1; // cin>>t; while (t--) { ll n, c; cin >> n; ll sum = 0; rep(i, 0, n) { cin >> a[i]; sum += a[i]; } memset(dp, -1, sizeof(dp)); ll ans = fun(n); ans = 2 * ans - sum; cout << ans; } return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
979,871
979,872
u029634979
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 3005; int a[maxn], dp[maxn][maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int l = n - 1; l >= 0; l--) { for (int r = l; r < n; r++) { if (r == l) dp[l][r] = a[l]; else dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]); } } cout << dp[0][n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 3005; ll a[maxn], dp[maxn][maxn]; int main() { ll n; cin >> n; for (ll i = 0; i < n; i++) cin >> a[i]; for (ll l = n - 1; l >= 0; l--) { for (ll r = l; r < n; r++) { if (r == l) dp[l][r] = a[l]; else dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]); } } cout << dp[0][n - 1] << endl; return 0; }
[ "variable_declaration.type.change", "control_flow.loop.for.initializer.change" ]
979,877
979,878
u943208163
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /* attention long longのシフト演算には気をつけよう タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも sizeは(int)とキャストしよう ごちゃごちゃ場合分けを考える前に全探索は考えましたか? 詰まった時に、別の分野の問題として考え直す(これdpでは?、グラフとしてみればいいのでは?) 多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか */ const ll mod = 1e9 + 7; void chmod(ll &M) { if (M >= mod) M %= mod; else if (M < 0) { M += (abs(M) / mod + 1) * mod; M %= mod; } } ll modpow(ll x, ll n) { if (n == 0) return 1; ll res = modpow(x, n / 2); if (n % 2 == 0) return res * res % mod; else return res * res % mod * x % mod; } ll power(ll x, ll n) { if (n == 0) return 1; ll res = power(x, n / 2); if (n % 2 == 0) return res * res; else return res * res * x; } int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; }; int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; }; /* <--------------------------------------------> */ typedef tuple<ll, ll, ll> T; int n; vector<vector<ll>> memo(3030, vector<ll>(3030, 0)); vector<ll> a(3030, 0); vector<vector<bool>> flg(3030, vector<bool>(3030, false)); ll rec(int l, int r) { if (flg[l][r]) return memo[l][r]; flg[l][r] = true; if (l == r) return memo[l][r] = a[l]; return memo[l][r] = min(a[l] - rec(l + 1, r), a[r] - rec(l, r - 1)); } int main() { cin.tie(0); ios::sync_with_stdio(false); // 条件はどちらも「(自分の点数)ー(相手の点数)」最大化しようとする // 前から取るのがいいのか、後ろから取るのがいいのかは、残った数を使ってゲームの結果が分かれば判断できる // dp[i][j] := // 区間[i,j]が残ってる時の、「次の手番の人の得点ーそうじゃない人の特点」 cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << rec(1, n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /* attention long longのシフト演算には気をつけよう タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも sizeは(int)とキャストしよう ごちゃごちゃ場合分けを考える前に全探索は考えましたか? 詰まった時に、別の分野の問題として考え直す(これdpでは?、グラフとしてみればいいのでは?) 多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか */ const ll mod = 1e9 + 7; void chmod(ll &M) { if (M >= mod) M %= mod; else if (M < 0) { M += (abs(M) / mod + 1) * mod; M %= mod; } } ll modpow(ll x, ll n) { if (n == 0) return 1; ll res = modpow(x, n / 2); if (n % 2 == 0) return res * res % mod; else return res * res % mod * x % mod; } ll power(ll x, ll n) { if (n == 0) return 1; ll res = power(x, n / 2); if (n % 2 == 0) return res * res; else return res * res * x; } int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; }; int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; }; /* <--------------------------------------------> */ typedef tuple<ll, ll, ll> T; int n; vector<vector<ll>> memo(3030, vector<ll>(3030, 0)); vector<ll> a(3030, 0); vector<vector<bool>> flg(3030, vector<bool>(3030, false)); ll rec(int l, int r) { if (flg[l][r]) return memo[l][r]; flg[l][r] = true; if (l == r) return memo[l][r] = a[l]; return memo[l][r] = max(a[l] - rec(l + 1, r), a[r] - rec(l, r - 1)); } int main() { cin.tie(0); ios::sync_with_stdio(false); // 条件はどちらも「(自分の点数)ー(相手の点数)」最大化しようとする // 前から取るのがいいのか、後ろから取るのがいいのかは、残った数を使ってゲームの結果が分かれば判断できる // dp[i][j] := // 区間[i,j]が残ってる時の、「次の手番の人の得点ーそうじゃない人の特点」 cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << rec(1, n) << endl; return 0; }
[ "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change", "function.return_value.change" ]
979,883
979,884
u052332717
cpp
p03169
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); int N; cin >> N; static int c[3]; for (int i = 0, t; i < N; ++i) { cin >> t; ++c[t - 1]; } static float dp[301][601][901]; /*function<double(int, int, int)> dfs = [&](int a, int b, int c) { if (a + b + c == 0) return 0.0; if (vis[a][b][c]) return dp[a][b][c]; vis[a][b][c] = 1; if (a) dp[a][b][c] += (dfs(a - 1, b + 1, c) + 1) * a / N; if (b) dp[a][b][c] += (dfs(a, b - 1, c + 1) + 1) * b / N; if (c) dp[a][b][c] += (dfs(a, b, c - 1) + 1) * c / N; int d = N - a - b - c; // if (d) dp[a][b][c] += (dfs(a, b, c) + 1) * d / N; return dp[a][b][c] = (dp[a][b][c] + 1.0 * d / N) * N / (N - d); };*/ for (int i = 0; i < c[2] + 1; ++i) { for (int j = 0; j < c[1] + c[2] + 1; ++j) { for (int k = 0; k < c[0] + c[1] + c[2] + 1; ++k) { if (i + j + k == 0) continue; if (i) dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * i / N; if (j) dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * j / N; if (k) dp[i][j][k] += (dp[i][j][k - 1] + 1) * k / N; int l = N - i - j - k; dp[i][j][k] = (dp[i][j][k] + 1.0 * l / N) * N / (N - l); } } } cout << fixed << setprecision(9) << dp[c[2]][c[1]][c[0]] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); int N; cin >> N; static int c[3]; for (int i = 0, t; i < N; ++i) { cin >> t; ++c[t - 1]; } static double dp[301][301][301]; /*function<double(int, int, int)> dfs = [&](int a, int b, int c) { if (a + b + c == 0) return 0.0; if (vis[a][b][c]) return dp[a][b][c]; vis[a][b][c] = 1; if (a) dp[a][b][c] += (dfs(a - 1, b + 1, c) + 1) * a / N; if (b) dp[a][b][c] += (dfs(a, b - 1, c + 1) + 1) * b / N; if (c) dp[a][b][c] += (dfs(a, b, c - 1) + 1) * c / N; int d = N - a - b - c; // if (d) dp[a][b][c] += (dfs(a, b, c) + 1) * d / N; return dp[a][b][c] = (dp[a][b][c] + 1.0 * d / N) * N / (N - d); };*/ for (int i = 0; i < c[2] + 1; ++i) { for (int j = 0; j < c[1] + c[2] + 1; ++j) { for (int k = 0; k < c[0] + c[1] + c[2] + 1; ++k) { if (i + j + k == 0) continue; if (i) dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * i / N; if (j) dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * j / N; if (k) dp[i][j][k] += (dp[i][j][k - 1] + 1) * k / N; int l = N - i - j - k; dp[i][j][k] = (dp[i][j][k] + 1.0 * l / N) * N / (N - l); } } } cout << fixed << setprecision(9) << dp[c[2]][c[1]][c[0]] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
979,888
979,889
u209551477
cpp
p03169
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); int N; cin >> N; static int c[3]; for (int i = 0, t; i < N; ++i) { cin >> t; ++c[t - 1]; } static double dp[301][601][901]; /*function<double(int, int, int)> dfs = [&](int a, int b, int c) { if (a + b + c == 0) return 0.0; if (vis[a][b][c]) return dp[a][b][c]; vis[a][b][c] = 1; if (a) dp[a][b][c] += (dfs(a - 1, b + 1, c) + 1) * a / N; if (b) dp[a][b][c] += (dfs(a, b - 1, c + 1) + 1) * b / N; if (c) dp[a][b][c] += (dfs(a, b, c - 1) + 1) * c / N; int d = N - a - b - c; // if (d) dp[a][b][c] += (dfs(a, b, c) + 1) * d / N; return dp[a][b][c] = (dp[a][b][c] + 1.0 * d / N) * N / (N - d); };*/ for (int i = 0; i < c[2] + 1; ++i) { for (int j = 0; j < c[1] + c[2] + 1; ++j) { for (int k = 0; k < c[0] + c[1] + c[2] + 1; ++k) { if (i + j + k == 0) continue; if (i) dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * i / N; if (j) dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * j / N; if (k) dp[i][j][k] += (dp[i][j][k - 1] + 1) * k / N; int l = N - i - j - k; dp[i][j][k] = (dp[i][j][k] + 1.0 * l / N) * N / (N - l); } } } cout << fixed << setprecision(9) << dp[c[2]][c[1]][c[0]] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); int N; cin >> N; static int c[3]; for (int i = 0, t; i < N; ++i) { cin >> t; ++c[t - 1]; } static double dp[301][301][301]; /*function<double(int, int, int)> dfs = [&](int a, int b, int c) { if (a + b + c == 0) return 0.0; if (vis[a][b][c]) return dp[a][b][c]; vis[a][b][c] = 1; if (a) dp[a][b][c] += (dfs(a - 1, b + 1, c) + 1) * a / N; if (b) dp[a][b][c] += (dfs(a, b - 1, c + 1) + 1) * b / N; if (c) dp[a][b][c] += (dfs(a, b, c - 1) + 1) * c / N; int d = N - a - b - c; // if (d) dp[a][b][c] += (dfs(a, b, c) + 1) * d / N; return dp[a][b][c] = (dp[a][b][c] + 1.0 * d / N) * N / (N - d); };*/ for (int i = 0; i < c[2] + 1; ++i) { for (int j = 0; j < c[1] + c[2] + 1; ++j) { for (int k = 0; k < c[0] + c[1] + c[2] + 1; ++k) { if (i + j + k == 0) continue; if (i) dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * i / N; if (j) dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * j / N; if (k) dp[i][j][k] += (dp[i][j][k - 1] + 1) * k / N; int l = N - i - j - k; dp[i][j][k] = (dp[i][j][k] + 1.0 * l / N) * N / (N - l); } } } cout << fixed << setprecision(9) << dp[c[2]][c[1]][c[0]] << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
979,890
979,889
u209551477
cpp
p03169
#include <bits/stdc++.h> #define MAXN 310 #define pii pair<int, int> #define pb push_back typedef long long ll; using namespace std; int n, f[4]; double dp[MAXN][MAXN][MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; f[t]++; } for (int k = 0; k < MAXN; k++) { for (int j = 0; j < MAXN; j++) { for (int i = 0; i < MAXN; i++) { if (i == 0 and j == 0 and k == 0) { dp[i][j][k] = 0; continue; } double t = 0; if (i > 0) t += (double)i * dp[i - 1][j][k] / n; if (j > 0) t += (double)j * dp[i + 1][j - 1][k] / n; if (k > 0) t += (double)k * dp[i][j + 1][k - 1] / n; t++; t /= (double)(i + j + k) / n; // cout << t; dp[i][j][k] = t; } } } cout << fixed << setprecision(11) << dp[f[1]][f[2]][f[3]]; }
#include <bits/stdc++.h> #define MAXN 310 #define pii pair<int, int> #define pb push_back typedef long long ll; using namespace std; int n, f[4]; double dp[MAXN][MAXN][MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { int t; cin >> t; f[t]++; } for (int k = 0; k < MAXN - 1; k++) { for (int j = 0; j < MAXN - 1; j++) { for (int i = 0; i < MAXN - 1; i++) { if (i == 0 and j == 0 and k == 0) { dp[i][j][k] = 0; continue; } double t = 0; if (i > 0) t += (double)i * dp[i - 1][j][k] / n; if (j > 0) t += (double)j * dp[i + 1][j - 1][k] / n; if (k > 0) t += (double)k * dp[i][j + 1][k - 1] / n; t++; t /= (double)(i + j + k) / n; // cout << t; dp[i][j][k] = t; } } } cout << fixed << setprecision(11) << dp[f[1]][f[2]][f[3]]; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
979,895
979,896
u190314045
cpp
p03169
#include "bits/stdc++.h" using namespace std; // typedef pair<int, int> P; #define int long long #define ll long long #define mod 1000000007 #define INF (1LL << 60) int N, c[4]; double dp[301][301][301]; double solve(int c1, int c2, int c3) { if (c1 == 0 && c2 == 0 && c3 == 0) return 0.0; if (dp[c1][c2][c3] >= 0.0) return dp[c1][c2][c3]; double ans = 0.0; if (c1 > 0) ans += (double)c1 / N * solve(c1 - 1, c2, c3); if (c2 > 0) ans += (double)c2 / N * solve(c1 + 1, c2 - 1, c3); if (c3 > 0) ans += (double)c3 / N * solve(c1, c2 + 1, c3 - 1); dp[c1][c2][c3] = (double)N / (c1 + c2 + c3) * (ans + 1.0); return dp[c1][c2][c3]; } signed main() { cin >> N; for (int i = 0; i < N; i++) { int t; cin >> t; c[t]++; } cout << fixed << setprecision(15) << solve(c[1], c[2], c[3]) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; // typedef pair<int, int> P; #define int long long #define ll long long #define mod 1000000007 #define INF (1LL << 60) int N, c[4]; double dp[301][301][301]; double solve(int c1, int c2, int c3) { if (c1 == 0 && c2 == 0 && c3 == 0) return 0.0; if (dp[c1][c2][c3] > 0.0) return dp[c1][c2][c3]; double ans = 0.0; if (c1 > 0) ans += (double)c1 / N * solve(c1 - 1, c2, c3); if (c2 > 0) ans += (double)c2 / N * solve(c1 + 1, c2 - 1, c3); if (c3 > 0) ans += (double)c3 / N * solve(c1, c2 + 1, c3 - 1); dp[c1][c2][c3] = (double)N / (c1 + c2 + c3) * (ans + 1.0); return dp[c1][c2][c3]; } signed main() { cin >> N; for (int i = 0; i < N; i++) { int t; cin >> t; c[t]++; } cout << setprecision(15) << solve(c[1], c[2], c[3]) << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove" ]
979,914
979,915
u592610268
cpp
p03169
#include <bits/stdc++.h> const int MN = 304; int N, A[4]; double dp[MN][MN][MN]; double solve(int s1, int s2, int s3) { if (!s1 && !s2 && !s3) return 0; if (dp[s1][s2][s3] >= 0.0) return dp[s1][s2][s3]; double ret = 1.0; if (s1) ret += solve(s1 - 1, s2, s3) * s1 / N; if (s2) ret += solve(s1 + 1, s2 - 1, s3) * s2 / N; if (s3) ret += solve(s1, s2 + 1, s3 - 1) * s3 / N; ret *= N / (s1 + s2 + s3); return dp[s1][s2][s3] = ret; } int main() { scanf("%d", &N); for (int i = 0, a; i < N; ++i) { scanf("%d", &a); A[a]++; } for (int i = 0; i < MN; ++i) for (int j = 0; j < MN; ++j) for (int k = 0; k < MN; ++k) dp[i][j][k] = -1.0; printf("%lf\n", solve(A[1], A[2], A[3])); }
#include <bits/stdc++.h> const int MN = 304; int N, A[4]; double dp[MN][MN][MN]; double solve(int s1, int s2, int s3) { if (!s1 && !s2 && !s3) return 0; if (dp[s1][s2][s3] >= 0.0) return dp[s1][s2][s3]; double ret = 1.0; if (s1) ret += solve(s1 - 1, s2, s3) * s1 / N; if (s2) ret += solve(s1 + 1, s2 - 1, s3) * s2 / N; if (s3) ret += solve(s1, s2 + 1, s3 - 1) * s3 / N; ret *= 1.0 * N / (s1 + s2 + s3); return dp[s1][s2][s3] = ret; } int main() { scanf("%d", &N); for (int i = 0, a; i < N; ++i) { scanf("%d", &a); A[a]++; } for (int i = 0; i < MN; ++i) for (int j = 0; j < MN; ++j) for (int k = 0; k < MN; ++k) dp[i][j][k] = -1.0; printf("%.9lf\n", solve(A[1], A[2], A[3])); }
[ "assignment.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
979,922
979,921
u596743351
cpp
p03169
#include <bits/stdc++.h> using namespace std; const int N = 3e2 + 5; double f[N][N][N]; int main() { int n; cin >> n; auto h = vector<int>(3, 0); for (int i = 1; i <= n; i++) { int x; cin >> x; h[x - 1]++; } for (int u3 = 0; u3 <= n; u3++) for (int u2 = 0; u2 <= n; u2++) for (int u1 = 0; u1 <= n; u1++) if (u1 + u2 + u3 <= n) { if (u1 == 0 && u2 == 0 && u3 == 0) continue; int u0 = n - u1 - u2 - u3; f[u1][u2][u3] = 1; if (u1) f[u1][u2][u3] += u1 * f[u1 - 1][u2][u3]; if (u2) f[u1][u2][u3] += u2 * f[u1 + 1][u2 - 1][u3]; if (u3) f[u1][u2][u3] += u3 * f[u1][u2 + 1][u3 - 1]; f[u1][u2][u3] /= n - u0; } cout << fixed << setprecision(12) << f[h[0]][h[1]][h[2]]; }
#include <bits/stdc++.h> using namespace std; const int N = 3e2 + 5; double f[N][N][N]; int main() { int n; cin >> n; auto h = vector<int>(3, 0); for (int i = 1; i <= n; i++) { int x; cin >> x; h[x - 1]++; } for (int u3 = 0; u3 <= n; u3++) for (int u2 = 0; u2 <= n; u2++) for (int u1 = 0; u1 <= n; u1++) if (u1 + u2 + u3 <= n) { if (u1 == 0 && u2 == 0 && u3 == 0) continue; int u0 = n - u1 - u2 - u3; f[u1][u2][u3] = n; if (u1) f[u1][u2][u3] += u1 * f[u1 - 1][u2][u3]; if (u2) f[u1][u2][u3] += u2 * f[u1 + 1][u2 - 1][u3]; if (u3) f[u1][u2][u3] += u3 * f[u1][u2 + 1][u3 - 1]; f[u1][u2][u3] /= n - u0; } cout << fixed << setprecision(12) << f[h[0]][h[1]][h[2]]; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
979,940
979,941
u596976719
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define print printf("==================\n") #define ll long long #define pi acos(-1.0) #define eps 1e-16 #define max3(a, b, c) max(a, max(b, c)) const ll INF = 1 << 30; #define mod 1000000007 typedef pair<double, double> payar; typedef struct { ll x, y; } point; priority_queue<payar, vector<payar>, greater<payar>> pq; /// accending vector<pair<double, payar>> vpp; vector<payar> vp; int n, k; ll ara[100005]; ll dp[3001][3001][3]; int rec(int i, int j, int player = 1) { if (i > j) return 0; if (i > n) return 0; if (j < 1) return 0; ll maxi = -1; ll maxi2 = -1; if (dp[i][j][player] != -1) return dp[i][j][player]; ll &ans = dp[i][j][player]; if (player == 1) ans = max(ara[i] + rec(i + 1, j, 2), ara[j] + rec(i, j - 1, 2)); if (player == 2) ans = min(-ara[j] + rec(i, j - 1, 1), -ara[i] + rec(i + 1, j, 1)); return ans; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> ara[i]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { dp[i][j][0] = -1; dp[i][j][1] = -1; dp[i][j][2] = -1; } } cout << rec(1, n, 1); return 0; }
#include <bits/stdc++.h> using namespace std; #define print printf("==================\n") #define ll long long #define pi acos(-1.0) #define eps 1e-16 #define max3(a, b, c) max(a, max(b, c)) const ll INF = 1 << 30; #define mod 1000000007 typedef pair<double, double> payar; typedef struct { ll x, y; } point; priority_queue<payar, vector<payar>, greater<payar>> pq; /// accending vector<pair<double, payar>> vpp; vector<payar> vp; int n, k; ll ara[100005]; ll dp[3001][3001][3]; ll rec(int i, int j, int player = 1) { if (i > j) return 0; if (i > n) return 0; if (j < 1) return 0; ll maxi = -1; ll maxi2 = -1; if (dp[i][j][player] != -1) return dp[i][j][player]; ll &ans = dp[i][j][player]; if (player == 1) ans = max(ara[i] + rec(i + 1, j, 2), ara[j] + rec(i, j - 1, 2)); if (player == 2) ans = min(-ara[j] + rec(i, j - 1, 1), -ara[i] + rec(i + 1, j, 1)); return ans; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> ara[i]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { dp[i][j][0] = -1; dp[i][j][1] = -1; dp[i][j][2] = -1; } } cout << rec(1, n, 1); return 0; }
[]
979,951
979,952
u826108161
cpp
p03171
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 15; const int MOD = 1e9 + 7; const long long INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", "r", stdin); int n; cin >> n; deque<long long> q; for (int i = 0; i < n; ++i) { int x; cin >> x; q.push_back(x); while (q.size() > 2 && (q.back() <= q[q.size() - 2] && q[q.size() - 2] >= q[q.size() - 3])) { int a = q.back() - q[q.size() - 2] + q[q.size() - 3]; q.pop_back(); q.pop_back(); q.pop_back(); q.push_back(a); } } long long p = 0; int i = 1; while (!q.empty()) { if (q.front() >= q.back()) { p += i * q.front(); q.pop_front(); } else { p += i * q.back(); q.pop_back(); } i = -i; } cout << p << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int MaxN = 1e5 + 15; const int MOD = 1e9 + 7; const long long INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", "r", stdin); int n; cin >> n; deque<long long> q; for (int i = 0; i < n; ++i) { int x; cin >> x; q.push_back(x); while (q.size() > 2 && (q.back() <= q[q.size() - 2] && q[q.size() - 2] >= q[q.size() - 3])) { long long a = q.back() - q[q.size() - 2] + q[q.size() - 3]; q.pop_back(); q.pop_back(); q.pop_back(); q.push_back(a); } } long long p = 0; int i = 1; while (!q.empty()) { if (q.front() >= q.back()) { p += i * q.front(); q.pop_front(); } else { p += i * q.back(); q.pop_back(); } i = -i; } cout << p << '\n'; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
979,960
979,961
u784576081
cpp
p03171
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int vals[N]; for (int i = 0; i < N; ++i) { cin >> vals[i]; } int DP[N][N]; // DP[i][j] = X-Y if vals[i..j] remains. for (int i = 0; i < N; ++i) { DP[i][i] = vals[i]; } /* Transitions depending on i + j % 2 if 1st guys turn DP[i][j] = max(DP[i - 1][j] + X[i], DP[i][j - 1] + X[j]) else DP[i][j] = min(DP[i - 1][j] + X[i], DP[i][j - 1] + X[j]) */ for (int L = N - 1; L >= 0; --L) { for (int R = L + 1; R < N; ++R) { DP[L][R] = max(vals[L] - DP[L + 1][R], vals[R] - DP[L][R - 1]); } } cout << DP[0][N - 1] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int vals[N]; for (int i = 0; i < N; ++i) { cin >> vals[i]; } long long DP[N][N]; // DP[i][j] = X-Y if vals[i..j] remains. for (int i = 0; i < N; ++i) { DP[i][i] = vals[i]; } /* Transitions depending on i + j % 2 if 1st guys turn DP[i][j] = max(DP[i - 1][j] + X[i], DP[i][j - 1] + X[j]) else DP[i][j] = min(DP[i - 1][j] + X[i], DP[i][j - 1] + X[j]) */ for (int L = N - 1; L >= 0; --L) { for (int R = L + 1; R < N; ++R) { DP[L][R] = max(vals[L] - DP[L + 1][R], vals[R] - DP[L][R - 1]); } } cout << DP[0][N - 1] << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
979,962
979,963
u702346849
cpp
p03171
#include <bits/stdc++.h> using namespace std; long long f[3001][3001]; int a[3001]; int main() { int i, j, n; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); if (n % 2 == 0) f[i][i] = a[i]; else f[i][i] = -a[i]; } for (j = 1; j < n; j++) { for (i = 1; i + j <= n; i++) { if (j % 2 == n % 2) { f[i][i + j] = min(f[i + 1][i + j] - a[i], f[i][i + j - 1] - a[i + j]); } else if (j % 2 != n % 2) { f[i][i + j] = max(a[i] + f[i + 1][j + i], f[i][i + j - 1] + a[i + j]); } } } printf("%lld", f[1][n]); return 0; }
#include <bits/stdc++.h> using namespace std; long long f[3001][3001]; int a[3001]; int main() { int i, j, n; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); if (n % 2 == 0) f[i][i] = -a[i]; else f[i][i] = a[i]; } for (j = 1; j < n; j++) { for (i = 1; i + j <= n; i++) { if (j % 2 == n % 2) { f[i][i + j] = min(f[i + 1][i + j] - a[i], f[i][i + j - 1] - a[i + j]); } else if (j % 2 != n % 2) { f[i][i + j] = max(a[i] + f[i + 1][j + i], f[i][i + j - 1] + a[i + j]); } } } printf("%lld", f[1][n]); return 0; }
[ "control_flow.branch.else.remove", "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add", "assignment.add" ]
979,966
979,967
u356929542
cpp
p03171
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> //#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; const ll INF = (1 << 30); const ll inf = (1LL << 50LL); const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; int n; int arr[maxn]; ll dp[3005][3005][2]; ll rek(int levo, int desno, int turn) { if (levo >= desno) { if (turn == 0) { return arr[levo]; } return 0; } if (dp[levo][desno][turn] != -1) { return dp[levo][desno][turn]; } ll ret; if (turn == 0) { ret = 0; ret = max(ret, rek(levo + 1, desno, 1 ^ turn) + arr[levo]); ret = max(ret, rek(levo, desno - 1, 1 ^ turn) + arr[desno]); } else { ret = inf; ret = min(ret, rek(levo + 1, desno, 1 ^ turn)); ret = min(ret, rek(levo, desno - 1, 1 ^ turn)); } return dp[levo][desno][turn] = ret; } int main(int argc, const char *argv[]) { ios_base::sync_with_stdio(false); // ifstream cin("in.txt"); cin >> n; ll sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } memset(dp, -1, sizeof dp); ll A = rek(0, n - 1, 0); ll B = sum - A; cout << (A - B) << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> //#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = (1 << 30); const ll inf = (1LL << 50LL); const int maxn = 1e5 + 5; const int MOD = 1e9 + 7; int n; ll arr[maxn]; ll dp[3005][3005][3]; ll rek(int levo, int desno, int turn) { if (levo >= desno) { if (turn == 0) { return arr[levo]; } return 0; } if (dp[levo][desno][turn] != -1) { return dp[levo][desno][turn]; } ll ret; if (turn == 0) { ret = 0; ret = max(ret, rek(levo + 1, desno, 1 ^ turn) + arr[levo]); ret = max(ret, rek(levo, desno - 1, 1 ^ turn) + arr[desno]); } else { ret = inf; ret = min(ret, rek(levo + 1, desno, 1 ^ turn)); ret = min(ret, rek(levo, desno - 1, 1 ^ turn)); } return dp[levo][desno][turn] = ret; } int main(int argc, const char *argv[]) { ios_base::sync_with_stdio(false); cin >> n; ll sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } memset(dp, -1, sizeof dp); ll A = rek(0, n - 1, 0); ll B = sum - A; cout << A - B << endl; return 0; }
[ "variable_declaration.type.narrow.change", "variable_declaration.type.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
979,968
979,969
u694083533
cpp
p03171
#include <algorithm> #include <cstdio> using namespace std; #define i64 long long int #define ran 3033 int n; int a[ran]; i64 f[ran][ran]; bool visd[ran][ran]; i64 dp(int l, int r) { if (l > r || visd[l][r]) return f[l][r]; i64 t = 0; if ((r - l) % 2 == (n - 1) % 2) t = max(dp(l + 1, r) + a[l], dp(l, r - 1) + a[r]); else t = min(dp(l + 1, r) - a[l], dp(l, r - 1) - a[r]); visd[l][r] = true; f[l][r] = t; return t; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); printf("%I64d\n", dp(1, n)); return 0; }
#include <algorithm> #include <cstdio> using namespace std; #define i64 long long int #define ran 3033 int n; int a[ran]; i64 f[ran][ran]; bool visd[ran][ran]; i64 dp(int l, int r) { if (l > r || visd[l][r]) return f[l][r]; i64 t = 0; if ((r - l) % 2 == (n - 1) % 2) t = max(dp(l + 1, r) + a[l], dp(l, r - 1) + a[r]); else t = min(dp(l + 1, r) - a[l], dp(l, r - 1) - a[r]); visd[l][r] = true; f[l][r] = t; return t; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); printf("%lld\n", dp(1, n)); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
979,970
979,971
u534772498
cpp
p03171
// In the Name of Allah. Ya Ali! #include <bits/stdc++.h> typedef long long ll; const ll MAX_N = 3000 + 5; const ll MOD = 1e9 + 7; using namespace std; int dp[MAX_N][MAX_N][2]; int a[MAX_N]; int n; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) dp[1][i][0] = a[i], dp[1][i][1] = -a[i]; for (int i = 2; i <= n; ++i) { for (int j = 1; j <= n - i + 1; ++j) { dp[i][j][0] = max(a[j] + dp[i - 1][j + 1][1], a[i + j - 1] + dp[i - 1][j][1]); dp[i][j][1] = min(dp[i - 1][j + 1][0] - a[j], dp[i - 1][j][0] - a[i + j - 1]); } } cout << dp[n][1][0]; return 0; }
// In the Name of Allah. Ya Ali! #include <bits/stdc++.h> typedef long long ll; const ll MAX_N = 3000 + 5; const ll MOD = 1e9 + 7; using namespace std; ll dp[MAX_N][MAX_N][2]; ll a[MAX_N]; int n; int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) dp[1][i][0] = a[i], dp[1][i][1] = -a[i]; for (int i = 2; i <= n; ++i) { for (int j = 1; j <= n - i + 1; ++j) { dp[i][j][0] = max(a[j] + dp[i - 1][j + 1][1], a[i + j - 1] + dp[i - 1][j][1]); dp[i][j][1] = min(dp[i - 1][j + 1][0] - a[j], dp[i - 1][j][0] - a[i + j - 1]); } } cout << dp[n][1][0]; return 0; }
[ "variable_declaration.type.change" ]
979,972
979,973
u509226403
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; #define forup(i, a, b) for (int i = (a); i < (b); ++i) #define fordn(i, a, b) for (int i = (a); i > (b); --i) #define rep(i, a) for (int i = 0; i < (a); ++i) #define gi(x) scanf("%d", &x) #define gl(x) cin >> x #define gd(x) scanf("%lf", &x) #define gs(x) scanf(" %s", x) #define D(x) cout << #x << " : " << x << endl #define fs first #define sc second #define pb push_back #define mp make_pair const int inf = numeric_limits<int>::max(); const LL linf = numeric_limits<LL>::max(); const int max_n = 3010; LL n, dp[max_n][max_n], a[max_n]; bool s[max_n][max_n]; LL f(int l, int r) { if (r < 0 || l >= n) return 0; if (s[l][r]) return dp[l][r]; s[l][r] = true; return dp[l][r] = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1)); } int main() { gl(n); rep(i, n) gl(a[i]); cout << f(0, n - 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; #define forup(i, a, b) for (int i = (a); i < (b); ++i) #define fordn(i, a, b) for (int i = (a); i > (b); --i) #define rep(i, a) for (int i = 0; i < (a); ++i) #define gi(x) scanf("%d", &x) #define gl(x) cin >> x #define gd(x) scanf("%lf", &x) #define gs(x) scanf(" %s", x) #define D(x) cout << #x << " : " << x << endl #define fs first #define sc second #define pb push_back #define mp make_pair const int inf = numeric_limits<int>::max(); const LL linf = numeric_limits<LL>::max(); const int max_n = 3010; LL n, dp[max_n][max_n], a[max_n]; bool s[max_n][max_n]; LL f(int l, int r) { if (r < 0 || l >= n || l > r) return 0; if (s[l][r]) return dp[l][r]; s[l][r] = true; return dp[l][r] = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1)); } int main() { gl(n); rep(i, n) gl(a[i]); cout << f(0, n - 1) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
979,976
979,977
u561426248
cpp
p03171
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <stdio.h> using namespace std; long long dp1[3000][3000]; long long dp2[3000][3000]; long long a[3000]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { dp1[i][i] = a[i]; dp2[i][i] = a[i]; } for (int i = N - 1; i >= 0; i--) { for (int j = i + 1; j < N; j++) { dp1[i][j] = max(a[i] + dp2[i + 1][j], a[j] + dp2[i][j - 1]); dp2[i][j] = min(dp1[i + 1][j] - a[i], dp1[i][j - 1] - a[j]); } } cout << dp1[0][N - 1] << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <stdio.h> using namespace std; long long dp1[3000][3000]; long long dp2[3000][3000]; long long a[3000]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { dp1[i][i] = a[i]; dp2[i][i] = -a[i]; } for (int i = N - 1; i >= 0; i--) { for (int j = i + 1; j < N; j++) { dp1[i][j] = max(a[i] + dp2[i + 1][j], a[j] + dp2[i][j - 1]); dp2[i][j] = min(dp1[i + 1][j] - a[i], dp1[i][j - 1] - a[j]); } } cout << dp1[0][N - 1] << endl; return 0; }
[ "expression.operation.unary.add" ]
979,985
979,986
u623349537
cpp
p03171
#include <algorithm> #include <cstdio> using namespace std; const int MAXN = 3 * 1e3 + 5; int n; long long a[MAXN]; long long z; void read_input() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); z += a[i]; } } pair<long long, long long> T[MAXN][MAXN][2]; pair<long long, long long> rec(int l, int r, int t) { if (l == r) { if (t == 0) return {a[l], 0}; if (t == 1) return {0, a[l]}; } if (T[l][r][t].first != 0 || T[l][r][t].second != 0) { return T[l][r][t]; } int f; if (t == 0) f = rec(l, r - 1, t ^ 1).first + a[r]; else f = rec(l, r - 1, t ^ 1).second + a[r]; int s; if (t == 0) s = rec(l + 1, r, t ^ 1).first + a[l]; else s = rec(l + 1, r, t ^ 1).second + a[l]; if (t == 1) { if (f > s) { return T[l][r][t] = {rec(l, r - 1, t ^ 1).first, f}; } else { return T[l][r][t] = {rec(l + 1, r, t ^ 1).first, s}; } } else { if (f > s) { return T[l][r][t] = {f, rec(l, r - 1, t ^ 1).second}; } else { return T[l][r][t] = {s, rec(l + 1, r, t ^ 1).second}; } } } void solve() { long long X = rec(0, n - 1, 0).first; // printf("%d\n", X); printf("%lld\n", 2 * X - z); } int main() { read_input(); solve(); return 0; }
#include <algorithm> #include <cstdio> using namespace std; const int MAXN = 3 * 1e3 + 5; int n; long long a[MAXN]; long long z; void read_input() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); z += a[i]; } } pair<long long, long long> T[MAXN][MAXN][2]; pair<long long, long long> rec(int l, int r, int t) { if (l == r) { if (t == 0) return {a[l], 0}; if (t == 1) return {0, a[l]}; } if (T[l][r][t].first != 0 || T[l][r][t].second != 0) { return T[l][r][t]; } long long f; if (t == 0) f = rec(l, r - 1, t ^ 1).first + a[r]; else f = rec(l, r - 1, t ^ 1).second + a[r]; long long s; if (t == 0) s = rec(l + 1, r, t ^ 1).first + a[l]; else s = rec(l + 1, r, t ^ 1).second + a[l]; if (t == 1) { if (f > s) { return T[l][r][t] = {rec(l, r - 1, t ^ 1).first, f}; } else { return T[l][r][t] = {rec(l + 1, r, t ^ 1).first, s}; } } else { if (f > s) { return T[l][r][t] = {f, rec(l, r - 1, t ^ 1).second}; } else { return T[l][r][t] = {s, rec(l + 1, r, t ^ 1).second}; } } } void solve() { long long X = rec(0, n - 1, 0).first; // printf("%lld\n", X); printf("%lld\n", 2 * X - z); } int main() { read_input(); solve(); return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
979,988
979,989
u666461127
cpp
p03171
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using piii = pair<pii, pii>; const int INF = 1e9 + 7; int memo[3001][3001][2]; int a[3000]; // f(a,b,c)で左端がa,右端がbの時のX-Yを返す。c=0の時太郎の番1の時次郎の番 int f(int l, int r, int state) { if (l > r) return 0; if (memo[l][r][state] != 0) return memo[l][r][state]; int ret = 0; if (state == 0) { ret = max(f(l + 1, r, 1) + a[l], f(l, r - 1, 1) + a[r]); } else { ret = min(f(l + 1, r, 0) - a[l], f(l, r - 1, 0) - a[r]); } return memo[l][r][state] = ret; return ret; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << f(0, n - 1, 0) << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using piii = pair<pii, pii>; const int INF = 1e9 + 7; ll memo[3001][3001][2]; int a[3000]; // f(a,b,c)で左端がa,右端がbの時のX-Yを返す。c=0の時太郎の番1の時次郎の番 ll f(int l, int r, int state) { if (l > r) return 0; if (memo[l][r][state] != 0) return memo[l][r][state]; ll ret = 0; if (state == 0) { ret = max(f(l + 1, r, 1) + a[l], f(l, r - 1, 1) + a[r]); } else { ret = min(f(l + 1, r, 0) - a[l], f(l, r - 1, 0) - a[r]); } return memo[l][r][state] = ret; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << f(0, n - 1, 0) << endl; return 0; }
[ "variable_declaration.type.change" ]
979,994
979,995
u406158207
cpp
p03171
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using piii = pair<pii, pii>; const int INF = 1e9 + 7; int memo[3001][3001][2]; int a[3000]; // f(a,b,c)で左端がa,右端がbの時のX-Yを返す。c=0の時太郎の番1の時次郎の番 int f(int l, int r, int state) { if (l > r) return 0; if (memo[l][r][state] != 0) return memo[l][r][state]; int ret = 0; if (state == 0) { ret = max(f(l + 1, r, 1) + a[l], f(l, r - 1, 1) + a[r]); } else { ret = min(f(l + 1, r, 0) - a[l], f(l, r - 1, 0) - a[r]); } return memo[l][r][state] = ret; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << f(0, n - 1, 0) << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using piii = pair<pii, pii>; const int INF = 1e9 + 7; ll memo[3001][3001][2]; int a[3000]; // f(a,b,c)で左端がa,右端がbの時のX-Yを返す。c=0の時太郎の番1の時次郎の番 ll f(int l, int r, int state) { if (l > r) return 0; if (memo[l][r][state] != 0) return memo[l][r][state]; ll ret = 0; if (state == 0) { ret = max(f(l + 1, r, 1) + a[l], f(l, r - 1, 1) + a[r]); } else { ret = min(f(l + 1, r, 0) - a[l], f(l, r - 1, 0) - a[r]); } return memo[l][r][state] = ret; } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } cout << f(0, n - 1, 0) << endl; return 0; }
[ "variable_declaration.type.change" ]
979,996
979,995
u406158207
cpp
p03171
#include "bits/stdc++.h" using namespace std; /* macro */ #define rep(i, a, b) for (int i = a; i < b; i++) #define revrep(i, a, b) for (int i = a; i > b; i--) #define int long long #define exist(s, e) ((s).find(e) != (s).end()) #define all(v) (v).begin(), (v).end() #define each(s, itr) for (auto(itr) = s.begin(); (itr) != s.end(); (itr)++) #define sum(v) accumulate(all(v), (0LL)) #define pb push_back /* alias */ template <class T> using vec = vector<T>; typedef vector<int> vi; typedef pair<int, int> pi; /* constant */ const int inf = 1000100010010010; const int mod = 1e9 + 7; int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1}; int dy[8] = {0, 1, 0, -1, -1, -1, 1, 1}; /* io_method */ int input() { int tmp; cin >> tmp; return tmp; } string raw_input() { string tmp; cin >> tmp; return tmp; } string readline() { string s; getline(cin, s); return s; } template <class T> void printx(T n) { cout << n; } template <class T, class U> void printx(pair<T, U> p) { cout << "(" << p.first << "," << p.second << ")"; } template <class T> void printx(vector<T> v) { cout << "{"; rep(i, 0, v.size()) { printx(v[i]); if (i != v.size() - 1) printx(","); } cout << "}"; } template <class T> void print(T n) { printx(n); cout << endl; } template <class T> void print(set<T> s) { cout << "{"; each(s, e) { if (e != s.begin()) printx(","); printx(*e); } cout << "}" << endl; } template <class T, class U> void print(map<T, U> mp) { cout << "{"; each(mp, e) { cout << "(" << e->first << "," << e->second << ")"; } cout << "}" << endl; } /* general_method */ template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } // template<typename T> auto cut(T &a, int l, int r){return T(a.begin()+l, // a.begin()+r);} /* main */ int n; vi arr; int dp[3010][3010]; int dfs(int l, int r) { if (l > r) return 0; if (dp[l][r] > -inf) return dp[l][r]; if (((r - l + 1) ^ n) ^ 1) { return dp[l][r] = max(arr[l] + dfs(l + 1, r), arr[r] + dfs(l, r - 1)); } else { return dp[l][r] = min(dfs(l + 1, r) - arr[l], dfs(l, r - 1) - arr[r]); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); n = input(); rep(i, 0, n) arr.pb(input()); rep(i, 0, 3010) rep(j, 0, 3010) dp[i][j] = -inf; print(dfs(0, n - 1)); }
#include "bits/stdc++.h" using namespace std; /* macro */ #define rep(i, a, b) for (int i = a; i < b; i++) #define revrep(i, a, b) for (int i = a; i > b; i--) #define int long long #define exist(s, e) ((s).find(e) != (s).end()) #define all(v) (v).begin(), (v).end() #define each(s, itr) for (auto(itr) = s.begin(); (itr) != s.end(); (itr)++) #define sum(v) accumulate(all(v), (0LL)) #define pb push_back /* alias */ template <class T> using vec = vector<T>; typedef vector<int> vi; typedef pair<int, int> pi; /* constant */ const int inf = 1000100010010010; const int mod = 1e9 + 7; int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1}; int dy[8] = {0, 1, 0, -1, -1, -1, 1, 1}; /* io_method */ int input() { int tmp; cin >> tmp; return tmp; } string raw_input() { string tmp; cin >> tmp; return tmp; } string readline() { string s; getline(cin, s); return s; } template <class T> void printx(T n) { cout << n; } template <class T, class U> void printx(pair<T, U> p) { cout << "(" << p.first << "," << p.second << ")"; } template <class T> void printx(vector<T> v) { cout << "{"; rep(i, 0, v.size()) { printx(v[i]); if (i != v.size() - 1) printx(","); } cout << "}"; } template <class T> void print(T n) { printx(n); cout << endl; } template <class T> void print(set<T> s) { cout << "{"; each(s, e) { if (e != s.begin()) printx(","); printx(*e); } cout << "}" << endl; } template <class T, class U> void print(map<T, U> mp) { cout << "{"; each(mp, e) { cout << "(" << e->first << "," << e->second << ")"; } cout << "}" << endl; } /* general_method */ template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } // template<typename T> auto cut(T &a, int l, int r){return T(a.begin()+l, // a.begin()+r);} /* main */ int n; vi arr; int dp[3010][3010]; int dfs(int l, int r) { if (l > r) return 0; if (dp[l][r] > -inf) return dp[l][r]; if (!(((r - l + 1) ^ n) & 1)) { return dp[l][r] = max(arr[l] + dfs(l + 1, r), arr[r] + dfs(l, r - 1)); } else { return dp[l][r] = min(dfs(l + 1, r) - arr[l], dfs(l, r - 1) - arr[r]); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); n = input(); rep(i, 0, n) arr.pb(input()); rep(i, 0, 3010) rep(j, 0, 3010) dp[i][j] = -inf; print(dfs(0, n - 1)); }
[ "control_flow.branch.if.condition.change" ]
979,997
979,998
u828847847
cpp
p03171
/*input 4 10 80 90 30 */ #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 tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") // order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld long double #define pii pair<int, int> #define f first #define s second #define pb emplace_back #define REP(i, n) for (ll i = 0; i < n; i++) #define sz(_a) (ll)(_a.size()) #define FILL(n) memset(n, 0, sizeof(n)) #define ALL(_a) _a.begin(), _a.end() const ll maxn = 100005; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 8000000000000000000LL; const int INF = 0x3f3f3f3f; const ll MOD = ll(1e9 + 7); const ld PI = acos(-1); const ld eps = 1e-9; ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int dp[3005][3005]; int arr[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; REP(i, n) cin >> arr[i]; for (int i = n - 1; i >= 0; i--) { for (int j = i; j < n; j++) { if (i == j) dp[i][j] = arr[i]; else dp[i][j] = max(arr[j] - dp[i][j - 1], arr[i] - dp[i + 1][j]); } } cout << dp[0][n - 1]; }
/*input 4 10 80 90 30 */ #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 tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") // order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld long double #define pii pair<int, int> #define f first #define s second #define pb emplace_back #define REP(i, n) for (ll i = 0; i < n; i++) #define sz(_a) (ll)(_a.size()) #define FILL(n) memset(n, 0, sizeof(n)) #define ALL(_a) _a.begin(), _a.end() const ll maxn = 100005; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 8000000000000000000LL; const int INF = 0x3f3f3f3f; const ll MOD = ll(1e9 + 7); const ld PI = acos(-1); const ld eps = 1e-9; ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } ll dp[3005][3005]; ll arr[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; REP(i, n) cin >> arr[i]; for (int i = n - 1; i >= 0; i--) { for (int j = i; j < n; j++) { if (i == j) dp[i][j] = arr[i]; else dp[i][j] = max(arr[j] - dp[i][j - 1], arr[i] - dp[i + 1][j]); } } cout << dp[0][n - 1]; }
[ "variable_declaration.type.change" ]
980,005
980,006
u110464018
cpp
p03171
/*input 4 10 80 90 30 */ #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 tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") // order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld long double #define pii pair<int, int> #define f first #define s second #define pb emplace_back #define REP(i, n) for (ll i = 0; i < n; i++) #define sz(_a) (ll)(_a.size()) #define FILL(n) memset(n, 0, sizeof(n)) #define ALL(_a) _a.begin(), _a.end() const ll maxn = 100005; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 8000000000000000000LL; const int INF = 0x3f3f3f3f; const ll MOD = ll(1e9 + 7); const ld PI = acos(-1); const ld eps = 1e-9; ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int dp[1005][1005]; int arr[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; REP(i, n) cin >> arr[i]; for (int i = n - 1; i >= 0; i--) { for (int j = i; j < n; j++) { if (i == j) dp[i][j] = arr[i]; else dp[i][j] = max(arr[j] - dp[i][j - 1], arr[i] - dp[i + 1][j]); } } cout << dp[0][n - 1]; }
/*input 4 10 80 90 30 */ #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 tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") // order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld long double #define pii pair<int, int> #define f first #define s second #define pb emplace_back #define REP(i, n) for (ll i = 0; i < n; i++) #define sz(_a) (ll)(_a.size()) #define FILL(n) memset(n, 0, sizeof(n)) #define ALL(_a) _a.begin(), _a.end() const ll maxn = 100005; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 8000000000000000000LL; const int INF = 0x3f3f3f3f; const ll MOD = ll(1e9 + 7); const ld PI = acos(-1); const ld eps = 1e-9; ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } ll dp[3005][3005]; ll arr[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; REP(i, n) cin >> arr[i]; for (int i = n - 1; i >= 0; i--) { for (int j = i; j < n; j++) { if (i == j) dp[i][j] = arr[i]; else dp[i][j] = max(arr[j] - dp[i][j - 1], arr[i] - dp[i + 1][j]); } } cout << dp[0][n - 1]; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
980,007
980,006
u110464018
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll solve(vector<int> &dq, int st, int end, vector<vector<ll>> &dp) { if (st > end) return 0; if (dp[st][end] != -1) return dp[st][end]; // dp[st][end] = max(max(solve(dq, st+1, end-1, dp), solve(dq, st+2, end, dp)) // + dq[st], max(solve(dq, st+1, end-1, dp), solve(dq, st, end-2, dp)) + // dq[end]); dp[st][end] = max(dq[st] - solve(dq, st + 1, end, dp), dq[end] - solve(dq, st, end - 1, dp)); return dp[st][end]; } int main() { int n; cin >> n; vector<int> dq; for (int i = 0; i < n; i++) { int t; cin >> t; dq.push_back(t); } vector<vector<ll>> dp(n, vector<ll>(n, -1)); // dp[0][n-1] = solve(dq, 0, n-1, dp); for (int i = 0; i < n; i++) { dp[i][i] = dq[i]; } for (int i = n - 1; i >= 0; i--) { for (int j = i; j < 0; j++) { if (i == j) dp[i][j] = dq[j]; else dp[i][j] = max(dq[i] - dp[i + 1][j], dq[j] - dp[i][j - 1]); } } cout << dp[0][n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll solve(vector<int> &dq, int st, int end, vector<vector<ll>> &dp) { if (st > end) return 0; if (dp[st][end] != -1) return dp[st][end]; // dp[st][end] = max(max(solve(dq, st+1, end-1, dp), solve(dq, st+2, end, dp)) // + dq[st], max(solve(dq, st+1, end-1, dp), solve(dq, st, end-2, dp)) + // dq[end]); dp[st][end] = max(dq[st] - solve(dq, st + 1, end, dp), dq[end] - solve(dq, st, end - 1, dp)); return dp[st][end]; } int main() { int n; cin >> n; vector<int> dq; for (int i = 0; i < n; i++) { int t; cin >> t; dq.push_back(t); } vector<vector<ll>> dp(n, vector<ll>(n, -1)); // dp[0][n-1] = solve(dq, 0, n-1, dp); for (int i = 0; i < n; i++) { dp[i][i] = dq[i]; } for (int i = n - 1; i >= 0; i--) { for (int j = i; j < n; j++) { if (i == j) dp[i][j] = dq[j]; else dp[i][j] = max(dq[i] - dp[i + 1][j], dq[j] - dp[i][j - 1]); } } cout << dp[0][n - 1] << endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
980,008
980,009
u662651036
cpp
p03171
#include <algorithm> #include <cstdio> using namespace std; int n, a[3005], dp[3005][3005]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); dp[i][i] = a[i]; } for (int i = n; i >= 1; i--) { for (int j = i + 1; j <= n; j++) { dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]); } } printf("%d\n", dp[1][n]); }
#include <algorithm> #include <cstdio> using namespace std; long long n, a[3005], dp[3005][3005]; int main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); dp[i][i] = a[i]; } for (int i = n; i >= 1; i--) { for (int j = i + 1; j <= n; j++) { dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]); } } printf("%lld\n", dp[1][n]); }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
980,013
980,014
u287687156
cpp
p03171
#include <bits/stdc++.h> using namespace std; struct point { int first, second; }; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } // DP[i][j] gives maximum value chhosen by player A and B // if()subarray{i.....j] isconsidered; point dp[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i][j].first = 0; dp[i][j].second = 0; } } for (int l = 1; l <= n; l++) { for (int i = 0; i < n - l + 1; i++) { int j = i + (l - 1); if (i == j) { dp[i][j].first = arr[i]; dp[i][j].second = 0; } else { if (arr[i] + dp[i + 1][j].second > arr[j] + dp[i][j - 1].second) { dp[i][j].first = arr[i] + dp[i + 1][j].second; dp[i][j].second = dp[i + 1][j].first; } else { dp[i][j].first = arr[j] + dp[i][j - 1].second; dp[i][j].second = dp[i][j - 1].first; } } } } // for(int i=0;i<n;i++){ // for(int j=0;j<n;j++){ // cout<<dp[i][j].first<<" "<<dp[i][j].second<<" "; // } // cout<<endl; // } int ans = 0; ans = dp[0][n - 1].first - dp[0][n - 1].second; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; struct point { long long int first, second; }; int main() { int n; cin >> n; long long int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } // DP[i][j] gives maximum value chhosen by player A and B // if()subarray{i.....j] isconsidered; point dp[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i][j].first = 0; dp[i][j].second = 0; } } for (int l = 1; l <= n; l++) { for (int i = 0; i < n - l + 1; i++) { int j = i + (l - 1); if (i == j) { dp[i][j].first = arr[i]; dp[i][j].second = 0; } else { if (arr[i] + dp[i + 1][j].second > arr[j] + dp[i][j - 1].second) { dp[i][j].first = arr[i] + dp[i + 1][j].second; dp[i][j].second = dp[i + 1][j].first; } else { dp[i][j].first = arr[j] + dp[i][j - 1].second; dp[i][j].second = dp[i][j - 1].first; } } } } // for(int i=0;i<n;i++){ // for(int j=0;j<n;j++){ // cout<<dp[i][j].first<<" "<<dp[i][j].second<<" "; // } // cout<<endl; // } long long int ans = 0; ans = dp[0][n - 1].first - dp[0][n - 1].second; cout << ans; return 0; }
[ "variable_declaration.type.widen.change" ]
980,015
980,016
u356853948
cpp
p03171
#include <bits/stdc++.h> using namespace std; int dfs(int l, int r, vector<long long int> &v, vector<vector<long long int>> &dp) { if (l == r) return v[l]; if (dp[l][r] != INT_MAX) return dp[l][r]; return dp[l][r] = max(v[l] - dfs(l + 1, r, v, dp), v[r] - dfs(l, r - 1, v, dp)); } int main() { int n; cin >> n; vector<long long int> v(n, 0); vector<vector<long long int>> dp(n, vector<long long int>(n, INT_MAX)); for (int i = 0; i < n; i++) cin >> v[i]; cout << dfs(0, n - 1, v, dp); return 0; }
#include <bits/stdc++.h> using namespace std; long long int dfs(int l, int r, vector<long long int> &v, vector<vector<long long int>> &dp) { if (l == r) return v[l]; if (dp[l][r] != INT_MAX) return dp[l][r]; return dp[l][r] = max(v[l] - dfs(l + 1, r, v, dp), v[r] - dfs(l, r - 1, v, dp)); } int main() { int n; cin >> n; vector<long long int> v(n, 0); vector<vector<long long int>> dp(n, vector<long long int>(n, INT_MAX)); for (int i = 0; i < n; i++) cin >> v[i]; cout << dfs(0, n - 1, v, dp); return 0; }
[ "variable_declaration.type.widen.change" ]
980,021
980,022
u719635221
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i, n) for (long long i = 0; i < n; ++i) #define REPP(i, m, n) for (long long i = m; i < n; ++i) #define rep(i, n) for (long long i = n - 1; i >= 0; --i) #define repp(i, n, m) for (long long i = n - 1; i >= m; --i) #define ALL(N) (N.begin(), N.end()) #define de cout << "line : " << __LINE__ << " debug" << endl; #define pb push_back #define pq priority_queue #define Dcout(N) cout << setprecision(20) << N << endl constexpr int INF = 2147483647; constexpr long long INFF = 9223372036854775807; int N; ll A[3100]; ll dp[3100][3100]; bool used[3100][3100]; int solve(int L, int R) { if (L > R) return 0; if (used[L][R]) return dp[L][R]; used[L][R] = 1; int diff = (N - R - L + 1) % 2; ll ans = 0; if (diff) { ans = INFF; ans = min(ans, solve(L + 1, R) - A[L]); ans = min(ans, solve(L, R - 1) - A[R]); } else { ans = -INFF; ans = max(ans, solve(L + 1, R) + A[L]); ans = max(ans, solve(L, R - 1) + A[R]); } return dp[L][R] = ans; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; REP(i, N) cin >> A[i]; cout << solve(0, N - 1) << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i, n) for (long long i = 0; i < n; ++i) #define REPP(i, m, n) for (long long i = m; i < n; ++i) #define rep(i, n) for (long long i = n - 1; i >= 0; --i) #define repp(i, n, m) for (long long i = n - 1; i >= m; --i) #define ALL(N) (N.begin(), N.end()) #define de cout << "line : " << __LINE__ << " debug" << endl; #define pb push_back #define pq priority_queue #define Dcout(N) cout << setprecision(20) << N << endl constexpr int INF = 2147483647; constexpr long long INFF = 9223372036854775807; int N; ll A[3100]; ll dp[3100][3100]; bool used[3100][3100]; ll solve(int L, int R) { if (L > R) return 0; if (used[L][R]) return dp[L][R]; used[L][R] = 1; int diff = (N - R - L + 1) % 2; ll ans = 0; if (diff) { ans = INFF; ans = min(ans, solve(L + 1, R) - A[L]); ans = min(ans, solve(L, R - 1) - A[R]); } else { ans = -INFF; ans = max(ans, solve(L + 1, R) + A[L]); ans = max(ans, solve(L, R - 1) + A[R]); } return dp[L][R] = ans; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; REP(i, N) cin >> A[i]; cout << solve(0, N - 1) << endl; }
[]
980,023
980,024
u901397311
cpp
p03171
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__) #else #define show(...) 42 #endif #define f first #define s second #define endl "\n" #define pb push_back #define oo 0x3f3f3f3f #define limit 1000000007 #define two pair<int, int> #define mod(x, m) ((x % m + m) % m) #define all(v) v.begin(), v.end() #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define fori(x, n) for (int i = x; i < n; i++) #define forj(y, m) for (int j = y; j < m; j++) #define fork(z, p) for (int k = z; k < p; k++) #define speedforces std::ios::sync_with_stdio(false) #define watch(x) cout << (#x) << " is " << (x) << "\n" #define input_from_file freopen("input.txt", "r", stdin); int dp[3005][3005]; int fun(int i, int j, vector<int> &v) { if (i > j || j < 1 || i > v.size()) return 0; if (i == j) return dp[i][i] = v[i]; if (dp[i][j] != -1) return dp[i][j]; dp[i][j] = min(fun(i + 2, j, v), fun(i + 1, j - 1, v)) + v[i]; return dp[i][j] = max(dp[i][j], min(fun(i + 1, j - 1, v), fun(i, j - 2, v)) + v[j]); } signed main() { // input_from_file; speedforces; int n; cin >> n; vector<int> v(n + 1); memset(dp, -1, sizeof dp); int sum = 0; fori(1, n + 1) cin >> v[i], sum += v[i]; cout << 2 * fun(1, n, v) - sum << endl; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__) #else #define show(...) 42 #endif #define f first #define s second #define endl "\n" #define pb push_back #define oo 0x3f3f3f3f #define limit 1000000007 #define two pair<int, int> #define mod(x, m) ((x % m + m) % m) #define all(v) v.begin(), v.end() #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define int long long int #define fori(x, n) for (int i = x; i < n; i++) #define forj(y, m) for (int j = y; j < m; j++) #define fork(z, p) for (int k = z; k < p; k++) #define speedforces std::ios::sync_with_stdio(false) #define watch(x) cout << (#x) << " is " << (x) << "\n" #define input_from_file freopen("input.txt", "r", stdin); int dp[3005][3005]; int fun(int i, int j, vector<int> &v) { if (i > j || j < 1 || i > v.size()) return 0; if (i == j) return dp[i][i] = v[i]; if (dp[i][j] != -1) return dp[i][j]; dp[i][j] = min(fun(i + 2, j, v), fun(i + 1, j - 1, v)) + v[i]; return dp[i][j] = max(dp[i][j], min(fun(i + 1, j - 1, v), fun(i, j - 2, v)) + v[j]); } signed main() { // input_from_file; speedforces; int n; cin >> n; vector<int> v(n + 1); memset(dp, -1, sizeof dp); int sum = 0; fori(1, n + 1) cin >> v[i], sum += v[i]; cout << 2 * fun(1, n, v) - sum << endl; }
[]
980,032
980,033
u520002141
cpp
p03171
#include <bits/stdc++.h> using namespace std; // dp[i] first player winns if its true stones left int dp[3005][3005]; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int r = 0, l = n - 1; for (l = n - 1; l >= 0; --l) { for (r = l; r < n; ++r) { if (l == r) { dp[l][r] = arr[l]; } else { dp[l][r] = max(arr[l] - dp[l + 1][r], arr[r] - dp[l][r - 1]); } } } cout << dp[0][n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; // dp[i] first player winns if its true stones left long long int dp[3005][3005]; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int r = 0, l = n - 1; for (l = n - 1; l >= 0; --l) { for (r = l; r < n; ++r) { if (l == r) { dp[l][r] = arr[l]; } else { dp[l][r] = max(arr[l] - dp[l + 1][r], arr[r] - dp[l][r - 1]); } } } cout << dp[0][n - 1]; return 0; }
[ "variable_declaration.type.widen.change" ]
980,034
980,035
u796511558
cpp
p03171
#include <bits/stdc++.h> using namespace std; // dp[i] first player winns if its true stones left int dp[3005][3005]; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int r = 0, l = n - 1; for (l = n - 1; l >= 0; l--) { for (r = l; r < n; r++) { if (l == r) { dp[l][r] = arr[l]; } else { dp[l][r] = max(arr[l] - dp[l + 1][r], arr[r] - dp[l][r - 1]); } } } cout << dp[0][n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; // dp[i] first player winns if its true stones left long long int dp[3005][3005]; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int r = 0, l = n - 1; for (l = n - 1; l >= 0; --l) { for (r = l; r < n; ++r) { if (l == r) { dp[l][r] = arr[l]; } else { dp[l][r] = max(arr[l] - dp[l + 1][r], arr[r] - dp[l][r - 1]); } } } cout << dp[0][n - 1]; return 0; }
[ "variable_declaration.type.widen.change" ]
980,036
980,035
u796511558
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb(x) push_back(x) #define ce(x) cout << x << endl; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define scl1(a) scanf("%lld", &a) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define rep(i, x, n, inc) for (i = x; i < n; i += inc) const int N = (int)3e3 + 5; int n; ll dp[N][N], a[N]; int f(ll i, ll j) { if (i < 1 or j < 1 or j > n or i > n) return 0; if (i == j) return a[i]; if (i > j) return 0; if (dp[i][j] != (-1)) return dp[i][j]; dp[i][j] = max(a[i] + min(f(i + 2, j), f(i + 1, j - 1)), a[j] + min(f(i, j - 2), f(i + 1, j - 1))); return dp[i][j]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t, i, j, z, k, s = 0; memset(dp, -1, sizeof(dp)); cin >> n; rep(i, 1, n + 1, 1) { cin >> a[i]; s += a[i]; } cout << (2 * f(1, n) - s) << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb(x) push_back(x) #define ce(x) cout << x << endl; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define scl1(a) scanf("%lld", &a) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define rep(i, x, n, inc) for (i = x; i < n; i += inc) const int N = (int)3e3 + 5; int n; ll dp[N][N], a[N]; ll f(ll i, ll j) { if (i < 1 or j < 1 or j > n or i > n) return 0; if (i == j) return a[i]; if (i > j) return 0; if (dp[i][j] != (-1)) return dp[i][j]; dp[i][j] = max(a[i] + min(f(i + 2, j), f(i + 1, j - 1)), a[j] + min(f(i, j - 2), f(i + 1, j - 1))); return dp[i][j]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t, i, j, z, k, s = 0; memset(dp, -1, sizeof(dp)); cin >> n; rep(i, 1, n + 1, 1) { cin >> a[i]; s += a[i]; } cout << (2 * f(1, n) - s) << endl; }
[]
980,037
980,038
u933735545
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb(x) push_back(x) #define ce(x) cout << x << endl; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define scl1(a) scanf("%lld", &a) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define rep(i, x, n, inc) for (i = x; i < n; i += inc) const int N = (int)3e3 + 5; int n; int dp[N][N], a[N]; int f(int i, int j) { if (i < 1 or j < 1 or j > n or i > n) return 0; if (i == j) return a[i]; if (i > j) return 0; if (dp[i][j] != (-1)) return dp[i][j]; dp[i][j] = max(a[i] + min(f(i + 2, j), f(i + 1, j - 1)), a[j] + min(f(i, j - 2), f(i + 1, j - 1))); return dp[i][j]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, i, j, z, k, s = 0; memset(dp, -1, sizeof(dp)); cin >> n; rep(i, 1, n + 1, 1) { cin >> a[i]; s += a[i]; } cout << (2 * f(1, n) - s) << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb(x) push_back(x) #define ce(x) cout << x << endl; using db = double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define scl1(a) scanf("%lld", &a) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define rep(i, x, n, inc) for (i = x; i < n; i += inc) const int N = (int)3e3 + 5; int n; ll dp[N][N], a[N]; ll f(ll i, ll j) { if (i < 1 or j < 1 or j > n or i > n) return 0; if (i == j) return a[i]; if (i > j) return 0; if (dp[i][j] != (-1)) return dp[i][j]; dp[i][j] = max(a[i] + min(f(i + 2, j), f(i + 1, j - 1)), a[j] + min(f(i, j - 2), f(i + 1, j - 1))); return dp[i][j]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t, i, j, z, k, s = 0; memset(dp, -1, sizeof(dp)); cin >> n; rep(i, 1, n + 1, 1) { cin >> a[i]; s += a[i]; } cout << (2 * f(1, n) - s) << endl; }
[ "variable_declaration.type.change" ]
980,039
980,038
u933735545
cpp
p03171
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; using vll = vector<vl>; //**関数リスト**// int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } bool pairCompare(const pll firstElof, pll secondElof) { return firstElof.second < secondElof.second; } ll nod(ll F) { ll keta = 1; while (F / 10 > 0) { keta++; F /= 10; } return keta; } ll gcd(ll x, ll y) { ll r; if (x < y) { swap(x, y); } while (y > 0) { r = x % y; x = y; y = r; } return x; } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll isPrime(ll x) { ll i; if (x < 2) { return 0; } else if (x == 2) { return 1; } else if (x % 2 == 0) { return 0; } else { for (i = 3; i * i <= x; i += 2) { if (x % 1 == 0) { return 0; } } return 1; } } void eratos(vl isPrime) { //(注)isPrimeのサイズはN+1にする!実際にはmain内に配置して使用 ll i, j; for (i = 0; i < isPrime.size(); i++) { isPrime[i] = 1; } isPrime[0] = 0; isPrime[1] = 0; for (i = 2; i * i <= isPrime.size() - 1; i++) { if (isPrime[i] == 1) { j = i * 2; while (j <= isPrime.size() - 1) { isPrime[j] = 0; j = j + i; } } } } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll alphabet(char C) { ll b = 0; ll key = 0; if (C == 'a') { return b; } b++; if (C == 'b') { return b; } b++; if (C == 'c') { return b; } b++; if (C == 'd') { return b; } b++; if (C == 'e') { return b; } b++; if (C == 'f') { return b; } b++; if (C == 'g') { return b; } b++; if (C == 'h') { return b; } b++; if (C == 'i') { return b; } b++; if (C == 'j') { return b; } b++; if (C == 'k') { return b; } b++; if (C == 'l') { return b; } b++; if (C == 'm') { return b; } b++; if (C == 'n') { return b; } b++; if (C == 'o') { return b; } b++; if (C == 'p') { return b; } b++; if (C == 'q') { return b; } b++; if (C == 'r') { return b; } b++; if (C == 's') { return b; } b++; if (C == 't') { return b; } b++; if (C == 'u') { return b; } b++; if (C == 'v') { return b; } b++; if (C == 'w') { return b; } b++; if (C == 'x') { return b; } b++; if (C == 'y') { return b; } b++; if (C == 'z') { return b; } return -1; } void bitSearch(ll n) { //実際にはコピーして中身を改変して使う ll i; for (i = 0; i < pow(2, n); i++) { ll p = i; for (i = 0; i < n; i++) { cout << p % 2; p /= 2; } cout << endl; } } void bfs(ll now) { //中身は毎回書き換えて使用 queue<ll> Q; Q.push(now); ll u; while (!Q.empty()) { u = Q.front(); Q.pop(); // ll v=; // Q.push(v); } } //**定義場所**// ll i, j, k, l, m, n, N, M, K, H, W; ll MOD = 1000000007; ll ans = 0; ll vis[3010][3010]; ll memo[3010][3010]; vl A(3010); //***********// //区間が左端Lから右端Rまでの時のdp(初期はR=0/L=N-1) ll dp(ll L, ll R) { if (L > R) return 0; //訪問済みであればメモした結果を返すだけ if (vis[L][R]) return memo[L][R]; //訪問済みであるかどうか vis[L][R] = 1; // N-(R-L+1)は今までに削った個数(=偶数なら次のターンは太郎) ll diff = N - (R - L + 1); ll res = 0; //先手か後手かの判定 if (diff % 2 == 0) { // X-Yの最大化 res = -1000000000; res = max(res, max(dp(L + 1, R) + A[L], dp(L, R - 1) + A[R])); } else { // X-Yの最小化 res = 1000000000; res = min(res, min(dp(L + 1, R) - A[L], dp(L, R - 1) - A[R])); } return memo[L][R] = res; } int main() { cin >> N; for (i = 0; i < N; i++) { cin >> A[i]; } cout << dp(0, N - 1); }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; using vll = vector<vl>; //**関数リスト**// int ctoi(char c) { switch (c) { case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default: return 0; } } bool pairCompare(const pll firstElof, pll secondElof) { return firstElof.second < secondElof.second; } ll nod(ll F) { ll keta = 1; while (F / 10 > 0) { keta++; F /= 10; } return keta; } ll gcd(ll x, ll y) { ll r; if (x < y) { swap(x, y); } while (y > 0) { r = x % y; x = y; y = r; } return x; } ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll isPrime(ll x) { ll i; if (x < 2) { return 0; } else if (x == 2) { return 1; } else if (x % 2 == 0) { return 0; } else { for (i = 3; i * i <= x; i += 2) { if (x % 1 == 0) { return 0; } } return 1; } } void eratos(vl isPrime) { //(注)isPrimeのサイズはN+1にする!実際にはmain内に配置して使用 ll i, j; for (i = 0; i < isPrime.size(); i++) { isPrime[i] = 1; } isPrime[0] = 0; isPrime[1] = 0; for (i = 2; i * i <= isPrime.size() - 1; i++) { if (isPrime[i] == 1) { j = i * 2; while (j <= isPrime.size() - 1) { isPrime[j] = 0; j = j + i; } } } } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll alphabet(char C) { ll b = 0; ll key = 0; if (C == 'a') { return b; } b++; if (C == 'b') { return b; } b++; if (C == 'c') { return b; } b++; if (C == 'd') { return b; } b++; if (C == 'e') { return b; } b++; if (C == 'f') { return b; } b++; if (C == 'g') { return b; } b++; if (C == 'h') { return b; } b++; if (C == 'i') { return b; } b++; if (C == 'j') { return b; } b++; if (C == 'k') { return b; } b++; if (C == 'l') { return b; } b++; if (C == 'm') { return b; } b++; if (C == 'n') { return b; } b++; if (C == 'o') { return b; } b++; if (C == 'p') { return b; } b++; if (C == 'q') { return b; } b++; if (C == 'r') { return b; } b++; if (C == 's') { return b; } b++; if (C == 't') { return b; } b++; if (C == 'u') { return b; } b++; if (C == 'v') { return b; } b++; if (C == 'w') { return b; } b++; if (C == 'x') { return b; } b++; if (C == 'y') { return b; } b++; if (C == 'z') { return b; } return -1; } void bitSearch(ll n) { //実際にはコピーして中身を改変して使う ll i; for (i = 0; i < pow(2, n); i++) { ll p = i; for (i = 0; i < n; i++) { cout << p % 2; p /= 2; } cout << endl; } } void bfs(ll now) { //中身は毎回書き換えて使用 queue<ll> Q; Q.push(now); ll u; while (!Q.empty()) { u = Q.front(); Q.pop(); // ll v=; // Q.push(v); } } //**定義場所**// ll i, j, k, l, m, n, N, M, K, H, W; ll MOD = 1000000007; ll ans = 0; ll vis[3010][3010]; ll memo[3010][3010]; vl A(3010); //***********// //区間が左端Lから右端Rまでの時のdp(初期はR=0/L=N-1) ll dp(ll L, ll R) { if (L > R) return 0; //訪問済みであればメモした結果を返すだけ if (vis[L][R]) return memo[L][R]; //訪問済みであるかどうか vis[L][R] = 1; // N-(R-L+1)は今までに削った個数(=偶数なら次のターンは太郎) ll diff = N - (R - L + 1); ll res = 0; //先手か後手かの判定 if (diff % 2 == 0) { // X-Yの最大化 res = -1000000000000000; res = max(res, max(dp(L + 1, R) + A[L], dp(L, R - 1) + A[R])); } else { // X-Yの最小化 res = 10000000000000000; res = min(res, min(dp(L + 1, R) - A[L], dp(L, R - 1) - A[R])); } return memo[L][R] = res; } int main() { cin >> N; for (i = 0; i < N; i++) { cin >> A[i]; } cout << dp(0, N - 1); }
[ "literal.number.change", "assignment.value.change" ]
980,040
980,041
u916974091
cpp
p03171
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } pair<int, int> dp[n][n]; for (int i = 0; i < n; i++) { dp[i][i].first = arr[i]; dp[i][i].second = 0; } for (int k = 1; k < n; k++) { for (int i = 0; i < n; i++) { int j = i + k; if (j >= n) break; int a1 = dp[i][j - 1].second + arr[j]; int a2 = dp[i + 1][j].second + arr[i]; dp[i][j].first = max(a1, a2); if (a1 > a2) { dp[i][j].second = dp[i][j - 1].first; } else { dp[i][j].second = dp[i + 1][j].first; } } } cout << dp[0][n - 1].first - dp[0][n - 1].second << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int long long int signed main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } pair<int, int> dp[n][n]; for (int i = 0; i < n; i++) { dp[i][i].first = arr[i]; dp[i][i].second = 0; } for (int k = 1; k < n; k++) { for (int i = 0; i < n; i++) { int j = i + k; if (j >= n) break; int a1 = dp[i][j - 1].second + arr[j]; int a2 = dp[i + 1][j].second + arr[i]; dp[i][j].first = max(a1, a2); if (a1 > a2) { dp[i][j].second = dp[i][j - 1].first; } else { dp[i][j].second = dp[i + 1][j].first; } } } cout << dp[0][n - 1].first - dp[0][n - 1].second << "\n"; }
[ "variable_declaration.type.widen.change" ]
980,043
980,044
u100071032
cpp
p03171
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <stdio.h> using namespace std; using namespace __gnu_pbds; #define ll long long typedef pair<int, int> pii; #define MOD 1000000007 #define MOD1 998244353 #define ff first #define ss second #define bn cout << "\n" #define o2(a, b) cout << a << " " << b #define sz(a) (a).size() #define o(a) cout << a #define MAX6 1000006 #define int ll #define all(x) x.begin(), x.end() #define ppii pair<int, pii> #define vi vector<int> #define vii vector<pii> #define viii vector<ppii> #define vs vector<string> #define pb push_back #define eb emplace_back #define endl '\n' #define MAX5 300005 #define MAX7 10000007 #define rep(i, a, b) for (__typeof((b)) i = (a); i <= (b); i++) #define nrep(i, b, a) for (__typeof((b)) i = (b); i >= (a); i--) #define mem(a) memset(a, 0, sizeof(a)) #define memneg(a) memset(a, -1, sizeof(a)) //#define se second #define LN 14 #define LIM 22 #define MAX_ALPHA 26 const long long INF64 = 1e18; const ll INF = 1e9; const double PI = acos(-1); #define ld long double typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; inline void max_self(ll &a, ll b) { a = max(a, b); } inline void min_self(ll &a, ll b) { a = min(a, b); } inline void add_self(ll &a, ll b) { a += b; if (a >= MOD) a -= MOD; } inline void sub_self(ll &a, ll b) { a -= b; if (a < 0) a += MOD; } inline int mul(int a, int b) { return (int)((long long)a * b % MOD); } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } int countDigits(int x) { int cnt = 0; while (x) { x /= 10; cnt++; } return cnt; } ll binExpo(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res % MOD; } int sum(int a) { int result = 0; while (a > 0) { result += a % 10; a /= 10; } return result; } const int nax = 3005; int dp[nax][nax]; void solve() { int n; cin >> n; vector<int> a(n); rep(i, 0, n - 1) cin >> a[i]; rep(L, 0, n - 1) { rep(R, L, n - 1) { if (L == R) dp[L][R] = a[L]; else dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]); } } cout << dp[0][n - 1] << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <stdio.h> using namespace std; using namespace __gnu_pbds; #define ll long long typedef pair<int, int> pii; #define MOD 1000000007 #define MOD1 998244353 #define ff first #define ss second #define bn cout << "\n" #define o2(a, b) cout << a << " " << b #define sz(a) (a).size() #define o(a) cout << a #define MAX6 1000006 #define int ll #define all(x) x.begin(), x.end() #define ppii pair<int, pii> #define vi vector<int> #define vii vector<pii> #define viii vector<ppii> #define vs vector<string> #define pb push_back #define eb emplace_back #define endl '\n' #define MAX5 300005 #define MAX7 10000007 #define rep(i, a, b) for (__typeof((b)) i = (a); i <= (b); i++) #define nrep(i, b, a) for (__typeof((b)) i = (b); i >= (a); i--) #define mem(a) memset(a, 0, sizeof(a)) #define memneg(a) memset(a, -1, sizeof(a)) //#define se second #define LN 14 #define LIM 22 #define MAX_ALPHA 26 const long long INF64 = 1e18; const ll INF = 1e9; const double PI = acos(-1); #define ld long double typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; inline void max_self(ll &a, ll b) { a = max(a, b); } inline void min_self(ll &a, ll b) { a = min(a, b); } inline void add_self(ll &a, ll b) { a += b; if (a >= MOD) a -= MOD; } inline void sub_self(ll &a, ll b) { a -= b; if (a < 0) a += MOD; } inline int mul(int a, int b) { return (int)((long long)a * b % MOD); } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } int countDigits(int x) { int cnt = 0; while (x) { x /= 10; cnt++; } return cnt; } ll binExpo(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b /= 2; } return res % MOD; } int sum(int a) { int result = 0; while (a > 0) { result += a % 10; a /= 10; } return result; } const int nax = 3005; int dp[nax][nax]; void solve() { int n; cin >> n; vector<int> a(n); rep(i, 0, n - 1) cin >> a[i]; nrep(L, n - 1, 0) { rep(R, L, n - 1) { if (L == R) dp[L][R] = a[L]; else dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]); } } cout << dp[0][n - 1] << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) solve(); return 0; }
[ "identifier.change", "call.function.change", "call.arguments.change", "call.arguments.add" ]
980,045
980,046
u351310875
cpp
p03171
#pragma GCC optimize("03") #include <bits/stdc++.h> #define int int64_t using namespace std; int n, temp; deque<int> q; int32_t main() { cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { cin >> temp; q.push_back(temp); if (q.size() > 2 and q.back() >= q[q.size() - 2] and q[q.size() - 2] >= q[q.size() - 3]) { temp = q.back() - q[q.size() - 2] + q[q.size() - 3]; q.pop_back(); q.pop_back(); q.pop_back(); q.push_back(temp); } } int res = 0, i = 1; while (!q.empty()) { if (q.front() >= q.back()) { res += i * q.front(); q.pop_front(); } else { res += i * q.back(); q.pop_back(); } i = -i; } cout << res << "\n"; return 0; }
#pragma GCC optimize("03") #include <bits/stdc++.h> #define int int64_t using namespace std; int n, temp; deque<int> q; int32_t main() { cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { cin >> temp; q.push_back(temp); while (q.size() > 2 and q.back() <= q[q.size() - 2] and q[q.size() - 2] >= q[q.size() - 3]) { temp = q.back() - q[q.size() - 2] + q[q.size() - 3]; q.pop_back(); q.pop_back(); q.pop_back(); q.push_back(temp); } } int res = 0, i = 1; while (!q.empty()) { if (q.front() >= q.back()) { res += i * q.front(); q.pop_front(); } else { res += i * q.back(); q.pop_back(); } i = -i; } cout << res << "\n"; return 0; }
[ "control_flow.branch.while.replace.add", "control_flow.loop.if.replace.remove", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
980,049
980,048
u127754559
cpp
p03171
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cout << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #define INFILE freopen("input.txt", "r", stdin) #else #define debug(x) #define INFILE #endif #define ALL(s) begin(s), end(s) #define RALL(s) rbegin(s), rend(s) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define RREP(i, a, b) for (int i = (a); i >= (b); i--) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll LL9_MOD = 1000000009LL; static constexpr ll LL7_MOD = 1000000007LL; static constexpr ll INF = 1LL << 60; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); ll dp[3010][3010]; int main(int argc, char *argv[]) { INFILE; ll n; cin >> n; vector<ll> seq(n); scan(seq); int sign = n % 2 ? 1 : -1; REP(i, 0, n) { dp[i][i + 1] = seq[i] * sign; } REP(k, 2, n + 1) { sign *= -1; REP(i, 0, n + 1 - k) { int start = i, end = i + k; auto change = sign > 0 ? chmax<ll> : chmin<ll>; ll result = sign * seq[start] + dp[start + 1][end]; change(result, sign * seq[end] + dp[start][end - 1]); dp[start][end] = result; } } cout << dp[0][n] << endl; return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cout << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #define INFILE freopen("input.txt", "r", stdin) #else #define debug(x) #define INFILE #endif #define ALL(s) begin(s), end(s) #define RALL(s) rbegin(s), rend(s) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define RREP(i, a, b) for (int i = (a); i >= (b); i--) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll LL9_MOD = 1000000009LL; static constexpr ll LL7_MOD = 1000000007LL; static constexpr ll INF = 1LL << 60; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); ll dp[3010][3010]; int main(int argc, char *argv[]) { INFILE; ll n; cin >> n; vector<ll> seq(n); scan(seq); int sign = n % 2 ? 1 : -1; REP(i, 0, n) { dp[i][i + 1] = seq[i] * sign; } REP(k, 2, n + 1) { sign *= -1; REP(i, 0, n + 1 - k) { int start = i, end = i + k; auto change = sign > 0 ? chmax<ll> : chmin<ll>; ll result = sign * seq[start] + dp[start + 1][end]; change(result, sign * seq[end - 1] + dp[start][end - 1]); dp[start][end] = result; } } cout << dp[0][n] << endl; return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
[ "expression.operation.binary.add" ]
980,052
980,053
u209647862
cpp
p03171
#include <bits/stdc++.h> #define ll long long using namespace std; ll dp[3010][3010]; ll a[3010]; int solve(int i, int j) { if (i > j) return 0; if (dp[i][j] != -1) return dp[i][j]; return dp[i][j] = max(a[i] - solve(i + 1, j), a[j] - solve(i, j - 1)); } int main() { int n; cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) cin >> a[i]; cout << solve(0, n - 1); }
#include <bits/stdc++.h> #define ll long long using namespace std; ll dp[3010][3010]; ll a[3010]; ll solve(int i, int j) { if (i > j) return 0; if (dp[i][j] != -1) return dp[i][j]; return dp[i][j] = max(a[i] - solve(i + 1, j), a[j] - solve(i, j - 1)); } int main() { int n; cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) cin >> a[i]; cout << solve(0, n - 1); }
[]
980,054
980,055
u565814877
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define _USE_MATH_DEFINES #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // DON'T USE THESE MACROS DURING ICPC PRACTICE #define For(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i <= b; i++) #define Down(i, n) for (int i = n - 1; i >= 0; i--) #define DOWN(i, a, b) for (int i = b; i >= a; i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef complex<ld> pt; typedef vector<pt> pol; typedef vector<int> vi; const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll INFLL = 0x3f3f3f3f3f3f3f3f; const ll MOD = 1e9 + 7; const ld EPS = 1e-10; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int n; cin >> n; int a[n]; For(i, n) { cin >> a[i]; } int dp[n][n][2]; For(d, n) { For(i, n - d) { if (d == 0) { dp[i][i][0] = a[i]; dp[i][i][1] = -a[i]; } else { dp[i][i + d][0] = max(dp[i][i + d - 1][1] + a[i + d], dp[i + 1][i + d][1] + a[i]); dp[i][i + d][1] = min(dp[i][i + d - 1][0] - a[i + d], dp[i + 1][i + d][0] - a[i]); } } } cout << dp[0][n - 1][0] << nl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _USE_MATH_DEFINES #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // DON'T USE THESE MACROS DURING ICPC PRACTICE #define For(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i <= b; i++) #define Down(i, n) for (int i = n - 1; i >= 0; i--) #define DOWN(i, a, b) for (int i = b; i >= a; i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef complex<ld> pt; typedef vector<pt> pol; typedef vector<int> vi; const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll INFLL = 0x3f3f3f3f3f3f3f3f; const ll MOD = 1e9 + 7; const ld EPS = 1e-10; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int n; cin >> n; int a[n]; For(i, n) { cin >> a[i]; } ll dp[n][n][2]; For(d, n) { For(i, n - d) { if (d == 0) { dp[i][i][0] = a[i]; dp[i][i][1] = -a[i]; } else { dp[i][i + d][0] = max(dp[i][i + d - 1][1] + a[i + d], dp[i + 1][i + d][1] + a[i]); dp[i][i + d][1] = min(dp[i][i + d - 1][0] - a[i + d], dp[i + 1][i + d][0] - a[i]); } } } cout << dp[0][n - 1][0] << nl; return 0; }
[ "variable_declaration.type.change" ]
980,066
980,067
u645327277
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define forn(i, n) for (int i = 0; i < n; i++) #define forn1(i, n) for (int i = 1; i <= n; i++) #define loop(i, sta, end, inc) for (int i = sta; i <= end; i += inc) #define itr(it, l) for (auto it = l.begin(); it != l.end(); it++) #define in(a, b, c) assert(b <= a && a <= c) #define pb push_back #define ll long long int #define fi first #define se second #define ii pair<long long int, long long int> #define vi vector<long long int> #define vii vector<pair<long long int, long long int>> #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define what_is(x) cerr << #x << " =" << x << " "; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define LINT_MAX 9223372036854775807 #define LINT_MIN -9223372036854775808 #define EPS 1e-9 #define MOD 1000000007 #define DEBUG 0 template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { if (DEBUG == 0) return; cerr << *it << " = " << a << " "; err(++it, args...); } int A[3000]; int dp[3000][3000]; int main() { // freopen("test.txt", "r", stdin); int n; cin >> n; forn(i, n) cin >> A[i]; forn(k, n) { forn(i, n - k) { if (i == i + k) dp[i][i] = A[i]; else dp[i][i + k] = max(A[i] - dp[i + 1][i + k], A[i + k] - dp[i][i + k - 1]); } } cout << dp[0][n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define forn(i, n) for (int i = 0; i < n; i++) #define forn1(i, n) for (int i = 1; i <= n; i++) #define loop(i, sta, end, inc) for (int i = sta; i <= end; i += inc) #define itr(it, l) for (auto it = l.begin(); it != l.end(); it++) #define in(a, b, c) assert(b <= a && a <= c) #define pb push_back #define ll long long int #define fi first #define se second #define ii pair<long long int, long long int> #define vi vector<long long int> #define vii vector<pair<long long int, long long int>> #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define what_is(x) cerr << #x << " =" << x << " "; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define LINT_MAX 9223372036854775807 #define LINT_MIN -9223372036854775808 #define EPS 1e-9 #define MOD 1000000007 #define DEBUG 0 template <typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; } void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { if (DEBUG == 0) return; cerr << *it << " = " << a << " "; err(++it, args...); } long long A[3000]; long long dp[3000][3000]; int main() { // freopen("test.txt", "r", stdin); int n; cin >> n; forn(i, n) cin >> A[i]; forn(k, n) { forn(i, n - k) { if (i == i + k) dp[i][i] = A[i]; else dp[i][i + k] = max(A[i] - dp[i + 1][i + k], A[i + k] - dp[i][i + k - 1]); } } cout << dp[0][n - 1] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
980,068
980,069
u858856811
cpp
p03171
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> dp(n, vector<int>(n, 0)); int sum = 0; for (int i = 0; i < n; i++) { int temp; cin >> temp; sum += temp; dp[i][i] = temp; } for (int i = 1; i <= n - 1; i++) { for (int j = 0; i + j < n; j++) { int col = j + i; int row = j; if (i == 1) { dp[row][col] = max(dp[row + 1][col], dp[row][col - 1]); } else { dp[row][col] = max(dp[row][row] + min(dp[row + 2][col], (dp[row + 1][col - 1])), dp[col][col] + min(dp[row + 1][col - 1], (dp[row][col - 2]))); } } } cout << 2 * dp[0][n - 1] - sum; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<long>> dp(n, vector<long>(n, 0)); long long sum = 0; for (int i = 0; i < n; i++) { long long temp; cin >> temp; sum += temp; dp[i][i] = temp; } for (int i = 1; i <= n - 1; i++) { for (int j = 0; i + j < n; j++) { int col = j + i; int row = j; if (i == 1) { dp[row][col] = max(dp[row + 1][col], dp[row][col - 1]); } else { dp[row][col] = max(dp[row][row] + min(dp[row + 2][col], (dp[row + 1][col - 1])), dp[col][col] + min(dp[row + 1][col - 1], (dp[row][col - 2]))); } } } cout << 2 * dp[0][n - 1] - sum; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
980,074
980,075
u388587443
cpp
p03171
#include <bits/stdc++.h> using namespace std; signed main() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int dp[n + 1][n + 1] = {}; for (int i = n; i >= 1; --i) { dp[i][i] = a[i]; for (int j = i + 1; j <= n; ++j) { dp[j][i] = max(a[i] - dp[j][i + 1], a[j] - dp[j - 1][i]); } } cout << dp[n][1]; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int dp[n + 1][n + 1] = {}; for (int i = n; i >= 1; --i) { dp[i][i] = a[i]; for (int j = i + 1; j <= n; ++j) { dp[j][i] = max(a[i] - dp[j][i + 1], a[j] - dp[j - 1][i]); } } cout << dp[n][1]; }
[]
980,076
980,077
u193815565
cpp
p03171
#include <iomanip> #include <iostream> #include <vector> using namespace std; int n; vector<int> a; int dp[3010][3010]; int main() { cin >> n; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int len = 1; len <= n; ++len) { for (int i = 0; i + len <= n; ++i) { int j = i + len; if ((n - len) % 2 == 0) { dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]); } else { dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]); } } } cout << dp[0][n] << endl; return 0; }
#include <iomanip> #include <iostream> #include <vector> using namespace std; int n; vector<long long> a; long long dp[3010][3010]; int main() { cin >> n; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int len = 1; len <= n; ++len) { for (int i = 0; i + len <= n; ++i) { int j = i + len; if ((n - len) % 2 == 0) { dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]); } else { dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]); } } } cout << dp[0][n] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
980,078
980,079
u899866702
cpp
p03171
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; #define ll long long int #define INF (2147483647) #define mod (1000000007) vector<vector<int>> dp; vector<vector<bool>> flags; vector<int> aa; int calc(int l, int r, bool first) { int tmp; if (flags[l][r]) { return dp[l][r]; } if (first) { if (l == r) { return aa[l]; } tmp = max(calc(l, r - 1, false) + aa[r], calc(l + 1, r, false) + aa[l]); } else { if (l == r) { return -aa[l]; } tmp = min(calc(l, r - 1, true) - aa[r], calc(l + 1, r, true) - aa[l]); } dp[l][r] = tmp; flags[l][r] = true; return tmp; } int main(void) { int N; cin >> N; aa.assign(N, 0); for (size_t i = 0; i < N; i++) { cin >> aa[i]; } dp.assign(N, vector<int>(N, 0)); flags.assign(N, vector<bool>(N, false)); cout << calc(0, N - 1, true) << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; #define ll long long int #define INF (2147483647) #define mod (1000000007) vector<vector<ll>> dp; vector<vector<bool>> flags; vector<int> aa; ll calc(int l, int r, bool first) { ll tmp; if (flags[l][r]) { return dp[l][r]; } if (first) { if (l == r) { return aa[l]; } tmp = max(calc(l, r - 1, false) + aa[r], calc(l + 1, r, false) + aa[l]); } else { if (l == r) { return -aa[l]; } tmp = min(calc(l, r - 1, true) - aa[r], calc(l + 1, r, true) - aa[l]); } dp[l][r] = tmp; flags[l][r] = true; return tmp; } int main(void) { int N; cin >> N; aa.assign(N, 0); for (size_t i = 0; i < N; i++) { cin >> aa[i]; } dp.assign(N, vector<ll>(N, 0)); flags.assign(N, vector<bool>(N, false)); cout << calc(0, N - 1, true) << endl; }
[ "variable_declaration.type.change", "call.arguments.change" ]
980,080
980,081
u333945892
cpp
p03171
#include <bits/stdc++.h> #define ll long long #define dl double #define pb push_back #define mp make_pair #define F first #define S second #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define mod 1000000007 #define P(a, b) pair<a, b> #define CIN(V, s, n) \ for (int i = s; i < n; i++) { \ cin >> V[i]; \ } #define COUT(V, s, n) \ for (int i = s; i < n; i++) { \ cout << V[i] << " "; \ } using namespace std; bool sortBylen(string &a, string &b) { if (a.size() > b.size()) return true; else if (a.size() == b.size()) { if (a > b) { return true; } else false; } else return false; } vector<vector<ll>> DP(3e3 + 1, vector<ll>(3e3 + 1, -1)); ll GT(vector<ll> &V, ll s, ll e, ll &n) { if (s > e) return 0; if (s == e - 1) return max(V[s], V[e]); if (s == e) return V[s]; if (DP[s + 2][e] == -1) DP[s + 2][e] = GT(V, s + 2, e, n); if (DP[s + 1][e - 1] == -1) DP[s + 1][e - 1] = GT(V, s + 2, e, n); if (DP[s][e - 2] == -1) DP[s][e - 2] = GT(V, s, e - 2, n); return max(V[s] + min(DP[s + 2][e], DP[s + 1][e - 1]), V[e] + min(DP[s + 1][e - 1], DP[s][e - 2])); } int main() { ll t = 1; // cin >> t; while (t--) { ll n, W, i, j, k = 2, l1, l2, m; ll r, c; cin >> n; ll ans = 0; vector<ll> V(n); for (i = 0; i < n; i++) { cin >> V[i]; ans += V[i]; } cout << (2LL * GT(V, 0, n - 1, n) - ans); } return 0; }
#include <bits/stdc++.h> #define ll long long #define dl double #define pb push_back #define mp make_pair #define F first #define S second #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define mod 1000000007 #define P(a, b) pair<a, b> #define CIN(V, s, n) \ for (int i = s; i < n; i++) { \ cin >> V[i]; \ } #define COUT(V, s, n) \ for (int i = s; i < n; i++) { \ cout << V[i] << " "; \ } using namespace std; bool sortBylen(string &a, string &b) { if (a.size() > b.size()) return true; else if (a.size() == b.size()) { if (a > b) { return true; } else false; } else return false; } vector<vector<ll>> DP(3e3 + 1, vector<ll>(3e3 + 1, -1)); ll GT(vector<ll> &V, ll s, ll e, ll &n) { if (s > e) return 0; if (s == e - 1) return max(V[s], V[e]); if (s == e) return V[s]; if (DP[s + 2][e] == -1) DP[s + 2][e] = GT(V, s + 2, e, n); if (DP[s + 1][e - 1] == -1) DP[s + 1][e - 1] = GT(V, s + 1, e - 1, n); if (DP[s][e - 2] == -1) DP[s][e - 2] = GT(V, s, e - 2, n); return max(V[s] + min(DP[s + 2][e], DP[s + 1][e - 1]), V[e] + min(DP[s + 1][e - 1], DP[s][e - 2])); } int main() { ll t = 1; // cin >> t; while (t--) { ll n, W, i, j, k = 2, l1, l2, m; ll r, c; cin >> n; ll ans = 0; vector<ll> V(n); for (i = 0; i < n; i++) { cin >> V[i]; ans += V[i]; } cout << (2LL * GT(V, 0, n - 1, n) - ans); } return 0; }
[ "literal.number.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change", "assignment.change" ]
980,084
980,085
u121266738
cpp
p03171
#include <bits/stdc++.h> using namespace std; const int MAXN = 3100; struct elem { long long int first; long long int second; }; elem dp[MAXN][MAXN]; long long int A[MAXN]; int N; void calcDP() { for (int i = 0; i < N; i++) dp[i][i].first = A[i]; for (int offset = 1; offset < N; offset++) { for (int i = 0; i + offset < N; i++) { if ((A[i] + dp[i + 1][i + offset].second - dp[i + 1][i + offset].first) > A[offset + i] + dp[i][i + offset - 1].second - dp[i][i + offset - 1].first) dp[i][i + offset].first = A[i] + dp[i + 1][i + offset].second, dp[i][i + offset].second = dp[i + 1][i + offset].first; else dp[i][i + offset].first = A[offset + i] + dp[i][i + offset - 1].second, dp[i][i + offset].second = dp[i + offset][i + offset - 1].first; } } } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; calcDP(); cout << dp[0][N - 1].first - dp[0][N - 1].second; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 3100; struct elem { long long int first; long long int second; }; elem dp[MAXN][MAXN]; long long int A[MAXN]; int N; void calcDP() { for (int i = 0; i < N; i++) dp[i][i].first = A[i]; for (int offset = 1; offset < N; offset++) { for (int i = 0; i + offset < N; i++) { if ((A[i] + dp[i + 1][i + offset].second - dp[i + 1][i + offset].first) > A[offset + i] + dp[i][i + offset - 1].second - dp[i][i + offset - 1].first) dp[i][i + offset].first = A[i] + dp[i + 1][i + offset].second, dp[i][i + offset].second = dp[i + 1][i + offset].first; else dp[i][i + offset].first = A[offset + i] + dp[i][i + offset - 1].second, dp[i][i + offset].second = dp[i][i + offset - 1].first; } } } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; calcDP(); cout << dp[0][N - 1].first - dp[0][N - 1].second; }
[ "expression.operation.binary.remove" ]
980,086
980,087
u059331720
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { lli n; cin >> n; vector<lli> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<vector<int>> dp(n, vector<int>(n)); for (int l = n - 1; l >= 0; l--) { for (int r = l; r < n; r++) { if (l == r) { dp[l][r] = v[l]; } else { dp[l][r] = max(v[l] - dp[l + 1][r], v[r] - dp[l][r - 1]); } } } cout << dp[0][n - 1] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { // freopen("input.txt","r",stdin); lli n; cin >> n; vector<lli> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<vector<lli>> dp(n, vector<lli>(n)); for (int l = n - 1; l >= 0; l--) { for (int r = l; r < n; r++) { if (l == r) { dp[l][r] = v[l]; } else { dp[l][r] = max(v[l] - dp[l + 1][r], v[r] - dp[l][r - 1]); } } } cout << dp[0][n - 1] << endl; }
[]
980,094
980,095
u798858168
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int main() { int n; cin >> n; vector<int> a(n); cin >> a; vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0)); for (int len = 1; len <= n; len++) { for (int i = 0; i + len <= n; i++) { int j = i + len; if ((n - len) % 2 == 0) { dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]); } else { dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]); } } } cout << dp[0][n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int main() { int n; cin >> n; vector<int> a(n); cin >> a; vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0)); for (int len = 1; len <= n; len++) { for (int i = 0; i + len <= n; i++) { int j = i + len; if ((n - len) % 2 == 0) { dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]); } else { dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]); } } } cout << dp[0][n] << endl; return 0; }
[ "call.arguments.change" ]
980,102
980,103
u171804186
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define ops cout << "ops" << endl; #define freopens \ freopen("cowpatibility.in", "r", stdin); \ freopen("cowpatibility.out", "w", stdout); #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DIM 3007 #define DIMM 100007 #define INF 1000000000007.0 #define X (ll)(1 << 32) #define eps 0.0000001 #define PI 3.14159265358979323846 #define MAX 25 #define MODULO (long long)1000000007 const long double gr = (1 + sqrt(5)) / 2; typedef int I; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<I, I> pII; typedef pair<ll, ll> pllll; typedef pair<ld, ld> pldld; typedef vector<I> vI; typedef vector<ll> vll; typedef vector<pllll> vpllll; typedef char cr; typedef string str; ll n; ll a[DIM], dp[DIM][DIM]; int main() { // ops; // freopens; fast; // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int l = 1; l <= n; l++) { for (int s = 1; s <= (n - s + 1); s++) { dp[s][l] = max((a[s + l - 1] - dp[s][l - 1]), (a[s] - dp[s + 1][l - 1])); } } cout << dp[1][n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ops cout << "ops" << endl; #define freopens \ freopen("cowpatibility.in", "r", stdin); \ freopen("cowpatibility.out", "w", stdout); #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DIM 3007 #define DIMM 100007 #define INF 1000000000007.0 #define X (ll)(1 << 32) #define eps 0.0000001 #define PI 3.14159265358979323846 #define MAX 25 #define MODULO (long long)1000000007 const long double gr = (1 + sqrt(5)) / 2; typedef int I; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<I, I> pII; typedef pair<ll, ll> pllll; typedef pair<ld, ld> pldld; typedef vector<I> vI; typedef vector<ll> vll; typedef vector<pllll> vpllll; typedef char cr; typedef string str; ll n; ll a[DIM], dp[DIM][DIM]; int main() { // ops; // freopens; fast; // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int l = 1; l <= n; l++) { for (int s = 1; s <= (n - l + 1); s++) { dp[s][l] = max((a[s + l - 1] - dp[s][l - 1]), (a[s] - dp[s + 1][l - 1])); } } cout << dp[1][n] << endl; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
980,106
980,107
u113008684
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int lim = 3e3 + 7; const int inf = 1e9 + 9; int dp[lim][lim][2]; vector<int> a; int solve(int i, int j, int t) { if (i > j) return 0; if (dp[i][j][t] != -1) return dp[i][j][t]; if (t) { dp[i][j][1] = max(a[i] + solve(i + 1, j, 0), a[j] + solve(i, j - 1, 0)); } else { dp[i][j][0] = min(-a[i] + solve(i + 1, j, 1), -a[j] + solve(i, j - 1, 1)); } return dp[i][j][t]; } void init() { for (int i = 0; i < lim; i++) { for (int j = 0; j < lim; j++) { dp[i][j][0] = -1; dp[i][j][1] = -1; } } } int main() { init(); int n; cin >> n; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } cout << solve(0, n - 1, 1); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int lim = 3e3 + 7; const int inf = 1e9 + 9; ll dp[lim][lim][2]; vector<int> a; ll solve(int i, int j, int t) { if (i > j) return 0; if (dp[i][j][t] != -1) return dp[i][j][t]; if (t) { dp[i][j][1] = max(a[i] + solve(i + 1, j, 0), a[j] + solve(i, j - 1, 0)); } else { dp[i][j][0] = min(-a[i] + solve(i + 1, j, 1), -a[j] + solve(i, j - 1, 1)); } return dp[i][j][t]; } void init() { for (int i = 0; i < lim; i++) { for (int j = 0; j < lim; j++) { dp[i][j][0] = -1; dp[i][j][1] = -1; } } } int main() { init(); int n; cin >> n; a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } cout << solve(0, n - 1, 1); return 0; }
[ "variable_declaration.type.change" ]
980,108
980,109
u515056330
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long ll; int dp[3001][3001]; int a[3001]; ll fun(int i, int j, bool flag) { if (i == j) { if (flag) return a[i]; else return -a[i]; } if (dp[i][j] != -1) return dp[i][j]; if (flag) return dp[i][j] = max(a[i] + fun(i + 1, j, !flag), a[j] + fun(i, j - 1, !flag)); return dp[i][j] = min(-a[i] + fun(i + 1, j, !flag), -a[j] + fun(i, j - 1, !flag)); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; memset(dp, -1, sizeof(dp)); cout << fun(0, n - 1, true) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[3001][3001]; ll a[3001]; ll fun(int i, int j, bool flag) { if (i == j) { if (flag) return a[i]; else return -a[i]; } if (dp[i][j] != -1) return dp[i][j]; if (flag) return dp[i][j] = max(a[i] + fun(i + 1, j, !flag), a[j] + fun(i, j - 1, !flag)); return dp[i][j] = min(-a[i] + fun(i + 1, j, !flag), -a[j] + fun(i, j - 1, !flag)); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; memset(dp, -1, sizeof(dp)); cout << fun(0, n - 1, true) << endl; return 0; }
[ "variable_declaration.type.change" ]
980,110
980,111
u003481187
cpp
p03171
#include <cmath> #include <fstream> #include <iostream> using namespace std; ifstream fin("file.in"); ofstream fout("file.out"); long long int nrnr, sum; int vec[3005]; long long int ras[3005][3005]; int main() { fin >> nrnr; for (int index = 0; index < nrnr; index++) { fin >> vec[index]; } for (int index = 0; index < nrnr; index++) { ras[index][index] = vec[index] * (nrnr % 2); sum += vec[index]; } for (int index = 1; index < nrnr; index++) { for (int index2 = 0; index + index2 < nrnr; index2++) { if ((nrnr - index) % 2) { ras[index2][index + index2] = max(vec[index2] + ras[index2 + 1][index + index2], vec[index + index2] + ras[index2][index + index2 - 1]); } else { ras[index2][index + index2] = min(ras[index2 + 1][index + index2], ras[index2][index + index2 - 1]); } } } fout << 2 * ras[0][nrnr - 1] - sum; return 0; }
#include <cmath> #include <fstream> #include <iostream> using namespace std; ifstream fin("file.in"); ofstream fout("file.out"); long long int nrnr, sum; int vec[3005]; long long int ras[3005][3005]; int main() { cin >> nrnr; for (int index = 0; index < nrnr; index++) { cin >> vec[index]; } for (int index = 0; index < nrnr; index++) { ras[index][index] = vec[index] * (nrnr % 2); sum += vec[index]; } for (int index = 1; index < nrnr; index++) { for (int index2 = 0; index + index2 < nrnr; index2++) { if ((nrnr - index) % 2) { ras[index2][index + index2] = max(vec[index2] + ras[index2 + 1][index + index2], vec[index + index2] + ras[index2][index + index2 - 1]); } else { ras[index2][index + index2] = min(ras[index2 + 1][index + index2], ras[index2][index + index2 - 1]); } } } cout << 2 * ras[0][nrnr - 1] - sum; return 0; }
[ "identifier.change", "expression.operation.binary.change", "io.output.change" ]
980,113
980,114
u147403872
cpp
p03171
#include <bits/stdc++.h> using namespace std; long long dp[3010][3010]; int a[3010]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; dp[i][i] = a[i]; } for (int len = 2; len <= n; len++) { for (int i = 0; i + len - 1 < n; i++) { int j = i + len - 1; dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]); } } if (n % 2 == 1) cout << dp[0][n - 1] << endl; else cout << -dp[0][n - 1] << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[3010][3010]; int a[3010]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; dp[i][i] = a[i]; } for (int len = 2; len <= n; len++) { for (int i = 0; i + len - 1 < n; i++) { int j = i + len - 1; dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]); } } if (n % 2 == 1) cout << dp[0][n - 1] << endl; else cout << dp[0][n - 1] << endl; } int main() { solve(); return 0; }
[ "expression.operation.unary.arithmetic.remove" ]
980,115
980,116
u183606119
cpp
p03171
#include <bits/stdc++.h> const int N = 3005; int n, a[N], dp[N][N][2]; bool calc[N][N][2]; long long f(int l, int r, bool ply) { if (calc[l][r][ply]) return dp[l][r][ply]; calc[l][r][ply] = true; if (l == r) return dp[l][r][ply] = (ply ? -a[l] : a[l]); long long x = f(l + 1, r, !ply) + (ply ? -a[l] : a[l]); long long y = f(l, r - 1, !ply) + (ply ? -a[r] : a[r]); return dp[l][r][ply] = ply ? std::min(x, y) : std::max(x, y); } int32_t main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); printf("%lld\n", f(0, n - 1, 0)); return 0; }
#include <bits/stdc++.h> const int N = 3005; int n, a[N]; long long dp[N][N][2]; bool calc[N][N][2]; long long f(int l, int r, bool ply) { if (calc[l][r][ply]) return dp[l][r][ply]; calc[l][r][ply] = true; if (l == r) return dp[l][r][ply] = (ply ? -a[l] : a[l]); long long x = f(l + 1, r, !ply) + (ply ? -a[l] : a[l]); long long y = f(l, r - 1, !ply) + (ply ? -a[r] : a[r]); return dp[l][r][ply] = (ply ? std::min(x, y) : std::max(x, y)); } int32_t main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); printf("%lld\n", f(0, n - 1, 0)); return 0; }
[ "function.return_value.change" ]
980,119
980,120
u030489681
cpp
p03171
/* *#*#*#* Author GaryMr *#*#*#* ######################################################################## 是否可以简化问题: 抓住数据范围哪里小 dfs or bfs 是否可以化具体为抽象 字符串问题是否可以用数学模拟递归过程(取c[i]或不取来算结果) 二分?左闭右开? long long? 逆向思维? dp? 贪心? 树的直径:随便找一点再走到它最远的点A,再从A最远的点走到最远B的点。AB就是树的直径 匹配括号 左减右>=0 字符串赋值字符加单引号 double> printf("%lf")输出小数点6位,%.16lf输出后十六位 多组数据清空? dp优化用g? 线段树:大小为n的8倍 线段树:左闭右开! 线段树:find: if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k]; 线段树:满二叉树 循环跳出条件 代数设出每个值寻找关系? 优先队列:priority_queue<类型> q; priority_queue<类,vector<类>, less<类> > pq1;     // 使用递减 priority_queue<类,vector<类>, greater<类> > pq2;   // 使用递增 判断括号,判断是否长度为偶数 1<<ceil(log2(double(n))) */ #include <bits/stdc++.h> #define rb(a, b, c) for (int a = b; a <= c; a++) #define rl(a, b, c) for (int a = b; a >= c; a--) #define niv vector<int> #define LL long long #define IT iterator #define FIR first #define SEC second using namespace std; const int MAX = 0x3f3f3f3f; typedef pair<int, int> mp; typedef pair<mp, mp> superpair; LL dp[3005][3005]; int n; LL a[3005]; int main() { memset(dp, 0, sizeof(dp)); scanf("%d", &n); rb(i, 1, n) scanf("%I64d", &a[i]); rl(i, n, 1) { // dp[i][i]=a[i]; rb(j, i, n) { dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]); } } printf("%I64d", dp[1][n]); return 0; }
/* *#*#*#* Author GaryMr *#*#*#* ######################################################################## 是否可以简化问题: 抓住数据范围哪里小 dfs or bfs 是否可以化具体为抽象 字符串问题是否可以用数学模拟递归过程(取c[i]或不取来算结果) 二分?左闭右开? long long? 逆向思维? dp? 贪心? 树的直径:随便找一点再走到它最远的点A,再从A最远的点走到最远B的点。AB就是树的直径 匹配括号 左减右>=0 字符串赋值字符加单引号 double> printf("%lf")输出小数点6位,%.16lf输出后十六位 多组数据清空? dp优化用g? 线段树:大小为n的8倍 线段树:左闭右开! 线段树:find: if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k]; 线段树:满二叉树 循环跳出条件 代数设出每个值寻找关系? 优先队列:priority_queue<类型> q; priority_queue<类,vector<类>, less<类> > pq1;     // 使用递减 priority_queue<类,vector<类>, greater<类> > pq2;   // 使用递增 判断括号,判断是否长度为偶数 1<<ceil(log2(double(n))) */ #include <bits/stdc++.h> #define rb(a, b, c) for (int a = b; a <= c; a++) #define rl(a, b, c) for (int a = b; a >= c; a--) #define niv vector<int> #define LL long long #define IT iterator #define FIR first #define SEC second using namespace std; const int MAX = 0x3f3f3f3f; typedef pair<int, int> mp; typedef pair<mp, mp> superpair; LL dp[3005][3005]; int n; LL a[3005]; int main() { memset(dp, 0, sizeof(dp)); scanf("%d", &n); rb(i, 1, n) scanf("%lld", &a[i]); rl(i, n, 1) { rb(j, i, n) { dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]); } } printf("%lld", dp[1][n]); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
980,123
980,124
u751730221
cpp
p03171
#include <bits/stdc++.h> using namespace std; int n, a[10005], f[3005][3005]; int F(int i, int j) { if (f[i][j] != -1) return f[i][j]; else if (i > j) { return 0; } else { int res; if ((i - 1 + n - j) % 2 == 0) { res = max(F(i + 1, j) + a[i], F(i, j - 1) + a[j]); } else { res = min(F(i + 1, j) - a[i], F(i, j - 1) - a[j]); } f[i][j] = res; return res; } } main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; memset(f, -1, sizeof(f)); cout << F(1, n); }
#include <bits/stdc++.h> using namespace std; #define int long long int n, a[10005], f[3005][3005]; int F(int i, int j) { if (f[i][j] != -1) return f[i][j]; else if (i > j) { return 0; } else { int res; if ((i - 1 + n - j) % 2 == 0) { res = max(F(i + 1, j) + a[i], F(i, j - 1) + a[j]); } else { res = min(F(i + 1, j) - a[i], F(i, j - 1) - a[j]); } f[i][j] = res; return res; } } main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; memset(f, -1, sizeof(f)); cout << F(1, n); }
[]
980,127
980,128
u818354373
cpp
p03171
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; vector<vector<int>> f(n, vector<int>(n, 0)); for (int i = 0; i < n; i++) if (n & 1) f[i][i] = a[i]; else f[i][i] = -a[i]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= n - i; j++) { if ((n - i) % 2 == 0) { f[j][j + i - 1] = max(f[j][j + i - 2] + a[j + i - 1], a[j] + f[j + 1][j + i - 1]); } else { f[j][j + i - 1] = min(f[j][j + i - 2] - a[j + i - 1], -a[j] + f[j + 1][j + i - 1]); } } } cout << f[0][n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; vector<vector<long long>> f(n, vector<long long>(n, 0)); for (int i = 0; i < n; i++) if (n & 1) f[i][i] = a[i]; else f[i][i] = -a[i]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= n - i; j++) { if ((n - i) % 2 == 0) { f[j][j + i - 1] = max(f[j][j + i - 2] + a[j + i - 1], a[j] + f[j + 1][j + i - 1]); } else { f[j][j + i - 1] = min(f[j][j + i - 2] - a[j + i - 1], -a[j] + f[j + 1][j + i - 1]); } } } cout << f[0][n - 1] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
980,129
980,130
u251828455
cpp
p03171
// L - Deque https://atcoder.jp/contests/dp/tasks/dp_l /* 入力例 4 10 80 90 30 // →出力 10 */ #include <bits/stdc++.h> using namespace std; int N; int a[4]; long long int mem[4][4]; int memflag[4][4]; long long int dp(int l, int r) { if (memflag[l][r] == 1) { return mem[l][r]; } else if (l == r) { mem[l][r] = a[l]; memflag[l][r] = 1; return mem[l][r]; } else { mem[l][r] = max(dp(l + 1, r) * (-1) + a[l], dp(l, r - 1) * (-1) + a[r]); memflag[l][r] = 1; return mem[l][r]; } } int main(void) { cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; for (int j = 0; j < N; j++) { memflag[i][j] = 0; } } cout << dp(0, N - 1); cout << ""; return 0; }
// L - Deque https://atcoder.jp/contests/dp/tasks/dp_l /* 入力例 4 10 80 90 30 // →出力 10 */ #include <bits/stdc++.h> using namespace std; int N; int a[3000]; long long int mem[3000][3000]; int memflag[3000][3000]; long long int dp(int l, int r) { if (memflag[l][r] == 1) { return mem[l][r]; } else if (l == r) { mem[l][r] = a[l]; memflag[l][r] = 1; return mem[l][r]; } else { mem[l][r] = max(dp(l + 1, r) * (-1) + a[l], dp(l, r - 1) * (-1) + a[r]); memflag[l][r] = 1; return mem[l][r]; } } int main(void) { cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; for (int j = 0; j < N; j++) { memflag[i][j] = 0; } } cout << dp(0, N - 1); cout << ""; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
980,131
980,132
u721871635
cpp
p03171
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int main() { ll N; cin >> N; ll value[N]; ll dp[N][N]; for (ll i = 0; i < N; i++) { cin >> value[i]; dp[i][i] = value[i]; } for (ll len = 2; len <= N; len++) { for (ll i = 0; i <= N - len; i++) { dp[i][i + len - 1] = max(value[i] - dp[i + 1][i + len - 1], value[i + len - 1] - dp[i][i + len - 2]); } } cout << dp[N - 1][N - 1] << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int main() { ll N; cin >> N; ll value[N]; ll dp[N][N]; for (ll i = 0; i < N; i++) { cin >> value[i]; dp[i][i] = value[i]; } for (ll len = 2; len <= N; len++) { for (ll i = 0; i <= N - len; i++) { dp[i][i + len - 1] = max(value[i] - dp[i + 1][i + len - 1], value[i + len - 1] - dp[i][i + len - 2]); } } cout << dp[0][N - 1] << endl; }
[ "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "io.output.change", "expression.operation.binary.remove" ]
980,133
980,134
u771978844
cpp
p03171
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int main() { ll N; cin >> N; ll value[N]; ll dp[N][N]; for (ll i = 0; i < N; i++) { cin >> value[i]; dp[i][i] = value[i]; } for (ll len = 2; len <= N; len++) { for (ll i = 0; i <= N - len; i++) { dp[i][i + len - 1] = max(value[i] - dp[i + 1][i + len - 1], value[i + len - 1] - dp[i][i + len - 2]); } } cout << dp[N][N] << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int main() { ll N; cin >> N; ll value[N]; ll dp[N][N]; for (ll i = 0; i < N; i++) { cin >> value[i]; dp[i][i] = value[i]; } for (ll len = 2; len <= N; len++) { for (ll i = 0; i <= N - len; i++) { dp[i][i + len - 1] = max(value[i] - dp[i + 1][i + len - 1], value[i + len - 1] - dp[i][i + len - 2]); } } cout << dp[0][N - 1] << endl; }
[ "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "io.output.change" ]
980,135
980,134
u771978844
cpp
p03171
#include <bits/stdc++.h> #define inf (1ll << 62) using namespace std; const int maxn = 3005; typedef long long ll; int A[maxn]; ll memo[maxn][maxn][2]; int solve(int i, int j, bool flag) { if (i == j) { if (flag) return -A[i]; else return A[i]; } ll &ans = memo[i][j][flag]; if (ans != -inf) return ans; int x = solve(i + 1, j, !flag) + ((flag) ? -A[i] : A[i]); int y = solve(i, j - 1, !flag) + ((flag) ? -A[j] : A[j]); if (!flag) return (ans = max(x, y)); else return (ans = min(x, y)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { memo[i][j][0] = memo[i][j][1] = -inf; } } cout << solve(1, N, 0); return 0; }
#include <bits/stdc++.h> #define inf (1ll << 62) using namespace std; const int maxn = 3005; typedef long long ll; int A[maxn]; ll memo[maxn][maxn][2]; ll solve(int i, int j, bool flag) { if (i == j) { if (flag) return -A[i]; else return A[i]; } ll &ans = memo[i][j][flag]; if (ans != -inf) return ans; ll x = solve(i + 1, j, !flag) + ((flag) ? -A[i] : A[i]); ll y = solve(i, j - 1, !flag) + ((flag) ? -A[j] : A[j]); if (!flag) return (ans = max(x, y)); else return (ans = min(x, y)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { memo[i][j][0] = memo[i][j][1] = -inf; } } cout << solve(1, N, 0); return 0; }
[ "variable_declaration.type.change" ]
980,136
980,137
u303586394
cpp
p03171
#include <bits/stdc++.h> #pragma GCC optimuze("Ofast") #pragma GCC optimuze("03") #pragma GCC optimuze("unroll-loops") #define F first #define S second #define pb push_back #define llong long long #define ld long double #define int llong #define endl '\n' using namespace std; const int N = 3e3 + 5; const int M = 2e3 + 5; const int MOD = 1e9 + 7; const int rx[] = {1, 0, -1, 0}; const int ry[] = {0, 1, 0, -1}; int dp[N][N]; int s[N][N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef ARINOCHKA freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); #endif // ARINOCHKA int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x); dp[i][1] = x; } for (int i = 0; i < n; i++) { s[i][1] = a[i]; for (int j = 1; j <= n; j++) { if (i + j >= n) break; s[i][j + 1] = s[i][j] + a[i + j]; } } // for(int i = 0; i < n; i++){ // for(int j = 0; j <= n; j++){ // cout << s[i][j] << ' '; // } // cout << endl; // } for (int l = 2; l <= n; l++) { for (int i = 0; i < n; i++) { // if (l + i >= n) continue; dp[i][l] = max(s[i][l] - dp[i + 1][l - 1], s[i][l] - dp[i][l - 1]); } } // cout << s << endl; cout << s[0][n] - 2 * dp[0][n - 1] << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimuze("Ofast") #pragma GCC optimuze("03") #pragma GCC optimuze("unroll-loops") #define F first #define S second #define pb push_back #define llong long long #define ld long double #define int llong #define endl '\n' using namespace std; const int N = 3e3 + 5; const int M = 2e3 + 5; const int MOD = 1e9 + 7; const int rx[] = {1, 0, -1, 0}; const int ry[] = {0, 1, 0, -1}; int dp[N][N]; int s[N][N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef ARINOCHKA freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); #endif // ARINOCHKA int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x); dp[i][1] = x; } for (int i = 0; i < n; i++) { s[i][1] = a[i]; for (int j = 1; j <= n; j++) { if (i + j >= n) break; s[i][j + 1] = s[i][j] + a[i + j]; } } // for(int i = 0; i < n; i++){ // for(int j = 0; j <= n; j++){ // cout << s[i][j] << ' '; // } // cout << endl; // } for (int l = 2; l <= n; l++) { for (int i = 0; i < n; i++) { // if (l + i >= n) continue; dp[i][l] = max(s[i][l] - dp[i + 1][l - 1], s[i][l] - dp[i][l - 1]); } } // cout << s << endl; cout << -s[0][n] + 2 * dp[0][n] << endl; return 0; }
[ "expression.operation.unary.add", "misc.opposites", "expression.operator.arithmetic.change", "io.output.change", "expression.operation.binary.remove" ]
980,140
980,141
u318879716
cpp
p03171
#include <bits/stdc++.h> #define rep(i, k, n) for (int i = k; i <= n; i++) #define per(i, n, k) for (int i = n; i >= k; i--) #define pb push_back #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define ll long long using namespace std; const int maxn = 3005; int f[maxn][maxn], a[maxn], n, j; int main() { scanf("%d", &n); rep(i, 1, n) scanf("%d", a + i), f[i][i] = a[i]; rep(len, 1, n) { rep(i, 1, n) { j = i + len - 1; if (j > n) break; else f[i][j] = max(a[i] - f[i + 1][j], a[j] - f[i][j - 1]); } } printf("%d", f[1][n]); return 0; }
#include <bits/stdc++.h> #define rep(i, k, n) for (int i = k; i <= n; i++) #define per(i, n, k) for (int i = n; i >= k; i--) #define pb push_back #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define ll long long using namespace std; const int maxn = 3005; ll f[maxn][maxn], a[maxn], n, j; int main() { scanf("%lld", &n); rep(i, 1, n) scanf("%lld", a + i), f[i][i] = a[i]; rep(len, 1, n) { rep(i, 1, n) { j = i + len - 1; if (j > n) break; else f[i][j] = max(a[i] - f[i + 1][j], a[j] - f[i][j - 1]); } } printf("%lld", f[1][n]); return 0; }
[ "variable_declaration.type.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
980,142
980,143
u052685836
cpp
p03171
#include <bits/stdc++.h> #include <iostream> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pii std::pair<int, int> #define pli std::pair<ll, int> #define pil std::pair<int, ll> #define psi std::pair<string, int> #define pll std::pair<ll, ll> #define pci std::pair<char, int> #define sll(x) scanf("%lld", &x) #define prll(x) printf("%lld ", x) #define pri(x) printf("%d ", x) #define si(x) scanf("%d", &x) #define pb push_back #define vll std::vector<ll> #define vpi std::vector<std::pair<int, int>> #define vi std::vector<int> #define vvi std::vector<std::vector<int>> #define vvpil std::vector<std::vector<std::pair<int, ll>>> #define vlpii std::vector<std::list<pii>> #define vlpil std::vector<std::list<pil>> #define li std::list<int> #define lpil std::list<pil> #define Endl printf("\n") #define vli vector<list<int>> #define vvll vector<vector<ll>> #define mp make_pair #define ma 100000000 #define mod 1000000007 const ll INF = 10000000000000; using namespace std; ll optimalStrategyOfGame(ll arr[], int n) { ll table[n][n]; for (int gap = 0; gap < n; ++gap) { for (int i = 0, j = gap; j < n; ++i, ++j) { int x = ((i + 2) <= j ? table[i + 2][j] : 0); int y = ((i + 1) <= j - 1 ? table[i + 1][j - 1] : 0); int z = (i <= (j - 2) ? table[i][j - 2] : 0); table[i][j] = max(arr[i] + min(x, y), arr[j] + min(y, z)); } } return table[0][n - 1]; } int main() { IOS; int n; cin >> n; ll a[n]; ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } cout << 2 * optimalStrategyOfGame(a, n) - sum; return 0; }
#include <bits/stdc++.h> #include <iostream> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pii std::pair<int, int> #define pli std::pair<ll, int> #define pil std::pair<int, ll> #define psi std::pair<string, int> #define pll std::pair<ll, ll> #define pci std::pair<char, int> #define sll(x) scanf("%lld", &x) #define prll(x) printf("%lld ", x) #define pri(x) printf("%d ", x) #define si(x) scanf("%d", &x) #define pb push_back #define vll std::vector<ll> #define vpi std::vector<std::pair<int, int>> #define vi std::vector<int> #define vvi std::vector<std::vector<int>> #define vvpil std::vector<std::vector<std::pair<int, ll>>> #define vlpii std::vector<std::list<pii>> #define vlpil std::vector<std::list<pil>> #define li std::list<int> #define lpil std::list<pil> #define Endl printf("\n") #define vli vector<list<int>> #define vvll vector<vector<ll>> #define mp make_pair #define ma 100000000 #define mod 1000000007 const ll INF = 10000000000000; using namespace std; ll optimalStrategyOfGame(ll arr[], int n) { ll table[n][n]; for (int gap = 0; gap < n; ++gap) { for (int i = 0, j = gap; j < n; ++i, ++j) { ll x = ((i + 2) <= j ? table[i + 2][j] : 0); ll y = ((i + 1) <= j - 1 ? table[i + 1][j - 1] : 0); ll z = (i <= (j - 2) ? table[i][j - 2] : 0); table[i][j] = max(arr[i] + min(x, y), arr[j] + min(y, z)); } } return table[0][n - 1]; } int main() { IOS; int n; cin >> n; ll a[n]; ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } cout << 2 * optimalStrategyOfGame(a, n) - sum; return 0; }
[ "variable_declaration.type.change" ]
980,150
980,151
u752814744
cpp
p03171
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; int main() { int n; cin >> n; vector<ll> stk; while (n--) { ll a; cin >> a; // cout << a << endl; stk.push_back(a); int q = stk.size(); while (q > 2 && stk[q - 1] <= stk[q - 2] && stk[q - 3] <= stk[q - 2]) { int ne = stk[q - 1] + stk[q - 3] - stk[q - 2]; for (int i = 0; i < 3; i++) stk.pop_back(); stk.push_back(ne); q -= 2; } } ll sum = 0; deque<ll> q; for (auto p : stk) q.push_back(p); int z = 1; while (q.size()) { if (q.front() >= q.back()) { sum += q.front() * z; q.pop_front(); } else { sum += q.back() * z; q.pop_back(); } z *= -1; } cout << sum; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define all(x) x.begin(), x.end() using namespace std; int main() { int n; cin >> n; vector<ll> stk; while (n--) { ll a; cin >> a; // cout << a << endl; stk.push_back(a); int q = stk.size(); while (q > 2 && stk[q - 1] <= stk[q - 2] && stk[q - 3] <= stk[q - 2]) { ll ne = stk[q - 1] + stk[q - 3] - stk[q - 2]; for (int i = 0; i < 3; i++) stk.pop_back(); stk.push_back(ne); q -= 2; } } ll sum = 0; deque<ll> q; for (auto p : stk) q.push_back(p); int z = 1; while (q.size()) { if (q.front() >= q.back()) { sum += q.front() * z; q.pop_front(); } else { sum += q.back() * z; q.pop_back(); } z *= -1; } cout << sum; }
[ "variable_declaration.type.change" ]
980,156
980,157
u013064880
cpp
p03171
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define pb push_back #define pii pair<int, int> #define fast ios_base::sync_with_stdio(0) #define mx 3002 ll arr[mx], dp[mx][mx][2]; int n; ll fun(int b, int e, int turn) { turn %= 2; if (b > e) return 0; ll &ret = dp[b][e][turn]; if (ret != -1) return ret; if (turn == 0) { turn++; ret = max(arr[b] + fun(b + 1, e, turn), arr[e] + fun(b, e - 1, turn)); } else { turn++; ret = max(-arr[b] + fun(b + 1, e, turn), -arr[e] + fun(b, e - 1, turn)); } return ret; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &arr[i]); memset(dp, -1, sizeof dp); printf("%lld\n", fun(1, n, 0)); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define pb push_back #define pii pair<int, int> #define fast ios_base::sync_with_stdio(0) #define mx 3002 ll arr[mx], dp[mx][mx][2]; int n; ll fun(int b, int e, int turn) { turn %= 2; if (b > e) return 0; ll &ret = dp[b][e][turn]; if (ret != -1) return ret; if (turn == 0) { turn++; ret = max(arr[b] + fun(b + 1, e, turn), arr[e] + fun(b, e - 1, turn)); } else { turn++; ret = min(-arr[b] + fun(b + 1, e, turn), -arr[e] + fun(b, e - 1, turn)); } return ret; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &arr[i]); memset(dp, -1, sizeof dp); printf("%lld\n", fun(1, n, 0)); }
[ "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change" ]
980,167
980,168
u701914155
cpp
p03171
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define enl printf("\n") #define case (t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%I64d", &(n)) #define nai(a, n) \ for (int i = 0; i < (n); i++) \ ni(a[i]) #define nal(a, n) \ for (int i = 0; i < (n); i++) \ nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%I64d\n", (n)) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int, int, hash<int>> ht; const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 3e3 + 5; const double eps = 1e-9; int c[MAXN], vis[MAXN][MAXN][2]; ll dp[MAXN][MAXN][2]; void solve(int a, int b, int x) { if (vis[a][b][x]) return; if (a == b) { if (x) dp[a][b][x] = -c[a]; else dp[a][b][x] = c[a]; vis[a][b][x] = 1; return; } if (a < b) { solve(a, b - 1, x ^ 1); solve(a + 1, b, x ^ 1); if (x) dp[a][b][x] = min(dp[a][b - 1][x ^ 1] - c[b], dp[a + 1][b][x ^ 1] - c[a]); else dp[a][b][x] = max(dp[a][b - 1][x ^ 1] + c[b], dp[a + 1][b][x ^ 1] + c[a]); } vis[a][b][x] = 1; } int main() { int n; ni(n); nai(c, n); solve(0, n - 1, 0); prl(dp[0][n - 1][0]); return 0; }
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define enl printf("\n") #define case (t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%lld", &(n)) #define nai(a, n) \ for (int i = 0; i < (n); i++) \ ni(a[i]) #define nal(a, n) \ for (int i = 0; i < (n); i++) \ nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%lld\n", (n)) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int, int, hash<int>> ht; const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 3e3 + 5; const double eps = 1e-9; int c[MAXN], vis[MAXN][MAXN][2]; ll dp[MAXN][MAXN][2]; void solve(int a, int b, int x) { if (vis[a][b][x]) return; if (a == b) { if (x) dp[a][b][x] = -c[a]; else dp[a][b][x] = c[a]; vis[a][b][x] = 1; return; } if (a < b) { solve(a, b - 1, x ^ 1); solve(a + 1, b, x ^ 1); if (x) dp[a][b][x] = min(dp[a][b - 1][x ^ 1] - c[b], dp[a + 1][b][x ^ 1] - c[a]); else dp[a][b][x] = max(dp[a][b - 1][x ^ 1] + c[b], dp[a + 1][b][x ^ 1] + c[a]); } vis[a][b][x] = 1; } int main() { int n; ni(n); nai(c, n); solve(0, n - 1, 0); prl(dp[0][n - 1][0]); return 0; }
[ "preprocessor.define.value.change" ]
980,171
980,172
u270920804
cpp
p03171
#include <bits/stdc++.h> using namespace std; long long dp[3000][3000][2], cs[3000]; int a[3000]; long long calc(int l, int r, bool turn) { int t = a[l]; if (l == r) return t; if (dp[l][r][turn] != -1) return dp[l][r][turn]; long long seg = cs[r] - (l ? cs[l - 1] : 0); int A = seg - calc(l + 1, r, turn ^ 1), b = seg - calc(l, r - 1, turn ^ 1); dp[l][r][turn] = max(A, b); return dp[l][r][turn]; } int main() { ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < 3000; ++i) { memset(dp[i], -1, sizeof(dp[i])); } int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; cs[i] = a[i] + cs[i - bool(i)]; } cout << 2 * calc(0, n - 1, 1) - cs[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[3000][3000][2], cs[3000]; int a[3000]; long long calc(int l, int r, bool turn) { int t = a[l]; if (l == r) return t; if (dp[l][r][turn] != -1) return dp[l][r][turn]; long long seg = cs[r] - (l ? cs[l - 1] : 0); long long A = seg - calc(l + 1, r, turn ^ 1), b = seg - calc(l, r - 1, turn ^ 1); dp[l][r][turn] = max(A, b); return dp[l][r][turn]; } int main() { ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < 3000; ++i) { memset(dp[i], -1, sizeof(dp[i])); } int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; cs[i] = a[i] + cs[i - bool(i)]; } cout << 2 * calc(0, n - 1, 1) - cs[n - 1]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
980,176
980,177
u279627039
cpp
p03171
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/STACK:16777216") #include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define ff first #define ss second typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int maxn = 1e5 + 7; const int inf = 2e9 + 7; const ll infl = 1e18 + 7; const long double eps = 1e-9; const ll mod = 1e9 + 7; int main() { #ifdef _DEBUG freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // _DEBUG ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<int>> dp(n, vector<int>(n, 0)); bool f = true; if (n % 2 == 0) f = false; for (int j = 1; j <= n; j++) { for (int i = 0; i < n; i++) { if (i + j - 1 >= n) break; if (f) { if (j == 1) dp[i][i] = a[i]; else if (j % 2 == 1) { dp[i][i + j - 1] = max(dp[i][i + j - 2] + a[i + j - 1], dp[i + 1][i + j - 1] + a[i]); } else { dp[i][i + j - 1] = min(dp[i][i + j - 2] - a[i + j - 1], dp[i + 1][i + j - 1] - a[i]); } } else { if (j == 1) dp[i][i] = -a[i]; else if (j % 2 == 1) { dp[i][i + j - 1] = min(dp[i][i + j - 2] - a[i + j - 1], dp[i + 1][i + j - 1] - a[i]); } else { dp[i][i + j - 1] = max(dp[i][i + j - 2] + a[i + j - 1], dp[i + 1][i + j - 1] + a[i]); } } } } cout << dp[0][n - 1]; return 0; }
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/STACK:16777216") #include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define ff first #define ss second typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int maxn = 1e5 + 7; const int inf = 2e9 + 7; const ll infl = 1e18 + 7; const long double eps = 1e-9; const ll mod = 1e9 + 7; int main() { #ifdef _DEBUG freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // _DEBUG ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<ll>> dp(n, vector<ll>(n, 0)); bool f = true; if (n % 2 == 0) f = false; for (int j = 1; j <= n; j++) { for (int i = 0; i < n; i++) { if (i + j - 1 >= n) break; if (f) { if (j == 1) dp[i][i] = a[i]; else if (j % 2 == 1) { dp[i][i + j - 1] = max(dp[i][i + j - 2] + a[i + j - 1], dp[i + 1][i + j - 1] + a[i]); } else { dp[i][i + j - 1] = min(dp[i][i + j - 2] - a[i + j - 1], dp[i + 1][i + j - 1] - a[i]); } } else { if (j == 1) dp[i][i] = -a[i]; else if (j % 2 == 1) { dp[i][i + j - 1] = min(dp[i][i + j - 2] - a[i + j - 1], dp[i + 1][i + j - 1] - a[i]); } else { dp[i][i + j - 1] = max(dp[i][i + j - 2] + a[i + j - 1], dp[i + 1][i + j - 1] + a[i]); } } } } cout << dp[0][n - 1]; return 0; }
[ "call.arguments.change" ]
980,190
980,191
u562824357
cpp
p03171
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define snuke srand((unsigned)clock() + (unsigned)time(NULL)); #define show(x) cout << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline istream &operator>>(istream &i, v(T) & v) { rep(j, sz(v)) i >> v[j]; return i; } template <typename T> string join(const v(T) & v) { stringstream s; rep(i, sz(v)) s << ' ' << v[i]; return s.str().substr(1); } template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) { if (sz(v)) o << join(v); return o; } template <typename T1, typename T2> inline istream &operator>>(istream &i, pair<T1, T2> &v) { return i >> v.fi >> v.se; } template <typename T1, typename T2> inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) { return o << v.fi << "," << v.se; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame \ { \ puts("-1"); \ return 0; \ } #define yn \ { puts("YES"); } \ else { \ puts("NO"); \ } const int MX = 3005; // ll solve(vi a) { // if (sz(a)&1) { // ll res = 0; // rep(i,sz(a)) res += (i&1)?-a[i]:a[i]; // return res; // } // ll res = -LINF; // rep(ti,2) { // vi b = a; // ll now = 0; // if (ti) { // now = b.back(); // b.pop_back(); // now -= solve(b); // } else { // now = b[0]; // b.erase(b.begin()); // now -= solve(b); // } // maxs(res,now); // } // return res; // } ll dp[MX][MX]; int used[MX][MX]; vi a; ll dfs(int l, int r) { if (l == r) return 0; if (used[l][r]) return dp[l][r]; used[l][r] = 1; ll res = 0; maxs(res, a[l] - dfs(l + 1, r)); maxs(res, a[r - 1] - dfs(l, r - 1)); return dp[l][r] = res; } int main() { int n; scanf("%d", &n); a = vi(n); cin >> a; // ll ans = solve(a); // cout<<ans<<endl; cout << dfs(0, n) << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define snuke srand((unsigned)clock() + (unsigned)time(NULL)); #define show(x) cout << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline istream &operator>>(istream &i, v(T) & v) { rep(j, sz(v)) i >> v[j]; return i; } template <typename T> string join(const v(T) & v) { stringstream s; rep(i, sz(v)) s << ' ' << v[i]; return s.str().substr(1); } template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) { if (sz(v)) o << join(v); return o; } template <typename T1, typename T2> inline istream &operator>>(istream &i, pair<T1, T2> &v) { return i >> v.fi >> v.se; } template <typename T1, typename T2> inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) { return o << v.fi << "," << v.se; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame \ { \ puts("-1"); \ return 0; \ } #define yn \ { puts("YES"); } \ else { \ puts("NO"); \ } const int MX = 3005; // ll solve(vi a) { // if (sz(a)&1) { // ll res = 0; // rep(i,sz(a)) res += (i&1)?-a[i]:a[i]; // return res; // } // ll res = -LINF; // rep(ti,2) { // vi b = a; // ll now = 0; // if (ti) { // now = b.back(); // b.pop_back(); // now -= solve(b); // } else { // now = b[0]; // b.erase(b.begin()); // now -= solve(b); // } // maxs(res,now); // } // return res; // } ll dp[MX][MX]; int used[MX][MX]; vi a; ll dfs(int l, int r) { if (l == r) return 0; if (used[l][r]) return dp[l][r]; used[l][r] = 1; ll res = -LINF; maxs(res, a[l] - dfs(l + 1, r)); maxs(res, a[r - 1] - dfs(l, r - 1)); return dp[l][r] = res; } int main() { int n; scanf("%d", &n); a = vi(n); cin >> a; // ll ans = solve(a); // cout<<ans<<endl; cout << dfs(0, n) << endl; return 0; }
[ "expression.operation.unary.add" ]
980,192
980,193
u457283867
cpp
p03171
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> P2; typedef pair<pair<int, int>, int> P3; typedef pair<pair<int, int>, pair<int, int>> P4; #define PB(a) push_back(a) #define MP(a, b) make_pair((a), (b)) #define M3P(a, b, c) make_pair(make_pair((a), (b)), (c)) #define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d))) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i) int main() { int N; cin >> N; vector<int> a(N); repp(i, 0, N) cin >> a[i]; vector<vector<int>> dp(N, vector<int>(N, 0)); repp(i, 0, N) dp[i][i] = a[i]; repp(d, 1, N) repp(i, 0, N - d) { int j = i + d; if (d & 1) { dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j]); } else { dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j]); } } cout << dp[0][N - 1] * (N % 2 == 0 ? -1 : 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> P2; typedef pair<pair<int, int>, int> P3; typedef pair<pair<int, int>, pair<int, int>> P4; #define PB(a) push_back(a) #define MP(a, b) make_pair((a), (b)) #define M3P(a, b, c) make_pair(make_pair((a), (b)), (c)) #define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d))) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i) int main() { int N; cin >> N; vector<LL> a(N); repp(i, 0, N) cin >> a[i]; vector<vector<LL>> dp(N, vector<LL>(N, 0)); repp(i, 0, N) dp[i][i] = a[i]; repp(d, 1, N) repp(i, 0, N - d) { int j = i + d; if (d & 1) { dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j]); } else { dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j]); } } cout << dp[0][N - 1] * (N % 2 == 0 ? -1 : 1) << endl; return 0; }
[ "call.arguments.change" ]
980,196
980,197
u007446928
cpp
p03172
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <iostream> #include <map> #include <math.h> #include <stack> #include <string.h> #include <unordered_map> #include <vector> using namespace std; const int INF = 1e9; #define ll long long #define int ll #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define testcase \ int t; \ cin >> t; \ while (t--) #define pb push_back #define endl "\n" #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(x, y, z, w) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #w << ": " << w << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(a) int((a).size()) #define pii pair<int, int> #define fi first #define se second #define ld long double #define vii vector<int> #define all(v) v.begin(), v.end() #define prec(n) fixed << setprecision(n) const int MOD = (int)1e9 + 7; const int MOD2 = 1007681537; const ll LINF = (ll)1e18; const ld PI = acos((ld)-1); const ld EPS = 1e-12; inline ll gcd(ll a, ll b) { ll r; while (b) { r = a % b; a = b; b = r; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll fpow(ll n, ll k, int p = MOD) { ll r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; } template <class T> inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; } inline void addmod(int &a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int &a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; } inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } template <class T> inline void get_arr(T arr[], int n) { for (int i = 0; i < n; i++) cin >> arr[i]; } template <class T> inline void print_arr(T arr[], int n) { for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } int32_t main() { int n, k; cin >> n >> k; vector<int> dp(n + 1); dp[0] = 1; for (int child = 0; child < n; child++) { int upto; cin >> upto; vii fake(k + 1); for (int used = k; used >= 0; used--) { int tmp = dp[used]; int L = used + 1; int R = used + min(upto, k - used); if (L <= R) { addmod(fake[L], tmp); if (R + 1 <= k) { submod(fake[R + 1], tmp); } } } int presum = 0; for (int i = 0; i <= k; i++) { addmod(presum, fake[i]); addmod(dp[i], presum); } } cout << dp[k] << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <iostream> #include <map> #include <math.h> #include <stack> #include <string.h> #include <unordered_map> #include <vector> using namespace std; const int INF = 1e9; #define ll long long #define int ll #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define testcase \ int t; \ cin >> t; \ while (t--) #define pb push_back #define endl "\n" #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(x, y, z, w) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << " | " << #w << ": " << w << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(a) int((a).size()) #define pii pair<int, int> #define fi first #define se second #define ld long double #define vii vector<int> #define all(v) v.begin(), v.end() #define prec(n) fixed << setprecision(n) const int MOD = (int)1e9 + 7; const int MOD2 = 1007681537; const ll LINF = (ll)1e18; const ld PI = acos((ld)-1); const ld EPS = 1e-12; inline ll gcd(ll a, ll b) { ll r; while (b) { r = a % b; a = b; b = r; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll fpow(ll n, ll k, int p = MOD) { ll r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; } template <class T> inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; } inline void addmod(int &a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int &a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; } inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } template <class T> inline void get_arr(T arr[], int n) { for (int i = 0; i < n; i++) cin >> arr[i]; } template <class T> inline void print_arr(T arr[], int n) { for (int i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; } int32_t main() { int n, k; cin >> n >> k; vector<int> dp(k + 1); dp[0] = 1; for (int child = 0; child < n; child++) { int upto; cin >> upto; vii fake(k + 1); for (int used = k; used >= 0; used--) { int tmp = dp[used]; int L = used + 1; int R = used + min(upto, k - used); if (L <= R) { addmod(fake[L], tmp); if (R + 1 <= k) { submod(fake[R + 1], tmp); } } } int presum = 0; for (int i = 0; i <= k; i++) { addmod(presum, fake[i]); addmod(dp[i], presum); } } cout << dp[k] << endl; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
980,212
980,213
u556783345
cpp
p03172
#include <bits/stdc++.h> #define ll long long int const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; ll dpp[k + 1] = {0}; dpp[0] = 1; for (int i = 0; i < n; i++) { int curr_lim; cin >> curr_lim; ll dp[k + 1] = {0}; for (int already = k; already >= 0; --already) { int l = already + 1; int r = already + min(k - already, curr_lim); if (l <= r) { dp[l] = (dp[l] + dpp[already + MOD]) % MOD; if (r + 1 <= k) { dp[r + 1] = (dp[r + 1] - dpp[already + MOD]) % MOD; } } } ll pre = 0; for (int j = 0; j <= k; j++) { pre = (pre + dp[j] + MOD) % MOD; dpp[j] = (dpp[j] + pre + MOD) % MOD; } } cout << dpp[k]; return 0; }
#include <bits/stdc++.h> #define ll long long int const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; ll dpp[k + 1] = {0}; dpp[0] = 1; for (int i = 0; i < n; i++) { int curr_lim; cin >> curr_lim; ll dp[k + 1] = {0}; for (int already = k; already >= 0; --already) { int l = already + 1; int r = already + min(k - already, curr_lim); if (l <= r) { dp[l] = (dp[l] + dpp[already] + MOD) % MOD; if (r + 1 <= k) { dp[r + 1] = (dp[r + 1] - dpp[already] + MOD) % MOD; } } } ll pre = 0; for (int j = 0; j <= k; j++) { pre = (pre + dp[j] + MOD) % MOD; dpp[j] = (dpp[j] + pre + MOD) % MOD; } } cout << dpp[k]; return 0; }
[]
980,214
980,215
u863091189
cpp
p03172
#include <bits/stdc++.h> #define ll long long int const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int dpp[k + 1] = {0}; dpp[0] = 1; for (int i = 0; i < n; i++) { int curr_lim; cin >> curr_lim; int dp[k + 1] = {0}; for (int already = k; already >= 0; --already) { int l = already + 1; int r = already + min(k - already, curr_lim); if (l <= r) { dp[l] = (dp[l] + dpp[already] + MOD) % MOD; if (r + 1 <= k) { dp[r + 1] = (dp[r + 1] - dpp[already] + MOD) % MOD; } } } int pre = 0; for (int j = 0; j <= k; j++) { pre = (pre + dp[j] + MOD) % MOD; dpp[j] = (dpp[j] + pre + MOD) % MOD; } } cout << dpp[k]; return 0; }
#include <bits/stdc++.h> #define ll long long int const int MOD = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; ll dpp[k + 1] = {0}; dpp[0] = 1; for (int i = 0; i < n; i++) { int curr_lim; cin >> curr_lim; ll dp[k + 1] = {0}; for (int already = k; already >= 0; --already) { int l = already + 1; int r = already + min(k - already, curr_lim); if (l <= r) { dp[l] = (dp[l] + dpp[already] + MOD) % MOD; if (r + 1 <= k) { dp[r + 1] = (dp[r + 1] - dpp[already] + MOD) % MOD; } } } ll pre = 0; for (int j = 0; j <= k; j++) { pre = (pre + dp[j] + MOD) % MOD; dpp[j] = (dpp[j] + pre + MOD) % MOD; } } cout << dpp[k]; return 0; }
[ "variable_declaration.type.change" ]
980,216
980,215
u863091189
cpp
p03172
#include <iostream> // @idea: digit dp // n: total number of children // s : current number of candies // dp(i, s) : all the ways s candies can be distributed from [1...i] using namespace std; const int NMAX = 1e2 + 11; const int KMAX = 1e5 + 11; const int MOD = 1e9 + 7; int n, k, a[NMAX], acc[KMAX], dp[NMAX][KMAX]; int solve(void) { dp[0][0] = 1; for (int s = 1; s <= k; ++s) dp[0][s] = 0; for (int i = 1; i <= n; ++i) { acc[0] = dp[i - 1][0]; for (int s = 1; s <= k; ++s) acc[s] = (acc[s - 1] + dp[i - 1][s]) % MOD; // reachable = [s - a[i], s] for (int s = 0; s <= k; ++s) dp[i][s] = (acc[s] - (s - a[i] - 1 >= 0 ? acc[s - a[i] - 1] : 0)) % MOD; } return dp[n][k]; } int main(void) { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << solve() << endl; return 0; }
#include <iostream> // @idea: digit dp // n: total number of children // s : current number of candies // dp(i, s) : all the ways s candies can be distributed from [1...i] using namespace std; const int NMAX = 1e2 + 11; const int KMAX = 1e5 + 11; const int MOD = 1e9 + 7; int n, k, a[NMAX], acc[KMAX], dp[NMAX][KMAX]; int solve(void) { dp[0][0] = 1; for (int s = 1; s <= k; ++s) dp[0][s] = 0; for (int i = 1; i <= n; ++i) { // 1. If the prefix sum exceeds MOD, it will not be strictly increasing acc[0] = dp[i - 1][0]; for (int s = 1; s <= k; ++s) acc[s] = (acc[s - 1] + dp[i - 1][s]) % MOD; // 2. reachable = [s - a[i], s] for (int s = 0; s <= k; ++s) dp[i][s] = (acc[s] - (s - a[i] - 1 >= 0 ? acc[s - a[i] - 1] : 0) + MOD) % MOD; // take care of possible negative results. See 1. } return dp[n][k]; } int main(void) { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << solve() << endl; return 0; }
[ "assignment.change" ]
980,219
980,220
u508183081
cpp
p03172
#include <iostream> // @idea: digit dp // n: total number of children // s : current number of candies // dp(i, s) : all the ways s candies can be distributed from [1...i] using namespace std; const int NMAX = 1e2 + 11; const int KMAX = 1e5 + 11; const int MOD = 1e9 + 7; int n, k, a[NMAX], acc[KMAX], dp[NMAX][KMAX]; int solve(void) { dp[0][0] = 1; for (int s = 1; s <= k; ++s) dp[0][s] = 0; for (int i = 1; i <= n; ++i) { acc[0] = dp[i - 1][0]; for (int s = 1; s <= k; ++s) acc[s] = (acc[s - 1] + dp[i - 1][s]) % MOD; // reachable = [s - a[i], s] for (int s = 0; s <= k; ++s) dp[i][s] = acc[s] - (s - a[i] - 1 >= 0 ? acc[s - a[i] - 1] : 0); } return dp[n][k]; } int main(void) { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << solve() << endl; return 0; }
#include <iostream> // @idea: digit dp // n: total number of children // s : current number of candies // dp(i, s) : all the ways s candies can be distributed from [1...i] using namespace std; const int NMAX = 1e2 + 11; const int KMAX = 1e5 + 11; const int MOD = 1e9 + 7; int n, k, a[NMAX], acc[KMAX], dp[NMAX][KMAX]; int solve(void) { dp[0][0] = 1; for (int s = 1; s <= k; ++s) dp[0][s] = 0; for (int i = 1; i <= n; ++i) { // 1. If the prefix sum exceeds MOD, it will not be strictly increasing acc[0] = dp[i - 1][0]; for (int s = 1; s <= k; ++s) acc[s] = (acc[s - 1] + dp[i - 1][s]) % MOD; // 2. reachable = [s - a[i], s] for (int s = 0; s <= k; ++s) dp[i][s] = (acc[s] - (s - a[i] - 1 >= 0 ? acc[s - a[i] - 1] : 0) + MOD) % MOD; // take care of possible negative results. See 1. } return dp[n][k]; } int main(void) { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << solve() << endl; return 0; }
[ "assignment.change" ]
980,221
980,220
u508183081
cpp
p03172
#include <iostream> // @idea: digit dp // n: total number of children // s : current number of candies // dp(i, s) : all the ways s candies can be distributed from [1...i] using namespace std; const int NMAX = 1e2 + 11; const int KMAX = 1e5 + 11; const int MOD = 1e9 + 7; int n, k, a[NMAX], acc[KMAX], dp[NMAX][KMAX]; int solve(void) { dp[0][0] = 1; for (int s = 1; s <= k; ++s) dp[0][s] = 0; for (int i = 1; i <= n; ++i) { acc[0] = dp[i - 1][0]; for (int s = 1; s <= k; ++s) acc[s] = (acc[s - 1] + dp[i - 1][s]) % MOD; // reachable = [s - a[i], s] for (int s = 0; s <= k; ++s) dp[i][s] = acc[s] - (s - a[i] - 1 >= 0 ? acc[s - a[i] - 1] : 0); } return dp[n][k]; } int main(void) { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << solve() << endl; return 0; }
#include <iostream> // @idea: digit dp // n: total number of children // s : current number of candies // dp(i, s) : all the ways s candies can be distributed from [1...i] using namespace std; const int NMAX = 1e2 + 11; const int KMAX = 1e5 + 11; const int MOD = 1e9 + 7; int n, k, a[NMAX], acc[KMAX], dp[NMAX][KMAX]; int solve(void) { dp[0][0] = 1; for (int s = 1; s <= k; ++s) dp[0][s] = 0; for (int i = 1; i <= n; ++i) { acc[0] = dp[i - 1][0]; for (int s = 1; s <= k; ++s) acc[s] = (acc[s - 1] + dp[i - 1][s]) % MOD; // reachable = [s - a[i], s] for (int s = 0; s <= k; ++s) dp[i][s] = (acc[s] - (s - a[i] - 1 >= 0 ? acc[s - a[i] - 1] : 0) + MOD) % MOD; } return dp[n][k]; } int main(void) { cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; cout << solve() << endl; return 0; }
[ "assignment.change" ]
980,221
980,222
u508183081
cpp
p03172
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int dp[N + 1][K + 1] = {}; vector<int> a(N + 1, 0); for (int i = 1; i <= N; ++i) { int tmp; cin >> tmp; a.at(i) = tmp; } for (int i = 0; i <= N; ++i) { dp[i][0] = 1; } for (int i = 1; i <= N; ++i) { for (int j = 1; j <= K; ++j) { dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % 1000000007; if (j - a.at(i) - 1 >= 0) { int tt = dp[i - 1][j - a.at(i) - 1]; dp[i][j] = (dp[i][j] - tt) % 1000000007; } // for(int l = 0; l <= a.at(i); ++l) // { // if(j-l >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j-l]) % 1000000007; // } } } cout << dp[N][K] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int dp[N + 1][K + 1] = {}; vector<int> a(N + 1, 0); for (int i = 1; i <= N; ++i) { int tmp; cin >> tmp; a.at(i) = tmp; } for (int i = 0; i <= N; ++i) { dp[i][0] = 1; } for (int i = 1; i <= N; ++i) { for (int j = 1; j <= K; ++j) { dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i][j - 1]) % 1000000007; if (j - a.at(i) - 1 >= 0) { int tt = dp[i - 1][j - a.at(i) - 1]; dp[i][j] = (dp[i][j] + 1000000007 - tt) % 1000000007; } // for(int l = 0; l <= a.at(i); ++l) // { // if(j-l >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j-l]) % 1000000007; // } } } cout << dp[N][K] << endl; return 0; }
[ "assignment.change" ]
980,223
980,224
u150012595
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define ll long long #define PII pair<ll, ll> #define VI vector<ll> #define VB vector<bool> #define VC vector<char> #define VVI vector<vector<ll>> #define VVC vector<vector<char>> #define VS vector<string> #define VP vector<PII> #define lf(i, a, b) for (ll i = a; i <= b; i++) #define lr(i, a, b) for (ll i = a; i >= b; i--) #define lfl(i, v) for (ll i = 0; i < v.size(); i++) #define lrl(i, v) for (ll i = (ll)(v.size()) - 1; i >= 0; i--) #define chk2(a, b) cout << "check : " << a << " " << b << endl #define chk3(a, b, c) cout << "check : " << a << " " << b << " " << c << endl #define chk4(a, b, c, d) \ cout << "check : " << a << " " << b << " " << c << " " << d << endl #define chk5(a, b, c, d, e) \ cout << "check : " << a << " " << b << " " << c << " " << d << " " << e \ << endl #define l_b(v, k) lower_bound(v.begin(), v.end(), k) - v.begin() #define u_b(v, k) upper_bound(v.begin(), v.end(), k) - v.begin() #define mod 1000000007 #define sort(v) sort(v.begin(), v.end()) #define p_b push_back #define p_f push_front #define m_p make_pair #define fir first #define sec second #define sz size() ll n, m, k; VI v; int main() { cin >> n >> k; v = VI(n + 1); VVI dp(n + 1, VI(k + 1, 0)); lf(i, 1, n) cin >> v[i]; ll ans; lf(i, 0, n) { lf(j, 0, k) { if (i == 0 && j == 0) dp[i][j] = 1; else if (i > 0) { ll minind = min(v[i], j); ll sum = 0; if (minind < j) sum = dp[i - 1][j] - dp[i - 1][j - minind - 1]; else sum = dp[i - 1][j]; dp[i][j] = sum % mod; } if (i == n && j == k) ans = dp[i][j]; } lf(j, 1, k) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define PII pair<ll, ll> #define VI vector<ll> #define VB vector<bool> #define VC vector<char> #define VVI vector<vector<ll>> #define VVC vector<vector<char>> #define VS vector<string> #define VP vector<PII> #define lf(i, a, b) for (ll i = a; i <= b; i++) #define lr(i, a, b) for (ll i = a; i >= b; i--) #define lfl(i, v) for (ll i = 0; i < v.size(); i++) #define lrl(i, v) for (ll i = (ll)(v.size()) - 1; i >= 0; i--) #define chk2(a, b) cout << "check : " << a << " " << b << endl #define chk3(a, b, c) cout << "check : " << a << " " << b << " " << c << endl #define chk4(a, b, c, d) \ cout << "check : " << a << " " << b << " " << c << " " << d << endl #define chk5(a, b, c, d, e) \ cout << "check : " << a << " " << b << " " << c << " " << d << " " << e \ << endl #define l_b(v, k) lower_bound(v.begin(), v.end(), k) - v.begin() #define u_b(v, k) upper_bound(v.begin(), v.end(), k) - v.begin() #define mod 1000000007 #define sort(v) sort(v.begin(), v.end()) #define p_b push_back #define p_f push_front #define m_p make_pair #define fir first #define sec second #define sz size() ll n, m, k; VI v; int main() { cin >> n >> k; v = VI(n + 1); VVI dp(n + 1, VI(k + 1, 0)); lf(i, 1, n) cin >> v[i]; ll ans; lf(i, 0, n) { lf(j, 0, k) { if (i == 0 && j == 0) dp[i][j] = 1; else if (i > 0) { ll minind = min(v[i], j); ll sum = 0; if (minind < j) sum = dp[i - 1][j] - dp[i - 1][j - minind - 1]; else sum = dp[i - 1][j]; dp[i][j] = (sum + mod) % mod; } if (i == n && j == k) ans = dp[i][j]; } lf(j, 1, k) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; } cout << ans << endl; }
[]
980,227
980,228
u752324944
cpp
p03172
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100 + 5; const int K = 1e5 + 5; const int MOD = 1e9 + 7; ll dp[N][K]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { vector<int> sum(k + 1); sum[0] = dp[i - 1][0]; for (int j = 1; j <= k; j++) { sum[j] = (sum[j - 1] + dp[i - 1][j]) % MOD; } for (int j = 0; j <= k; j++) { // for (int give = 0; give <= min(a[i], j); give++) { // (dp[i][j] += dp[i - 1][j - give]) %= MOD; // } int add = sum[j]; int leave = j - a[i] - 1; if (leave >= 0) { add = (add + sum[leave] + MOD) % MOD; } dp[i][j] = add; } } cout << dp[n][k] << '\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100 + 5; const int K = 1e5 + 5; const int MOD = 1e9 + 7; ll dp[N][K]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { vector<int> sum(k + 1); sum[0] = dp[i - 1][0]; for (int j = 1; j <= k; j++) { sum[j] = (sum[j - 1] + dp[i - 1][j]) % MOD; } for (int j = 0; j <= k; j++) { // for (int give = 0; give <= min(a[i], j); give++) { // (dp[i][j] += dp[i - 1][j - give]) %= MOD; // } int add = sum[j]; int leave = j - a[i] - 1; if (leave >= 0) { add = (add - sum[leave] + MOD) % MOD; } dp[i][j] = add; } } cout << dp[n][k] << '\n'; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "expression.operation.binary.change" ]
980,229
980,230
u927525869
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int dp[n + 1][k + 1]; dp[0][0] = 1; for (int i = 1; i <= k; i++) { dp[0][i] = 0; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD - ((j - 1 - arr[i - 1] >= 0) ? dp[i - 1][j - 1 - arr[i - 1]] : 0); } } } cout << dp[n][k]; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } int dp[n + 1][k + 1]; dp[0][0] = 1; for (int i = 1; i <= k; i++) { dp[0][i] = 0; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) % MOD - ((j - 1 - arr[i - 1] >= 0) ? dp[i - 1][j - 1 - arr[i - 1]] : 0) + MOD) % MOD; } } } cout << dp[n][k]; return 0; }
[ "assignment.change" ]
980,250
980,251
u284577220
cpp
p03172
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; #define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl int add(int a, int b) { return (a + b < MOD) ? (a + b) : (a + b - MOD); } int sub(int a, int b) { return (a > b) ? (a - b) : (a - b + MOD); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> dp(k + 1, 1), cp(k + 1, 0); for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { int l = max(j - a[i], 0), r = j; cp[j] = (l > 0) ? sub(dp[r], dp[l - 1]) : dp[r]; if (j > 0) { cp[j] = add(cp[j], cp[j - 1]); } } dp = cp; } dp[k] = sub(dp[k], ((k > 0) ? dp[k - 1] : 0)); cout << dp[k] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; #define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl int add(int a, int b) { return (a + b < MOD) ? (a + b) : (a + b - MOD); } int sub(int a, int b) { return (a >= b) ? (a - b) : (a - b + MOD); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> dp(k + 1, 1), cp(k + 1, 0); for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { int l = max(j - a[i], 0), r = j; cp[j] = (l > 0) ? sub(dp[r], dp[l - 1]) : dp[r]; if (j > 0) { cp[j] = add(cp[j], cp[j - 1]); } } dp = cp; } dp[k] = sub(dp[k], ((k > 0) ? dp[k - 1] : 0)); cout << dp[k] << '\n'; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "function.return_value.change", "expression.operation.binary.change" ]
980,266
980,267
u222758739
cpp
p03172
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define mod 1e9 + 7 #define pb push_back void add_self(int &here, int y) { here += y; if (here > mod) here -= mod; return; } void sub_self(int &here, int y) { here -= y; if (here < 0) here += mod; return; } int main(void) { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> dp(k + 1, 0); // dp[i] - used candies dp[0] = 1; for (int i = 0; i < n; i++) { // n children vector<int> fake(k + 1); for (int used = k; used >= 0; used--) { int l = used + 1; int r = used + min(k - used, a[i]); if (l <= r) { add_self(fake[l], dp[used]); if (r < k) { sub_self(fake[r + 1], dp[used]); } } } int temp = 0; for (int x = 0; x <= k; x++) { add_self(temp, fake[x]); add_self(dp[x], temp); } } cout << dp[k] << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define mod 1e9 + 7 #define pb push_back void add_self(int &here, int y) { here += y; if (here >= mod) here -= mod; return; } void sub_self(int &here, int y) { here -= y; if (here <= 0) here += mod; return; } int main(void) { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> dp(k + 1, 0); // dp[i] - used candies dp[0] = 1; for (int i = 0; i < n; i++) { // n children vector<int> fake(k + 1); for (int used = k; used >= 0; used--) { int l = used + 1; int r = used + min(k - used, a[i]); if (l <= r) { add_self(fake[l], dp[used]); if (r < k) { sub_self(fake[r + 1], dp[used]); } } } int temp = 0; for (int x = 0; x <= k; x++) { add_self(temp, fake[x]); add_self(dp[x], temp); } } cout << dp[k] << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
980,275
980,276
u894836225
cpp
p03172
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1]) % mod; } cout << dp[k] % mod << endl; return 0; }
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1] + mod) % mod; } cout << dp[k] << endl; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
980,285
980,286
u889896098
cpp
p03172
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1]) % mod; } cout << dp[k] << endl; return 0; }
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1] + mod) % mod; } cout << dp[k] << endl; return 0; }
[ "assignment.change" ]
980,287
980,286
u889896098
cpp
p03172
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1]) % mod; } cout << dp[k] % mod << endl; return 0; }
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1] + mod) % mod; } cout << dp[k] % mod << endl; return 0; }
[ "assignment.change" ]
980,285
980,288
u889896098
cpp
p03172
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1]) % mod; } cout << dp[k] << endl; return 0; }
#include <bits/stdc++.h> #define int long long int // comment for large arrays #define pll pair<int, int> #define dbl long double #define ff first #define ss second #define endl "\n" #define mod 1000000007 #define eps 0.00000001 #define INF 10000000000000001 #define all(x) (x).begin(), (x).end() #define LB(v, x) (lower_bound(all(v), x) - v.begin()) #define UB(v, x) (upper_bound(all(v), x) - v.begin()) #define size(x) (int)(x).size() #define pb(x) push_back(x) #define pf(x) push_front(x) #define popb() pop_back() #define popf() pop_front() #define mp(x, y) make_pair((x), (y)) #define vec(dt) vector<dt> #define vv(dt) vector<vector<dt>> #define fastio(x) \ ios_base::sync_with_stdio(x); \ cin.tie(NULL) #define init(v, s) memset(v, s, sizeof(v)) #define bug(x) \ cerr << "LINE: " << __LINE__ << " || click to see test details " << #x \ << " = " << x << endl #define loop(i, s, n) for (int i = s; i < n; i++) #define print(v) \ for (auto it : v) \ cout << it << " "; \ cout << endl using namespace std; signed main() { fastio(0); int n, k; cin >> n >> k; int a[n + 1], dp[k + 1]; loop(i, 1, n + 1) cin >> a[i]; init(dp, 0); loop(i, 0, k + 1) if (i <= a[1]) dp[i] = 1; loop(i, 2, n + 1) { loop(j, 1, k + 1) dp[j] = (dp[j] + dp[j - 1]) % mod; for (int j = k; j > 0; j--) if (j > a[i]) dp[j] = (dp[j] - dp[j - a[i] - 1] + mod) % mod; } cout << dp[k] % mod << endl; return 0; }
[ "assignment.change" ]
980,287
980,288
u889896098
cpp
p03172
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using namespace std; #define a_macro(args...) sum(args) #define mp make_pair #define eb emplace_back #define mt make_tuple #define fi first #define se second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef long long ll; const ll mod = 1e9 + 7; typedef tuple<int, int, int> State; // operator< defined typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef double ld; int main(int argc, const char **argv) { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k, i, j, l; cin >> n >> k; int a[n]; for (i = 0; i < n; ++i) cin >> a[i]; ll dp[n + 2][k + 1]; // memset(dp,0,sizeof(dp)); for (i = 0; i <= k; ++i) { dp[1][i] = (i > a[1]) ? 0 : 1; } for (i = 2; i <= n; ++i) { for (j = 0; j <= k; ++j) { if (j == 0) dp[i][j] = dp[i - 1][j]; else dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] - ((j - a[i - 1] - 1 >= 0) ? dp[i - 1][j - a[i - 1] - 1] : 0)) % mod; } } cout << dp[n][k]; #ifndef LOCAL_DEFINE cerr << "Time elapsed: " << 1e1 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif // LOCAL_DEFINE return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; using namespace std; #define a_macro(args...) sum(args) #define mp make_pair #define eb emplace_back #define mt make_tuple #define fi first #define se second #define pb push_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef long long ll; const ll mod = 1e9 + 7; typedef tuple<int, int, int> State; // operator< defined typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef double ld; int main(int argc, const char **argv) { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k, i, j, l; cin >> n >> k; int a[n]; for (i = 0; i < n; ++i) cin >> a[i]; ll dp[n + 2][k + 1]; // memset(dp,0,sizeof(dp)); for (i = 0; i <= k; ++i) { dp[1][i] = (i > a[0]) ? 0 : 1; } for (i = 2; i <= n; ++i) { for (j = 0; j <= k; ++j) { if (j == 0) dp[i][j] = dp[i - 1][j]; else dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] - ((j - a[i - 1] - 1 >= 0) ? dp[i - 1][j - a[i - 1] - 1] : 0)) % mod; } } cout << dp[n][k]; #ifndef LOCAL_DEFINE cerr << "Time elapsed: " << 1e1 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif // LOCAL_DEFINE return 0; }
[ "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
980,302
980,303
u450304927
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define watch(x) cout << (#x) << " is " << (x) << endl #define f(t) for (ll i = 0; i < t; i++) #define bs(a, x) binary_search(a.begin(), a.end(), x) #define ll long long int #define ul unsigned long int #define ld long double #define umpi unordered_map<int, int> #define umpl unordered_map<ll, ll> #define vi vector<int> #define vl vector<ll> #define pb push_back #define mod 1000000007 #define N 10000000 #define all(a) a.begin(), a.end() #define point pair<int, int> const int inf = 1000000007; const ll linf = 1ll * inf * inf; inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; } inline ll sub(ll a, ll b) { ll c = a - b; if (c < 0) c += mod; return c; } inline ll add(ll a, ll b) { ll c = a + b; if (c > mod) c -= mod; return c; } struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; int main() { fio; ll t; t = 1; while (t--) { ll n, k; cin >> n >> k; vl a(n); f(n) cin >> a[i]; ll dp[k + 1]; memset(dp, 0, sizeof(dp)); dp[0] = 1; for (ll i = 0; i < n; i++) { vl fake(k + 1, 0); for (ll used = k; used >= 0; used--) { ll l = used + 1; ll r = used + min(a[i], k - used); if (l <= r) { fake[l] = add(fake[l], dp[used]); if (r + 1 <= k) { fake[r + 1] = sub(fake[r + 1], dp[used]); } } } ll sum = 0; for (ll j = 0; j <= k; j++) { sum = add(sum, fake[j]); dp[j] = add(dp[j], sum); } } cout << dp[k] << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define watch(x) cout << (#x) << " is " << (x) << endl #define f(t) for (ll i = 0; i < t; i++) #define bs(a, x) binary_search(a.begin(), a.end(), x) #define ll long long int #define ul unsigned long int #define ld long double #define umpi unordered_map<int, int> #define umpl unordered_map<ll, ll> #define vi vector<int> #define vl vector<ll> #define pb push_back #define mod 1000000007 #define N 10000000 #define all(a) a.begin(), a.end() #define point pair<int, int> const int inf = 1000000007; const ll linf = 1ll * inf * inf; inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; } inline ll sub(ll a, ll b) { ll c = a - b; if (c < 0) c += mod; return c; } inline ll add(ll a, ll b) { ll c = a + b; if (c >= mod) c -= mod; return c; } struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; int main() { fio; ll t; t = 1; while (t--) { ll n, k; cin >> n >> k; vl a(n); f(n) cin >> a[i]; ll dp[k + 1]; memset(dp, 0, sizeof(dp)); dp[0] = 1; for (ll i = 0; i < n; i++) { vl fake(k + 1, 0); for (ll used = k; used >= 0; used--) { ll l = used + 1; ll r = used + min(a[i], k - used); if (l <= r) { fake[l] = add(fake[l], dp[used]); if (r + 1 <= k) { fake[r + 1] = sub(fake[r + 1], dp[used]); } } } ll sum = 0; for (ll j = 0; j <= k; j++) { sum = add(sum, fake[j]); dp[j] = add(dp[j], sum); } } cout << dp[k] << "\n"; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
980,308
980,309
u626186340
cpp
p03172
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { int n, k; cin >> n >> k; vector<int> pref(k), dp(k); dp[0] = 1; for (int kid = 1; kid <= n; kid++) { int c; cin >> c; pref[0] = dp[0]; dp[0] = 0; for (int i = 1; i <= k; i++) { pref[i] = (pref[i - 1] + dp[i]) % MOD; } for (int i = 0; i <= k; i++) { dp[i] = (pref[i] - (i - c >= 0 ? pref[i - c - 1] : 0)) % MOD; } } int ans = dp[k]; if (ans < 0) ans += MOD; printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { int n, k; cin >> n >> k; vector<int> pref(k + 1), dp(k + 1); dp[0] = 1; for (int kid = 1; kid <= n; kid++) { int c; cin >> c; pref[0] = dp[0]; dp[0] = 0; for (int i = 1; i <= k; i++) { pref[i] = (pref[i - 1] + dp[i]) % MOD; } for (int i = 0; i <= k; i++) { dp[i] = (pref[i] - (i - c >= 0 ? pref[i - c - 1] : 0)) % MOD; } } int ans = dp[k]; if (ans < 0) ans += MOD; printf("%d\n", ans); return 0; }
[ "assignment.change" ]
980,312
980,313
u158312277
cpp
p03172
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(k + 2)); // 0~k+1 dp[0][0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= k; j++) { dp[i][j] += dp[i - 1][j]; dp[i][j] %= mod; if (j + a[i - 1] <= k) { dp[i][j + a[i - 1] + 1] -= dp[i - 1][j]; dp[i][j + a[i - 1] + 1] %= mod; dp[i][j + a[i - 1] + 1] %= mod; } else { dp[i][k + 1] -= dp[i - 1][j]; dp[i][k + 1] += mod; dp[i][k + 1] %= mod; } } for (ll j = 0; j <= k; j++) { dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= mod; } } cout << dp[n][k] << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) { cin >> a[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(k + 2)); // 0~k+1 dp[0][0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= k; j++) { dp[i][j] += dp[i - 1][j]; dp[i][j] %= mod; if (j + a[i - 1] <= k) { dp[i][j + a[i - 1] + 1] -= dp[i - 1][j]; dp[i][j + a[i - 1] + 1] += mod; dp[i][j + a[i - 1] + 1] %= mod; } else { dp[i][k + 1] -= dp[i - 1][j]; dp[i][k + 1] += mod; dp[i][k + 1] %= mod; } } for (ll j = 0; j <= k; j++) { dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= mod; } } cout << dp[n][k] << endl; return 0; }
[ "expression.operator.change" ]
980,314
980,315
u882039496
cpp
p03172
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> arr(n); for (int z = 1; z <= n; z++) { cin >> arr[z]; } vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)); dp[0][0] = 1; ll count = 0; for (int z = 1; z <= n; z++) { ll sum = 0; count += arr[z]; for (int x = 0; x <= count && x <= k; x++) { if (x > arr[z]) sum -= dp[z - 1][x - arr[z] - 1]; sum += dp[z - 1][x]; if (sum < 0) sum += mod; dp[z][x] += sum; dp[z][x] %= mod; sum %= mod; } } // for (int z=0;z<=n;z++){ // for (int x=0;x<=k;x++){ // cout << dp[z][x] << " "; // } cout << endl; // } cout << dp[n][k] << endl; cin >> n; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> arr(n + 1); for (int z = 1; z <= n; z++) { cin >> arr[z]; } vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)); dp[0][0] = 1; ll count = 0; for (int z = 1; z <= n; z++) { ll sum = 0; count += arr[z]; for (int x = 0; x <= count && x <= k; x++) { if (x > arr[z]) sum -= dp[z - 1][x - arr[z] - 1]; sum += dp[z - 1][x]; if (sum < 0) sum += mod; dp[z][x] += sum; dp[z][x] %= mod; sum %= mod; } } // for (int z=0;z<=n;z++){ // for (int x=0;x<=k;x++){ // cout << dp[z][x] << " "; // } cout << endl; // } cout << dp[n][k] << endl; cin >> n; }
[ "assignment.change" ]
980,326
980,327
u553927381
cpp
p03172
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> arr(n + 1); for (int z = 1; z <= n; z++) { cin >> arr[z]; } vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)); dp[0][0] = 1; ll count = 0; for (int z = 1; z <= n; z++) { ll sum = 0; count += arr[z]; for (int x = 0; x <= count && x <= k; x++) { if (x > arr[z]) sum -= dp[z - 1][x - arr[z] - 1]; else sum += dp[z - 1][x]; if (sum < 0) sum += mod; dp[z][x] += sum; dp[z][x] %= mod; sum %= mod; } } // for (int z=0;z<=n;z++){ // for (int x=0;x<=k;x++){ // cout << dp[z][x] << " "; // } cout << endl; // } cout << dp[n][k] << endl; cin >> n; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> arr(n + 1); for (int z = 1; z <= n; z++) { cin >> arr[z]; } vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)); dp[0][0] = 1; ll count = 0; for (int z = 1; z <= n; z++) { ll sum = 0; count += arr[z]; for (int x = 0; x <= count && x <= k; x++) { if (x > arr[z]) sum -= dp[z - 1][x - arr[z] - 1]; sum += dp[z - 1][x]; if (sum < 0) sum += mod; dp[z][x] += sum; dp[z][x] %= mod; sum %= mod; } } // for (int z=0;z<=n;z++){ // for (int x=0;x<=k;x++){ // cout << dp[z][x] << " "; // } cout << endl; // } cout << dp[n][k] << endl; cin >> n; }
[ "control_flow.branch.else.remove" ]
980,328
980,327
u553927381
cpp
p03172
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> arr(n); for (int z = 0; z < n; z++) { cin >> arr[z]; } sort(arr.begin(), arr.end()); arr.insert(arr.begin(), 0); vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)); dp[0][0] = 1; ll count = 0; for (int z = 1; z <= n; z++) { ll sum = 0; count += arr[z]; for (int x = 0; x <= count && x <= k; x++) { if (x > arr[z]) sum -= dp[z - 1][x - arr[z] - 1]; else sum += dp[z - 1][x]; if (sum < 0) sum += mod; dp[z][x] += sum; dp[z][x] %= mod; sum %= mod; } } cout << dp[n][k] << endl; cin >> n; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; vector<ll> arr(n); for (int z = 0; z < n; z++) { cin >> arr[z]; } sort(arr.begin(), arr.end()); arr.insert(arr.begin(), 0); vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)); dp[0][0] = 1; ll count = 0; for (int z = 1; z <= n; z++) { ll sum = 0; count += arr[z]; for (int x = 0; x <= count && x <= k; x++) { if (x > arr[z]) sum -= dp[z - 1][x - arr[z] - 1]; sum += dp[z - 1][x]; if (sum < 0) sum += mod; dp[z][x] += sum; dp[z][x] %= mod; sum %= mod; } } // for (int z=0;z<=n;z++){ // for (int x=0;x<=k;x++){ // cout << dp[z][x] << " "; // } cout << endl; // } cout << dp[n][k] << endl; cin >> n; }
[ "control_flow.branch.else.remove" ]
980,329
980,330
u553927381
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } vector<int64_t> dp(k + 1, 0); dp.at(0) = 1; vector<int64_t> cumsum_dp(k + 2, 1); cumsum_dp.at(0) = 0; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) { dp.at(j) = (cumsum_dp.at(j + 1) - cumsum_dp.at(max(0, j - a.at(i)))) % MOD; } for (int j = 2; j <= k + 1; j++) { cumsum_dp.at(j) = (cumsum_dp.at(j - 1) + dp.at(j - 1)) % MOD; } } cout << dp.at(k) << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } vector<int64_t> dp(k + 1, 0); dp.at(0) = 1; vector<int64_t> cumsum_dp(k + 2, 1); cumsum_dp.at(0) = 0; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) { dp.at(j) = (cumsum_dp.at(j + 1) - cumsum_dp.at(max(0, j - a.at(i))) + MOD) % MOD; } for (int j = 2; j <= k + 1; j++) { cumsum_dp.at(j) = (cumsum_dp.at(j - 1) + dp.at(j - 1)) % MOD; } } cout << dp.at(k) << endl; }
[ "assignment.change" ]
980,331
980,332
u711693740
cpp
p03172
// Om Sree Sai Ram #include "bits/stdc++.h" using namespace std; const int mod = 1e9 + 7; int add_self(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } int sub_self(int &a, int b) { a -= b; if (a <= mod) { a += mod; } } int main() { int n, k; cin >> n >> k; vector<int> dp(k + 1); // dp[i] represents number of ways to get into state in which i candies are // distributed. dp[0] = 1; for (int i = 0; i < n; i++) { int upto; cin >> upto; vector<int> diff(k + 1); for (int j = k; j >= 0; j--) { int tmp = dp[j]; // for order(n*k^2) algorithm int L = j + 1; int R = j + min(upto, k - j); if (L <= R) { add_self(diff[L], tmp); if (R + 1 <= k) { sub_self(diff[R + 1], tmp); } } // for(int dat=L;dat<=R;dat++) // { // if(dat<=k) // { // dp[dat] += tmp; // } // } } int prefix = 0; for (int i = 0; i <= k; i++) { // cout<<"diff "<<i<<endl; add_self(prefix, diff[i]); // cout<<"prefix "<<prefix<<endl; add_self(dp[i], prefix); } } cout << dp[k] << endl; }
// Om Sree Sai Ram #include "bits/stdc++.h" using namespace std; const int mod = 1e9 + 7; int add_self(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } int sub_self(int &a, int b) { a -= b; if (a <= 0) { a += mod; } } int main() { int n, k; cin >> n >> k; vector<int> dp(k + 1); // dp[i] represents number of ways to get into state in which i candies are // distributed. dp[0] = 1; for (int i = 0; i < n; i++) { int upto; cin >> upto; vector<int> diff(k + 1); for (int j = k; j >= 0; j--) { int tmp = dp[j]; // for order(n*k^2) algorithm int L = j + 1; int R = j + min(upto, k - j); if (L <= R) { add_self(diff[L], tmp); if (R + 1 <= k) { sub_self(diff[R + 1], tmp); } } // for(int dat=L;dat<=R;dat++) // { // if(dat<=k) // { // dp[dat] += tmp; // } // } } int prefix = 0; for (int i = 0; i <= k; i++) { // cout<<"diff "<<i<<endl; add_self(prefix, diff[i]); // cout<<"prefix "<<prefix<<endl; add_self(dp[i], prefix); } } cout << dp[k] << endl; }
[ "identifier.replace.remove", "literal.replace.add", "control_flow.branch.if.condition.change" ]
980,336
980,337
u279912110
cpp
p03172
#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 tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define CLOCK_START clock_t chrono_clk_beg = clock() #define CLOCK_END \ clock_t chrono_clk_end = clock(); \ cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec" #define bug(args...) \ cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), \ cerr << '\n' #define all(x) x.begin(), x.end() #define INF (1LL << 30) #define INF32 (1LL << 62) #define F first #define S second #define M_PI 3.14159265358979323846 #define MOD 1000000007 #define int ll typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll; typedef cc_hash_table<int, int, hash<int>> intHashTable; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; inline int powMod(int a, int b) { int x = 1; while (b > 0) { if (b & 1) x = (x * a) % MOD; a = (a * a) % MOD; b >>= 1; } return x; } inline int multiply(int x, int y) { return ((x % MOD) * (y % MOD)) % MOD; } inline int divide(int x, int y) { return ((x % MOD) * powMod(y % MOD, MOD - 2)) % MOD; } inline int ceil(int a, int b) { return (a + b - 1) / b; } int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int inverseMod(int a, int m) { a = a % m; for (ll x = 1; x < m; x++) if ((a * x) % m == 1) return x; return -1; } void err(istringstream *iss) {} template <typename T, typename... Args> void err(istringstream *iss, const T &_val, const Args &...args) { string _name; *iss >> _name; if (_name.back() == ',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args...); } int str_replace(string &str, const string &from, const string &to, int limit = -1) { if (from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while ((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; } template <int D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template <typename... Args> vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {} }; template <typename T> struct vec<1, T> : public vector<T> { vec(int n = 0, T val = T()) : vector<T>(n, val) {} }; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vec<1, int> arr(n); for (auto &x : arr) cin >> x; vec<2, int> DP(n, k + 1); for (int j = 0; j <= k; ++j) DP[0][j] = (j <= arr[0]); for (int i = 1; i < n; ++i) { for (int j = 1; j <= k; ++j) DP[i - 1][j] = (DP[i - 1][j] + DP[i - 1][j - 1]) % MOD; for (int j = 0; j <= k; ++j) DP[i][j] = (j - arr[i] - 1 >= 0) ? (DP[i - 1][j] - DP[i - 1][j - arr[i] - 1]) % MOD : DP[i - 1][j]; } cout << DP[n - 1][k] << '\n'; 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 tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define CLOCK_START clock_t chrono_clk_beg = clock() #define CLOCK_END \ clock_t chrono_clk_end = clock(); \ cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec" #define bug(args...) \ cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), \ cerr << '\n' #define all(x) x.begin(), x.end() #define INF (1LL << 30) #define INF32 (1LL << 62) #define F first #define S second #define M_PI 3.14159265358979323846 #define MOD 1000000007 #define int ll typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll; typedef cc_hash_table<int, int, hash<int>> intHashTable; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; inline int powMod(int a, int b) { int x = 1; while (b > 0) { if (b & 1) x = (x * a) % MOD; a = (a * a) % MOD; b >>= 1; } return x; } inline int multiply(int x, int y) { return ((x % MOD) * (y % MOD)) % MOD; } inline int divide(int x, int y) { return ((x % MOD) * powMod(y % MOD, MOD - 2)) % MOD; } inline int ceil(int a, int b) { return (a + b - 1) / b; } int gcd(int a, int b) { while (b) { a %= b; swap(a, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } int inverseMod(int a, int m) { a = a % m; for (ll x = 1; x < m; x++) if ((a * x) % m == 1) return x; return -1; } void err(istringstream *iss) {} template <typename T, typename... Args> void err(istringstream *iss, const T &_val, const Args &...args) { string _name; *iss >> _name; if (_name.back() == ',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args...); } int str_replace(string &str, const string &from, const string &to, int limit = -1) { if (from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while ((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; } template <int D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template <typename... Args> vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {} }; template <typename T> struct vec<1, T> : public vector<T> { vec(int n = 0, T val = T()) : vector<T>(n, val) {} }; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vec<1, int> arr(n); for (auto &x : arr) cin >> x; vec<2, int> DP(n, k + 1); for (int j = 0; j <= k; ++j) DP[0][j] = (j <= arr[0]); for (int i = 1; i < n; ++i) { for (int j = 1; j <= k; ++j) DP[i - 1][j] = (DP[i - 1][j] + DP[i - 1][j - 1]) % MOD; for (int j = 0; j <= k; ++j) DP[i][j] = (j - arr[i] - 1 >= 0) ? (DP[i - 1][j] - DP[i - 1][j - arr[i] - 1] + MOD) % MOD : DP[i - 1][j]; } cout << DP[n - 1][k] << '\n'; return 0; }
[ "expression.operation.binary.add" ]
980,343
980,344
u562572302
cpp