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 |
|---|---|---|---|---|---|---|---|
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
ll n, k, bd[101][200001], a;
int main() {
cin >> n >> k;
memset(bd, 0, sizeof(bd));
bd[0][k] = 1;
for (int i = 1; i <= n; i++) {
cin >> a;
bd[i][k] = 1;
for (int j = k - 1; j >= 0; j--) {
bd[i][j] = (bd[i][j + 1] - bd[i - 1][j + a + 1] + bd[i - 1][j]) % M;
// cout << bd[i][j] << ' ';
}
// cout << "\n";
}
cout << bd[n][0] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9 + 7;
ll n, k, bd[101][200001], a;
int main() {
cin >> n >> k;
memset(bd, 0, sizeof(bd));
bd[0][k] = 1;
for (int i = 1; i <= n; i++) {
cin >> a;
bd[i][k] = 1;
for (int j = k - 1; j >= 0; j--) {
bd[i][j] = (bd[i][j + 1] - bd[i - 1][j + a + 1] + bd[i - 1][j] + M) % M;
}
}
cout << bd[n][0] << "\n";
} | [
"assignment.change"
] | 980,904 | 980,903 | u762629133 | cpp |
p03172 | #include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace std;
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const LL MOD = 1000000000 + 7;
const LD EPS = 0.0000001;
#define MPP(a, b, c) MP(MP(a, b), c)
#define PII pair<pair<LL, LL>, LL>
LL pows(LL a, LL b) {
if (b == 0)
return 1LL;
LL temp = pows(a, b / 2);
temp = (temp * temp) % MOD;
if (b % 2)
temp = (temp * a) % MOD;
return temp;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
LL n, k;
cin >> n >> k;
LL arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
// for (int i = 0; i < n; i++){
// for (int j = 0; j <= k; j++) dp[i][j] = 0;
// }
if (k == 0) {
cout << 0 << endl;
return 0;
}
vector<vector<LL>> dp(n, vector<LL>(k + 1));
for (int i = 0; i <= min(arr[0], k); i++)
dp[0][i] = 1;
for (int i = 1; i <= k; i++)
dp[0][i] += dp[0][i - 1];
for (LL i = 1; i < n; i++) {
dp[i].resize(k + 1, 0);
for (LL j = 0; j <= k; j++) {
int mn = max(0LL, j - arr[i]);
dp[i][j] = dp[i - 1][j];
if (mn != 0) {
dp[i][j] = (dp[i][j] - dp[i - 1][mn - 1] + MOD) % MOD;
}
}
for (int j = 1; j <= k; j++)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
}
// for (int i = 0; i < n; i++){
// for (int j = 1; j <= k; j++){
// cout << dp[i][j] - dp[i][j - 1] << " ";
// }
// cout << endl;
// }
LL ans = (dp[n - 1][k] + MOD - dp[n - 1][k - 1]) % MOD;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace std;
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const LL MOD = 1000000000 + 7;
const LD EPS = 0.0000001;
#define MPP(a, b, c) MP(MP(a, b), c)
#define PII pair<pair<LL, LL>, LL>
LL pows(LL a, LL b) {
if (b == 0)
return 1LL;
LL temp = pows(a, b / 2);
temp = (temp * temp) % MOD;
if (b % 2)
temp = (temp * a) % MOD;
return temp;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
LL n, k;
cin >> n >> k;
LL arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
// for (int i = 0; i < n; i++){
// for (int j = 0; j <= k; j++) dp[i][j] = 0;
// }
if (k == 0) {
cout << 1 << endl;
return 0;
}
vector<vector<LL>> dp(n, vector<LL>(k + 1));
for (int i = 0; i <= min(arr[0], k); i++)
dp[0][i] = 1;
for (int i = 1; i <= k; i++)
dp[0][i] += dp[0][i - 1];
for (LL i = 1; i < n; i++) {
dp[i].resize(k + 1, 0);
for (LL j = 0; j <= k; j++) {
int mn = max(0LL, j - arr[i]);
dp[i][j] = dp[i - 1][j];
if (mn != 0) {
dp[i][j] = (dp[i][j] - dp[i - 1][mn - 1] + MOD) % MOD;
}
}
for (int j = 1; j <= k; j++)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
}
// for (int i = 0; i < n; i++){
// for (int j = 1; j <= k; j++){
// cout << dp[i][j] - dp[i][j - 1] << " ";
// }
// cout << endl;
// }
LL ans = (dp[n - 1][k] + MOD - dp[n - 1][k - 1]) % MOD;
cout << ans << endl;
return 0;
}
| [
"literal.number.change",
"io.output.change"
] | 980,916 | 980,917 | u109311178 | cpp |
p03172 | #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define SORT(A) sort(A.begin(), A.end())
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001
int main(void) {
ll N, K;
inp(N);
inp(K);
vector<ll> a;
rep(i, N) {
ll num;
inp(num);
a.push_back(num);
}
vector<vector<ll>> dp(N, vector<ll>(K + 1, 0));
rep(j, K + 1) {
if (j <= a[0])
dp[0][j] = 1;
else
dp[0][j] = 0;
}
rep(i, N) dp[i][0] = 1;
rep2(i, 1, N) rep2(j, 1, K + 1) {
if (a[i] >= j)
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - a[i] - 1];
dp[i][j] %= MOD;
}
/* rep(i,N){
rep(j,K+1) cout << dp[i][j] << ",";
cout << endl;
} */
out(dp[N - 1][K]);
}
| #include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, f, n) for (int i = f; i < n; i++)
#define SORT(A) sort(A.begin(), A.end())
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001
int main(void) {
ll N, K;
inp(N);
inp(K);
vector<ll> a;
rep(i, N) {
ll num;
inp(num);
a.push_back(num);
}
vector<vector<ll>> dp(N, vector<ll>(K + 1, 0));
rep(j, K + 1) {
if (j <= a[0])
dp[0][j] = 1;
else
dp[0][j] = 0;
}
rep(i, N) dp[i][0] = 1;
rep2(i, 1, N) rep2(j, 1, K + 1) {
if (a[i] >= j)
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
else
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + MOD - dp[i - 1][j - a[i] - 1];
dp[i][j] %= MOD;
}
/* rep(i,N){
rep(j,K+1) cout << dp[i][j] << ",";
cout << endl;
} */
out(dp[N - 1][K]);
}
| [
"assignment.change"
] | 980,924 | 980,925 | u086672186 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vll a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vll dp(k + 1), nx;
dp[0] = 1;
for (int person = 0; person < n; person++) {
nx = vll(k + 2, 0);
for (int candies = 0; candies <= k; candies++) {
ll ways = dp[candies] % MOD;
nx[candies] += ways;
nx[min(candies + a[person], k) + 1] -= ways;
}
for (int i = 0; i <= k; i++)
dp[i] = (nx[i] + (i > 0 ? dp[i - 1] : 0)) % MOD;
}
cout << (dp[k] % MOD) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vll a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vll dp(k + 1), nx;
dp[0] = 1;
for (int person = 0; person < n; person++) {
nx = vll(k + 2, 0);
for (int candies = 0; candies <= k; candies++) {
ll ways = dp[candies] % MOD;
nx[candies] += ways;
nx[min(candies + a[person], k) + 1] -= ways;
}
for (int i = 0; i <= k; i++)
dp[i] = (nx[i] + (i > 0 ? dp[i - 1] : 0) + MOD) % MOD;
}
cout << (dp[k] % MOD) << endl;
} | [
"assignment.change"
] | 980,929 | 980,930 | u737620206 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vll a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vll dp(k + 1), nx;
dp[0] = 1;
for (int person = 0; person < n; person++) {
nx = vll(k + 2, 0);
for (int candies = 0; candies <= k; candies++) {
ll ways = dp[candies] % MOD;
nx[candies] = ways;
nx[min(candies + a[person], k) + 1] -= ways;
}
for (int i = 0; i <= k; i++)
dp[i] = (nx[i] + (i > 0 ? dp[i - 1] : 0)) % MOD;
}
cout << (dp[k] % MOD) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vll a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vll dp(k + 1), nx;
dp[0] = 1;
for (int person = 0; person < n; person++) {
nx = vll(k + 2, 0);
for (int candies = 0; candies <= k; candies++) {
ll ways = dp[candies] % MOD;
nx[candies] += ways;
nx[min(candies + a[person], k) + 1] -= ways;
}
for (int i = 0; i <= k; i++)
dp[i] = (nx[i] + (i > 0 ? dp[i - 1] : 0) + MOD) % MOD;
}
cout << (dp[k] % MOD) << endl;
} | [
"assignment.value.change",
"assignment.change"
] | 980,931 | 980,930 | u737620206 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vll a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vll dp(k + 1, 0), nx;
dp[0] = 1;
for (int person = 0; person < n; person++) {
nx = vll(k + 2, 0);
for (int candies = 0; candies <= k; candies++) {
ll ways = dp[candies];
nx[candies] += ways;
nx[min(candies + a[person], k) + 1] -= ways;
}
for (int i = 0; i <= k; i++)
dp[i] = (nx[i] + (i > 0 ? dp[i - 1] : 0)) % MOD;
}
cout << (dp[k]) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vector<long long>> mll;
typedef vector<pair<long long, long long>> vpl;
typedef pair<long long, long long> pll;
#define minimize(var, val) (var = min((val), var))
const long long MOD = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
vll a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vll dp(k + 1, 0), nx;
dp[0] = 1;
for (int person = 0; person < n; person++) {
nx = vll(k + 2, 0);
for (int candies = 0; candies <= k; candies++) {
ll ways = dp[candies];
nx[candies] += ways;
nx[min(candies + a[person], k) + 1] -= ways;
}
for (int i = 0; i <= k; i++)
dp[i] = (nx[i] + (i > 0 ? dp[i - 1] : 0) + MOD) % MOD;
}
cout << (dp[k]) << endl;
} | [
"assignment.change"
] | 980,932 | 980,933 | u513227008 | cpp |
p03172 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define ppi pair<int, int>
#define mp make_pair
const int mod = 1e9 + 7;
const int N = 2e5 + 111, N2 = 1e2 + 11;
ll dp[N2][N], cum[N];
int arr[N2];
int main() {
#ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);
#endif
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
scanf("%d", arr + i);
dp[n][0] = 1;
for (int i = 0; i <= k; i++)
cum[i + 1] = 1;
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= k; j++)
dp[i][j] = cum[j + 1] - cum[max(j - arr[i], 0)];
for (int j = 0; j <= k; j++)
cum[j + 1] = (cum[j] + dp[i][j]) % mod;
}
cout << dp[0][k];
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define ppi pair<int, int>
#define mp make_pair
const int mod = 1e9 + 7;
const int N = 2e5 + 111, N2 = 1e2 + 11;
ll dp[N2][N], cum[N];
int arr[N2];
int main() {
#ifndef ONLINE_JUDGE
// freopen("inp.txt", "r", stdin);
#endif
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
scanf("%d", arr + i);
dp[n][0] = 1;
for (int i = 0; i <= k; i++)
cum[i + 1] = 1;
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= k; j++)
dp[i][j] = (cum[j + 1] - cum[max(j - arr[i], 0)] + mod) % mod;
for (int j = 0; j <= k; j++)
cum[j + 1] = (cum[j] + dp[i][j]) % mod;
}
cout << dp[0][k];
}
| [
"assignment.change"
] | 980,942 | 980,943 | u509031869 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, j, n, k;
cin >> n >> k;
vector<long long int> a(n);
for (i = 0; i < n; i++)
cin >> a[i];
long long int mod = 1000000007;
vector<vector<long long int>> poss(n + 1);
poss[1] = vector<long long int>(k + 1, 0);
for (i = 0; i <= k; i++) {
if (i <= a[0])
poss[1][i] = 1;
}
for (i = 2; i <= n; i++) {
poss[i] = vector<long long int>(k + 1, 0);
long long int sum = 0;
for (j = 0; j <= k; j++) {
if (j <= a[i - 1])
sum = (sum + poss[i - 1][j]) % mod;
else {
sum = (sum + poss[i - 1][j] - poss[i - 1][j - a[i - 1] - 1]) % mod;
}
poss[i][j] = sum % mod;
}
}
cout << poss[n][k] % mod << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, j, n, k;
cin >> n >> k;
vector<long long int> a(n);
for (i = 0; i < n; i++)
cin >> a[i];
long long int mod = 1000000007;
vector<vector<long long int>> poss(n + 1);
poss[1] = vector<long long int>(k + 1, 0);
for (i = 0; i <= k; i++) {
if (i <= a[0])
poss[1][i] = 1;
}
for (i = 2; i <= n; i++) {
poss[i] = vector<long long int>(k + 1, 0);
long long int sum = 0;
for (j = 0; j <= k; j++) {
if (j <= a[i - 1])
sum = (sum + poss[i - 1][j]);
else {
sum = (sum + poss[i - 1][j] - poss[i - 1][j - a[i - 1] - 1]);
}
poss[i][j] = sum % mod;
}
}
cout << poss[n][k] % mod << endl;
} | [
"expression.operation.binary.remove"
] | 980,944 | 980,945 | u780411062 | cpp |
p03172 | #include <algorithm>
#include <iostream>
using namespace std;
long long int MOD = 1000000007;
long long int dp[105][100005], sum[105][100005];
int N, K;
int a[100005];
int main(void) {
cin >> N >> K;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
dp[0][K] = 1;
for (int i = 1; i <= N; i++) {
sum[i - 1][0] = dp[i - 1][0];
for (int j = 1; j <= K; j++) {
sum[i - 1][j] = (sum[i - 1][j - 1] + dp[i - 1][j]) % MOD;
}
dp[i][0] = sum[i - 1][min(K, 0 + a[i])];
for (int k = 0; k <= K; k++) {
dp[i][k] = (sum[i - 1][min(K, k + a[i])] - sum[i - 1][k - 1] + MOD) % MOD;
}
}
cout << dp[N][0] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long int MOD = 1000000007;
long long int dp[105][100005], sum[105][100005];
int N, K;
int a[100005];
int main(void) {
cin >> N >> K;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
dp[0][K] = 1;
for (int i = 1; i <= N; i++) {
sum[i - 1][0] = dp[i - 1][0];
for (int j = 1; j <= K; j++) {
sum[i - 1][j] = (sum[i - 1][j - 1] + dp[i - 1][j]) % MOD;
}
dp[i][0] = sum[i - 1][min(K, 0 + a[i])];
for (int k = 1; k <= K; k++) {
dp[i][k] = (sum[i - 1][min(K, k + a[i])] - sum[i - 1][k - 1] + MOD) % MOD;
}
}
cout << dp[N][0] << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 980,954 | 980,955 | u835297884 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << " = " << x << endl;
#define MAXN 112
#define MAXK 112345
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define MOD 1000000007
int N, K;
int vals[MAXN];
ll dp[MAXN][MAXK];
ll prefix[MAXN][MAXK];
ll add(ll a, ll b) { return (a + b) % MOD; }
ll sub(ll a, ll b) { return (a - b) % MOD; }
ll get_prefix(int row, int L, int R) {
ll result = prefix[row][R];
if (L - 1 >= 0)
return sub(result, prefix[row][L - 1]);
return result;
}
// no candies should be left over.
int main() {
scanf("%d%d", &N, &K);
for (int i = 0; i < N; i++) {
scanf("%d", &vals[i]);
}
memset(dp, 0, sizeof(dp));
dp[N][0] = 1;
for (int i = 0; i <= K; i++) {
prefix[N][i] = 1;
}
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j <= K; j++) {
if (j == 0) {
dp[i][j] = 1;
prefix[i][j] = 1;
} else {
int c = min(j, vals[i]);
dp[i][j] = add(dp[i][j], get_prefix(i + 1, j - c, j));
prefix[i][j] = add(prefix[i][j - 1], dp[i][j]);
}
}
}
//~ for (int i = 0; i < N; i++)
//~ {
//~ for (int j = 0; j <= K; j++)
//~ {
//~ printf("%d ", prefix[i][j]);
//~ }
//~ printf("\n");
//~ }
//~ printf("\n");
//~ for (int i = 0; i < N; i++)
//~ {
//~ for (int j = 0; j <= K; j++)
//~ {
//~ printf("%d ", dp[i][j]);
//~ }
//~ printf("\n");
//~ }
printf("%lld\n", dp[0][K]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << " = " << x << endl;
#define MAXN 112
#define MAXK 112345
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define MOD 1000000007
int N, K;
int vals[MAXN];
ll dp[MAXN][MAXK];
ll prefix[MAXN][MAXK];
ll add(ll a, ll b) { return (a + b) % MOD; }
ll sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll get_prefix(int row, int L, int R) {
ll result = prefix[row][R];
if (L - 1 >= 0)
return sub(result, prefix[row][L - 1]);
return result;
}
// no candies should be left over.
int main() {
scanf("%d%d", &N, &K);
for (int i = 0; i < N; i++) {
scanf("%d", &vals[i]);
}
memset(dp, 0, sizeof(dp));
dp[N][0] = 1;
for (int i = 0; i <= K; i++) {
prefix[N][i] = 1;
}
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j <= K; j++) {
if (j == 0) {
dp[i][j] = 1;
prefix[i][j] = 1;
} else {
int c = min(j, vals[i]);
dp[i][j] = add(dp[i][j], get_prefix(i + 1, j - c, j));
prefix[i][j] = add(prefix[i][j - 1], dp[i][j]);
}
}
}
//~ for (int i = 0; i < N; i++)
//~ {
//~ for (int j = 0; j <= K; j++)
//~ {
//~ printf("%d ", prefix[i][j]);
//~ }
//~ printf("\n");
//~ }
//~ printf("\n");
//~ for (int i = 0; i < N; i++)
//~ {
//~ for (int j = 0; j <= K; j++)
//~ {
//~ printf("%d ", dp[i][j]);
//~ }
//~ printf("\n");
//~ }
printf("%lld\n", dp[0][K]);
return 0;
}
| [
"expression.operation.binary.add"
] | 980,956 | 980,957 | u183528320 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llinf 1e17
#define nllinf -4e18
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define repup(a, b, i) for (i = a; i <= b; i++)
#define repdown(a, b, i) for (i = b; i >= a; i--)
#define repupx(a, b, i, x) for (i = a; i <= b; i += x)
#define repit(v, it) for (it = v.begin(); it != v.end(); it++)
#define itall(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second
#define err(n) cout << n << " ";
#define t1 cout << ",";
ll MOD = 1e9 + 7;
void add_self(ll &a, ll b) {
a += b;
if (a > MOD)
a -= MOD;
}
void sub_self(ll &a, ll b) {
a -= b;
a = ((a % MOD) + MOD) % MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll i, j, k;
ll f;
ll n;
cin >> n >> k;
ll dp[k + 4] = {0};
dp[0] = 1;
repup(0, n - 1, i) {
ll b[k + 2] = {0};
ll x;
cin >> x;
repdown(0, k, j) {
sub_self(b[j + min(k - j, x) + 1], dp[j]);
add_self(b[j + 1], dp[j]);
}
repup(1, k + 1, j) {
add_self(b[j], b[j - 1]);
add_self(dp[j - 1], b[j - 1]);
}
}
cout << dp[k];
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llinf 1e17
#define nllinf -4e18
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define repup(a, b, i) for (i = a; i <= b; i++)
#define repdown(a, b, i) for (i = b; i >= a; i--)
#define repupx(a, b, i, x) for (i = a; i <= b; i += x)
#define repit(v, it) for (it = v.begin(); it != v.end(); it++)
#define itall(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second
#define err(n) cout << n << " ";
#define t1 cout << ",";
ll MOD = 1e9 + 7;
void add_self(ll &a, ll b) {
a += b;
if (a >= MOD)
a -= MOD;
}
void sub_self(ll &a, ll b) {
a -= b;
a = ((a % MOD) + MOD) % MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll i, j, k;
ll f;
ll n;
cin >> n >> k;
ll dp[k + 4] = {0};
dp[0] = 1;
repup(0, n - 1, i) {
ll b[k + 2] = {0};
ll x;
cin >> x;
repdown(0, k, j) {
sub_self(b[j + min(k - j, x) + 1], dp[j]);
add_self(b[j + 1], dp[j]);
}
repup(1, k + 1, j) {
add_self(b[j], b[j - 1]);
add_self(dp[j - 1], b[j - 1]);
}
}
cout << dp[k];
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 980,960 | 980,961 | u651678455 | cpp |
p03172 | #include <iostream>
using namespace std;
int a[101];
long long b[101][100005];
long long c[101][100005];
int main() {
int mod = 1000000000 + 7;
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < k; i++)
if (i <= a[0])
b[1][i] = 1;
for (int i = 2; i <= n; i++) {
c[i - 1][0] = 1;
for (int j = 1; j <= k; j++) {
c[i - 1][j] = c[i - 1][j - 1] + b[i - 1][j];
c[i - 1][j] %= mod;
}
for (int j = 0; j <= k; j++) {
b[i][j] = c[i - 1][j];
if (j - a[i - 1] - 1 >= 0) {
b[i][j] -= c[i - 1][j - a[i - 1] - 1];
if (b[i][j] < 0)
b[i][j] += mod;
}
}
}
cout << b[n][k];
return 0;
} | #include <iostream>
using namespace std;
int a[101];
long long b[101][100005];
long long c[101][100005];
int main() {
int mod = 1000000000 + 7;
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i <= k; i++)
if (i <= a[0])
b[1][i] = 1;
for (int i = 2; i <= n; i++) {
c[i - 1][0] = 1;
for (int j = 1; j <= k; j++) {
c[i - 1][j] = c[i - 1][j - 1] + b[i - 1][j];
c[i - 1][j] %= mod;
}
for (int j = 0; j <= k; j++) {
b[i][j] = c[i - 1][j];
if (j - a[i - 1] - 1 >= 0) {
b[i][j] -= c[i - 1][j - a[i - 1] - 1];
if (b[i][j] < 0)
b[i][j] += mod;
}
}
}
cout << b[n][k];
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 980,968 | 980,969 | u933569811 | cpp |
p03172 | #include <bits/stdc++.h>
#define ld long double
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define roflan \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define int long long
using namespace std;
const int mod = (int)1e9 + 7;
void ad(int &a, int b) {
a += b;
if (a > mod)
a -= mod;
}
void su(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
}
signed main() {
roflan;
int n, k;
cin >> n >> k;
vector<int> dp(k + 1);
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0] = 1;
for (int i = 0; i < n; i++) {
vector<int> pref(k + 1);
for (int used = k; used >= 0; used--) {
int L = used + 1;
int R = used + min(k - used, a[i]);
if (L <= R) {
ad(pref[L], dp[used]);
if (R + 1 <= k)
su(pref[R + 1], dp[used]);
}
}
int sum = 0;
for (int i = 0; i <= k; i++) {
ad(sum, pref[i]);
ad(dp[i], sum);
}
}
cout << dp[k];
return 14 / 88;
} | #include <bits/stdc++.h>
#define ld long double
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define roflan \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define int long long
using namespace std;
const int mod = (int)1e9 + 7;
void ad(int &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void su(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
}
signed main() {
roflan;
int n, k;
cin >> n >> k;
vector<int> dp(k + 1);
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0] = 1;
for (int i = 0; i < n; i++) {
vector<int> pref(k + 1);
for (int used = k; used >= 0; used--) {
int L = used + 1;
int R = used + min(k - used, a[i]);
if (L <= R) {
ad(pref[L], dp[used]);
if (R + 1 <= k)
su(pref[R + 1], dp[used]);
}
}
int sum = 0;
for (int i = 0; i <= k; i++) {
ad(sum, pref[i]);
ad(dp[i], sum);
}
}
cout << dp[k];
return 14 / 88;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 980,974 | 980,975 | u266436174 | cpp |
p03172 | #include <algorithm>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define endl cout << "\n"
#define lli long long int
#define ld long double
#define M_PI (3.14159265358979323846264338327950288)
#define MOD (1000000007)
using namespace std;
// fast-exponentiation-lli
unsigned lli expo_fast(lli a, lli b) {
a = a;
lli result = 1;
while (b) {
// multiplyint(tos(result), a);
if (b & 1)
result = (result * a);
b >>= 1;
a = (a * a);
}
return (result);
}
void take_in(vector<lli> *arr) {
for (int i = 0; i < arr->size(); i++)
cin >> (*(arr))[i];
}
lli gcd(lli a, lli b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
/* Iterative Function to calculate (x^y)%p in O(log y) */
unsigned lli power(lli x, unsigned lli y, lli p) {
lli res = 1; // Initialize result
x = x % p; // Update x if it is more than or equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
lli n, k;
cin >> n >> k;
vector<lli> arr(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i];
vector<vector<lli>> dp(k + 1, vector<lli>(n + 1, 0));
for (int i = 0; i <= k; i++) {
dp[i][1] = (i <= arr[1]) ? 1 : 0;
}
for (int j = 2; j <= n; j++) {
for (int i = 0; i <= k; i++) {
if (i == 0)
dp[i][j] = dp[i][j - 1] % MOD;
else {
if (i <= arr[j])
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
else
dp[i][j] =
(dp[i][j - 1] + dp[i - 1][j] - dp[i - arr[j] - 1][j - 1]) % MOD;
}
}
}
cout << dp[k][n];
// system("PAUSE");
}
| #include <algorithm>
#include <bitset>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define endl cout << "\n"
#define lli long long int
#define ld long double
#define M_PI (3.14159265358979323846264338327950288)
#define MOD (1000000007)
using namespace std;
// fast-exponentiation-lli
unsigned lli expo_fast(lli a, lli b) {
a = a;
lli result = 1;
while (b) {
// multiplyint(tos(result), a);
if (b & 1)
result = (result * a);
b >>= 1;
a = (a * a);
}
return (result);
}
void take_in(vector<lli> *arr) {
for (int i = 0; i < arr->size(); i++)
cin >> (*(arr))[i];
}
lli gcd(lli a, lli b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
/* Iterative Function to calculate (x^y)%p in O(log y) */
unsigned lli power(lli x, unsigned lli y, lli p) {
lli res = 1; // Initialize result
x = x % p; // Update x if it is more than or equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
lli n, k;
cin >> n >> k;
vector<lli> arr(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i];
vector<vector<lli>> dp(k + 1, vector<lli>(n + 1, 0));
for (int i = 0; i <= k; i++) {
dp[i][1] = (i <= arr[1]) ? 1 : 0;
}
for (int j = 2; j <= n; j++) {
for (int i = 0; i <= k; i++) {
if (i == 0)
dp[i][j] = dp[i][j - 1] % MOD;
else {
if (i <= arr[j])
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
else
dp[i][j] =
(MOD + dp[i][j - 1] + dp[i - 1][j] - dp[i - arr[j] - 1][j - 1]) %
MOD;
}
}
}
cout << dp[k][n];
// system("PAUSE");
}
| [
"assignment.change"
] | 980,976 | 980,977 | u922164368 | cpp |
p03172 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1));
rep(i, n + 1) { dp[i][0] = 1; }
for (int i = 1; i < n + 1; i++) {
rep(j, k) {
if (j - a[i - 1] >= 0) {
dp[i][j + 1] =
(dp[i][j] + dp[i - 1][j + 1] - dp[i - 1][j - a[i - 1]]) % MOD;
} else {
dp[i][j + 1] = (dp[i][j] + dp[i - 1][j + 1]) % MOD;
}
}
}
cout << dp[n][k] << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1));
rep(i, n + 1) { dp[i][0] = 1; }
for (int i = 1; i < n + 1; i++) {
rep(j, k) {
if (j - a[i - 1] >= 0) {
dp[i][j + 1] =
(dp[i][j] + dp[i - 1][j + 1] - dp[i - 1][j - a[i - 1]] + MOD) % MOD;
} else {
dp[i][j + 1] = (dp[i][j] + dp[i - 1][j + 1]) % MOD;
}
}
}
cout << dp[n][k] << endl;
return 0;
} | [
"assignment.change"
] | 980,978 | 980,979 | u762183504 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
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++) {
if (a[i - 1] >= j) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
} else {
dp[i][j] =
((dp[i][j - 1] + dp[i - 1][j])) % MOD - dp[i - 1][j - a[i - 1] - 1];
}
}
}
cout << dp[n][k] % MOD;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
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++) {
if (a[i - 1] >= j) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
} else {
dp[i][j] = (((dp[i][j - 1] + dp[i - 1][j])) % MOD -
dp[i - 1][j - a[i - 1] - 1] + MOD) %
MOD;
}
}
}
cout << dp[n][k] % MOD;
} | [
"assignment.change"
] | 980,986 | 980,987 | u741856489 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(x) (x).begin(), (x).end()
#define foreach(u, v) for (auto(u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int inf = 1e9;
const ll linf = 1LL << 60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
template <class T> class BIT {
public:
int n;
vector<T> bit;
BIT() {}
BIT(int n_) { init(n_); }
void init(int n_) {
n = n_;
bit.resize(n + 1);
clear();
}
T sum(int i) {
T s = 0;
while (i > 0) {
s += bit[i];
s %= mod;
i -= i & -i;
}
return s;
}
void add(int i, T x) {
while (i <= n) {
bit[i] += x;
bit[i] %= mod;
i += i & -i;
}
}
void clear() {
for (int i = 0; i < n; i++) {
bit[i] = 0;
}
}
};
/*
dp[i][j]
i個めのアメをj番目の子供に挙げる
BITを使う
dp[i][j] = dp[i-1][j] + dp[i-1][j-1] ...
+ dp[i-1][max(0, j-a[i])]
*/
int main() {
int n, k;
cin >> n >> k;
vi a(n);
rep(i, n) cin >> a[i];
BIT<ll> bit[n + 1];
rep(i, n + 1) bit[i].init(k + 2);
bit[0].add(1, 1);
rep(i, n) repi(j, 1, k + 2) {
bit[i + 1].add(j, (bit[i].sum(j) - bit[i].sum(max(0, j - a[i] - 1))) % mod);
}
cout << bit[n].sum(k + 1) - bit[n].sum(k) << endl;
/*
rep(i, n+1){
repi(j, 1, k+2){
cout << bit[i].sum(j)-bit[i].sum(j-1) << " ";
}
cout << endl;
}
*/
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(x) (x).begin(), (x).end()
#define foreach(u, v) for (auto(u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const int inf = 1e9;
const ll linf = 1LL << 60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
template <class T> class BIT {
public:
int n;
vector<T> bit;
BIT() {}
BIT(int n_) { init(n_); }
void init(int n_) {
n = n_;
bit.resize(n + 1);
clear();
}
T sum(int i) {
T s = 0;
while (i > 0) {
s += bit[i];
s %= mod;
i -= i & -i;
}
return s;
}
void add(int i, T x) {
while (i <= n) {
bit[i] += x;
bit[i] %= mod;
i += i & -i;
}
}
void clear() {
for (int i = 0; i < n; i++) {
bit[i] = 0;
}
}
};
/*
dp[i][j]
i個めのアメをj番目の子供に挙げる
BITを使う
dp[i][j] = dp[i-1][j] + dp[i-1][j-1] ...
+ dp[i-1][max(0, j-a[i])]
*/
int main() {
int n, k;
cin >> n >> k;
vi a(n);
rep(i, n) cin >> a[i];
BIT<ll> bit[n + 1];
rep(i, n + 1) bit[i].init(k + 2);
bit[0].add(1, 1);
rep(i, n) repi(j, 1, k + 2) {
bit[i + 1].add(j, (bit[i].sum(j) - bit[i].sum(max(0, j - a[i] - 1))) % mod);
}
cout << (bit[n].sum(k + 1) - bit[n].sum(k) + mod) % mod << endl;
/*
rep(i, n+1){
repi(j, 1, k+2){
cout << bit[i].sum(j)-bit[i].sum(j-1) << " ";
}
cout << endl;
}
*/
return 0;
}
| [
"expression.operation.binary.add"
] | 980,995 | 980,996 | u057866967 | cpp |
p03172 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pii pair<int, int>
#define ll long long
#define IMAX 1000000007
#define in2d(i, j, H, W) (0 <= i && i < H && 0 <= j && j < W)
using namespace std;
int main() {
cout << fixed << setprecision(11);
int N, K;
cin >> N >> K;
vector<ll> a(N + 1);
for (int i = 1; i <= N; i++)
cin >> a[i];
vector<vector<ll>> dp(N + 1, vector<ll>(K + 1, 0));
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 - 1] + dp[i - 1][j]) % IMAX;
if (j > a[i])
dp[i][j] = (dp[i][j] - dp[i - 1][j - a[i] - 1]) % IMAX;
}
// for(int i=0;i<=N;i++){
// for(int j=0;j<=K;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[N][K] << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pii pair<int, int>
#define ll long long
#define IMAX 1000000007
#define in2d(i, j, H, W) (0 <= i && i < H && 0 <= j && j < W)
using namespace std;
int main() {
cout << fixed << setprecision(11);
int N, K;
cin >> N >> K;
vector<ll> a(N + 1);
for (int i = 1; i <= N; i++)
cin >> a[i];
vector<vector<ll>> dp(N + 1, vector<ll>(K + 1, 0));
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 - 1] + dp[i - 1][j]) % IMAX;
if (j > a[i])
dp[i][j] = (dp[i][j] + IMAX - dp[i - 1][j - a[i] - 1]) % IMAX;
}
// for(int i=0;i<=N;i++){
// for(int j=0;j<=K;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[N][K] << endl;
return 0;
}
| [
"assignment.change"
] | 980,999 | 981,000 | u537874719 | cpp |
p03172 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pii pair<int, int>
#define ll long long
#define IMAX 1000000007
#define in2d(i, j, H, W) (0 <= i && i < H && 0 <= j && j < W)
using namespace std;
int main() {
cout << fixed << setprecision(11);
int N, K;
cin >> N >> K;
vector<int> a(N + 1);
for (int i = 1; i <= N; i++)
cin >> a[i];
vector<vector<int>> dp(N + 1, vector<int>(K + 1, 0));
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 - 1] + dp[i - 1][j]) % IMAX;
if (j > a[i])
dp[i][j] = (dp[i][j] - dp[i - 1][j - a[i] - 1]) % IMAX;
}
// for(int i=0;i<=N;i++){
// for(int j=0;j<=K;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[N][K] << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pii pair<int, int>
#define ll long long
#define IMAX 1000000007
#define in2d(i, j, H, W) (0 <= i && i < H && 0 <= j && j < W)
using namespace std;
int main() {
cout << fixed << setprecision(11);
int N, K;
cin >> N >> K;
vector<ll> a(N + 1);
for (int i = 1; i <= N; i++)
cin >> a[i];
vector<vector<ll>> dp(N + 1, vector<ll>(K + 1, 0));
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 - 1] + dp[i - 1][j]) % IMAX;
if (j > a[i])
dp[i][j] = (dp[i][j] + IMAX - dp[i - 1][j - a[i] - 1]) % IMAX;
}
// for(int i=0;i<=N;i++){
// for(int j=0;j<=K;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[N][K] << endl;
return 0;
}
| [
"call.arguments.change",
"assignment.change"
] | 981,001 | 981,000 | u537874719 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
const ll MOD = (ll)1e9 + 7;
int main() {
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll k;
cin >> k;
vl a(n);
FOR(i, 0, n) cin >> a[i];
vvl dp(n + 1, vl(k + 1, 0));
dp[0][0] = 1;
FOR(i, 1, n + 1) {
ll len = 0;
ll ges = 0;
FOR(j, 0, k + 1) {
ges = (ges + dp[i - 1][j]) % MOD;
if (len == a[i - 1] + 1) {
ges = (ges - dp[i - 1][j - a[i - 1] - 1]) % MOD;
} else {
len++;
}
dp[i][j] = ges;
}
}
cout << dp[n][k] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
const ll MOD = (ll)1e9 + 7;
int main() {
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll k;
cin >> k;
vl a(n);
FOR(i, 0, n) cin >> a[i];
vvl dp(n + 1, vl(k + 1, 0));
dp[0][0] = 1;
FOR(i, 1, n + 1) {
ll len = 0;
ll ges = 0;
FOR(j, 0, k + 1) {
ges = (ges + dp[i - 1][j]) % MOD;
if (len == a[i - 1] + 1) {
ges = ((ges - dp[i - 1][j - a[i - 1] - 1]) + MOD) % MOD;
} else {
len++;
}
dp[i][j] = ges;
}
}
cout << dp[n][k] << endl;
return 0;
}
| [] | 981,002 | 981,003 | u420597302 | cpp |
p03172 | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define INF 1LL << 60
int main() {
ll mod = 1e9 + 7;
ll N, K;
cin >> N >> K;
vector<ll> a(N);
for (ll i = 0; i < N; i++)
cin >> a[i];
// dp[i][k]: i番目までの子供がk個の飴を分ける方法
vector<vector<ll>> dp(N, vector<ll>(K + 1));
for (ll i = 0; i < N; i++)
dp[i][0] = ll(1);
for (ll i = 0; i < N; i++)
for (ll k = 1; k <= K; k++)
if (i == 0) {
if (a[i] >= k)
dp[i][k] = ll(1);
} else {
if (k - 1 - a[i] >= 0)
dp[i][k] =
(dp[i][k - 1] - dp[i - 1][k - 1 - a[i]] + dp[i - 1][k]) % mod;
else
dp[i][k] = (dp[i][k - 1] + dp[i - 1][k]) % mod;
}
cout << dp[N - 1][K] << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define INF 1LL << 60
int main() {
ll mod = 1e9 + 7;
ll N, K;
cin >> N >> K;
vector<ll> a(N);
for (ll i = 0; i < N; i++)
cin >> a[i];
// dp[i][k]: i番目までの子供がk個の飴を分ける方法
vector<vector<ll>> dp(N, vector<ll>(K + 1));
for (ll i = 0; i < N; i++)
dp[i][0] = ll(1);
for (ll i = 0; i < N; i++)
for (ll k = 1; k <= K; k++)
if (i == 0) {
if (a[i] >= k)
dp[i][k] = ll(1);
} else {
if (k - 1 - a[i] >= 0)
dp[i][k] =
(dp[i][k - 1] - dp[i - 1][k - 1 - a[i]] + dp[i - 1][k] + mod) %
mod;
else
dp[i][k] = (dp[i][k - 1] + dp[i - 1][k]) % mod;
}
cout << dp[N - 1][K] % mod << endl;
return 0;
} | [
"assignment.change"
] | 981,004 | 981,005 | u941028483 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vpl = vector<pll>;
using vvpl = vector<vpl>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define R(a, i) for (ll a = 0; a < (i); (a)++)
#define FOR(a, i, j) for (ll a = (i); a < (j); (a)++)
#define RD(a, i) for (ll a = (i)-1; (a) >= 0; (a)--)
#define FORD(a, i, j) for (ll a = (j)-1; (a) >= (i); (a)--)
#define xx first
#define yy second
#define pb push_back
#define all(X) begin(X), end(X)
#define sz(X) (X).size()
const ll oo = 0x3f3f3f3f3f3f3f3f;
const ld eps = 1e-9;
#define DBG 0
#define TR(X) \
{ \
if (DBG) \
cerr << (#X) << " = " << (X) << "\n"; \
}
#define TRM(X, i, j) \
{ \
if (DBG) \
cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j]) << "\n"; \
}
#define hline \
{ \
if (DBG) \
cerr << "--------------------------------------------------------------" \
"--------" \
<< "\n"; \
}
#define PK(X) \
{ \
if (DBG) \
cerr << (X) << "\n"; \
}
const ll mod = 1e9 + 7;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
TR(N);
TR(K);
vvl dp(N + 2, vl(K + 2, 0));
ll bisher = 0;
FOR(i, 1, N + 1) {
ll ai;
cin >> ai;
bisher += ai;
dp[i][0] = 1;
FOR(j, 1, K + 1) {
if (j <= ai) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
} else if (j <= bisher) {
dp[i][j] =
(dp[i - 1][j] + dp[i][j - 1] - dp[i][j - ai - 1] + mod) % mod;
}
TRM(dp, i, j);
}
}
cout << dp[N][K] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vpl = vector<pll>;
using vvpl = vector<vpl>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define R(a, i) for (ll a = 0; a < (i); (a)++)
#define FOR(a, i, j) for (ll a = (i); a < (j); (a)++)
#define RD(a, i) for (ll a = (i)-1; (a) >= 0; (a)--)
#define FORD(a, i, j) for (ll a = (j)-1; (a) >= (i); (a)--)
#define xx first
#define yy second
#define pb push_back
#define all(X) begin(X), end(X)
#define sz(X) (X).size()
const ll oo = 0x3f3f3f3f3f3f3f3f;
const ld eps = 1e-9;
#define DBG 0
#define TR(X) \
{ \
if (DBG) \
cerr << (#X) << " = " << (X) << "\n"; \
}
#define TRM(X, i, j) \
{ \
if (DBG) \
cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j]) << "\n"; \
}
#define hline \
{ \
if (DBG) \
cerr << "--------------------------------------------------------------" \
"--------" \
<< "\n"; \
}
#define PK(X) \
{ \
if (DBG) \
cerr << (X) << "\n"; \
}
const ll mod = 1e9 + 7;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
TR(N);
TR(K);
vvl dp(N + 2, vl(K + 2, 0));
ll bisher = 0;
FOR(i, 1, N + 1) {
ll ai;
cin >> ai;
bisher += ai;
dp[i][0] = 1;
FOR(j, 1, K + 1) {
if (j <= ai) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
} else if (j <= bisher) {
dp[i][j] =
(dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - ai - 1] + mod) % mod;
}
TRM(dp, i, j);
}
}
cout << dp[N][K] << endl;
}
| [] | 981,006 | 981,007 | u615346437 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vpl = vector<pll>;
using vvpl = vector<vpl>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define R(a, i) for (ll a = 0; a < (i); (a)++)
#define FOR(a, i, j) for (ll a = (i); a < (j); (a)++)
#define RD(a, i) for (ll a = (i)-1; (a) >= 0; (a)--)
#define FORD(a, i, j) for (ll a = (j)-1; (a) >= (i); (a)--)
#define xx first
#define yy second
#define pb push_back
#define all(X) begin(X), end(X)
#define sz(X) (X).size()
const ll oo = 0x3f3f3f3f3f3f3f3f;
const ld eps = 1e-9;
#define DBG 0
#define TR(X) \
{ \
if (DBG) \
cerr << (#X) << " = " << (X) << "\n"; \
}
#define TRM(X, i, j) \
{ \
if (DBG) \
cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j]) << "\n"; \
}
#define hline \
{ \
if (DBG) \
cerr << "--------------------------------------------------------------" \
"--------" \
<< "\n"; \
}
#define PK(X) \
{ \
if (DBG) \
cerr << (X) << "\n"; \
}
const ll mod = 1e9 + 7;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
TR(N);
TR(K);
vvl dp(N + 2, vl(K + 2, 0));
ll bisher = 0;
FOR(i, 1, N + 1) {
ll ai;
cin >> ai;
bisher += ai;
dp[i][0] = 1;
FOR(j, 1, K + 1) {
if (j <= ai) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
} else if (j <= bisher) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i][j - ai - 1]) % mod;
}
TRM(dp, i, j);
}
}
cout << dp[N][K] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vpl = vector<pll>;
using vvpl = vector<vpl>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define R(a, i) for (ll a = 0; a < (i); (a)++)
#define FOR(a, i, j) for (ll a = (i); a < (j); (a)++)
#define RD(a, i) for (ll a = (i)-1; (a) >= 0; (a)--)
#define FORD(a, i, j) for (ll a = (j)-1; (a) >= (i); (a)--)
#define xx first
#define yy second
#define pb push_back
#define all(X) begin(X), end(X)
#define sz(X) (X).size()
const ll oo = 0x3f3f3f3f3f3f3f3f;
const ld eps = 1e-9;
#define DBG 0
#define TR(X) \
{ \
if (DBG) \
cerr << (#X) << " = " << (X) << "\n"; \
}
#define TRM(X, i, j) \
{ \
if (DBG) \
cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j]) << "\n"; \
}
#define hline \
{ \
if (DBG) \
cerr << "--------------------------------------------------------------" \
"--------" \
<< "\n"; \
}
#define PK(X) \
{ \
if (DBG) \
cerr << (X) << "\n"; \
}
const ll mod = 1e9 + 7;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
TR(N);
TR(K);
vvl dp(N + 2, vl(K + 2, 0));
ll bisher = 0;
FOR(i, 1, N + 1) {
ll ai;
cin >> ai;
bisher += ai;
dp[i][0] = 1;
FOR(j, 1, K + 1) {
if (j <= ai) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
} else if (j <= bisher) {
dp[i][j] =
(dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - ai - 1] + mod) % mod;
}
TRM(dp, i, j);
}
}
cout << dp[N][K] << endl;
}
| [
"assignment.change"
] | 981,008 | 981,007 | u615346437 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, mod = 1000000007;
cin >> n >> k;
vector<int> A(n, 0);
for (int i = 0; i < n; i++)
cin >> A[i];
vector<vector<long long int>> dp(n, vector<long long int>(k + 1, 0));
vector<vector<long long int>> prefix(n, vector<long long int>(k + 1, 0));
for (int i = 0; i < n; i++) {
dp[i][0] = 1;
prefix[i][0] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = 1; j <= k; j++) {
if (i == 0) {
if (j <= A[i])
dp[i][j] = 1;
} else {
int index = max(0, j - A[i]);
if (index == 0)
dp[i][j] = prefix[i - 1][j];
else
dp[i][j] = (prefix[i - 1][j] - prefix[i - 1][index - 1]) % mod;
}
prefix[i][j] = (prefix[i][j - 1] + dp[i][j]) % mod;
}
}
cout << dp[n - 1][k];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, mod = 1000000007;
cin >> n >> k;
vector<int> A(n, 0);
for (int i = 0; i < n; i++)
cin >> A[i];
vector<vector<long long int>> dp(n, vector<long long int>(k + 1, 0));
vector<vector<long long int>> prefix(n, vector<long long int>(k + 1, 0));
for (int i = 0; i < n; i++) {
dp[i][0] = 1;
prefix[i][0] = 1;
}
for (int i = 0; i < n; i++) {
for (int j = 1; j <= k; j++) {
if (i == 0) {
if (j <= A[i])
dp[i][j] = 1;
} else {
int index = max(0, j - A[i]);
if (index == 0)
dp[i][j] = prefix[i - 1][j];
else
dp[i][j] =
((prefix[i - 1][j] - prefix[i - 1][index - 1]) % mod + mod) % mod;
}
prefix[i][j] = (prefix[i][j - 1] + dp[i][j]) % mod;
}
}
cout << dp[n - 1][k];
} | [
"assignment.change"
] | 981,009 | 981,010 | u719635221 | cpp |
p03172 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L + 7;
int n;
vector<int> inp;
vector<vector<ll>> dp;
ll candp(int k, int i = 0) {
// cout<<i<<" "<<j<<" "<<c<<" "<<sum<<'\n';
if (k == 0)
return 1;
if (i == n)
return 0;
if (dp[i][k] != -1)
return dp[i][k];
ll ans = 0;
for (int a = 0; a <= inp[i]; a++) {
if (k - a >= 0) {
ans += candp(k - a, i + 1);
ans %= mod;
} else
break;
}
return dp[i][k] = ans;
}
ll cf_solver(int k) {
vector<vector<ll>> cf_dp(k + 1, vector<ll>(n + 1, 1));
for (int a = 1; a <= k; a++) {
for (int i = 1; i <= n; i++) {
ll ans = 0;
int sub = min(a, inp[i]);
sub++;
if (a - sub == -1)
ans = cf_dp[a][i - 1];
else
ans = cf_dp[a][i - 1] - cf_dp[a - sub][i - 1];
if (ans < 0)
ans += mod;
ans += cf_dp[a - 1][i];
ans %= mod;
cf_dp[a][i] = ans;
}
}
ll ret_val = cf_dp[k][n];
if (k > 0)
ret_val -= -cf_dp[k - 1][n];
if (ret_val < 0)
ret_val += mod;
ret_val %= mod;
return ret_val;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int k;
cin >> n >> k;
inp.resize(n + 1);
dp.assign(n + 1, vector<ll>(k + 1, -1));
for (int i = 1; i <= n; i++) {
cin >> inp[i];
}
// cout<<candp(k)<<'\n';
cout << cf_solver(k) << '\n';
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L + 7;
int n;
vector<int> inp;
vector<vector<ll>> dp;
ll candp(int k, int i = 0) {
// cout<<i<<" "<<j<<" "<<c<<" "<<sum<<'\n';
if (k == 0)
return 1;
if (i == n)
return 0;
if (dp[i][k] != -1)
return dp[i][k];
ll ans = 0;
for (int a = 0; a <= inp[i]; a++) {
if (k - a >= 0) {
ans += candp(k - a, i + 1);
ans %= mod;
} else
break;
}
return dp[i][k] = ans;
}
ll cf_solver(int k) {
vector<vector<ll>> cf_dp(k + 1, vector<ll>(n + 1, 1));
for (int a = 1; a <= k; a++) {
for (int i = 1; i <= n; i++) {
ll ans = 0;
int sub = min(a, inp[i]);
sub++;
if (a - sub == -1)
ans = cf_dp[a][i - 1];
else
ans = cf_dp[a][i - 1] - cf_dp[a - sub][i - 1];
if (ans < 0)
ans += mod;
ans += cf_dp[a - 1][i];
ans %= mod;
cf_dp[a][i] = ans;
}
}
ll ret_val = cf_dp[k][n];
if (k > 0)
ret_val -= cf_dp[k - 1][n];
if (ret_val < 0)
ret_val += mod;
ret_val %= mod;
return ret_val;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int k;
cin >> n >> k;
inp.resize(n + 1);
dp.assign(n + 1, vector<ll>(k + 1, -1));
for (int i = 1; i <= n; i++) {
cin >> inp[i];
}
// cout<<candp(k)<<'\n';
cout << cf_solver(k) << '\n';
}
| [
"expression.operation.unary.arithmetic.remove"
] | 980,802 | 980,803 | u351351871 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j;
cin >> n >> k;
int m = 1e9 + 7;
int a[n + 1], s[k + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 1][k + 1];
dp[0][0] = 1;
for (i = 1; i <= k; i++)
dp[0][i] = 0;
for (i = 1; i <= n; i++) {
s[0] = dp[i - 1][0];
for (j = 1; j <= k; j++)
s[j] = (s[j - 1] + dp[i - 1][j]) % m;
for (j = 0; j <= k; j++) {
int x = s[j];
int y = j - a[i] - 1;
if (y >= 0)
x = (x - s[y]) % m;
dp[i][j] = x;
}
}
cout << dp[n][k];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j;
cin >> n >> k;
int m = 1e9 + 7;
int a[n + 1], s[k + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 1][k + 1];
dp[0][0] = 1;
for (i = 1; i <= k; i++)
dp[0][i] = 0;
for (i = 1; i <= n; i++) {
s[0] = dp[i - 1][0];
for (j = 1; j <= k; j++)
s[j] = (s[j - 1] + dp[i - 1][j]) % m;
for (j = 0; j <= k; j++) {
int x = s[j];
int y = j - a[i] - 1;
if (y >= 0)
x = (x - s[y] + m) % m;
dp[i][j] = x;
}
}
cout << dp[n][k];
} | [
"assignment.change"
] | 980,804 | 980,805 | u391913928 | cpp |
p03172 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0);
typedef long long ll;
#define pb push_back
typedef pair<ll, ll> pi;
int main() {
IOS();
int n;
int k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
ll dp[n + 1][k + 1] = {0ll};
for (int j = 0; j <= k; j++) {
if (j <= a[1])
dp[1][j] = 1;
else
dp[1][j] = 0;
}
for (int i = 2; 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][j - 1] + dp[i - 1][j] -
((j - a[i] - 1 >= 0) ? dp[i - 1][j - a[i] - 1] : 0)) %
MOD;
}
}
}
cout << dp[n][k] << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0);
typedef long long ll;
#define pb push_back
typedef pair<ll, ll> pi;
int main() {
IOS();
int n;
int k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
ll dp[n + 1][k + 1] = {0ll};
for (int j = 0; j <= k; j++) {
if (j <= a[1])
dp[1][j] = 1;
else
dp[1][j] = 0;
}
for (int i = 2; i <= n; i++) {
for (int 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 >= 0) ? dp[i - 1][j - a[i] - 1] : 0)) %
MOD;
}
}
}
cout << dp[n][k] << endl;
return 0;
} | [
"assignment.change"
] | 980,806 | 980,807 | u230561415 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define ll int
ll mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
ll x[n], dp[k + 1] = {};
dp[0] = 1;
for (ll &i : x)
cin >> i;
for (ll i = 0; i < n; i++) {
ll pre[k + 2] = {};
for (ll j = 0; j <= k; j++)
pre[j + 1] = pre[j] + dp[j], pre[j + 1] %= mod;
for (ll j = k; j >= 0; j--) {
dp[j] += pre[j] - pre[max(j - x[i], 0)];
dp[j] = (dp[j] + mod) % mod;
}
}
cout << dp[k];
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
ll x[n], dp[k + 1] = {};
dp[0] = 1;
for (ll &i : x)
cin >> i;
for (ll i = 0; i < n; i++) {
ll pre[k + 2] = {};
for (ll j = 0; j <= k; j++)
pre[j + 1] = pre[j] + dp[j], pre[j + 1] %= mod;
for (ll j = k; j >= 0; j--) {
dp[j] += pre[j] - pre[max(j - x[i], 0ll)];
dp[j] = (dp[j] + mod) % mod;
}
}
cout << dp[k];
}
| [
"preprocessor.define.value.change",
"call.arguments.change"
] | 980,808 | 981,011 | u699490860 | cpp |
p03172 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000
using namespace std;
const int N = 2e5 + 10;
LL dp[110][N];
LL a[N], pr[N];
int n, k;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
pr[i] = pr[i - 1] + a[i];
for (int i = 0; i <= k; i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++)
dp[i][j] =
(dp[i - 1][j] - (a[i] >= j ? 0 : dp[i - 1][j - a[i] - 1]) + MOD) %
MOD;
for (int j = 1; j <= k; j++)
dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
}
printf("%lld\n", dp[n][k] - dp[n][k - 1] + MOD % MOD);
cin >> n;
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000
using namespace std;
const int N = 2e5 + 10;
LL dp[110][N];
LL a[N], pr[N];
int n, k;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
pr[i] = pr[i - 1] + a[i];
for (int i = 0; i <= k; i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++)
dp[i][j] =
(dp[i - 1][j] - (a[i] >= j ? 0 : dp[i - 1][j - a[i] - 1]) + MOD) %
MOD;
for (int j = 1; j <= k; j++)
dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
}
printf("%lld\n", (dp[n][k] - dp[n][k - 1] % MOD + MOD) % MOD);
cin >> n;
} | [
"call.arguments.change"
] | 981,012 | 981,013 | u406924690 | cpp |
p03172 | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000
using namespace std;
const int N = 2e5 + 10;
LL dp[110][N];
LL a[N], pr[N];
int n, k;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
pr[i] = pr[i - 1] + a[i];
for (int i = 0; i <= k; i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++)
dp[i][j] =
(dp[i - 1][j] - (a[i] >= j ? 0 : dp[i - 1][j - a[i] - 1]) + MOD) %
MOD;
for (int j = 1; j <= k; j++)
dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
}
printf("%lld\n", dp[n][k] - dp[n][k - 1] % MOD);
cin >> n;
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <stdio.h>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
//#include <tchar.h>
//#include <intrin.h>
#define F first
#define S second
#define LL long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 1000000000000000000
using namespace std;
const int N = 2e5 + 10;
LL dp[110][N];
LL a[N], pr[N];
int n, k;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
pr[i] = pr[i - 1] + a[i];
for (int i = 0; i <= k; i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++)
dp[i][j] =
(dp[i - 1][j] - (a[i] >= j ? 0 : dp[i - 1][j - a[i] - 1]) + MOD) %
MOD;
for (int j = 1; j <= k; j++)
dp[i][j] = (dp[i][j - 1] + dp[i][j]) % MOD;
}
printf("%lld\n", (dp[n][k] - dp[n][k - 1] % MOD + MOD) % MOD);
cin >> n;
} | [
"call.arguments.change"
] | 981,014 | 981,013 | u406924690 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _cin \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define endl "\n"
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define repd(i, a, b) for (ll i = a; i >= b; --i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define mll map<ll, ll>
#define sz(x) (ll) x.size()
#define sll set<ll>
#define pll pair<ll, ll>
#define F first
#define S second
const ll MAX = 1000004;
const ll INF = 1e18L + 5;
int main() {
_cin
// READ
// WRITE
ll n,
k;
cin >> n >> k;
ll a[n + 1];
rep(i, 1, n + 1) cin >> a[i];
ll dp[n + 1][k + 1];
dp[0][0] = 1;
rep(i, 1, k + 1) dp[0][i] = 0;
rep(i, 1, n + 1) {
vll sum(k + 1, 0);
sum[0] = dp[i - 1][0];
rep(j, 1, k + 1) sum[j] = (sum[j - 1] + dp[i - 1][j]) % hell;
rep(j, 0, k + 1) {
if (j <= a[i]) {
dp[i][j] = sum[j];
} else {
ll s = (j - a[i] - 1);
dp[i][j] = (sum[j] - sum[s]) % hell;
}
}
sum.clear();
}
cout << dp[n][k] % hell << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _cin \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define endl "\n"
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define repd(i, a, b) for (ll i = a; i >= b; --i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define mll map<ll, ll>
#define sz(x) (ll) x.size()
#define sll set<ll>
#define pll pair<ll, ll>
#define F first
#define S second
const ll MAX = 1000004;
const ll INF = 1e18L + 5;
int main() {
_cin
// READ
// WRITE
ll n,
k;
cin >> n >> k;
ll a[n + 1];
rep(i, 1, n + 1) cin >> a[i];
ll dp[n + 1][k + 1];
dp[0][0] = 1;
rep(i, 1, k + 1) dp[0][i] = 0;
rep(i, 1, n + 1) {
vll sum(k + 1, 0);
sum[0] = dp[i - 1][0];
rep(j, 1, k + 1) sum[j] = (sum[j - 1] + dp[i - 1][j]) % hell;
rep(j, 0, k + 1) {
if (j <= a[i]) {
dp[i][j] = sum[j];
} else {
ll s = (j - a[i] - 1);
dp[i][j] = (sum[j] - sum[s] + hell) % hell;
}
}
sum.clear();
}
cout << dp[n][k] % hell << endl;
} | [
"assignment.change"
] | 981,017 | 981,018 | u272596102 | cpp |
p03172 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int solve(vector<int> &v, int n, int k) {
long long dp[n + 2][k + 2];
for (int j = 0; j <= k; j++)
dp[1][j] = (j > v[1]) ? 0 : 1;
for (int i = 2; 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][j - 1] + dp[i - 1][j] -
((j - v[i] - 1 >= 0) ? dp[i - 1][j - v[i] - 1] : 0)) %
1000000007;
}
}
return dp[n][k];
}
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
cout << solve(v, n, k);
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int solve(vector<int> &v, int n, int k) {
long long dp[n + 2][k + 2];
for (int j = 0; j <= k; j++)
dp[1][j] = (j > v[1]) ? 0 : 1;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = (1000000007 + dp[i][j - 1] + dp[i - 1][j] -
((j - v[i] - 1 >= 0) ? dp[i - 1][j - v[i] - 1] : 0)) %
1000000007;
}
}
return dp[n][k];
}
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
cout << solve(v, n, k);
return 0;
} | [
"assignment.change"
] | 981,023 | 981,024 | u817291402 | cpp |
p03172 | #include <bits/stdc++.h>
#define boost_io \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define debug(x) cout << #x << ":" << x << " "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF = 1e9 + 7;
ll INF = 1e11;
void solve() {
int n, k;
cin >> n >> k;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
v<v<ll>> dp(n + 1, v<ll>(k + 1));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = 1;
} else if (i == 0) {
dp[i][j] = dp[i][j - 1];
} else {
int h = j - a[i - 1];
if (h <= 0)
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % modF;
else
dp[i][j] =
(dp[i - 1][j] - dp[i - 1][h - 1] + dp[i][j - 1] + modF) % modF;
}
}
}
if (k == 0) {
cout << 1 << "\n";
return;
}
cout << dp[n][k] - dp[n][k - 1] << "\n";
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
#define boost_io \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define debug(x) cout << #x << ":" << x << " "
#define all(a) (a).begin(), (a).end()
#define cast static_cast
#define vi vector<int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF = 1e9 + 7;
ll INF = 1e11;
void solve() {
int n, k;
cin >> n >> k;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
v<v<ll>> dp(n + 1, v<ll>(k + 1));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = 1;
} else if (i == 0) {
dp[i][j] = dp[i][j - 1];
} else {
int h = j - a[i - 1];
if (h <= 0)
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % modF;
else
dp[i][j] =
(dp[i - 1][j] - dp[i - 1][h - 1] + dp[i][j - 1] + modF) % modF;
}
}
}
if (k == 0) {
cout << 1 << "\n";
return;
}
cout << (dp[n][k] - dp[n][k - 1] + modF) % modF << "\n";
}
int main() {
solve();
return 0;
} | [
"expression.operation.binary.add"
] | 981,030 | 981,031 | u087802159 | cpp |
p03172 | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ld double
using namespace std;
const int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
int dp[n + 2][k + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= k && i <= arr[0]; i++)
dp[1][i] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
dp[i][j] = dp[i - 1][j] % mod;
if (j - 1 >= 0)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
if (j - 1 - arr[i - 1] >= 0)
dp[i][j] = (dp[i][j] - dp[i - 1][j - 1 - arr[i - 1]]) % mod;
}
}
/*for(int i=1;i<=n;i++)
{for(int j=0;j<=k;j++)
cout<<dp[i][j]<<" ";
cout<<"\n";
}*/
cout << dp[n][k] << "\n";
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ld double
using namespace std;
const int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
int dp[n + 2][k + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= k && i <= arr[0]; i++)
dp[1][i] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
dp[i][j] = dp[i - 1][j] % mod;
if (j - 1 >= 0)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
if (j - 1 - arr[i - 1] >= 0)
dp[i][j] = (dp[i][j] - dp[i - 1][j - 1 - arr[i - 1]] + mod) % mod;
}
}
/*for(int i=1;i<=n;i++)
{for(int j=0;j<=k;j++)
cout<<dp[i][j]<<" ";
cout<<"\n";
}*/
cout << dp[n][k] << "\n";
return 0;
} | [
"assignment.change"
] | 981,032 | 981,033 | u332705919 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int solve(vector<int> &vec, int n, int k) {
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++)
dp[1][j] = (j > vec[1]) ? 0 : 1;
for (int i = 2; i <= n; i++) {
for (int 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 > vec[i] - 1 > 0) ? dp[i - 1][j - vec[i] - 1] : 0)) %
mod;
}
}
}
return dp[n][k];
}
signed main() {
int n, k;
cin >> n >> k;
vector<int> vec(n + 1);
for (int i = 1; i <= n; i++)
cin >> vec[i];
cout << solve(vec, n, k);
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int solve(vector<int> &vec, int n, int k) {
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++)
dp[1][j] = (j > vec[1]) ? 0 : 1;
for (int i = 2; i <= n; i++) {
for (int 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 - vec[i] - 1 >= 0) ? dp[i - 1][j - vec[i] - 1] : 0)) %
mod;
}
}
}
return dp[n][k];
}
signed main() {
int n, k;
cin >> n >> k;
vector<int> vec(n + 1);
for (int i = 1; i <= n; i++)
cin >> vec[i];
cout << solve(vec, n, k);
} | [
"assignment.value.change",
"expression.operation.binary.change",
"expression.operator.compare.change"
] | 981,036 | 981,037 | u922620013 | cpp |
p03172 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ff first
#define endl "\n"
#define ss second
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom pair<int, pair<int, int>>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define mod 1000000007
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
ll arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll dp[n][k + 1];
for (int j = 0; j <= k; j++) {
dp[0][j] = (j > arr[0]) ? 0 : 1;
}
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] -
((j > arr[i]) ? dp[i - 1][j - arr[i] - 1] : 0)) %
mod;
}
}
}
cout << dp[n - 1][k];
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ff first
#define endl "\n"
#define ss second
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom pair<int, pair<int, int>>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
#define mod 1000000007
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
ll arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll dp[n][k + 1];
for (int j = 0; j <= k; j++) {
dp[0][j] = (j > arr[0]) ? 0 : 1;
}
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] -
((j > arr[i]) ? dp[i - 1][j - arr[i] - 1] : 0) + mod) %
mod;
}
}
}
cout << dp[n - 1][k];
return 0;
} | [
"assignment.change"
] | 981,045 | 981,046 | u535940884 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;
int main() {
ll n, k;
cin >> n >> k;
vec a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
mat dp(n + 1, vec(k + 10));
dp[0][0] = 1;
for (ll i = 0; i < n; i++) {
vec sum(k + 1);
for (ll j = 0; j <= k; j++) {
(sum[j + 1] = sum[j] + dp[i][j]) %= mod;
}
for (ll j = 0; j <= k; j++) {
dp[i + 1][j] = (sum[j + 1] - sum[max(0LL, j - a[i])] + mod) % mod;
}
}
cout << dp[n][k] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;
int main() {
ll n, k;
cin >> n >> k;
vec a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
mat dp(n + 1, vec(k + 10));
dp[0][0] = 1;
for (ll i = 0; i < n; i++) {
vec sum(k + 10);
for (ll j = 0; j <= k; j++) {
(sum[j + 1] = sum[j] + dp[i][j]) %= mod;
}
for (ll j = 0; j <= k; j++) {
dp[i + 1][j] = (sum[j + 1] - sum[max(0LL, j - a[i])] + mod) % mod;
}
}
cout << dp[n][k] << endl;
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 981,047 | 981,048 | u718758485 | cpp |
p03172 |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
dp[1][j] = a[1] >= j ? 1 : 0;
}
for (int i = 2; 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][j - 1] + dp[i - 1][j] -
((j - 1 - a[i]) >= 0 ? dp[i - 1][j - 1 - a[i]] : 0)) %
1000000007;
}
}
}
cout << dp[n][k];
} |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
dp[1][j] = a[1] >= j ? 1 : 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = (1000000007 + dp[i][j - 1] + dp[i - 1][j] -
((j - 1 - a[i]) >= 0 ? dp[i - 1][j - 1 - a[i]] : 0)) %
1000000007;
}
}
}
cout << dp[n][k];
} | [
"assignment.change"
] | 981,049 | 981,050 | u536383397 | cpp |
p03172 |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
dp[1][j] = a[1] >= j ? 1 : 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = (1000000007 + dp[i][j - 1] + dp[i - 1][j] -
((j - 1 - a[i]) > 0 ? dp[i - 1][j - 1 - a[i]] : 0)) %
1000000007;
}
}
}
cout << dp[n][k];
} |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
dp[1][j] = a[1] >= j ? 1 : 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = (1000000007 + dp[i][j - 1] + dp[i - 1][j] -
((j - 1 - a[i]) >= 0 ? dp[i - 1][j - 1 - a[i]] : 0)) %
1000000007;
}
}
}
cout << dp[n][k];
} | [
"expression.operator.compare.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 981,051 | 981,050 | u536383397 | cpp |
p03172 |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
dp[1][j] = a[1] >= j ? 1 : 0;
}
for (int i = 2; 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][j - 1] + dp[i - 1][j] -
((j - 1 - a[i]) > 0 ? dp[i - 1][j - 1 - a[i]] : 0)) %
1000000007;
}
}
}
cout << dp[n][k];
} |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define int long long
int32_t main() {
int n, k;
cin >> n >> k;
int a[n + 2];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
dp[1][j] = a[1] >= j ? 1 : 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = (1000000007 + dp[i][j - 1] + dp[i - 1][j] -
((j - 1 - a[i]) >= 0 ? dp[i - 1][j - 1 - a[i]] : 0)) %
1000000007;
}
}
}
cout << dp[n][k];
} | [
"assignment.change",
"expression.operator.compare.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 981,052 | 981,050 | u536383397 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
ll arr[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
ll dp[n + 1][k + 1]; // dp[i][j] is number of ways to distribute j candies
// among first i people
for (int i = 1; i <= k; i++) {
dp[0][i] = 0;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
ll sum[k + 1]; // sum[j] is number of ways to distribute atmost j candies
// among i-1 people
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++) {
ll upper = sum[j];
ll lower_index = j - arr[i] - 1;
if (lower_index >= 0) {
upper = (upper - sum[lower_index] % MOD);
}
dp[i][j] = upper % MOD;
}
}
cout << dp[n][k] % MOD << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
ll arr[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
ll dp[n + 1][k + 1]; // dp[i][j] is number of ways to distribute j candies
// among first i people
for (int i = 1; i <= k; i++) {
dp[0][i] = 0;
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
ll sum[k + 1]; // sum[j] is number of ways to distribute atmost j candies
// among i-1 people
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++) {
ll upper = sum[j];
ll lower_index = j - arr[i] - 1;
if (lower_index >= 0) {
upper = (upper - sum[lower_index] + MOD) % MOD;
}
dp[i][j] = upper % MOD;
}
}
cout << dp[n][k] % MOD << "\n";
return 0;
}
| [
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"assignment.change"
] | 981,058 | 981,059 | u238930677 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1e9 + 7;
signed main() {
lint N, K;
cin >> N >> K;
vector<lint> a(N);
for (lint i = 0; i < N; i++)
cin >> a[i];
vector<vector<lint>> dp(N + 1, vector<lint>(K + 1, 0));
for (lint i = 0; i <= N; i++)
dp[i][0] = 1;
for (lint i = 0; i < N; i++) {
for (lint j = 1; j <= K; j++) {
if (j - 1 - a[i] >= 0) {
dp[i + 1][j] = dp[i + 1][j - 1] + dp[i][j] - dp[i][j - 1 - a[i]];
dp[i + 1][j] %= MOD;
} else
dp[i + 1][j] = dp[i + 1][j - 1] + dp[i][j];
dp[i + 1][j] %= MOD;
}
}
cout << dp[N][K] << endl;
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1e9 + 7;
signed main() {
lint N, K;
cin >> N >> K;
vector<lint> a(N);
for (lint i = 0; i < N; i++)
cin >> a[i];
vector<vector<lint>> dp(N + 1, vector<lint>(K + 1, 0));
for (lint i = 0; i <= N; i++)
dp[i][0] = 1;
for (lint i = 0; i < N; i++) {
for (lint j = 1; j <= K; j++) {
if (j - 1 - a[i] >= 0) {
dp[i + 1][j] = dp[i + 1][j - 1] + dp[i][j] - dp[i][j - 1 - a[i]] + MOD;
dp[i + 1][j] %= MOD;
} else
dp[i + 1][j] = dp[i + 1][j - 1] + dp[i][j];
dp[i + 1][j] %= MOD;
}
}
cout << dp[N][K] << endl;
} | [
"assignment.change"
] | 981,064 | 981,065 | u265359795 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout << #n << ' ' << n << endl;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i];
ll dp[n + 1][k + 1];
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
for (int j = 1; j <= k; j++)
dp[0][j] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (j <= a[i])
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
else
dp[i][j] =
(dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - a[i] - 1]) % mod;
}
}
cout << dp[n][k] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout << #n << ' ' << n << endl;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i];
ll dp[n + 1][k + 1];
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
for (int j = 1; j <= k; j++)
dp[0][j] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (j <= a[i])
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
else
dp[i][j] =
(dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - a[i] - 1] + mod) % mod;
}
}
cout << dp[n][k] << endl;
}
| [
"assignment.change"
] | 981,068 | 981,069 | u486906248 | cpp |
p03172 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define inp 20
#define check exit(0)
#define nl cout << endl;
#define mod 1000000007
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define deb(v) \
for (int i = 0; i < v.size(); i++) { \
cout << v[i]; \
(i == v.size() - 1) ? cout << "\n" : cout << " "; \
}
#define jaldi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ordered_set \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
// Errichto ... ;)
void md(ll &a) { a %= mod; }
void add_self(int &a, int b) {
a += b;
if (a >= mod) {
a -= mod;
}
}
void sub_self(int &a, int b) {
a -= b;
if (a < 0) {
a += mod;
}
}
int main() {
jaldi
int n,
k;
cin >> n >> k;
vector<int> dp(k + 1, 0);
dp[0] = 1;
for (int child = 1; child <= n; child++) {
int upto;
cin >> upto;
vector<int> tmp(k + 2, 0);
for (int ubho = k; ubho >= 0; ubho--) {
int toadd = dp[ubho];
int l = ubho + 1;
int r = ubho + min(upto, k - ubho);
if (l <= r) {
add_self(tmp[l], toadd);
sub_self(tmp[r + 1], toadd);
}
}
int ps = 0;
for (int i = 0; i <= k; i++) {
ps += tmp[i];
ps %= mod;
dp[i] += tmp[i];
dp[i] %= mod;
// add_self(ps,tmp[i]);
// add_self(dp[i],ps);
}
}
cout << dp[k];
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define inp 20
#define check exit(0)
#define nl cout << endl;
#define mod 1000000007
#define ll long long int
#define trace(x) cerr << #x << " : " << x << endl;
#define deb(v) \
for (int i = 0; i < v.size(); i++) { \
cout << v[i]; \
(i == v.size() - 1) ? cout << "\n" : cout << " "; \
}
#define jaldi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ordered_set \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
// Errichto ... ;)
void md(ll &a) { a %= mod; }
void add_self(int &a, int b) {
a += b;
if (a >= mod) {
a -= mod;
}
}
void sub_self(int &a, int b) {
a -= b;
if (a < 0) {
a += mod;
}
}
int main() {
jaldi
int n,
k;
cin >> n >> k;
vector<int> dp(k + 1, 0);
dp[0] = 1;
for (int child = 1; child <= n; child++) {
int upto;
cin >> upto;
vector<int> tmp(k + 2, 0);
for (int ubho = k; ubho >= 0; ubho--) {
int toadd = dp[ubho];
int l = ubho + 1;
int r = ubho + min(upto, k - ubho);
if (l <= r) {
add_self(tmp[l], toadd);
sub_self(tmp[r + 1], toadd);
}
}
int ps = 0;
for (int i = 0; i <= k; i++) {
ps += tmp[i];
ps %= mod;
dp[i] += ps;
dp[i] %= mod;
// add_self(ps,tmp[i]);
// add_self(dp[i],ps);
}
}
cout << dp[k];
return 0;
} | [
"assignment.value.change"
] | 981,070 | 981,071 | u319910051 | cpp |
p03172 | #include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX
#define dd double
#define fi first
#define se second
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long, long long>>
#define vpcl vector<pair<char, long long>>
#define vpsl vector<pair<string, long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long, long long>
#define pll pair<long long, long long>
#define psl pair<string, long long>
#define mcl map<char, long long>
#define msl map<string, long long>
#define pcl pair<char, long long>
#define mmll multimap<long long, long long>
#define mmcl multimap<char, long long>
#define mmsl multimap<string, long long>
#define sll set<long long>
#define sc set<char>
#define ss set<string>
#define msll multiset<long long>
#define msc multiset<char>
#define mss multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
using namespace __gnu_pbds;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll modexp(ll x, ll n, ll p) { // modular exponential function
if (n == 0) {
return 1;
}
ll u = modexp(x, n / 2, p);
u = u * u % p;
if (n % 2 == 1) {
u = (u * x) % p;
}
return u;
}
ll gcd(ll a, ll b) { // Eulers algorithm
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll m = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
ll arr[n];
rep(i, 0, n - 1) { cin >> arr[i]; }
ll pst[k + 1][n], dp[k + 1][n];
// pst -> prefix sum array
// dp[i][j] -> ways to distribute i candies among j children;
rep(i, 0, k) {
rep(j, 0, n - 1) {
if (i == 0) {
dp[i][j] = 1;
pst[i][j] = 1;
continue;
}
if (j == 0) {
if (arr[j] >= i) {
dp[i][j] = 1;
if (i >= 1) {
pst[i][j] = (1 + pst[i - 1][j] % m) % m;
} else {
pst[i][j] = 1;
}
} else {
dp[i][j] = 0;
pst[i][j] = pst[i - 1][j] % m;
}
continue;
}
if (arr[j] >= i) {
dp[i][j] = pst[i][j - 1] % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
} else {
dp[i][j] = (pst[i][j - 1] % m - pst[i - arr[j] - 1][j - 1] % m) % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
}
}
}
cout << dp[k][n - 1];
}
| #include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX
#define dd double
#define fi first
#define se second
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long, long long>>
#define vpcl vector<pair<char, long long>>
#define vpsl vector<pair<string, long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long, long long>
#define pll pair<long long, long long>
#define psl pair<string, long long>
#define mcl map<char, long long>
#define msl map<string, long long>
#define pcl pair<char, long long>
#define mmll multimap<long long, long long>
#define mmcl multimap<char, long long>
#define mmsl multimap<string, long long>
#define sll set<long long>
#define sc set<char>
#define ss set<string>
#define msll multiset<long long>
#define msc multiset<char>
#define mss multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
using namespace __gnu_pbds;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll modexp(ll x, ll n, ll p) { // modular exponential function
if (n == 0) {
return 1;
}
ll u = modexp(x, n / 2, p);
u = u * u % p;
if (n % 2 == 1) {
u = (u * x) % p;
}
return u;
}
ll gcd(ll a, ll b) { // Eulers algorithm
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll m = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
ll arr[n];
rep(i, 0, n - 1) { cin >> arr[i]; }
ll pst[k + 1][n], dp[k + 1][n];
// pst -> prefix sum array
// dp[i][j] -> ways to distribute i candies among j children;
rep(i, 0, k) {
rep(j, 0, n - 1) {
if (i == 0) {
dp[i][j] = 1;
pst[i][j] = 1;
continue;
}
if (j == 0) {
if (arr[j] >= i) {
dp[i][j] = 1;
if (i >= 1) {
pst[i][j] = (1 + pst[i - 1][j] % m) % m;
} else {
pst[i][j] = 1;
}
} else {
dp[i][j] = 0;
pst[i][j] = pst[i - 1][j] % m;
}
continue;
}
if (arr[j] >= i) {
dp[i][j] = pst[i][j - 1] % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
} else {
dp[i][j] =
((pst[i][j - 1] % m - pst[i - arr[j] - 1][j - 1] % m) + m) % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
}
}
}
cout << dp[k][n - 1];
}
| [] | 981,072 | 981,073 | u228876479 | cpp |
p03172 | #include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX
#define dd double
#define fi first
#define se second
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long, long long>>
#define vpcl vector<pair<char, long long>>
#define vpsl vector<pair<string, long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long, long long>
#define pll pair<long long, long long>
#define psl pair<string, long long>
#define mcl map<char, long long>
#define msl map<string, long long>
#define pcl pair<char, long long>
#define mmll multimap<long long, long long>
#define mmcl multimap<char, long long>
#define mmsl multimap<string, long long>
#define sll set<long long>
#define sc set<char>
#define ss set<string>
#define msll multiset<long long>
#define msc multiset<char>
#define mss multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
using namespace __gnu_pbds;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll modexp(ll x, ll n, ll p) { // modular exponential function
if (n == 0) {
return 1;
}
ll u = modexp(x, n / 2, p);
u = u * u % p;
if (n % 2 == 1) {
u = (u * x) % p;
}
return u;
}
ll gcd(ll a, ll b) { // Eulers algorithm
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll m = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
ll arr[n];
rep(i, 0, n - 1) { cin >> arr[i]; }
ll pst[k + 1][n], dp[k + 1][n];
rep(i, 0, k) {
rep(j, 0, n - 1) {
if (i == 0) {
dp[i][j] = 1;
pst[i][j] = 1;
continue;
}
if (j == 0) {
if (arr[j] >= i) {
dp[i][j] = 1;
if (i >= 1) {
pst[i][j] = (1 + pst[i - 1][j] % m) % m;
} else {
pst[i][j] = 1;
}
} else {
dp[i][j] = 0;
pst[i][j] = pst[i - 1][j] % m;
}
continue;
}
if (arr[j] >= i) {
dp[i][j] = pst[i][j - 1] % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
} else {
dp[i][j] = (pst[i][j - 1] % m - pst[i - arr[j] - 1][j - 1] % m) % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
}
}
}
// rep(i,0,k){
// rep(j,0,n-1){
// cout<<dp[i][j]<<" ";
// }
// cout<<"\n";
// }
// rep(i,0,k){
// rep(j,0,n-1){
// cout<<pst[i][j]<<" ";
// }
// cout<<"\n";
// }
cout << dp[k][n - 1];
}
| #include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX
#define dd double
#define fi first
#define se second
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long, long long>>
#define vpcl vector<pair<char, long long>>
#define vpsl vector<pair<string, long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long, long long>
#define pll pair<long long, long long>
#define psl pair<string, long long>
#define mcl map<char, long long>
#define msl map<string, long long>
#define pcl pair<char, long long>
#define mmll multimap<long long, long long>
#define mmcl multimap<char, long long>
#define mmsl multimap<string, long long>
#define sll set<long long>
#define sc set<char>
#define ss set<string>
#define msll multiset<long long>
#define msc multiset<char>
#define mss multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
using namespace __gnu_pbds;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
ll modexp(ll x, ll n, ll p) { // modular exponential function
if (n == 0) {
return 1;
}
ll u = modexp(x, n / 2, p);
u = u * u % p;
if (n % 2 == 1) {
u = (u * x) % p;
}
return u;
}
ll gcd(ll a, ll b) { // Eulers algorithm
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll m = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
ll arr[n];
rep(i, 0, n - 1) { cin >> arr[i]; }
ll pst[k + 1][n], dp[k + 1][n];
// pst -> prefix sum array
// dp[i][j] -> ways to distribute i candies among j children;
rep(i, 0, k) {
rep(j, 0, n - 1) {
if (i == 0) {
dp[i][j] = 1;
pst[i][j] = 1;
continue;
}
if (j == 0) {
if (arr[j] >= i) {
dp[i][j] = 1;
if (i >= 1) {
pst[i][j] = (1 + pst[i - 1][j] % m) % m;
} else {
pst[i][j] = 1;
}
} else {
dp[i][j] = 0;
pst[i][j] = pst[i - 1][j] % m;
}
continue;
}
if (arr[j] >= i) {
dp[i][j] = pst[i][j - 1] % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
} else {
dp[i][j] =
((pst[i][j - 1] % m - pst[i - arr[j] - 1][j - 1] % m) + m) % m;
pst[i][j] = (pst[i - 1][j] % m + dp[i][j] % m) % m;
}
}
}
cout << dp[k][n - 1];
}
| [] | 981,074 | 981,073 | u228876479 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
int solve(vector<int> &v, int n, int k) {
vector<vector<ll>> dp(n + 2, vector<ll>(k + 2, 0));
for (int j = 1; j <= k; j++)
dp[1][j] = (j > v[1]) ? 0 : 1;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0)
dp[i][j] = (dp[i - 1][j]) % mod;
else
dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] -
((j - v[i] - 1 >= 0) ? dp[i - 1][j - v[i] - 1] : 0)) %
mod;
}
}
return dp[n][k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i < n + 1; i++)
cin >> v[i];
cout << solve(v, n, k);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
int solve(vector<int> &v, int n, int k) {
vector<vector<ll>> dp(n + 2, vector<ll>(k + 2, 0));
for (int j = 0; j <= k; j++)
dp[1][j] = (j > v[1]) ? 0 : 1;
for (int i = 2; i <= n; i++) {
for (int 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 - v[i] - 1 >= 0) ? dp[i - 1][j - v[i] - 1] : 0)) %
mod;
}
}
return dp[n][k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i < n + 1; i++)
cin >> v[i];
cout << solve(v, n, k);
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operation.binary.remove"
] | 981,078 | 981,079 | u210383346 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
// 自動でmodを取ってくれる整数型
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint f(int n) { // 2のn乗
if (n == 0)
return 1;
mint x = f(n / 2);
x *= x;
if (n % 2 == 1)
x *= 2;
return x;
}
// a^n mod を計算する
long long modpow(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// indexは1から始まる!
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template <typename T> struct BIT {
int n;
vector<T> d;
BIT(int n = 0) { init(n); }
void init(int nn) {
n = nn;
d.resize(nn + 1);
}
void add(int i, T x = 1) {
for (i++; i <= n; i += i & -i) {
d[i] += x;
}
}
T sum(int i) { // [1,x]
T x = 0;
for (i++; i; i -= i & -i) {
x += d[i];
}
return x;
}
T sum(int l, int r) { // [l,r)
return sum(r - 1) - sum(l - 1);
}
};
// BIT配列の宣言 N:配列数, n:各要素数+1;
// BIT<int> bit[N];
// rep(i,N) bit[i].init(n);
//////////////////////////
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
BIT<mint> dp[n + 1];
rep(i, n + 1) dp[i].init(k + 2);
dp[0].add(k + 1, 1);
rep(i, n + 1) {
for (int j = 1; j <= k + 1; j++) {
dp[i + 1].add(j, dp[i].sum(j, min(k + 1, j + a[i]) + 1));
}
}
cout << dp[n].sum(1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
// 自動でmodを取ってくれる整数型
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint f(int n) { // 2のn乗
if (n == 0)
return 1;
mint x = f(n / 2);
x *= x;
if (n % 2 == 1)
x *= 2;
return x;
}
// a^n mod を計算する
long long modpow(long long a, long long n) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// indexは1から始まる!
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template <typename T> struct BIT {
int n;
vector<T> d;
BIT(int n = 0) { init(n); }
void init(int nn) {
n = nn;
d.resize(nn + 1);
}
void add(int i, T x = 1) {
for (i++; i <= n; i += i & -i) {
d[i] += x;
}
}
T sum(int i) { // [1,x]
T x = 0;
for (i++; i; i -= i & -i) {
x += d[i];
}
return x;
}
T sum(int l, int r) { // [l,r)
return sum(r - 1) - sum(l - 1);
}
};
// BIT配列の宣言 N:配列数, n:各要素数+1;
// BIT<int> bit[N];
// rep(i,N) bit[i].init(n);
//////////////////////////
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
BIT<mint> dp[n + 1];
rep(i, n + 1) dp[i].init(k + 2);
dp[0].add(k + 1, 1);
rep(i, n) {
for (int j = 1; j <= k + 1; j++) {
dp[i + 1].add(j, dp[i].sum(j, min(k + 1, j + a[i]) + 1));
}
}
cout << dp[n].sum(1) << endl;
}
| [
"expression.operation.binary.remove"
] | 981,083 | 981,084 | u393698851 | cpp |
p03172 | // AUTHOR: RAVAN_2070
// PUNE INSTITUTE OF COMPUTER TECHNOLOGY
// Atcoder Educational DP
// M-Candies
/*
I ♥ CLARICE STARLING
EXPLAINATION BELOW->
Dp
*/
// Iterative Solution
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define MOD7 1000000007
const ll INF = (ll)1e18 + 5;
void solve() {
int n, k, i, j;
cin >> n >> k;
int ps[k + 2][n], dp[k + 1][n], A[n];
fo(i, 0, n) cin >> A[i];
fo(j, 0, n) ps[0][j] = 0;
foe(i, 0, k) {
dp[i][n - 1] = ((i <= A[n - 1]) ? 1 : 0);
ps[i + 1][n - 1] = ps[i][n - 1] + dp[i][n - 1];
}
for (j = n - 2; j >= 0; j--) {
for (i = 0; i <= k; i++) {
int low, high;
low = max(0, i - A[j]);
high = i;
dp[i][j] = (ps[high + 1][j + 1] - ps[low][j + 1]) % MOD7;
ps[i + 1][j] = (ps[i][j] + dp[i][j]) % MOD7;
}
}
cout << dp[k][0] % MOD7 << "\n";
}
int main() {
fastio solve();
return 0;
}
| // AUTHOR: RAVAN_2070
// PUNE INSTITUTE OF COMPUTER TECHNOLOGY
// Atcoder Educational DP
// M-Candies
/*
I ♥ CLARICE STARLING
EXPLAINATION BELOW->
Dp
If you think in terms of Brute force
Ans can found by considering all subsequences for which sum of candies given
is exactly == K and just go on adding up the count.. But the Time Complexity
will be around O(n!)
Observation
Let F(i,j) be number of ways to to distribute exactly i candies considering
people from jth index to n; the F(i,j)=(jth distributed 0 candies)*F(i,j+1) +
(jth distributed 1 candy)*F(i-1,j+1) +....(to jth distributed k
candies)*F(i-k,j+1)+.. Hence from this we can clearly observe both properties
1)Overlapping subproblems
2)Optimal Substructure
Time Complexity O(n^2)
*/
// Iterative Solution
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define MOD7 1000000007
const ll INF = (ll)1e18 + 5;
void solve() {
int n, k, i, j;
cin >> n >> k;
int ps[k + 2][n], dp[k + 1][n], A[n];
fo(i, 0, n) cin >> A[i];
fo(j, 0, n) ps[0][j] = 0;
foe(i, 0, k) {
dp[i][n - 1] = ((i <= A[n - 1]) ? 1 : 0);
ps[i + 1][n - 1] = ps[i][n - 1] + dp[i][n - 1];
}
for (j = n - 2; j >= 0; j--) {
for (i = 0; i <= k; i++) {
int low, high;
low = max(0, i - A[j]);
high = i;
dp[i][j] = (ps[high + 1][j + 1] - ps[low][j + 1] + MOD7) % MOD7;
ps[i + 1][j] = (ps[i][j] + dp[i][j]) % MOD7;
}
}
cout << dp[k][0] % MOD7 << "\n";
}
int main() {
fastio solve();
return 0;
}
| [
"assignment.change"
] | 981,089 | 981,090 | u799238092 | cpp |
p03172 | // AUTHOR: RAVAN_2070
// PUNE INSTITUTE OF COMPUTER TECHNOLOGY
// Atcoder Educational DP
// M-Candies
/*
I ♥ CLARICE STARLING
EXPLAINATION BELOW->
Dp
*/
// Iterative Solution
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define MOD7 1000000007
const ll INF = (ll)1e18 + 5;
void solve() {
int n, k, i, j;
cin >> n >> k;
int ps[k + 2][n], dp[k + 1][n], A[n];
fo(i, 0, n) cin >> A[i];
fo(j, 0, n) ps[0][j] = 0;
foe(i, 0, k) {
dp[i][n - 1] = ((i <= A[n - 1]) ? 1 : 0);
ps[i + 1][n - 1] = ps[i][n - 1] + dp[i][n - 1];
}
for (j = n - 2; j >= 0; j--) {
for (i = 0; i <= k; i++) {
int low, high;
low = max(0, i - A[j]);
high = i;
dp[i][j] = (ps[high + 1][j + 1] - ps[low][j + 1]) % MOD7;
ps[i + 1][j] = (ps[i][j] + dp[i][j]) % MOD7;
}
}
cout << dp[k][0] % MOD7 << "\n";
}
int main() {
fastio solve();
return 0;
}
| // AUTHOR: RAVAN_2070
// PUNE INSTITUTE OF COMPUTER TECHNOLOGY
// Atcoder Educational DP
// M-Candies
/*
I ♥ CLARICE STARLING
EXPLAINATION BELOW->
Dp
*/
// Iterative Solution
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (i = a; i < b; i++)
#define foe(i, a, b) for (i = a; i <= b; i++)
#define MOD7 1000000007
const ll INF = (ll)1e18 + 5;
void solve() {
int n, k, i, j;
cin >> n >> k;
int ps[k + 2][n], dp[k + 1][n], A[n];
fo(i, 0, n) cin >> A[i];
fo(j, 0, n) ps[0][j] = 0;
foe(i, 0, k) {
dp[i][n - 1] = ((i <= A[n - 1]) ? 1 : 0);
ps[i + 1][n - 1] = ps[i][n - 1] + dp[i][n - 1];
}
for (j = n - 2; j >= 0; j--) {
for (i = 0; i <= k; i++) {
int low, high;
low = max(0, i - A[j]);
high = i;
dp[i][j] = (ps[high + 1][j + 1] - ps[low][j + 1] + MOD7) % MOD7;
ps[i + 1][j] = (ps[i][j] + dp[i][j]) % MOD7;
}
}
cout << dp[k][0] % MOD7 << "\n";
}
int main() {
fastio solve();
return 0;
}
| [
"assignment.change"
] | 981,089 | 981,091 | u799238092 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int)1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
ll a[n + 1], dp[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[0][i] = 0;
}
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++) {
if (j <= a[i]) {
dp[i][j] = sum[j];
} else {
dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
}
}
sum.clear();
}
cout << dp[n][k] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int)1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
ll a[n + 1], dp[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 1; i <= k; i++) {
dp[0][i] = 0;
}
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++) {
if (j <= a[i]) {
dp[i][j] = sum[j];
} else {
dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
}
}
sum.clear();
}
cout << dp[n][k] << "\n";
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 981,096 | 981,097 | u217234114 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int)1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
ll a[n + 1], dp[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[0][i] = 0;
}
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++) {
if (j <= a[i]) {
dp[i][j] = sum[j];
} else {
dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
}
}
sum.clear();
}
cout << dp[n][k] % mod << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int)1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
ll a[n + 1], dp[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 1; i <= k; i++) {
dp[0][i] = 0;
}
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++) {
if (j <= a[i]) {
dp[i][j] = sum[j];
} else {
dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
}
}
sum.clear();
}
cout << dp[n][k] << "\n";
} | [
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 981,098 | 981,097 | u217234114 | cpp |
p03172 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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;
}
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint dp[105][100005];
mint cum[105][100005];
int main() {
int n, K;
cin >> n >> K;
int a[n];
rep(i, n) cin >> a[i];
dp[0][0] = 1;
// for(int i=1;i<=n;i++){
// rep(j,K+1){
// rep(k,a[i-1]+1){
// if(j-k>=0)dp[i][j]+=dp[i-1][j-k];
// }
// }
// }
for (int i = 1; i <= n; i++) {
rrep(j, K + 1) cum[i][j] = cum[i][j - 1] + dp[i - 1][j - 1];
rep(j, K + 1) dp[i][j] = cum[i][j + 1] - cum[i][max(0, j - a[i])];
}
// rep(i,n+1){
// rep(j,K+1){
// cout << dp[i][j];
// }
// cout << endl;
// }
cout << dp[n][K] << endl;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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;
}
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint dp[105][100005];
mint cum[105][100005];
int main() {
int n, K;
cin >> n >> K;
int a[n];
rep(i, n) cin >> a[i];
dp[0][0] = 1;
// for(int i=1;i<=n;i++){
// rep(j,K+1){
// rep(k,a[i-1]+1){
// if(j-k>=0)dp[i][j]+=dp[i-1][j-k];
// }
// }
// }
for (int i = 1; i <= n; i++) {
rrep(j, K + 1) cum[i][j] = cum[i][j - 1] + dp[i - 1][j - 1];
rep(j, K + 1) dp[i][j] = cum[i][j + 1] - cum[i][max(0, j - a[i - 1])];
}
// rep(i,n+1){
// rep(j,K+1){
// cout << dp[i][j];
// }
// cout << endl;
// }
cout << dp[n][K] << endl;
} | [
"assignment.change"
] | 981,104 | 981,105 | u639032323 | cpp |
p03172 | // dp(i,j) -> no of ways to distribute j candies to first i children
/*
dp(n,k) = dp(n-1,k) + dp(n-1,k-1) + dp(n-1,k-2) + ...... + dp(n-1,k-an)
dp(i,j) = dp(i-1,j-x) for x from [0,ai]
base case:-
dp(1,j) = {
1 , j<=a1
0 , j>a1
}
dp(i,k-1) = dp(i,k) - dp(i-1,k) + dp(i-1,k-1-ai)
dp(i,j+1) = dp(i,j) + dp(i-1,j+1) - dp(i,j-ai) ->main formula
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int solve(int *a, int n, int k) {
ll dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
if (j <= a[1])
dp[1][j] = 1;
else
dp[1][j] = 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = (mod + dp[i - 1][j] + dp[i][j - 1] -
((j - 1 - a[i] >= 0) ? dp[i][j - a[i] - 1] : 0)) %
mod;
}
}
}
return dp[n][k];
}
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cout << solve(a, n, k);
return 0;
}
| // dp(i,j) -> no of ways to distribute j candies to first i children
/*
dp(n,k) = dp(n-1,k) + dp(n-1,k-1) + dp(n-1,k-2) + ...... + dp(n-1,k-an)
dp(i,j) = dp(i-1,j-x) for x from [0,ai]
base case:-
dp(1,j) = {
1 , j<=a1
0 , j>a1
}
dp(i,k-1) = dp(i,k) - dp(i-1,k) + dp(i-1,k-1-ai)
dp(i,j+1) = dp(i,j) + dp(i-1,j+1) - dp(i,j-ai) ->main formula
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int solve(int *a, int n, int k) {
ll dp[n + 2][k + 2];
for (int j = 0; j <= k; j++) {
if (j <= a[1])
dp[1][j] = 1;
else
dp[1][j] = 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = (mod + dp[i - 1][j] + dp[i][j - 1] -
((j - 1 - a[i] >= 0) ? dp[i - 1][j - a[i] - 1] : 0)) %
mod;
}
}
}
return dp[n][k];
}
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cout << solve(a, n, k);
return 0;
}
| [
"assignment.change"
] | 981,106 | 981,107 | u493816639 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long mod = 1e9 + 7;
int N, K;
cin >> N >> K;
vector<int> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
vector<vector<long long>> dp(N, vector<long long>(K + 1, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K + 1; j++) {
if (j == 0) {
dp[i][j] = 1;
continue;
}
if (i == 0) {
if (j <= a[i])
dp[i][j] = 1;
else
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
if (j > a[i])
dp[i][j] -= dp[i - 1][j - 1 - a[i]];
dp[i][j] %= mod;
}
}
cout << dp[N - 1][K] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int mod = 1e9 + 7;
int N, K;
cin >> N >> K;
vector<int> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
vector<vector<long long>> dp(N, vector<long long>(K + 1, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K + 1; j++) {
if (j == 0) {
dp[i][j] = 1;
continue;
}
if (i == 0) {
if (j <= a[i])
dp[i][j] = 1;
else
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
if (j > a[i])
dp[i][j] += mod - dp[i - 1][j - 1 - a[i]];
dp[i][j] %= mod;
}
}
cout << dp[N - 1][K] << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.narrow.change",
"expression.operator.change",
"assignment.change"
] | 981,108 | 981,109 | u929569377 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
int main() {
int mod = 1e9 + 7;
int N, K;
cin >> N >> K;
vector<int> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
vector<vector<long long>> dp(N, vector<long long>(K + 1, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K + 1; j++) {
if (j == 0) {
dp[i][j] = 1;
continue;
}
if (i == 0) {
if (j <= a[i])
dp[i][j] = 1;
else
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
if (j > a[i])
dp[i][j] -= dp[i - 1][j - 1 - a[i]];
dp[i][j] %= mod;
}
}
cout << dp[N - 1][K] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int mod = 1e9 + 7;
int N, K;
cin >> N >> K;
vector<int> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
vector<vector<long long>> dp(N, vector<long long>(K + 1, 0));
for (int i = 0; i < N; i++) {
for (int j = 0; j < K + 1; j++) {
if (j == 0) {
dp[i][j] = 1;
continue;
}
if (i == 0) {
if (j <= a[i])
dp[i][j] = 1;
else
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
if (j > a[i])
dp[i][j] += mod - dp[i - 1][j - 1 - a[i]];
dp[i][j] %= mod;
}
}
cout << dp[N - 1][K] << endl;
return 0;
}
| [
"expression.operator.change",
"assignment.change"
] | 981,110 | 981,109 | u929569377 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a - 1)
#define trav(x, a) for (auto &x : a)
const int MX = 2e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = 1061109567; // 4557430888798830399LL
const ld EPS = 1e-9;
const ld PI = acos(-1);
ll dp[105][MX], arr[MX];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, K;
cin >> N >> K;
FOR(i, 1, N + 1) cin >> arr[i];
dp[0][0] = 1;
FOR(i, 1, N + 1) {
FOR(j, 1, K + 1) dp[i - 1][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
F0R(j, K + 1)
dp[i][j] = (dp[i][j] +
(dp[i - 1][j] - (j > arr[i] ? dp[i - 1][j - arr[i] - 1] : 0))) %
MOD;
}
cout << dp[N][K] << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a - 1)
#define trav(x, a) for (auto &x : a)
const int MX = 2e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = 1061109567; // 4557430888798830399LL
const ld EPS = 1e-9;
const ld PI = acos(-1);
ll dp[105][MX], arr[MX];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, K;
cin >> N >> K;
FOR(i, 1, N + 1) cin >> arr[i];
dp[0][0] = 1;
FOR(i, 1, N + 1) {
FOR(j, 1, K + 1) dp[i - 1][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
F0R(j, K + 1)
dp[i][j] =
(dp[i][j] +
((dp[i - 1][j] - (j > arr[i] ? dp[i - 1][j - arr[i] - 1] : 0) + MOD) %
MOD)) %
MOD;
}
cout << dp[N][K] << "\n";
}
| [
"assignment.change"
] | 981,111 | 981,112 | u867529352 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (auto i = 1; i <= n; ++i) {
cin >> a[i];
}
// dp[i][j] - No. of ways to distribute j chocolates to the first i people
int dp[n + 1][k + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (auto i = 1; i <= n; ++i) {
vector<int> prefix(k + 1, 0);
prefix[0] = dp[i - 1][0];
for (auto m = 1; m <= k; ++m) {
prefix[m] = (prefix[m - 1] + dp[i - 1][m]) % MOD;
}
for (auto j = 0; j <= k; ++j) {
dp[i][j] =
(prefix[j] - (j - a[i] - 1 >= 0 ? prefix[j - a[i] - 1] : 0)) % MOD;
}
}
// dbg(dp[2][0]);
cout << dp[n][k] << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (auto i = 1; i <= n; ++i) {
cin >> a[i];
}
// dp[i][j] - No. of ways to distribute j chocolates to the first i people
int dp[n + 1][k + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (auto i = 1; i <= n; ++i) {
vector<int> prefix(k + 1, 0);
prefix[0] = dp[i - 1][0];
for (auto m = 1; m <= k; ++m) {
prefix[m] = (prefix[m - 1] + dp[i - 1][m]) % MOD;
}
for (auto j = 0; j <= k; ++j) {
dp[i][j] =
(prefix[j] - (j - a[i] - 1 >= 0 ? prefix[j - a[i] - 1] : 0) + MOD) %
MOD;
}
}
// dbg(dp[2][0]);
cout << dp[n][k] << "\n";
}
| [
"assignment.change"
] | 981,117 | 981,118 | u859247867 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define INF 9223372036854;
#define ll long long
const long long m = 1000000007;
int main() {
ll n, k;
cin >> n >> k;
ll dp[2][k + 1];
memset(dp, 0, sizeof(dp));
ll arr[n] = {0};
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll i, j, x, l, c;
for (i = 0; i < 2; i++) {
dp[i][0] = 1;
}
for (i = 0; i <= k; i++) {
dp[0][i] = 1;
}
for (c = 1; c <= n; c++) {
for (j = 1; j <= k; j++) {
x = min(arr[c - 1], j);
i = c % 2;
if (x == j) {
if (i == 0)
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = dp[i - 1][j];
} else {
if (i == 0)
dp[i][j] = (dp[i + 1][j] - dp[i + 1][j - x - 1] + m) % m;
else
dp[i][j] = (dp[i - 1][j] - dp[i - 1][j - x - 1] + m) % m;
}
dp[i][j] = (dp[i][j] % m + dp[i][j - 1] % m) % m;
}
}
if (k == 0)
cout << dp[n % 2][k];
else
cout << dp[n % 2][k] - dp[n % 2][k - 1];
}
| #include <bits/stdc++.h>
using namespace std;
#define INF 9223372036854;
#define ll long long
const long long m = 1000000007;
int main() {
ll n, k;
cin >> n >> k;
ll dp[2][k + 1];
memset(dp, 0, sizeof(dp));
ll arr[n] = {0};
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
ll i, j, x, l, c;
for (i = 0; i < 2; i++) {
dp[i][0] = 1;
}
for (i = 0; i <= k; i++) {
dp[0][i] = 1;
}
for (c = 1; c <= n; c++) {
for (j = 1; j <= k; j++) {
x = min(arr[c - 1], j);
i = c % 2;
if (x == j) {
if (i == 0)
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = dp[i - 1][j];
} else {
if (i == 0)
dp[i][j] = (dp[i + 1][j] - dp[i + 1][j - x - 1] + m) % m;
else
dp[i][j] = (dp[i - 1][j] - dp[i - 1][j - x - 1] + m) % m;
}
dp[i][j] = (dp[i][j] % m + dp[i][j - 1] % m) % m;
}
}
if (k == 0)
cout << dp[n % 2][k];
else
cout << (dp[n % 2][k] - dp[n % 2][k - 1] + m) % m;
}
| [
"expression.operation.binary.add"
] | 981,119 | 981,120 | u759567410 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7; /// A simpler way to write 1,000,000,007
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dp[n + 1][k + 1];
dp[0][0] = 1;
for (int i = 1; i <= k; i++) /// Set the initial values
{
dp[0][i] = 1;
}
for (int i = 1; i <= n; i++) {
int sums[k + 1];
sums[0] = dp[i - 1][0];
for (int j = 1; j <= k; j++) {
sums[j] = (sums[j - 1] + dp[i - 1][j]) %
mod; /// Calculate the prefix sums for i-1
}
for (int j = 0; j <= k; j++) {
int tr = sums[j]; /// Sum of dp[i-1][0...j]
int unreachable =
j - a[i] - 1; /// We need to subtract the sum of the first
/// "unreachable" elements (dp[i-1][0...unreachable])
if (unreachable >= 0) {
tr = (tr - sums[unreachable] + mod) %
mod; /// Add mod to make sure that "tr-sums[unreachable]" is not
/// negative.
}
dp[i][j] = tr;
}
}
cout << dp[n][k];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7; /// A simpler way to write 1,000,000,007
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dp[n + 1][k + 1];
dp[0][0] = 1;
for (int i = 1; i <= k; i++) /// Set the initial values
{
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
int sums[k + 1];
sums[0] = dp[i - 1][0];
for (int j = 1; j <= k; j++) {
sums[j] = (sums[j - 1] + dp[i - 1][j]) %
mod; /// Calculate the prefix sums for i-1
}
for (int j = 0; j <= k; j++) {
int tr = sums[j]; /// Sum of dp[i-1][0...j]
int unreachable =
j - a[i] - 1; /// We need to subtract the sum of the first
/// "unreachable" elements (dp[i-1][0...unreachable])
if (unreachable >= 0) {
tr = (tr - sums[unreachable] + mod) %
mod; /// Add mod to make sure that "tr-sums[unreachable]" is not
/// negative.
}
dp[i][j] = tr;
}
}
cout << dp[n][k];
return 0;
}
| [
"literal.number.change",
"assignment.value.change"
] | 981,123 | 981,124 | u091850723 | cpp |
p03172 | #include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
#define mp make_pair
using namespace std;
const long long mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
int k;
cin >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<long long> dp(k + 1, 1);
for (int i = 1; i <= n; i++) {
vector<long long> new_dp(k + 1);
for (int j = 0; j <= k; j++) {
int l = max(0, j - a[i]);
if (l == 0) {
new_dp[j] += dp[j];
new_dp[j] %= mod;
} else {
new_dp[j] += (dp[j] - dp[l - 1] + mod) % mod;
new_dp[j] %= mod;
}
}
for (int j = 0; j <= k; j++) {
dp[j] = new_dp[j];
if (j > 0) {
dp[j] += dp[j - 1];
dp[j] %= mod;
}
}
}
cout << ((k == 0) ? 1 : (dp[k] - dp[k - 1])) << endl;
}
int main() {
solve();
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
#define mp make_pair
using namespace std;
const long long mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
int k;
cin >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<long long> dp(k + 1, 1);
for (int i = 1; i <= n; i++) {
vector<long long> new_dp(k + 1);
for (int j = 0; j <= k; j++) {
int l = max(0, j - a[i]);
if (l == 0) {
new_dp[j] += dp[j];
new_dp[j] %= mod;
} else {
new_dp[j] += (dp[j] - dp[l - 1] + mod) % mod;
new_dp[j] %= mod;
}
}
for (int j = 0; j <= k; j++) {
dp[j] = new_dp[j];
if (j > 0) {
dp[j] += dp[j - 1];
dp[j] %= mod;
}
}
}
cout << ((k == 0) ? 1 : (dp[k] - dp[k - 1] + mod) % mod) << endl;
}
int main() {
solve();
return 0;
} | [
"expression.operation.binary.add"
] | 981,125 | 981,126 | u183606119 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define precise(x) cout << fixed << setprecision(12) << x
#define test cout << "#";
const ll INF = 1e18L + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> v(n + 1);
for (ll x = 1; x <= n; x++)
cin >> v[x];
ll ans[n + 1][k + 1];
for (ll x = 0; x <= k; x++) {
if (x <= v[1])
ans[1][x] = 1;
else {
ans[1][x] = 0;
}
}
for (ll x = 2; x <= n; x++) {
for (ll y = 0; y <= k; y++) {
if (y == 0)
ans[x][y] = ans[x - 1][y];
else
ans[x][y] = ans[x][y - 1] + ans[x - 1][y] -
((y - v[x] - 1) >= 0 ? ans[x - 1][y - v[x] - 1] : 0);
ans[x][y] %= mod;
}
}
cout << ans[n][k];
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define precise(x) cout << fixed << setprecision(12) << x
#define test cout << "#";
const ll INF = 1e18L + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<ll> v(n + 1);
for (ll x = 1; x <= n; x++)
cin >> v[x];
ll ans[n + 1][k + 1];
for (ll x = 0; x <= k; x++) {
if (x <= v[1])
ans[1][x] = 1;
else {
ans[1][x] = 0;
}
}
for (ll x = 2; x <= n; x++) {
for (ll y = 0; y <= k; y++) {
if (y == 0)
ans[x][y] = ans[x - 1][y];
else
ans[x][y] = (mod + ans[x][y - 1] + ans[x - 1][y] -
((y - v[x] - 1) >= 0 ? ans[x - 1][y - v[x] - 1] : 0));
ans[x][y] %= mod;
}
}
cout << ans[n][k];
} | [] | 981,131 | 981,132 | u466535000 | cpp |
p03172 |
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
#define el '\n'
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
const int mod = 1000000007;
// const int mod=998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t, n, m, k, q, x, a, b, c, d, y, l, r;
cin >> n >> k;
vi v(n + 1);
ll dp[n + 1][k + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= k; i++) {
dp[0][i] = 1;
}
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j <= v[i]) {
dp[i][j] = dp[i - 1][j];
dp[i][j] %= mod;
} else {
dp[i][j] = dp[i - 1][j] - dp[i - 1][j - v[i] - 1];
dp[i][j] %= mod;
}
}
for (int j = 1; j <= k && i != n; j++) {
dp[i][j] += dp[i][j - 1];
dp[i][j] %= mod;
}
}
cout << dp[n][k] << el;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
#define el '\n'
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
const int mod = 1000000007;
// const int mod=998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t, n, m, k, q, x, a, b, c, d, y, l, r;
cin >> n >> k;
vi v(n + 1);
ll dp[n + 1][k + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= k; i++) {
dp[0][i] = 1;
}
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j <= v[i]) {
dp[i][j] = dp[i - 1][j];
dp[i][j] %= mod;
} else {
dp[i][j] = dp[i - 1][j] - dp[i - 1][j - v[i] - 1];
dp[i][j] %= mod;
}
}
for (int j = 1; j <= k && i != n; j++) {
dp[i][j] += dp[i][j - 1];
dp[i][j] %= mod;
}
}
cout << (dp[n][k] + mod) % mod << el;
return 0;
}
| [
"expression.operation.binary.add"
] | 981,133 | 981,134 | u829147556 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i, n) for (int i = 0; i < n; i++)
#define rep(i, st, en) for (int i = st; i <= en; i++)
#define repn(i, st, en) for (int i = st; i >= en; i--)
#define sq(a) (a * a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int mod = 1e9 + 7;
void add_self(int &a, int b) {
a += b;
if (a > mod)
a -= mod;
}
void sub_self(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
}
void solve() {
int n, k;
cin >> n >> k;
int a[n + 1];
vector<int> dp(k + 1);
dp[0] = 1;
for (int child = 0; child < n; ++child) {
int ub;
cin >> ub;
vector<int> fake(k + 1);
for (int used = k; used >= 0; --used) {
int temp = dp[used];
int L = used + 1;
int R = used + min(k - used, ub);
if (L <= R) {
add_self(fake[L], temp);
if (R + 1 <= k)
sub_self(fake[R + 1], temp);
}
/*
for(int i=L; i<=R; i++){
add_self(dp[i], temp); /// range update from L to R with temp, we
can use BIT to do that, instead use pref sum concept
}
*/
}
int prefix_sum = 0;
for (int i = 0; i <= k; i++) {
add_self(prefix_sum, fake[i]);
add_self(dp[i], prefix_sum);
}
}
cout << dp[k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i, n) for (int i = 0; i < n; i++)
#define rep(i, st, en) for (int i = st; i <= en; i++)
#define repn(i, st, en) for (int i = st; i >= en; i--)
#define sq(a) (a * a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int mod = 1e9 + 7;
void add_self(int &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void sub_self(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
}
void solve() {
int n, k;
cin >> n >> k;
int a[n + 1];
vector<int> dp(k + 1);
dp[0] = 1;
for (int child = 0; child < n; ++child) {
int ub;
cin >> ub;
vector<int> fake(k + 1);
for (int used = k; used >= 0; --used) {
int temp = dp[used];
int L = used + 1;
int R = used + min(k - used, ub);
if (L <= R) {
add_self(fake[L], temp);
if (R + 1 <= k)
sub_self(fake[R + 1], temp);
}
/*
for(int i=L; i<=R; i++){
add_self(dp[i], temp); /// range update from L to R with temp, we
can use BIT to do that, instead use pref sum concept
}
*/
}
int prefix_sum = 0;
for (int i = 0; i <= k; i++) {
add_self(prefix_sum, fake[i]);
add_self(dp[i], prefix_sum);
}
}
cout << dp[k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 981,135 | 981,136 | u639514683 | cpp |
p03172 | /*
author : Divyansh Gupta
*/
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
void print_err() { cerr << "\n"; }
template <class T, class... Arg> void print_err(T x, Arg &&...args) {
cerr << x << " ";
print_err(args...);
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif
#define test_case \
int test_cases; \
cin >> test_cases; \
while (test_cases--)
#define lu(var, l, r) for (var = l; var < r; var++)
#define ld(var, r, l) for (var = r; var >= l; var--)
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>;
#define pii pair<int, int>
#define br cout << "\n"
#define sp cout << " "
#define pr cout <<
#define in cin >>
#define f first
#define s second
#define mod 1000000007
void solve() {
int n, k, i, j, x, l;
ll ans;
vi A;
in n;
in k;
A.pb(0);
lu(i, 0, n) {
in x;
A.pb(x);
}
int dp[n + 1][k + 1];
lu(i, 0, k + 1) { dp[0][i] = 1; }
lu(i, 0, n) { dp[i][0] = 1; }
lu(i, 1, n) {
lu(j, 1, k + 1) {
ans = 0ll;
if (j - A[i] > 0) {
ans = dp[i - 1][j] - dp[i - 1][j - A[i] - 1];
} else {
ans = dp[i - 1][j];
}
dp[i][j] = (ans + dp[i][j - 1]) % mod;
}
}
ans = 0;
if (k - A[n] > 0) {
ans = dp[n - 1][k] - dp[n - 1][k - A[n] - 1];
} else {
ans = dp[n - 1][k];
}
pr ans;
br;
}
int main() {
solve();
return 0;
} | /*
author : Divyansh Gupta
*/
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
void print_err() { cerr << "\n"; }
template <class T, class... Arg> void print_err(T x, Arg &&...args) {
cerr << x << " ";
print_err(args...);
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif
#define test_case \
int test_cases; \
cin >> test_cases; \
while (test_cases--)
#define lu(var, l, r) for (var = l; var < r; var++)
#define ld(var, r, l) for (var = r; var >= l; var--)
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>;
#define pii pair<int, int>
#define br cout << "\n"
#define sp cout << " "
#define pr cout <<
#define in cin >>
#define f first
#define s second
#define mod 1000000007
void solve() {
int n, k, i, j, x, l;
ll ans;
vi A;
in n;
in k;
A.pb(0);
lu(i, 0, n) {
in x;
A.pb(x);
}
int dp[n + 1][k + 1];
lu(i, 0, k + 1) { dp[0][i] = 1; }
lu(i, 0, n) { dp[i][0] = 1; }
lu(i, 1, n) {
lu(j, 1, k + 1) {
ans = 0ll;
if (j - A[i] > 0) {
ans = mod + dp[i - 1][j] - dp[i - 1][j - A[i] - 1];
} else {
ans = dp[i - 1][j];
}
dp[i][j] = (ans + dp[i][j - 1]) % mod;
}
}
ans = 0;
if (k - A[n] > 0) {
ans = mod + dp[n - 1][k] - dp[n - 1][k - A[n] - 1];
} else {
ans = dp[n - 1][k];
}
pr ans % mod;
br;
}
int main() {
solve();
return 0;
} | [
"assignment.change"
] | 981,139 | 981,140 | u992065512 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, string> PIS;
typedef vector<int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z, n) for (int i = z; i < n; i++)
#define fork(z, n) for (int k = z; k < n; k++)
#define forii(z, n) for (int i = z; i <= n; i++)
#define forkk(z, n) for (int k = z; k <= n; k++)
#define mod 1000000007
int maxElement(int arr[], int n) {
int maxi = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > maxi)
maxi = arr[i];
}
return maxi;
}
int minElement(int arr[], int n) {
int mini = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < mini)
mini = arr[i];
}
return mini;
}
string trim(const string &str) {
size_t first = str.find_first_not_of(' ');
if (string::npos == first) {
return str;
}
int last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> arr(n + 1);
fori(1, n + 1) cin >> arr[i];
ll dp[n + 1][k + 1];
dp[0][0] = 1;
fori(1, k + 1) dp[0][i] = 0;
fori(1, n + 1) dp[i][0] = 1;
fori(1, n + 1) {
ll sum[k + 1];
sum[0] = 1;
for (int p = 1; p <= k; p++)
sum[p] = ((sum[p - 1] % mod) + (dp[i - 1][p] % mod)) % mod;
for (int p = 0; p <= k; p++) {
if (p - arr[i] - 1 >= 0)
dp[i][p] = sum[p] - sum[p - arr[i] - 1];
else
dp[i][p] = sum[p];
}
}
/* fori(0,n+1) */
/* { */
/* for(int p=0;p<=k;p++) */
/* cout<<dp[i][p]<<" "; */
/* cout<<endl; */
/* } */
cout << dp[n][k] << endl;
cerr << "Time elapsed" << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, string> PIS;
typedef vector<int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z, n) for (int i = z; i < n; i++)
#define fork(z, n) for (int k = z; k < n; k++)
#define forii(z, n) for (int i = z; i <= n; i++)
#define forkk(z, n) for (int k = z; k <= n; k++)
#define mod 1000000007
int maxElement(int arr[], int n) {
int maxi = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > maxi)
maxi = arr[i];
}
return maxi;
}
int minElement(int arr[], int n) {
int mini = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < mini)
mini = arr[i];
}
return mini;
}
string trim(const string &str) {
size_t first = str.find_first_not_of(' ');
if (string::npos == first) {
return str;
}
int last = str.find_last_not_of(' ');
return str.substr(first, (last - first + 1));
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> arr(n + 1);
fori(1, n + 1) cin >> arr[i];
ll dp[n + 1][k + 1];
dp[0][0] = 1;
fori(1, k + 1) dp[0][i] = 0;
fori(1, n + 1) dp[i][0] = 1;
fori(1, n + 1) {
ll sum[k + 1];
sum[0] = 1;
for (int p = 1; p <= k; p++)
sum[p] = ((sum[p - 1] % mod) + (dp[i - 1][p] % mod)) % mod;
for (int p = 0; p <= k; p++) {
if (p - arr[i] - 1 >= 0)
dp[i][p] = (sum[p] - sum[p - arr[i] - 1] + mod) %
mod; // subtraction may lead to negative number.
else
dp[i][p] = sum[p];
}
}
/* fori(0,n+1) */
/* { */
/* for(int p=0;p<=k;p++) */
/* cout<<dp[i][p]<<" "; */
/* cout<<endl; */
/* } */
cout << dp[n][k] << endl;
cerr << "Time elapsed" << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
| [
"assignment.change"
] | 981,141 | 981,142 | u829019938 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define f(i, x, y) for (int i = x; i < y; i++)
#define ll long long
#define mp make_pair
#define F first
#define S second
#define N 100005
#define mod 1000000007
int main() {
int n, k;
cin >> n >> k;
int a[n];
f(i, 0, n) cin >> a[i];
int dp[n + 1][k + 1];
memset(dp, 0, sizeof(dp));
f(j, 0, k + 1) dp[1][j] = (j <= a[0]) ? 1 : 0;
f(i, 2, n + 1) f(j, 0, k + 1) {
if (j == 0)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] -
((j - 1 - a[i - 1] >= 0) ? dp[i - 1][j - 1 - a[i - 1]] : 0)) %
mod;
}
cout << dp[n][k] % mod;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define f(i, x, y) for (int i = x; i < y; i++)
#define ll long long
#define mp make_pair
#define F first
#define S second
#define N 100005
#define mod 1000000007
int main() {
int n, k;
cin >> n >> k;
int a[n];
f(i, 0, n) cin >> a[i];
ll dp[n + 1][k + 1];
memset(dp, 0, sizeof(dp));
f(j, 0, k + 1) dp[1][j] = (j <= a[0]) ? 1 : 0;
f(i, 2, n + 1) f(j, 0, k + 1) {
if (j == 0)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] -
((j - 1 - a[i - 1] >= 0) ? dp[i - 1][j - 1 - a[i - 1]] : 0)) %
mod;
}
cout << dp[n][k] % mod;
return 0;
} | [
"variable_declaration.type.change"
] | 981,143 | 981,144 | u440947888 | cpp |
p03172 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define sp << " " <<
#define cst(x) cout << fixed << setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int>>;
using que_d = priority_queue<int>;
using pint = pair<int, int>;
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;
}
int n, k;
vector<vector<ll>> dp;
vector<ll> sum;
void rui(int i) {
rep(j, k + 2) sum.at(j) = 0;
for (int j = 1; j <= k + 1; j++) {
sum.at(j) += (sum.at(j - 1) + dp.at(i).at(j - 1)) % mod;
}
return;
}
int main() {
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a.at(i);
dp.resize(n + 1, vector<ll>(k + 1));
sum.resize(k + 2, 0);
rep(i, k + 1) dp.at(0).at(i) = 0;
rep(i, n + 1) dp.at(i).at(0) = 1;
for (int i = 1; i <= n; i++) {
rui(i - 1);
for (int j = 1; j <= k; j++) {
int point = max(0, j - a.at(i));
ll ans = sum.at(j + 1) - sum.at(point);
while (ans <= 0)
ans += mod;
dp.at(i).at(j) = ans;
}
}
cout << dp.at(n).at(k) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define sp << " " <<
#define cst(x) cout << fixed << setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int>>;
using que_d = priority_queue<int>;
using pint = pair<int, int>;
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;
}
int n, k;
vector<vector<ll>> dp;
vector<ll> sum;
void rui(int i) {
rep(j, k + 2) sum.at(j) = 0;
for (int j = 1; j <= k + 1; j++) {
sum.at(j) += (sum.at(j - 1) + dp.at(i).at(j - 1)) % mod;
}
return;
}
int main() {
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a.at(i);
dp.resize(n + 1, vector<ll>(k + 1));
sum.resize(k + 2, 0);
rep(i, k + 1) dp.at(0).at(i) = 0;
rep(i, n + 1) dp.at(i).at(0) = 1;
for (int i = 1; i <= n; i++) {
rui(i - 1);
for (int j = 1; j <= k; j++) {
int point = max(0, j - a.at(i));
ll ans = sum.at(j + 1) - sum.at(point);
while (ans < 0)
ans += mod;
dp.at(i).at(j) = ans;
}
}
cout << dp.at(n).at(k) << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 981,158 | 981,159 | u314260680 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INTF 1000000007
int main() {
int n, k;
cin >> n >> k;
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<ll> pref(k + 1, 0);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
pref[0] = dp[i - 1][0];
for (int h = 1; h <= k; h++)
pref[h] = (pref[h - 1] + dp[i - 1][h]) % INTF;
for (int j = 0; j <= k; j++) {
ll l = pref[j];
ll r = (j > a) ? pref[j - a - 1] : 0;
dp[i][j] = (dp[i][j] + (l - r)) % INTF;
}
}
cout << dp[n][k];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INTF 1000000007
int main() {
int n, k;
cin >> n >> k;
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<ll> pref(k + 1, 0);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
pref[0] = dp[i - 1][0];
for (int h = 1; h <= k; h++)
pref[h] = pref[h - 1] + dp[i - 1][h];
for (int j = 0; j <= k; j++) {
ll l = pref[j];
ll r = (j > a) ? pref[j - a - 1] : 0;
dp[i][j] = (dp[i][j] + (l - r)) % INTF;
}
}
cout << dp[n][k];
return 0;
} | [
"expression.operation.binary.remove"
] | 981,160 | 981,161 | u060865231 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define input_from_file freopen("input.txt", "r", stdin);
int main() {
// input_from_file;
ll n, m, k, x;
cin >> n >> k;
vector<ll> vec(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> vec[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)),
prefix(n + 1, vector<ll>(k + 1, 0));
for (int i = 0; i <= n; i++) {
dp[i][0] = 1;
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= k; j++) {
dp[i - 1][j] += dp[i - 1][j - 1];
if (j > vec[i])
dp[i][j] = (dp[i - 1][j] % mod - dp[i - 1][j - vec[i] - 1] % mod) % mod;
else
dp[i][j] = dp[i - 1][j] % mod;
}
}
cout << dp[n][k] % mod;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define input_from_file freopen("input.txt", "r", stdin);
int main() {
// input_from_file;
ll n, m, k, x;
cin >> n >> k;
vector<ll> vec(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> vec[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0)),
prefix(n + 1, vector<ll>(k + 1, 0));
for (int i = 0; i <= n; i++) {
dp[i][0] = 1;
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= k; j++) {
dp[i - 1][j] += dp[i - 1][j - 1];
// if(i==1) dp[i][j]= j>vec[i-1]? 0: 1 ;
if (j > vec[i])
dp[i][j] = (dp[i - 1][j] + mod - dp[i - 1][j - vec[i] - 1]) % mod;
else
dp[i][j] = dp[i - 1][j] % mod;
}
}
cout << dp[n][k] % mod;
return 0;
}
| [
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 981,162 | 981,163 | u066630187 | cpp |
p03173 | #include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define REPN(i, a, b) for (long long i = a; i <= b; --i)
#define rep(i, a, b) for (long long i = a; i < b; ++i)
#define rep0(i, b) for (long long i = 0; i < b; ++i)
#define REP0(i, b) for (long long i = 0; i <= b; ++i)
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
int MODE = 1e9 + 7;
ll prefix[403];
ll dp[403][403];
ll arr[403];
int n;
ll helper(int left, int right) {
if (left < 0 || right > n - 1 || left > right || left == right) {
return 0;
}
if (dp[left][right] != -1) {
return dp[left][right];
}
ll minimum = 1e18 + 5;
for (int i = left; i <= right; ++i) {
minimum = min(minimum, helper(left, i) + helper(i + 1, right));
}
return dp[left][right] = minimum + prefix[right] - prefix[left - 1];
}
int main() {
cin >> n;
memset(dp, -1, sizeof(dp));
rep0(i, n) { cin >> arr[i]; }
prefix[0] = 0;
rep0(i, n + 1) { prefix[i] = prefix[i - 1] + arr[i]; }
cout << helper(0, n - 1) << endl;
/*for(int i=0; i<n; ++i)
{
dp[i][i] = 0;
}
for(int i=n-2; i>=0; --i)
{
for(int j=i+1; j<n; ++j)
{
dp[i][j] = 1e18+5;
ll s = prefix[j] - prefix[i-1];
for(int k = i; k<j; ++k)
{
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s);
}
}
}*/
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define REPN(i, a, b) for (long long i = a; i <= b; --i)
#define rep(i, a, b) for (long long i = a; i < b; ++i)
#define rep0(i, b) for (long long i = 0; i < b; ++i)
#define REP0(i, b) for (long long i = 0; i <= b; ++i)
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
int MODE = 1e9 + 7;
ll prefix[403];
ll dp[403][403];
ll arr[403];
int n;
ll helper(int left, int right) {
if (left < 0 || right > n - 1 || left > right || left == right) {
return 0;
}
if (dp[left][right] != -1) {
return dp[left][right];
}
ll minimum = 1e18 + 5;
for (int i = left; i < right; ++i) {
minimum = min(minimum, helper(left, i) + helper(i + 1, right));
}
return dp[left][right] = minimum + prefix[right] - prefix[left - 1];
}
int main() {
cin >> n;
memset(dp, -1, sizeof(dp));
rep0(i, n) { cin >> arr[i]; }
prefix[0] = 0;
rep0(i, n + 1) { prefix[i] = prefix[i - 1] + arr[i]; }
cout << helper(0, n - 1) << endl;
/*for(int i=0; i<n; ++i)
{
dp[i][i] = 0;
}
for(int i=n-2; i>=0; --i)
{
for(int j=i+1; j<n; ++j)
{
dp[i][j] = 1e18+5;
ll s = prefix[j] - prefix[i-1];
for(int k = i; k<j; ++k)
{
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s);
}
}
}*/
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 981,170 | 981,171 | u747883255 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<long long int> A(n);
for (int i = 0; i < n; ++i)
cin >> A[i];
vector<vector<long long int>> dp(n, vector<long long int>(n, INT_MAX));
int L, R;
for (L = n - 1; L >= 0; --L) {
for (R = L; R < n; ++R) {
if (L == R) {
dp[L][R] = 0;
} else {
long long int s = 0;
for (int i = L; i <= R; ++i)
s += A[i];
for (int i = L; i < R; ++i) {
dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
}
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
} | // C++ program to print all the cycles
// in an undirected graph
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<long long int> A(n);
for (int i = 0; i < n; ++i)
cin >> A[i];
vector<vector<long long int>> dp(n, vector<long long int>(n, 1e18 + 8));
int L, R;
for (L = n - 1; L >= 0; --L) {
for (R = L; R < n; ++R) {
if (L == R) {
dp[L][R] = 0;
} else {
long long int s = 0;
for (int i = L; i <= R; ++i)
s += A[i];
// dp[L][R]=1e18+5;
for (int i = L; i < R; ++i) {
dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
}
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
}
| [
"assignment.change"
] | 981,177 | 981,178 | u150020640 | cpp |
p03173 | #include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;
const int MAXN = 500005;
const long MOD = (long)(1e9 + 7);
vector<int> adj[MAXN];
vector<pair<int, int>> G[MAXN];
Int N, M, K;
Int B, C, H, W;
Int X, Y, Z;
vector<Int> A;
Int ceilS(Int x, Int y) { return (x + y - 1) / y; }
using D = long double;
Int perform(Int x) { return (x * (x + 1)) / 2LL; }
vector<Int> dp;
bool VIS[MAXN];
void dfs(int u) {
VIS[u] = true;
for (auto &v : adj[u]) {
if (!VIS[v])
dfs(v);
dp[u] = max(dp[u], 1 + dp[v]);
}
}
int main() {
cin >> N;
A.resize(N);
for (auto &x : A)
cin >> x;
vector<vector<Int>> dp(N, vector<Int>(N, 1e13));
for (int i = 0; i < N; ++i)
dp[i][i] = 0;
vector<int> pref(N);
pref[0] = A[0];
for (int i = 1; i < N; ++i) {
pref[i] = pref[i - 1] + A[i];
}
for (int length = 1; length <= N; ++length) {
for (int i = 0; i < N - length + 1; ++i) {
int j = i + length - 1;
for (int k = i; k < j; ++k) {
Int sum = pref[j] - (i ? pref[i - 1] : 0);
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum);
}
}
}
cout << dp[0][N - 1] << "\n";
}
| #include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;
const int MAXN = 500005;
const long MOD = (long)(1e9 + 7);
vector<int> adj[MAXN];
vector<pair<int, int>> G[MAXN];
Int N, M, K;
Int B, C, H, W;
Int X, Y, Z;
vector<Int> A;
Int ceilS(Int x, Int y) { return (x + y - 1) / y; }
using D = long double;
Int perform(Int x) { return (x * (x + 1)) / 2LL; }
vector<Int> dp;
bool VIS[MAXN];
void dfs(int u) {
VIS[u] = true;
for (auto &v : adj[u]) {
if (!VIS[v])
dfs(v);
dp[u] = max(dp[u], 1 + dp[v]);
}
}
int main() {
cin >> N;
A.resize(N);
for (auto &x : A)
cin >> x;
vector<vector<Int>> dp(N, vector<Int>(N, 1e13));
for (int i = 0; i < N; ++i)
dp[i][i] = 0;
vector<Int> pref(N);
pref[0] = A[0];
for (int i = 1; i < N; ++i) {
pref[i] = pref[i - 1] + A[i];
}
for (int length = 1; length <= N; ++length) {
for (int i = 0; i < N - length + 1; ++i) {
int j = i + length - 1;
for (int k = i; k < j; ++k) {
Int sum = pref[j] - (i ? pref[i - 1] : 0);
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum);
}
}
}
cout << dp[0][N - 1] << "\n";
}
| [] | 981,181 | 981,182 | u212948109 | cpp |
p03173 | #include <cstring>
#include <iostream>
using namespace std;
int a[401];
int dp[401][401], h[401][401];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
memset(dp, 0x3f, sizeof(dp));
for (int len = 1; len <= n; len++)
for (int i = 1; i <= n; i++) {
int j = i + len - 1;
if (j > n)
continue;
if (i == j)
dp[i][j] = 0;
h[i][j] = h[i][j - 1] + a[j];
for (int k = i; k < j; k++)
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + h[i][k] + h[k + 1][j]);
}
cout << dp[1][n];
return 0;
} | #include <cstring>
#include <iostream>
using namespace std;
long long a[401];
long long dp[401][401], h[401][401];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
memset(dp, 0x3f, sizeof(dp));
for (int len = 1; len <= n; len++)
for (int i = 1; i <= n; i++) {
int j = i + len - 1;
if (j > n)
continue;
if (i == j)
dp[i][j] = 0;
h[i][j] = h[i][j - 1] + a[j];
for (int k = i; k < j; k++)
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + h[i][k] + h[k + 1][j]);
}
cout << dp[1][n];
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 981,185 | 981,186 | u490890356 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define ffor(n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef unordered_map<string, int> umsi;
int32_t main() {
fast_io;
int n;
cin >> n;
vi a(n);
c(a, n);
vii dp(n, vi(n, INT_MAX));
vi pre(n + 1, 0);
for (int i = 1; i <= n; i++)
pre[i] = a[i - 1] + pre[i - 1];
for (int i = 0; i < n; i++)
dp[i][i] = 0;
for (int i = 0; i < n - 1; i++)
dp[i][i + 1] = a[i] + a[i + 1];
for (int size = 3; size <= n; size++) {
for (int i = 0; i <= n - size; i++) {
for (int l = i; l < i + size - 1; l++)
dp[i][i + size - 1] =
min(dp[i][i + size - 1],
pre[i + size] - pre[i] + dp[i][l] + dp[l + 1][i + size - 1]);
}
}
cout << dp[0][n - 1];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define c(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define ffor(n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector<float> vf;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef unordered_map<string, int> umsi;
int32_t main() {
fast_io;
int n;
cin >> n;
vi a(n);
c(a, n);
vii dp(n, vi(n, LLONG_MAX));
vi pre(n + 1, 0);
for (int i = 1; i <= n; i++)
pre[i] = a[i - 1] + pre[i - 1];
for (int i = 0; i < n; i++)
dp[i][i] = 0;
for (int i = 0; i < n - 1; i++)
dp[i][i + 1] = a[i] + a[i + 1];
for (int size = 3; size <= n; size++) {
for (int i = 0; i <= n - size; i++) {
for (int l = i; l < i + size - 1; l++)
dp[i][i + size - 1] =
min(dp[i][i + size - 1],
pre[i + size] - pre[i] + dp[i][l] + dp[l + 1][i + size - 1]);
}
}
cout << dp[0][n - 1];
return 0;
} | [] | 981,193 | 981,194 | u900229905 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, pair<ll, char>>
#define sorted(a_1) sort(a_1.begin(), a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(), a_1.rend())
#define t1(a_1) cout << a_1 << endl;
#define t2(a_1) \
for (auto it_test : a_1) \
cout << it_test << " ";
#define MOD 1000000007
ll dp[401][401];
int topDown(vector<ll> &arr, vector<ll> &pref, int l, int r) {
// if(l>r) return 0;
// cout<<l<<" "<<r<<endl;
if (dp[l][r] > -1)
return dp[l][r];
if (r - l == 1)
return dp[l][r] = arr[l] + arr[r];
if (r == l)
return dp[l][r] = 0;
ll ans = 1e18 + 5;
for (int i = l; i < r; i++) {
ans = min(ans, topDown(arr, pref, l, i) + topDown(arr, pref, i + 1, r) +
pref[r] - pref[l - 1]);
}
dp[l][r] = ans;
return ans;
}
void solve() {
int n;
cin >> n;
vector<ll> arr(n + 1), pref(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> arr[i];
pref[1] = arr[1];
for (int i = 2; i <= n; i++)
pref[i] = pref[i - 1] + arr[i];
memset(dp, -1, sizeof(dp));
ll ans = topDown(arr, pref, 1, n);
t1(ans)
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, pair<ll, char>>
#define sorted(a_1) sort(a_1.begin(), a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(), a_1.rend())
#define t1(a_1) cout << a_1 << endl;
#define t2(a_1) \
for (auto it_test : a_1) \
cout << it_test << " ";
#define MOD 1000000007
ll dp[401][401];
ll topDown(vector<ll> &arr, vector<ll> &pref, int l, int r) {
// if(l>r) return 0;
// cout<<l<<" "<<r<<endl;
if (dp[l][r] > -1)
return dp[l][r];
if (r - l == 1)
return dp[l][r] = arr[l] + arr[r];
if (r == l)
return dp[l][r] = 0;
ll ans = 1e18 + 5;
for (int i = l; i < r; i++) {
ans = min(ans, topDown(arr, pref, l, i) + topDown(arr, pref, i + 1, r) +
pref[r] - pref[l - 1]);
}
dp[l][r] = ans;
return ans;
}
void solve() {
int n;
cin >> n;
vector<ll> arr(n + 1), pref(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> arr[i];
pref[1] = arr[1];
for (int i = 2; i <= n; i++)
pref[i] = pref[i - 1] + arr[i];
memset(dp, -1, sizeof(dp));
ll ans = topDown(arr, pref, 1, n);
t1(ans)
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
while (t--) {
solve();
}
return 0;
} | [] | 981,197 | 981,198 | u806983635 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, pair<ll, char>>
#define sorted(a_1) sort(a_1.begin(), a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(), a_1.rend())
#define t1(a_1) cout << a_1 << endl;
#define t2(a_1) \
for (auto it_test : a_1) \
cout << it_test << " ";
#define MOD 1000000007
ll dp[401][401];
int topDown(vector<ll> &arr, vector<ll> &pref, int l, int r) {
// if(l>r) return 0;
// cout<<l<<" "<<r<<endl;
if (dp[l][r] > -1)
return dp[l][r];
if (r - l == 1)
return dp[l][r] = arr[l] + arr[r];
if (r == l)
return dp[l][r] = 0;
ll ans = INT_MAX;
for (int i = l; i < r; i++) {
ans = min(ans, topDown(arr, pref, l, i) + topDown(arr, pref, i + 1, r) +
pref[r] - pref[l - 1]);
}
dp[l][r] = ans;
return ans;
}
void solve() {
int n;
cin >> n;
vector<ll> arr(n + 1), pref(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> arr[i];
pref[1] = arr[1];
for (int i = 2; i <= n; i++)
pref[i] = pref[i - 1] + arr[i];
memset(dp, -1, sizeof(dp));
ll ans = topDown(arr, pref, 1, n);
t1(ans)
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<ll, pair<ll, char>>
#define sorted(a_1) sort(a_1.begin(), a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(), a_1.rend())
#define t1(a_1) cout << a_1 << endl;
#define t2(a_1) \
for (auto it_test : a_1) \
cout << it_test << " ";
#define MOD 1000000007
ll dp[401][401];
ll topDown(vector<ll> &arr, vector<ll> &pref, int l, int r) {
// if(l>r) return 0;
// cout<<l<<" "<<r<<endl;
if (dp[l][r] > -1)
return dp[l][r];
if (r - l == 1)
return dp[l][r] = arr[l] + arr[r];
if (r == l)
return dp[l][r] = 0;
ll ans = 1e18 + 5;
for (int i = l; i < r; i++) {
ans = min(ans, topDown(arr, pref, l, i) + topDown(arr, pref, i + 1, r) +
pref[r] - pref[l - 1]);
}
dp[l][r] = ans;
return ans;
}
void solve() {
int n;
cin >> n;
vector<ll> arr(n + 1), pref(n + 1, 0);
for (int i = 1; i <= n; i++)
cin >> arr[i];
pref[1] = arr[1];
for (int i = 2; i <= n; i++)
pref[i] = pref[i - 1] + arr[i];
memset(dp, -1, sizeof(dp));
ll ans = topDown(arr, pref, 1, n);
t1(ans)
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
while (t--) {
solve();
}
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add"
] | 981,200 | 981,198 | u806983635 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> p(N);
vector<int> imos(N + 1);
vector<vector<int64_t>> dp(N, vector<int64_t>(N));
for (int i = 0; i < N; i++) {
cin >> p[i];
imos[i + 1] = p[i];
imos[i + 1] += imos[i];
}
for (int i = 1; i < N; i++) {
for (int j = i; j < N; j++) {
int a = j - i, b = j;
int64_t A = 167167167167167;
for (int k = a; k < b; k++) {
A = min(A, dp[a][k] + dp[k + 1][b]);
}
dp[a][b] = A + imos[b + 1] - imos[a];
}
}
cout << dp[0][N - 1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int64_t> p(N);
vector<int64_t> imos(N + 1);
vector<vector<int64_t>> dp(N, vector<int64_t>(N));
for (int i = 0; i < N; i++) {
cin >> p[i];
imos[i + 1] = p[i];
imos[i + 1] += imos[i];
}
for (int i = 1; i < N; i++) {
for (int j = i; j < N; j++) {
int a = j - i, b = j;
int64_t A = 167167167167167;
for (int k = a; k < b; k++) {
A = min(A, dp[a][k] + dp[k + 1][b]);
}
dp[a][b] = A + imos[b + 1] - imos[a];
}
}
cout << dp[0][N - 1] << endl;
} | [
"variable_declaration.type.primitive.change"
] | 981,203 | 981,204 | u158290747 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define IOS \
cin.sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a; i <= b; i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair<int, int>;
#define pal pair<ll, ll>;
#define vi vector<int>;
#define vl vector<ll>;
#define vpai vector<pii>;
const int mod = 1e9 + 7;
const int INF = 1e15;
const int sze = 3005;
void solve() {
int n;
cin >> n;
ll dp[n + 5][n + 5];
ll arr[n];
mem(arr);
rep(i, n) cin >> arr[i];
ll pre[n];
pre[0] = arr[0];
repn(i, 1, n - 1) pre[i] = pre[i - 1] + arr[i];
memset(dp, 0, sizeof(dp));
rep(i, n) rep(j, n) dp[i][j] = INF;
rep(i, n) dp[i][i] = 0;
// rep(i,n) cout<<pre[i]<<" ";
for (int len = 2; len <= n; len++) {
for (int i = 0; i <= n - len; i++) {
int j = i + len - 1;
for (int k = i + 1; k <= j; k++) {
int x = 0;
if (i != 0)
x = pre[i - 1];
dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k][j] + pre[j] - x);
// cout<<"hello\n";
}
}
}
cout << dp[0][n - 1] << endl;
}
int main() {
IOS;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS \
cin.sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a; i <= b; i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair<int, int>;
#define pal pair<ll, ll>;
#define vi vector<int>;
#define vl vector<ll>;
#define vpai vector<pii>;
const int mod = 1e9 + 7;
const ll INF = 1e15;
const int sze = 3005;
void solve() {
int n;
cin >> n;
ll dp[n + 5][n + 5];
ll arr[n];
mem(arr);
rep(i, n) cin >> arr[i];
ll pre[n];
pre[0] = arr[0];
repn(i, 1, n - 1) pre[i] = pre[i - 1] + arr[i];
memset(dp, 0, sizeof(dp));
rep(i, n) rep(j, n) dp[i][j] = INF;
rep(i, n) dp[i][i] = 0;
// rep(i,n) cout<<pre[i]<<" ";
for (int len = 2; len <= n; len++) {
for (int i = 0; i <= n - len; i++) {
int j = i + len - 1;
for (int k = i + 1; k <= j; k++) {
ll x = 0;
if (i != 0)
x = pre[i - 1];
dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k][j] + pre[j] - x);
// cout<<"hello\n";
}
}
}
cout << dp[0][n - 1] << endl;
}
int main() {
IOS;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | [
"variable_declaration.type.change"
] | 981,207 | 981,206 | u176621115 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define fr(i, k) for (i = 0; i < k; i++)
#define ALL(c) (c).begin(), (c).end()
#define deb(x) cerr << #x << " = " << x << endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
fastio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
void solve() {
ll n, i, j, k, c, ans = 0;
cin >> n;
ll a[n];
for (i = 0; i < n; i++)
cin >> a[i];
vector<vector<ll>> dp(n, vector<ll>(n, INT_MAX));
vector<vector<ll>> sum(n, vector<ll>(n));
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
if (i == j)
sum[i][j] = a[j];
else
sum[i][j] = sum[i][j - 1] + a[j];
}
}
for (i = 0; i < n; i++)
dp[i][i] = 0;
for (c = 1; c < n; c++) {
i = 0;
j = c;
while (j < n) {
for (k = i; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[i][j]);
}
j++;
i++;
}
}
ans = dp[0][n - 1];
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define fr(i, k) for (i = 0; i < k; i++)
#define ALL(c) (c).begin(), (c).end()
#define deb(x) cerr << #x << " = " << x << endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
fastio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
void solve() {
ll n, i, j, k, c, ans = 0;
cin >> n;
ll a[n];
for (i = 0; i < n; i++)
cin >> a[i];
vector<vector<ll>> dp(n, vector<ll>(n, INF));
vector<vector<ll>> sum(n, vector<ll>(n));
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
if (i == j)
sum[i][j] = a[j];
else
sum[i][j] = sum[i][j - 1] + a[j];
}
}
for (i = 0; i < n; i++)
dp[i][i] = 0;
for (c = 1; c < n; c++) {
i = 0;
j = c;
while (j < n) {
for (k = i; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[i][j]);
}
j++;
i++;
}
}
ans = dp[0][n - 1];
cout << ans << endl;
}
| [] | 981,212 | 981,213 | u928817789 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define fr(i, k) for (i = 0; i < k; i++)
#define ALL(c) (c).begin(), (c).end()
#define deb(x) cerr << #x << " = " << x << endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
fastio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
ll calc(ll a[], ll i, ll j, vector<vector<ll>> &sum, vector<vector<ll>> &dp) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
ll ans = INT_MAX;
for (int k = i; k < j; k++) {
ans = min(ans,
sum[i][j] + calc(a, i, k, sum, dp) + calc(a, k + 1, j, sum, dp));
}
return dp[i][j] = ans;
}
void solve() {
ll n, i, j, k, c;
cin >> n;
ll a[n];
for (i = 0; i < n; i++)
cin >> a[i];
vector<vector<ll>> dp(n, vector<ll>(n, -1));
vector<vector<ll>> sum(n, vector<ll>(n));
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
if (i == j)
sum[i][j] = a[j];
else
sum[i][j] = sum[i][j - 1] + a[j];
}
}
cout << calc(a, 0, n - 1, sum, dp) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define fr(i, k) for (i = 0; i < k; i++)
#define ALL(c) (c).begin(), (c).end()
#define deb(x) cerr << #x << " = " << x << endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
fastio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
ll calc(ll a[], ll i, ll j, vector<vector<ll>> &sum, vector<vector<ll>> &dp) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
ll ans = INF;
for (int k = i; k < j; k++) {
ans = min(ans,
sum[i][j] + calc(a, i, k, sum, dp) + calc(a, k + 1, j, sum, dp));
}
return dp[i][j] = ans;
}
void solve() {
ll n, i, j, k, c;
cin >> n;
ll a[n];
for (i = 0; i < n; i++)
cin >> a[i];
vector<vector<ll>> dp(n, vector<ll>(n, -1));
vector<vector<ll>> sum(n, vector<ll>(n));
for (i = 0; i < n; i++) {
for (j = i; j < n; j++) {
if (i == j)
sum[i][j] = a[j];
else
sum[i][j] = sum[i][j - 1] + a[j];
}
}
cout << calc(a, 0, n - 1, sum, dp) << endl;
}
| [
"variable_declaration.value.change",
"identifier.change"
] | 981,214 | 981,215 | u928817789 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define fr(i, k) for (i = 0; i < k; i++)
#define ALL(c) (c).begin(), (c).end()
#define deb(x) cerr << #x << " = " << x << endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
fastio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
ll calc(ll a[], ll i, ll j, vector<vector<ll>> &sum, vector<vector<ll>> &dp) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
ll ans = INT_MAX;
for (int k = i; k < j; k++) {
ans = min(ans,
sum[i][j] + calc(a, i, k, sum, dp) + calc(a, k + 1, j, sum, dp));
}
return dp[i][j] = ans;
}
void solve() {
ll n, i, j, k, c;
cin >> n;
ll a[n + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -1));
vector<vector<ll>> sum(n + 1, vector<ll>(n + 1));
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
if (i == j)
sum[i][j] = a[j];
else
sum[i][j] = sum[i][j - 1] + a[j];
}
}
cout << calc(a, 1, n, sum, dp) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define fr(i, k) for (i = 0; i < k; i++)
#define ALL(c) (c).begin(), (c).end()
#define deb(x) cerr << #x << " = " << x << endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int main() {
fastio;
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
ll calc(ll a[], ll i, ll j, vector<vector<ll>> &sum, vector<vector<ll>> &dp) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
ll ans = INF;
for (int k = i; k < j; k++) {
ans = min(ans,
sum[i][j] + calc(a, i, k, sum, dp) + calc(a, k + 1, j, sum, dp));
}
return dp[i][j] = ans;
}
void solve() {
ll n, i, j, k, c;
cin >> n;
ll a[n + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, -1));
vector<vector<ll>> sum(n + 1, vector<ll>(n + 1));
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
if (i == j)
sum[i][j] = a[j];
else
sum[i][j] = sum[i][j - 1] + a[j];
}
}
cout << calc(a, 1, n, sum, dp) << endl;
}
| [
"variable_declaration.value.change",
"identifier.change"
] | 981,216 | 981,217 | u928817789 | cpp |
p03173 | #include <bits/stdc++.h>
#define filename "slimes"
#define int long long
#define oo 1e9
#define N 405
using namespace std;
int n, a[N];
int f[N][N];
bool chk[N][N];
void open() {
// freopen(filename".inp","r",stdin) ;
// freopen(filename".out","w",stdout) ;
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void readin() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
}
int calc(int i, int j) {
if (chk[i][j])
return f[i][j];
if (i == j)
return 0;
chk[i][j] = 1;
int &ans = f[i][j];
int res = a[j] - a[i - 1];
int Min = oo;
for (int x = i; x < j; x++) {
Min = min(Min, calc(i, x) + calc(x + 1, j));
}
return ans = res + Min;
}
signed main() {
open();
readin();
cout << calc(1, n);
} | #include <bits/stdc++.h>
#define filename "slimes"
#define int long long
#define oo 1e18
#define N 405
using namespace std;
int n, a[N];
int f[N][N];
bool chk[N][N];
void open() {
// freopen(filename".inp","r",stdin) ;
// freopen(filename".out","w",stdout) ;
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void readin() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
}
int calc(int i, int j) {
if (chk[i][j])
return f[i][j];
if (i == j)
return 0;
chk[i][j] = 1;
int &ans = f[i][j];
int res = a[j] - a[i - 1];
int Min = oo;
for (int x = i; x < j; x++) {
Min = min(Min, calc(i, x) + calc(x + 1, j));
}
return ans = res + Min;
}
signed main() {
open();
readin();
cout << calc(1, n);
} | [
"preprocessor.define.value.change",
"literal.float.change"
] | 981,225 | 981,226 | u416328102 | cpp |
p03173 | #include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll n, x;
vi s;
vector<ll> ps;
ll dp[401][401];
ll calc(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l == r)
return 0;
ll ans = 1e9;
rep(i, l + 1, r) {
ans = min(ans,
ps[r] - (l == 0 ? 0 : ps[l - 1]) + calc(l, i - 1) + calc(i, r));
}
return dp[l][r] = ans;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin.sync_with_stdio(0);
cin.tie();
cin.exceptions(cin.failbit);
cin >> n;
rep(i, 1, n) {
cin >> x;
s.pb(x);
ps.pb(x + (i == 1 ? 0 : ps[i - 2]));
}
rep(i, 0, 400) {
rep(j, 0, 400) { dp[i][j] = -1; }
}
cout << calc(0, n - 1);
} | #include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll n, x;
vi s;
vector<ll> ps;
ll dp[401][401];
ll calc(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l == r)
return 0;
ll ans = 1e18;
rep(i, l + 1, r) {
ans = min(ans,
ps[r] - (l == 0 ? 0 : ps[l - 1]) + calc(l, i - 1) + calc(i, r));
}
return dp[l][r] = ans;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin.sync_with_stdio(0);
cin.tie();
cin.exceptions(cin.failbit);
cin >> n;
rep(i, 1, n) {
cin >> x;
s.pb(x);
ps.pb(x + (i == 1 ? 0 : ps[i - 2]));
}
rep(i, 0, 400) {
rep(j, 0, 400) { dp[i][j] = -1; }
}
cout << calc(0, n - 1);
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 981,227 | 981,228 | u028221335 | cpp |
p03173 | #include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int n, x;
vi s;
vector<ll> ps;
ll dp[401][401];
ll calc(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l == r)
return 0;
ll ans = 1e9;
rep(i, l + 1, r) {
ans = min(ans,
ps[r] - (l == 0 ? 0 : ps[l - 1]) + calc(l, i - 1) + calc(i, r));
}
return dp[l][r] = ans;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin.sync_with_stdio(0);
cin.tie();
cin.exceptions(cin.failbit);
cin >> n;
rep(i, 1, n) {
cin >> x;
s.pb(x);
ps.pb(x + (i == 1 ? 0 : ps[i - 2]));
}
rep(i, 0, 400) {
rep(j, 0, 400) { dp[i][j] = -1; }
}
cout << calc(0, n - 1);
} | #include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll n, x;
vi s;
vector<ll> ps;
ll dp[401][401];
ll calc(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l == r)
return 0;
ll ans = 1e18;
rep(i, l + 1, r) {
ans = min(ans,
ps[r] - (l == 0 ? 0 : ps[l - 1]) + calc(l, i - 1) + calc(i, r));
}
return dp[l][r] = ans;
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin.sync_with_stdio(0);
cin.tie();
cin.exceptions(cin.failbit);
cin >> n;
rep(i, 1, n) {
cin >> x;
s.pb(x);
ps.pb(x + (i == 1 ? 0 : ps[i - 2]));
}
rep(i, 0, 400) {
rep(j, 0, 400) { dp[i][j] = -1; }
}
cout << calc(0, n - 1);
} | [
"variable_declaration.type.change",
"literal.number.change",
"variable_declaration.value.change"
] | 981,229 | 981,228 | u028221335 | cpp |
p03173 | // https://atcoder.jp/contests/dp/tasks/dp_n
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define INF LLONG_MAX
#define minf INT_MIN
#define MINF LLONG_MIN
#define pb push_back
#define all(v) v.begin(), v.end()
#define print(v) \
for (auto x : v) \
cout << x << " "; \
cout << "\n";
#define printn(v) \
for (auto x : v) \
cout << x << "\n";
#define F first
#define S second
#define mp make_pair
// dp(i,j) : minimum cost to combines slimes from range i to j to make single
// slimes dp(i,i) ; 0 dp(i,j) : sum(i,j) + dp(i,k) + dp(k+1,j) where k belongs
// from i to j-1
ll dp[401][401];
int sum[401][401];
vector<int> v;
ll slime(int i, int j) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
ll min_cost = INF;
for (int k = i; k + 1 <= j; k++)
min_cost = min(min_cost, sum[i][j] + slime(i, k) + slime(k + 1, j));
return dp[i][j] = min_cost;
}
void pre_processing(int n) {
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
sum[i][j] = v[j] + (j == i ? 0 : sum[i][j - 1]);
}
int32_t main() {
fastio;
memset(dp, -1, sizeof dp);
int n;
cin >> n;
v.resize(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
pre_processing(n);
cout << slime(1, n) << endl;
} | // https://atcoder.jp/contests/dp/tasks/dp_n
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define INF LLONG_MAX
#define minf INT_MIN
#define MINF LLONG_MIN
#define pb push_back
#define all(v) v.begin(), v.end()
#define print(v) \
for (auto x : v) \
cout << x << " "; \
cout << "\n";
#define printn(v) \
for (auto x : v) \
cout << x << "\n";
#define F first
#define S second
#define mp make_pair
// dp(i,j) : minimum cost to combines slimes from range i to j to make single
// slimes dp(i,i) ; 0 dp(i,j) : sum(i,j) + dp(i,k) + dp(k+1,j) where k belongs
// from i to j-1
ll dp[401][401];
ll sum[401][401];
vector<int> v;
ll slime(int i, int j) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
ll min_cost = INF;
for (int k = i; k + 1 <= j; k++)
min_cost = min(min_cost, sum[i][j] + slime(i, k) + slime(k + 1, j));
return dp[i][j] = min_cost;
}
void pre_processing(int n) {
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
sum[i][j] = v[j] + (j == i ? 0 : sum[i][j - 1]);
}
int32_t main() {
fastio;
memset(dp, -1, sizeof dp);
int n;
cin >> n;
v.resize(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
pre_processing(n);
cout << slime(1, n) << endl;
} | [
"variable_declaration.type.change"
] | 981,230 | 981,231 | u315416184 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x, y) fixed << setprecision(y) << x
#define pq priority_queue<int>
#define mpq priority_queue<int, vector<int>, greater<int>>
#define gcd(x, y) __gcd(x, y)
#define mp make_pair
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i, j, k;
cin >> n;
int a[n];
for (i = 0; i < n; i++)
cin >> a[i];
int s[n];
s[0] = a[0];
for (i = 1; i < n; i++)
s[i] = s[i - 1] + a[i];
int dp[n][n];
memset(dp, 0, sizeof(dp));
for (i = 0; i < n; i++)
dp[i][i] = a[i];
for (i = 1; i < n; i++)
dp[i - 1][i] = a[i] + a[i - 1];
for (i = 2; i < n; i++) {
for (j = 0; j + i < n; j++) {
dp[j][j + i] = INT_MAX;
for (k = j; k < (i + j); k++) {
int ans = dp[j][k] + dp[k + 1][j + i] + s[k] - s[j] + a[j] + s[j + i] -
s[k + 1] + a[k + 1];
if (k == j)
ans -= a[k];
if (k + 1 == (i + j))
ans -= a[i + j];
dp[j][j + i] = min(dp[j][j + i], ans);
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x, y) fixed << setprecision(y) << x
#define pq priority_queue<int>
#define mpq priority_queue<int, vector<int>, greater<int>>
#define gcd(x, y) __gcd(x, y)
#define mp make_pair
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i, j, k;
cin >> n;
int a[n];
for (i = 0; i < n; i++)
cin >> a[i];
int s[n];
s[0] = a[0];
for (i = 1; i < n; i++)
s[i] = s[i - 1] + a[i];
int dp[n][n];
memset(dp, 0, sizeof(dp));
for (i = 0; i < n; i++)
dp[i][i] = a[i];
for (i = 1; i < n; i++)
dp[i - 1][i] = a[i] + a[i - 1];
for (i = 2; i < n; i++) {
for (j = 0; j + i < n; j++) {
dp[j][j + i] = inf;
for (k = j; k < (i + j); k++) {
int ans = dp[j][k] + dp[k + 1][j + i] + s[k] - s[j] + a[j] + s[j + i] -
s[k + 1] + a[k + 1];
if (k == j)
ans -= a[k];
if (k + 1 == (i + j))
ans -= a[i + j];
dp[j][j + i] = min(dp[j][j + i], ans);
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change"
] | 981,232 | 981,233 | u851992913 | cpp |
p03173 | /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
int dp[401][401];
ll cost(int i, int j, vector<ll> &v) {
if (i >= j) {
return 0; // it simply means their is already a single slime....i==j
} else {
if (dp[i][j] != -1)
return dp[i][j]; // recursion+memoisation...
ll ans = LLONG_MAX;
ll sum = 0;
for (ll k = i; k <= j; k++) {
sum += v[k]; // ye current slime ko banane ka cost hai....
}
for (int k = i; k <= j - 1; k++) {
ans =
min(ans, (dp[i][k] != -1 ? dp[i][k] : cost(i, k, v)) +
(dp[k + 1][j] != -1 ? dp[k + 1][j] : cost(k + 1, j, v)) +
sum);
}
return dp[i][j] = ans;
}
}
ll solve(int n, vector<ll> &v) {
memset(dp, -1, sizeof(dp));
return cost(1, n, v);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ll> v(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> v[i];
}
cout << solve(n, v);
return 0;
}
| /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
ll dp[401][401];
ll cost(int i, int j, vector<ll> &v) {
if (i >= j) {
return 0; // it simply means their is already a single slime....i==j
} else {
if (dp[i][j] != -1)
return dp[i][j]; // recursion+memoisation...
ll ans = LLONG_MAX;
ll sum = 0;
for (ll k = i; k <= j; k++) {
sum += v[k]; // ye current slime ko banane ka cost hai....
}
for (int k = i; k <= j - 1; k++) {
ans =
min(ans, (dp[i][k] != -1 ? dp[i][k] : cost(i, k, v)) +
(dp[k + 1][j] != -1 ? dp[k + 1][j] : cost(k + 1, j, v)) +
sum);
}
return dp[i][j] = ans;
}
}
ll solve(int n, vector<ll> &v) {
memset(dp, -1, sizeof(dp));
return cost(1, n, v);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ll> v(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> v[i];
}
cout << solve(n, v);
return 0;
}
| [
"variable_declaration.type.change"
] | 981,234 | 981,235 | u881931540 | cpp |
p03173 | /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
int dp[401][401];
ll cost(int i, int j, vector<ll> &v) {
if (i == j) {
return 0; // it simply means their is already a single slime....
} else {
if (dp[i][j] != -1)
return dp[i][j]; // recursion+memoisation...
ll ans = LLONG_MAX;
ll sum = 0;
for (ll k = i; k <= j; k++) {
sum += v[k]; // ye current slime ko banane ka cost hai....
}
for (int k = i; k <= j - 1; k++) {
ans =
min(ans, (dp[i][k] != -1 ? dp[i][k] : cost(i, k, v)) +
(dp[k + 1][j] != -1 ? dp[k + 1][j] : cost(k + 1, j, v)) +
sum);
}
return dp[i][j] = ans;
}
}
ll solve(int n, vector<ll> &v) {
memset(dp, -1, sizeof(dp));
return cost(1, n, v);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ll> v(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> v[i];
}
cout << solve(n, v);
return 0;
}
| /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
ll dp[401][401];
ll cost(int i, int j, vector<ll> &v) {
if (i >= j) {
return 0; // it simply means their is already a single slime....i==j
} else {
if (dp[i][j] != -1)
return dp[i][j]; // recursion+memoisation...
ll ans = LLONG_MAX;
ll sum = 0;
for (ll k = i; k <= j; k++) {
sum += v[k]; // ye current slime ko banane ka cost hai....
}
for (int k = i; k <= j - 1; k++) {
ans =
min(ans, (dp[i][k] != -1 ? dp[i][k] : cost(i, k, v)) +
(dp[k + 1][j] != -1 ? dp[k + 1][j] : cost(k + 1, j, v)) +
sum);
}
return dp[i][j] = ans;
}
}
ll solve(int n, vector<ll> &v) {
memset(dp, -1, sizeof(dp));
return cost(1, n, v);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<ll> v(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> v[i];
}
cout << solve(n, v);
return 0;
}
| [
"variable_declaration.type.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 981,236 | 981,235 | u881931540 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
int bs_upper_bound(int a[], int n, int x) {
int l = 0;
int h = n; // Not n - 1
while (l < h) {
int mid = l + (h - l) / 2;
if (x >= a[mid]) {
l = mid + 1;
} else {
h = mid;
}
}
return l;
}
int bs_lower_bound(int a[], int n, int x) {
int l = 0;
int h = n; // Not n - 1
while (l < h) {
int mid = l + (h - l) / 2;
if (x <= a[mid]) {
h = mid;
} else {
l = mid + 1;
}
}
return l;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
int main() {
IOS;
int n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
ll dp[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
dp[i][j] = LONG_MAX;
}
for (int i = 0; i < n; i++)
dp[i][i] = 0;
for (int k = 2; k <= n; k++) {
for (int i = 0; i < n; i++) {
ll s = a[i];
for (int j = i + 1; j < i + k; j++) {
s += a[j];
for (int l = i; l < j; l++)
dp[i][j] = min(dp[i][j], s + dp[i][l] + dp[l + 1][j]);
}
}
}
cout << dp[0][n - 1];
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
int bs_upper_bound(int a[], int n, int x) {
int l = 0;
int h = n; // Not n - 1
while (l < h) {
int mid = l + (h - l) / 2;
if (x >= a[mid]) {
l = mid + 1;
} else {
h = mid;
}
}
return l;
}
int bs_lower_bound(int a[], int n, int x) {
int l = 0;
int h = n; // Not n - 1
while (l < h) {
int mid = l + (h - l) / 2;
if (x <= a[mid]) {
h = mid;
} else {
l = mid + 1;
}
}
return l;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
int main() {
IOS;
int n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
ll dp[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
dp[i][j] = LONG_MAX;
}
for (int i = 0; i < n; i++)
dp[i][i] = 0;
for (int k = 2; k <= n; k++) {
for (int i = 0; i < n - k + 1; i++) {
ll s = a[i];
for (int j = i + 1; j < i + k; j++) {
s += a[j];
for (int l = i; l < j; l++)
dp[i][j] = min(dp[i][j], s + dp[i][l] + dp[l + 1][j]);
}
}
}
cout << dp[0][n - 1];
}
| [
"control_flow.loop.for.condition.change"
] | 981,246 | 981,247 | u023403724 | cpp |
p03173 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int dp[403][403];
vi arr(403);
int n;
int sum(int l, int r) {
int s = 0;
for (int i = l; i <= r; i++)
s += arr[i];
return s;
}
int memo(int s, int e) {
if (s >= e)
return dp[s][e] = 0;
if (dp[s][e] != -1)
return dp[s][e];
int ans = 1e18 + 5;
for (int i = s; i <= e - 1; i++) {
ans = min(ans, memo(s, i) + memo(i + 1, e) + sum(s, e));
}
return dp[s][e] = ans;
}
int32_t main() {
c_p_c();
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
// cout<<memo(0,n-1);
cout << dp[0][n - 1];
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int dp[403][403];
vi arr(403);
int n;
int sum(int l, int r) {
int s = 0;
for (int i = l; i <= r; i++)
s += arr[i];
return s;
}
int memo(int s, int e) {
if (s >= e)
return dp[s][e] = 0;
if (dp[s][e] != -1)
return dp[s][e];
int ans = 1e18 + 5;
for (int i = s; i <= e - 1; i++) {
ans = min(ans, memo(s, i) + memo(i + 1, e) + sum(s, e));
}
return dp[s][e] = ans;
}
int32_t main() {
c_p_c();
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cout << memo(0, n - 1);
// cout<<dp[0][n-1];
return 0;
} | [
"io.output.change"
] | 981,257 | 981,258 | u682269149 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 305;
const int NIL = -1;
const ll LINF = 1LL << 50;
const int mod = 1e+9 + 7;
/* global variables */
/* funciton */
/* main */
int main() {
int N;
cin >> N;
vector<ll> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
// sum(a[i], ... , a[j]) = cum[j+1] - cum[i];
vector<ll> cum(N + 2);
for (int i = 0; i <= N; i++)
cum[i + 1] = cum[i] + a[i];
// dp[x][y] = a[x] ~ a[y-1]までを合体させる時の最小コスト
vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, LINF));
for (int i = 0; i <= N; i++) {
dp[i][i + 1] = 0;
}
for (int len = 1; len <= N; len++) {
for (int x = 0; x <= N - len; x++) {
int y = x + len;
for (int z = x + 1; z < y; z++) {
ll cost = dp[x][z] + dp[z][y] + (cum[z] - cum[x]) + (cum[y] - cum[z]);
dp[x][y] = min(dp[x][y], cost);
}
}
}
cout << dp[0][N] << '\n';
} | #include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 305;
const int NIL = -1;
const ll LINF = 1LL << 50;
const int mod = 1e+9 + 7;
/* global variables */
/* funciton */
/* main */
int main() {
int N;
cin >> N;
vector<ll> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
// sum(a[i], ... , a[j]) = cum[j+1] - cum[i];
vector<ll> cum(N + 2);
for (int i = 0; i <= N; i++)
cum[i + 1] = cum[i] + a[i];
// dp[x][y] = a[x] ~ a[y-1]までを合体させる時の最小コスト
vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, LINF));
for (int i = 0; i < N; i++) {
dp[i][i + 1] = 0;
}
for (int len = 1; len <= N; len++) {
for (int x = 0; x <= N - len; x++) {
int y = x + len;
for (int z = x + 1; z < y; z++) {
ll cost = dp[x][z] + dp[z][y] + (cum[z] - cum[x]) + (cum[y] - cum[z]);
dp[x][y] = min(dp[x][y], cost);
}
}
}
cout << dp[0][N] << '\n';
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 981,259 | 981,260 | u603234915 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18L + 18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
vector<int> a(N);
vector<vector<long long>> dp(N, vector<long long>(N));
for (int i = 0; i < N; ++i) {
cin >> a[i];
if (i > 0)
a[i] += a[i - 1];
}
auto sum = [&](int st, int dr) {
if (st == 0)
return a[dr];
return a[dr] - a[st - 1];
};
for (int L = N - 2; L >= 0; --L)
for (int R = L + 1; R < N; ++R) {
dp[L][R] = INF;
for (int i = L; i < R; ++i)
dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum(L, R));
}
cout << dp[0][N - 1];
}
| #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18L + 18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
vector<long long> a(N);
vector<vector<long long>> dp(N, vector<long long>(N));
for (int i = 0; i < N; ++i) {
cin >> a[i];
if (i > 0)
a[i] += a[i - 1];
}
auto sum = [&](int st, int dr) {
if (st == 0)
return a[dr];
return a[dr] - a[st - 1];
};
for (int L = N - 2; L >= 0; --L)
for (int R = L + 1; R < N; ++R) {
dp[L][R] = INF;
for (int i = L; i < R; ++i)
dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + sum(L, R));
}
cout << dp[0][N - 1];
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 981,261 | 981,262 | u934482833 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef unordered_map<int, int> mii;
typedef unordered_map<char, int> mci;
typedef unordered_map<string, int> msi;
#define pb push_back
#define f first
#define s second
void solve() {
int n, b, e, sum;
cin >> n;
vi A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
vvi dp(n, vi(n));
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
b = j, e = j + i - 1;
dp[b][e] = INF;
sum = 0;
for (int k = b; k <= e; k++) {
sum += A[k];
}
for (int k = b; k <= e - 1; k++) {
dp[b][e] = min(dp[b][e], dp[b][k] + dp[k + 1][e] + sum);
}
}
}
// for(int i=0;i<n;i++) {
// for(int j=0;j<n;j++) {
// cout<<dp[i][j]<<' ';
// }
// cout<<endl;
// }
cout << dp[0][n - 1] << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
//#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
int tc;
tc = 1;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const int MOD = 1e9 + 7;
const int INF = 1e18 + 7;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef unordered_map<int, int> mii;
typedef unordered_map<char, int> mci;
typedef unordered_map<string, int> msi;
#define pb push_back
#define f first
#define s second
void solve() {
int n, b, e, sum;
cin >> n;
vi A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
vvi dp(n, vi(n));
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
b = j, e = j + i - 1;
dp[b][e] = INF;
sum = 0;
for (int k = b; k <= e; k++) {
sum += A[k];
}
for (int k = b; k <= e - 1; k++) {
dp[b][e] = min(dp[b][e], dp[b][k] + dp[k + 1][e] + sum);
}
}
}
// for(int i=0;i<n;i++) {
// for(int j=0;j<n;j++) {
// cout<<dp[i][j]<<' ';
// }
// cout<<endl;
// }
cout << dp[0][n - 1] << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
//#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
int tc;
tc = 1;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
} | [
"literal.number.change",
"expression.operation.binary.change"
] | 981,263 | 981,264 | u022282624 | cpp |
p03173 | #include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;
constexpr int kMax = 400;
int main() {
LL dp[kMax][kMax];
int N;
std::cin >> N;
std::vector<LL> a(N), ac(N + 1);
for (int i = 0; i < N; ++i)
std::cin >> a[i];
ac[0] = 0;
for (int i = 0; i < N; ++i)
ac[i + 1] = ac[i] + a[i];
for (int i = 0; i < N - 1; ++i)
dp[i][i + 1] = 0;
for (int j = 2; j <= N; ++j) {
for (int i = 0; i <= N - j; ++i) {
dp[i][i + j] = dp[i + 1][i + j];
for (int k = i + 2; k < j; ++k) {
dp[i][i + j] = std::min(dp[i][i + j], dp[i][k] + dp[k][i + j]);
}
dp[i][i + j] += ac[i + j] - ac[i];
}
}
std::cout << dp[0][N] << std::endl;
}
| #include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;
constexpr int kMax = 401;
int main() {
LL dp[kMax][kMax];
int N;
std::cin >> N;
std::vector<LL> a(N), ac(N + 1);
for (int i = 0; i < N; ++i)
std::cin >> a[i];
ac[0] = 0;
for (int i = 0; i < N; ++i)
ac[i + 1] = ac[i] + a[i];
for (int i = 0; i < N; ++i)
dp[i][i + 1] = 0;
for (int j = 2; j <= N; ++j) {
for (int i = 0; i <= N - j; ++i) {
dp[i][i + j] = dp[i + 1][i + j];
for (int k = i + 2; k < i + j; ++k) {
dp[i][i + j] = std::min(dp[i][i + j], dp[i][k] + dp[k][i + j]);
}
dp[i][i + j] += ac[i + j] - ac[i];
}
}
std::cout << dp[0][N] << std::endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 981,267 | 981,268 | u116523315 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[401][401];
ll a[401];
void solve(ll n, ll m) {
if (dp[n][m] != -1) {
return;
}
dp[n][m] = INT_MAX;
ll sum = 0;
if (n == m) {
dp[n][m] = 0;
return;
}
for (int i = n; i <= m; i++) {
sum += a[i];
}
for (int i = n; i < m; i++) {
solve(n, i);
solve(i + 1, m);
dp[n][m] = min(dp[n][m], dp[n][i] + dp[i + 1][m] + sum);
}
}
int main() {
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = -1;
}
}
solve(0, n - 1);
cout << dp[0][n - 1];
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[401][401];
ll a[401];
void solve(ll n, ll m) {
if (dp[n][m] != -1) {
return;
}
dp[n][m] = LONG_LONG_MAX;
ll sum = 0;
if (n == m) {
dp[n][m] = 0;
return;
}
for (int i = n; i <= m; i++) {
sum += a[i];
}
for (int i = n; i < m; i++) {
solve(n, i);
solve(i + 1, m);
dp[n][m] = min(dp[n][m], dp[n][i] + dp[i + 1][m] + sum);
}
}
int main() {
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = -1;
}
}
solve(0, n - 1);
cout << dp[0][n - 1];
} | [
"assignment.value.change",
"identifier.change"
] | 981,269 | 981,270 | u139996323 | cpp |
p03173 | #include <cstring>
#include <iostream>
#include <vector>
#define INF (1LL << 60)
using namespace std;
long long int dp[3001][3001];
long long int sum[3001][3001];
long long int slimes(vector<int> &v, int i, int j) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j]; // Look-Up
long long int minCost = INF;
for (int k = i; k < j; k++) {
minCost =
min(minCost, sum[i][j] + slimes(v, i, (i + k)) + slimes(v, (k + 1), j));
}
return (dp[i][j] = minCost);
}
void preprocess(vector<int> &v, int n) {
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
sum[i][j] = v[j] + ((j == i) ? 0 : sum[i][j - 1]);
}
}
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
preprocess(v, n);
cout << slimes(v, 1, n) << endl;
return 0;
} | #include <cstring>
#include <iostream>
#include <vector>
#define INF (1LL << 60)
using namespace std;
long long int dp[3001][3001];
long long int sum[3001][3001];
long long int slimes(vector<int> &v, int i, int j) {
if (i == j)
return 0;
if (dp[i][j] != -1)
return dp[i][j]; // Look-Up
long long int minCost = INF;
for (int k = i; k < j; k++) {
minCost =
min(minCost, (sum[i][j] + slimes(v, i, k) + slimes(v, (k + 1), j)));
}
return (dp[i][j] = minCost);
}
void preprocess(vector<int> &v, int n) {
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
sum[i][j] = v[j] + ((j == i) ? 0 : sum[i][j - 1]);
}
}
}
int main() {
int n;
cin >> n;
memset(dp, -1, sizeof(dp));
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
preprocess(v, n);
cout << slimes(v, 1, n) << endl;
return 0;
} | [
"call.arguments.change"
] | 981,271 | 981,272 | u148301183 | cpp |
p03173 | #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
void prefix(ll arr[], ll n, vector<ll> &sum) {
ll s = 0;
for (ll i = 0; i < n; i++) {
s = s + arr[i];
sum[i] = s;
// cout<<i<<" "<<sum[i]<<endl;
}
}
int main() {
ll n;
cin >> n;
ll arr[n];
for (ll i = 0; i < n; i++) {
cin >> arr[i];
}
ll dp[n][n];
vector<ll> sum(n);
// dp[i][j] ----minimum cost to combine from i to j
prefix(arr, n, sum);
// cout<<sum[0]<<" "<<sum[1]<<" "<<sum[2]<<endl;
for (ll i = n - 1; i >= 0; i--) {
for (ll j = i; j < n; j++) {
if (i == j)
dp[i][j] = 0;
else {
dp[i][j] = INT_MAX;
for (ll k = i; k < j; k++) {
if (i - 1 >= 0)
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1]);
else
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j]);
}
}
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
cout << dp[0][n - 1] << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
void prefix(ll arr[], ll n, vector<ll> &sum) {
ll s = 0;
for (ll i = 0; i < n; i++) {
s = s + arr[i];
sum[i] = s;
// cout<<i<<" "<<sum[i]<<endl;
}
}
int main() {
ll n;
cin >> n;
ll arr[n];
for (ll i = 0; i < n; i++) {
cin >> arr[i];
}
ll dp[n][n];
vector<ll> sum(n);
// dp[i][j] ----minimum cost to combine from i to j
prefix(arr, n, sum);
// cout<<sum[0]<<" "<<sum[1]<<" "<<sum[2]<<endl;
for (ll i = n - 1; i >= 0; i--) {
for (ll j = i; j < n; j++) {
if (i == j)
dp[i][j] = 0;
else {
dp[i][j] = 1e18 + 5;
for (ll k = i; k < j; k++) {
if (i - 1 >= 0)
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1]);
else
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j]);
}
}
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
cout << dp[0][n - 1] << endl;
} | [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"assignment.change"
] | 981,293 | 981,294 | u507656909 | cpp |
p03173 | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n + 1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x) * (x)
#define pii pair<int, int>
#define pdd pair<double, double>
#define endl '\n'
#define PI 3.14159265
//#define TOAD
#ifdef TOAD
#define bug(x) cerr << __LINE__ << ": " << #x << " is " << x << endl
#define IOS()
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll << 60;
const int iinf = 2147483647;
const ll mod = 1e9 + 7;
const ll maxn = 5e3 + 5;
ll pw(ll x, ll p) {
ll ret = 1;
while (p > 0) {
if (p & 1) {
ret *= x;
}
x *= x;
x %= mod;
p >>= 1;
}
return ret;
}
ll inv(ll a, ll b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; }
int dp[405][405];
signed main() {
IOS();
int n;
cin >> n;
vector<int> vc(n + 1);
REP1(i, n) cin >> vc[i];
vector<int> pf(n + 1);
pf[1] = vc[1];
REP1(i, n - 1) { pf[i + 1] = pf[i] + vc[i + 1]; }
/*REP1(i,n) cout<<pf[i]<<' ';
cout<<endl;
*/
REP(i, n + 1) REP(j, n + 1) dp[i][j] = iinf;
for (int i = n; i >= 1; i--) {
FOR(j, i, n + 1) {
if (i == j) {
dp[i][j] = 0;
continue;
}
FOR(k, i, j) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + pf[j] - pf[i - 1]);
}
bug(i);
bug(j);
bug(dp[i][j]);
}
}
cout << dp[1][n] << endl;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n + 1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x) * (x)
#define pii pair<int, int>
#define pdd pair<double, double>
#define endl '\n'
#define PI 3.14159265
//#define TOAD
#ifdef TOAD
#define bug(x) cerr << __LINE__ << ": " << #x << " is " << x << endl
#define IOS()
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll << 60;
const int iinf = 1ll << 60;
const ll mod = 1e9 + 7;
const ll maxn = 5e3 + 5;
ll pw(ll x, ll p) {
ll ret = 1;
while (p > 0) {
if (p & 1) {
ret *= x;
}
x *= x;
x %= mod;
p >>= 1;
}
return ret;
}
ll inv(ll a, ll b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; }
int dp[405][405];
signed main() {
IOS();
int n;
cin >> n;
vector<int> vc(n + 1);
REP1(i, n) cin >> vc[i];
vector<int> pf(n + 1);
pf[1] = vc[1];
REP1(i, n - 1) { pf[i + 1] = pf[i] + vc[i + 1]; }
/*REP1(i,n) cout<<pf[i]<<' ';
cout<<endl;
*/
REP(i, n + 1) REP(j, n + 1) dp[i][j] = iinf;
for (int i = n; i >= 1; i--) {
FOR(j, i, n + 1) {
if (i == j) {
dp[i][j] = 0;
continue;
}
FOR(k, i, j) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + pf[j] - pf[i - 1]);
}
bug(i);
bug(j);
bug(dp[i][j]);
}
}
cout << dp[1][n] << endl;
} | [
"literal.number.change"
] | 981,303 | 981,304 | u205731847 | cpp |
p03173 |
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
int dp[405][405];
vector<int> s(405);
int dfs(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
int now = 1001001001;
for (int i = l; i <= r - 1; i++) {
now = min(now, dfs(l, i) + dfs(i + 1, r));
}
dp[l][r] = now + s[r + 1] - s[l];
// cout<<dp[l][r]<<"l"<<l<<"r"<<r<<endl;
return dp[l][r];
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
s[0] = 0;
rep(i, n) s[i + 1] = s[i] + a[i];
rep(i, 405) rep(j, 405) dp[i][j] = -1;
rep(i, n) dp[i][i] = 0;
cout << dfs(0, n - 1);
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
ll dp[405][405];
vector<ll> s(405);
ll dfs(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
ll now = INF;
for (int i = l; i <= r - 1; i++) {
now = min(now, dfs(l, i) + dfs(i + 1, r));
}
dp[l][r] = now + s[r + 1] - s[l];
// cout<<dp[l][r]<<"l"<<l<<"r"<<r<<endl;
return dp[l][r];
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
s[0] = 0;
rep(i, n) s[i + 1] = s[i] + a[i];
rep(i, 405) rep(j, 405) dp[i][j] = -1;
rep(i, n) dp[i][i] = 0;
cout << dfs(0, n - 1);
}
| [
"variable_declaration.type.change",
"variable_declaration.value.change",
"identifier.replace.add",
"literal.replace.remove"
] | 981,305 | 981,306 | u289381123 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.