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 "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"
using namespace std;
const long long int MOD = 1000000007;
// const long long int MOD = 998244353;
// long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K;
vector<vector<long long int>> dp(2, vector<long long int>(K + 5));
dp[1][0] = 1;
for (int i = 0; i < N; i++) {
cin >> M;
for (auto &j : dp[i & 1])
j = 0;
for (int j = 0; j <= K; j++) {
dp[i & 1][j] += dp[(i ^ 1) & 1][j];
dp[i & 1][min(j + M, K) + 1] -= dp[(i ^ 1) & 1][j];
}
for (int j = 1; j <= K + 1; j++) {
dp[i & 1][j] += dp[i & 1][j - 1];
dp[i & 1][j] %= MOD;
}
}
cout << dp[(N ^ 1) & 1][K] << endl;
} | #include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"
using namespace std;
const long long int MOD = 1000000007;
// const long long int MOD = 998244353;
// long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K;
vector<vector<long long int>> dp(2, vector<long long int>(K + 5));
dp[1][0] = 1;
for (int i = 0; i < N; i++) {
cin >> M;
for (auto &j : dp[i & 1])
j = 0;
for (int j = 0; j <= K; j++) {
dp[i & 1][j] += dp[(i ^ 1) & 1][j];
dp[i & 1][min(j + M, K) + 1] -= dp[(i ^ 1) & 1][j] - MOD;
}
for (int j = 1; j <= K + 1; j++) {
dp[i & 1][j] += dp[i & 1][j - 1];
dp[i & 1][j] %= MOD;
}
}
cout << dp[(N ^ 1) & 1][K] << endl;
} | [
"assignment.change"
] | 981,893 | 981,894 | u468700753 | cpp |
p03172 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
const int N = 101 + 1;
const int K = 1e5 + 1;
const int MOD = 1e9 + 7;
int a[N];
int dp[N][K];
int prefsum[N][K];
int sub(int a, int b) {
a -= b;
if (a < 0)
return a + MOD;
}
int getsum(int row, int l, int r) {
if (l == 0)
return prefsum[row][r];
return sub(prefsum[row][r], prefsum[row][l - 1]);
}
void add(int &a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
int plus(int a, int b) {
add(a, b);
return a;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
prefsum[i][0] = dp[i][0];
for (int j = 1; j <= k; ++j) {
prefsum[i][j] = prefsum[i][j - 1];
add(prefsum[i][j], dp[i][j]);
}
for (int j = 0; j <= k; ++j) {
int l = max(0, j - a[i]);
int r = j;
dp[i + 1][j] = getsum(i, l, r);
}
}
int answer = 0;
cout << dp[n][k] << "\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
const int N = 101 + 1;
const int K = 1e5 + 1;
const int MOD = 1e9 + 7;
int a[N];
int dp[N][K];
int prefsum[N][K];
int sub(int a, int b) {
a -= b;
if (a < 0)
return a + MOD;
return a;
}
int getsum(int row, int l, int r) {
if (l == 0)
return prefsum[row][r];
return sub(prefsum[row][r], prefsum[row][l - 1]);
}
void add(int &a, int b) {
a += b;
if (a >= MOD)
a -= MOD;
}
int plus(int a, int b) {
add(a, b);
return a;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
prefsum[i][0] = dp[i][0];
for (int j = 1; j <= k; ++j) {
prefsum[i][j] = prefsum[i][j - 1];
add(prefsum[i][j], dp[i][j]);
}
for (int j = 0; j <= k; ++j) {
int l = max(0, j - a[i]);
int r = j;
dp[i + 1][j] = getsum(i, l, r);
}
}
int answer = 0;
cout << dp[n][k] << "\n";
return 0;
} | [
"control_flow.return.add"
] | 981,903 | 981,904 | u217145434 | cpp |
p03172 | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
FOR(i, 1, n + 1) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<vector<ll>> sum(n + 1, vector<ll>(k + 2, 0));
dp[0][0] = 1;
sum[0][0] = 1;
FOR(i, 1, n + 1) {
sum[i - 1][0] = 0;
REP(j, k + 1) sum[i - 1][j + 1] = (dp[i - 1][j] + sum[i - 1][j]) % mod;
REP(j, k + 1) {
int l = max(0, j - a[i]), r = j + 1;
dp[i][j] = (sum[i - 1][r] - sum[i - 1][l]) % mod;
}
}
cout << dp[n][k] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
FOR(i, 1, n + 1) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<vector<ll>> sum(n + 1, vector<ll>(k + 2, 0));
dp[0][0] = 1;
sum[0][0] = 1;
FOR(i, 1, n + 1) {
sum[i - 1][0] = 0;
REP(j, k + 1) sum[i - 1][j + 1] = (dp[i - 1][j] + sum[i - 1][j]) % mod;
REP(j, k + 1) {
int l = max(0, j - a[i]), r = j + 1;
dp[i][j] = (sum[i - 1][r] - sum[i - 1][l] + mod) % mod;
}
}
cout << dp[n][k] << endl;
return 0;
}
| [
"assignment.change"
] | 981,908 | 981,909 | u772304668 | cpp |
p03172 | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
FOR(i, 1, n + 1) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<vector<ll>> sum(n + 1, vector<ll>(k + 2, 0));
dp[0][0] = 1;
sum[0][0] = 1;
FOR(i, 1, n + 1) {
sum[i - 1][0] = 0;
REP(j, k + 1) sum[i - 1][j + 1] = (dp[i - 1][j] + sum[i - 1][j]) % mod;
REP(j, k + 1) {
int l = max(0, j - a[i]), r = j + 1;
dp[i][j] = sum[i - 1][r] - sum[i - 1][l];
}
}
cout << dp[n][k] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
FOR(i, 1, n + 1) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<vector<ll>> sum(n + 1, vector<ll>(k + 2, 0));
dp[0][0] = 1;
sum[0][0] = 1;
FOR(i, 1, n + 1) {
sum[i - 1][0] = 0;
REP(j, k + 1) sum[i - 1][j + 1] = (dp[i - 1][j] + sum[i - 1][j]) % mod;
REP(j, k + 1) {
int l = max(0, j - a[i]), r = j + 1;
dp[i][j] = (sum[i - 1][r] - sum[i - 1][l] + mod) % mod;
}
}
cout << dp[n][k] << endl;
return 0;
}
| [
"assignment.change"
] | 981,910 | 981,909 | u772304668 | cpp |
p03172 | #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
FOR(i, 1, n + 1) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<vector<ll>> sum(n + 1, vector<ll>(k + 2, 0));
dp[0][0] = 1;
sum[0][0] = 1;
FOR(i, 1, n + 1) {
sum[i - 1][0] = 0;
REP(j, k + 1) sum[i - 1][j + 1] = (dp[i - 1][j] + sum[i - 1][j]) % mod;
REP(j, k + 1) {
int r = max(0, j - a[i]), l = j + 1;
dp[i][j] = (sum[i - 1][l] - sum[i - 1][r]) % mod;
}
}
cout << dp[n][k] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
int a[n + 1];
FOR(i, 1, n + 1) cin >> a[i];
vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0));
vector<vector<ll>> sum(n + 1, vector<ll>(k + 2, 0));
dp[0][0] = 1;
sum[0][0] = 1;
FOR(i, 1, n + 1) {
sum[i - 1][0] = 0;
REP(j, k + 1) sum[i - 1][j + 1] = (dp[i - 1][j] + sum[i - 1][j]) % mod;
REP(j, k + 1) {
int l = max(0, j - a[i]), r = j + 1;
dp[i][j] = (sum[i - 1][r] - sum[i - 1][l] + mod) % mod;
}
}
cout << dp[n][k] << endl;
return 0;
}
| [
"variable_declaration.name.change",
"identifier.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"assignment.change"
] | 981,911 | 981,909 | u772304668 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;
// macros
#define rep(i, a, b) for (int i = a; i < b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for (auto it = (c).begin(); it != c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout << (#x) << " is " << (x) << "\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first << 32 | (p).second)
// template functions
template <typename T> inline void printV(vector<T> &a) {
rep(i, 0, sz(a)) { cout << a[i] << " "; }
cout << "\n";
}
template <typename T> inline void printV(vector<T> &a, int n) {
rep(i, 0, n) { cout << a[i] << " "; }
cout << "\n";
}
template <typename T> inline void printVV(vector<vector<T>> &a) {
rep(i, 0, sz(a)) { printV(a[i]); }
cout << "\n";
}
template <typename T> inline void clearVV(vector<vector<T>> &a) {
for (auto &x : a) {
x.clear();
}
a.clear();
}
template <typename T> inline void assignVV(vector<vector<T>> &a, T val) {
for (int i = 0; i < sz(a); i++) {
for (int j = 0; j < sz(a[i]); j++) {
a[i][j] = val;
}
}
}
// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9 + 7;
const int MAX = 1e5;
inline int add(int a, int b) { return ((ll)a + b) % modn; }
inline int mul(int a, int b) { return ((ll)a * b) % modn; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// Your code here
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
vector<vector<int>> psum(n + 1, vector<int>(k + 1));
vector<vector<int>> dp(n + 1, vector<int>(k + 1));
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 0; j <= k; j++) {
dp[1][j] = (j <= a[1] ? 1 : 0);
if (j > 0)
psum[1][j] = add(psum[1][j - 1], dp[1][j]);
else
psum[1][j] = dp[1][j];
}
//~ printV(psum[1]);
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j > a[i]) {
dp[i][j] = psum[i - 1][j] - psum[i - 1][j - a[i] - 1];
psum[i][j] = add(psum[i][j - 1], dp[i][j]);
continue;
}
dp[i][j] = psum[i - 1][j];
if (j > 0)
psum[i][j] = add(psum[i][j - 1], dp[i][j]);
else
psum[i][j] = dp[i][j];
}
}
cout << dp[n][k] << "\n";
//~ printV(dp[n]);
//~ printVV(dp);
//~ printVV(psum);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;
// macros
#define rep(i, a, b) for (int i = a; i < b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for (auto it = (c).begin(); it != c.end(); it++)
#define pb push_back
#define mp make_pair
#define bitcount __builtin_popcount
#define ispresent(c, x) ((c).find(x) != (c).end())
#define watch(x) cout << (#x) << " is " << (x) << "\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first << 32 | (p).second)
// template functions
template <typename T> inline void printV(vector<T> &a) {
rep(i, 0, sz(a)) { cout << a[i] << " "; }
cout << "\n";
}
template <typename T> inline void printV(vector<T> &a, int n) {
rep(i, 0, n) { cout << a[i] << " "; }
cout << "\n";
}
template <typename T> inline void printVV(vector<vector<T>> &a) {
rep(i, 0, sz(a)) { printV(a[i]); }
cout << "\n";
}
template <typename T> inline void clearVV(vector<vector<T>> &a) {
for (auto &x : a) {
x.clear();
}
a.clear();
}
template <typename T> inline void assignVV(vector<vector<T>> &a, T val) {
for (int i = 0; i < sz(a); i++) {
for (int j = 0; j < sz(a[i]); j++) {
a[i][j] = val;
}
}
}
// constants
const long double eps = 1e-9;
const int inf = 5e8;
const int modn = 1e9 + 7;
const int MAX = 1e5;
inline int add(int a, int b) { return ((ll)a + b + modn) % modn; }
inline int mul(int a, int b) { return ((ll)a * b) % modn; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// Your code here
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
vector<vector<int>> psum(n + 1, vector<int>(k + 1));
vector<vector<int>> dp(n + 1, vector<int>(k + 1));
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 0; j <= k; j++) {
dp[1][j] = (j <= a[1] ? 1 : 0);
if (j > 0)
psum[1][j] = add(psum[1][j - 1], dp[1][j]);
else
psum[1][j] = dp[1][j];
}
//~ printV(psum[1]);
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (j > a[i]) {
dp[i][j] = add(psum[i - 1][j], -psum[i - 1][j - a[i] - 1]);
psum[i][j] = add(psum[i][j - 1], dp[i][j]);
continue;
}
dp[i][j] = psum[i - 1][j];
if (j > 0)
psum[i][j] = add(psum[i][j - 1], dp[i][j]);
else
psum[i][j] = dp[i][j];
}
}
cout << dp[n][k] << "\n";
//~ printV(dp[n]);
//~ printVV(dp);
//~ printVV(psum);
return 0;
}
| [
"expression.operation.binary.add",
"call.add",
"call.arguments.change"
] | 981,921 | 981,922 | u493148162 | cpp |
p03172 | #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 105, MAX_K = 1e5 + 5, MOD = 1e9 + 7;
long long no_of_ways[MAX_N][MAX_K], sum_no_of_ways[MAX_N][MAX_K];
int main() {
int no_of_people, no_of_candies;
cin >> no_of_people >> no_of_candies;
vector<int> limit(no_of_people + 1);
for (int i = 1; i <= no_of_people; i++)
cin >> limit[i];
// f(i, j) = f(i - 1, j) + f(i - 1, j - 1) + f(i - 1, j - 2) + f(i - 1, j - 3)
// + ... + f(i - 1, j - a_i);
no_of_ways[0][0] = 1;
for (int i = 1; i <= no_of_candies; i++)
no_of_ways[0][i] = 0;
for (int i = 1; i <= no_of_people; i++) {
sum_no_of_ways[i - 1][0] = no_of_ways[i - 1][0];
for (int j = 1; j <= no_of_candies; j++) {
sum_no_of_ways[i][j] =
(sum_no_of_ways[i - 1][j - 1] + no_of_ways[i - 1][j]) % MOD;
}
for (int j = 0; j <= no_of_candies; j++) {
int left = j, right = (j - limit[i] - 1);
no_of_ways[i][j] = sum_no_of_ways[i - 1][left];
if (right >= 0) {
no_of_ways[i][j] =
(no_of_ways[i][j] - sum_no_of_ways[i - 1][right] + MOD) % MOD;
}
}
}
cout << no_of_ways[no_of_people][no_of_candies];
return 0;
}
| #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 105, MAX_K = 1e5 + 5, MOD = 1e9 + 7;
long long no_of_ways[MAX_N][MAX_K], sum_no_of_ways[MAX_N][MAX_K];
int main() {
int no_of_people, no_of_candies;
cin >> no_of_people >> no_of_candies;
vector<int> limit(no_of_people + 1);
for (int i = 1; i <= no_of_people; i++)
cin >> limit[i];
// f(i, j) = f(i - 1, j) + f(i - 1, j - 1) + f(i - 1, j - 2) + f(i - 1, j - 3)
// + ... + f(i - 1, j - a_i);
no_of_ways[0][0] = 1;
for (int i = 1; i <= no_of_candies; i++)
no_of_ways[0][i] = 0;
for (int i = 1; i <= no_of_people; i++) {
sum_no_of_ways[i - 1][0] = no_of_ways[i - 1][0];
for (int j = 1; j <= no_of_candies; j++) {
sum_no_of_ways[i - 1][j] =
(sum_no_of_ways[i - 1][j - 1] + no_of_ways[i - 1][j]) % MOD;
}
for (int j = 0; j <= no_of_candies; j++) {
int left = j, right = (j - limit[i] - 1);
no_of_ways[i][j] = sum_no_of_ways[i - 1][left];
if (right >= 0) {
no_of_ways[i][j] =
(no_of_ways[i][j] - sum_no_of_ways[i - 1][right] + MOD) % MOD;
}
}
}
cout << no_of_ways[no_of_people][no_of_candies];
return 0;
}
| [
"assignment.change"
] | 981,923 | 981,924 | u927253988 | cpp |
p03172 | #include <iostream>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
vector<int> dp(K + 1, 0);
dp[0] = 1;
for (int i = 0; i < N; ++i) {
vector<int> dp_(K + 1, 0);
int s = 0;
for (int j = 0; j <= K; ++j) {
s += dp[j], s %= mod;
if (j > A[i])
s -= mod - dp[j - A[i] - 1], s %= mod;
dp_[j] += s, dp_[j] %= mod;
}
dp = dp_;
}
cout << dp[K] << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
const int mod = 1e9 + 7;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; ++i)
cin >> A[i];
vector<int> dp(K + 1, 0);
dp[0] = 1;
for (int i = 0; i < N; ++i) {
vector<int> dp_(K + 1, 0);
int s = 0;
for (int j = 0; j <= K; ++j) {
s += dp[j], s %= mod;
if (j > A[i])
s += mod - dp[j - A[i] - 1], s %= mod;
dp_[j] += s, dp_[j] %= mod;
}
dp = dp_;
}
cout << dp[K] << endl;
}
| [
"expression.operator.change"
] | 981,927 | 981,928 | u107077660 | cpp |
p03172 | #include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long int dp[n][k + 1];
long long int sum[n][k + 1];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k; j++) {
dp[i][j] = 0;
if (i == 0) {
if (j <= arr[0]) {
dp[i][j] = 1;
} else {
dp[i][j] = 0;
}
if (j == 0) {
sum[i][j] = dp[i][j];
} else {
sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD;
}
} else {
if (arr[i] >= j) {
dp[i][j] = sum[i - 1][j] % MOD;
} else {
dp[i][j] = (sum[i - 1][j] - sum[i - 1][j - arr[i] - 1]) % MOD;
}
if (j == 0) {
sum[i][j] = dp[i][j] % MOD;
} else {
sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD;
}
}
// cout << dp[i][j] << " " << sum[i][j] << " ";
}
// cout << "\n";
}
cout << dp[n - 1][k] % MOD << "\n";
return 0;
} | #include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long int dp[n][k + 1];
long long int sum[n][k + 1];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k; j++) {
dp[i][j] = 0;
if (i == 0) {
if (j <= arr[0]) {
dp[i][j] = 1;
} else {
dp[i][j] = 0;
}
if (j == 0) {
sum[i][j] = dp[i][j];
} else {
sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD;
}
} else {
if (arr[i] >= j) {
dp[i][j] = sum[i - 1][j] % MOD;
} else {
dp[i][j] =
((sum[i - 1][j] - sum[i - 1][j - arr[i] - 1]) % MOD + MOD) % MOD;
}
if (j == 0) {
sum[i][j] = dp[i][j] % MOD;
} else {
sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD;
}
}
// cout << dp[i][j] << " " << sum[i][j] << " ";
}
// cout << "\n";
}
cout << dp[n - 1][k] % MOD << "\n";
return 0;
} | [
"assignment.change"
] | 981,937 | 981,938 | u806543889 | cpp |
p03172 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
#define MAXN 100
#define MAXK 100000
const ll p = 1000000007;
int main() {
ll n, k;
cin >> n >> k;
ll dp[n + 1][k + 1];
ll a[n];
REP(i, n) cin >> a[i];
REP(j, k + 1) {
if (j == 0)
dp[0][j] = 1;
else
dp[0][j] = 0;
}
REP(i, n) {
ll sum = 0;
REP(j, k + 1) {
if (j < a[i] + 1)
sum += dp[i][j];
else
sum += dp[i][j] - dp[i][j - a[i] - 1];
sum %= p;
dp[i + 1][j] = sum;
}
}
cout << dp[n][k] << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
#define MAXN 100
#define MAXK 100000
const ll p = 1000000007;
int main() {
ll n, k;
cin >> n >> k;
ll dp[n + 1][k + 1];
ll a[n];
REP(i, n) cin >> a[i];
REP(j, k + 1) {
if (j == 0)
dp[0][j] = 1;
else
dp[0][j] = 0;
}
REP(i, n) {
ll sum = 0;
REP(j, k + 1) {
if (j < a[i] + 1)
sum += dp[i][j];
else
sum += dp[i][j] - dp[i][j - a[i] - 1] + p;
sum %= p;
dp[i + 1][j] = sum;
}
}
cout << dp[n][k] << endl;
return 0;
}
| [
"assignment.change"
] | 981,939 | 981,940 | u780950519 | cpp |
p03172 | #include <iostream>
#include <vector>
using namespace std;
static const int kModulo = 1000 * 1000 * 1000 + 7;
int main() {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int> ways(K + 1, 0);
ways[0] = 1;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
vector<int> partial(N + 1);
for (int j = 0; j <= K; ++j) {
partial[j] = ways[j];
if (j > 0)
partial[j] = (partial[j] + partial[j - 1]) % kModulo;
}
for (int j = 0; j <= K; ++j) {
ways[j] = partial[j];
if (j > a)
ways[j] = (ways[j] + kModulo - partial[j - a - 1]) % kModulo;
}
}
cout << ways[K] << "\n";
}
| #include <iostream>
#include <vector>
using namespace std;
static const int kModulo = 1000 * 1000 * 1000 + 7;
int main() {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int> ways(K + 1, 0);
ways[0] = 1;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
vector<int> partial(K + 1);
for (int j = 0; j <= K; ++j) {
partial[j] = ways[j];
if (j > 0)
partial[j] = (partial[j] + partial[j - 1]) % kModulo;
}
for (int j = 0; j <= K; ++j) {
ways[j] = partial[j];
if (j > a)
ways[j] = (ways[j] + kModulo - partial[j - a - 1]) % kModulo;
}
}
cout << ways[K] << "\n";
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 981,950 | 981,951 | u577270802 | cpp |
p03172 | #include <iostream>
#include <vector>
using namespace std;
static const int kModulo = 1000 * 1000 * 1000 + 7;
int main() {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int> ways(K + 1, 0);
ways[0] = 1;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
vector<int> partial(N);
for (int j = 0; j <= K; ++j) {
partial[j] = ways[j];
if (j > 0)
partial[j] = (partial[j] + partial[j - 1]) % kModulo;
}
for (int j = 0; j <= K; ++j) {
ways[j] = partial[j];
if (j > a)
ways[j] = (ways[j] + kModulo - partial[j - a - 1]) % kModulo;
}
}
cout << ways[K] << "\n";
}
| #include <iostream>
#include <vector>
using namespace std;
static const int kModulo = 1000 * 1000 * 1000 + 7;
int main() {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int> ways(K + 1, 0);
ways[0] = 1;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
vector<int> partial(K + 1);
for (int j = 0; j <= K; ++j) {
partial[j] = ways[j];
if (j > 0)
partial[j] = (partial[j] + partial[j - 1]) % kModulo;
}
for (int j = 0; j <= K; ++j) {
ways[j] = partial[j];
if (j > a)
ways[j] = (ways[j] + kModulo - partial[j - a - 1]) % kModulo;
}
}
cout << ways[K] << "\n";
}
| [
"assignment.change"
] | 981,952 | 981,951 | u577270802 | cpp |
p03172 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> v(n);
for (int i = 0; i < n; ++i)
scanf("%d", &v[i]);
const int M = 1000000007;
vector<vector<unsigned int>> dp(n + 1, vector<unsigned int>(k + 1));
fill(dp[n].begin(), dp[n].end(), 1);
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j <= k; ++j) {
int l = max(0, j - v[i]);
int r = j;
dp[i][j] = dp[i + 1][r];
if (l) {
dp[i][j] += M - dp[i + 1][l - 1] + M;
if (dp[i][j] >= M)
dp[i][j] -= M;
}
if (j) {
dp[i][j] += dp[i][j - 1] + M;
if (dp[i][j] >= M)
dp[i][j] -= M;
}
}
}
printf("%d\n", (dp[0][k] + M - (k ? dp[0][k - 1] : 0)) % M);
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> v(n);
for (int i = 0; i < n; ++i)
scanf("%d", &v[i]);
const int M = 1000000007;
vector<vector<unsigned int>> dp(n + 1, vector<unsigned int>(k + 1));
fill(dp[n].begin(), dp[n].end(), 1);
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j <= k; ++j) {
int l = max(0, j - v[i]);
int r = j;
dp[i][j] = dp[i + 1][r];
if (l) {
dp[i][j] += M - dp[i + 1][l - 1] + M;
if (dp[i][j] >= M)
dp[i][j] %= M;
}
if (j) {
dp[i][j] += dp[i][j - 1] + M;
if (dp[i][j] >= M)
dp[i][j] %= M;
}
}
}
printf("%d\n", (int)(dp[0][k] + M - (k ? dp[0][k - 1] : 0)) % M);
return 0;
} | [
"expression.operator.change"
] | 981,961 | 981,962 | u977184814 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define _ << '\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS \
ios_base::sync_with_stdio(false); \
cout.tie(0); \
cin.tie(0);
int main() {
IOS 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));
for (int i = 0; i <= n; ++i) {
dp[i][0] = 1;
}
for (int i = 1; i <= k; ++i) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) % MOD -
((j > a[i]) ? dp[i - 1][j - a[i] - 1] : 0) % MOD) %
MOD;
}
}
cout << dp[n][k];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define _ << '\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS \
ios_base::sync_with_stdio(false); \
cout.tie(0); \
cin.tie(0);
int main() {
IOS 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));
for (int i = 0; i <= n; ++i) {
dp[i][0] = 1;
}
for (int i = 1; i <= k; ++i) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) -
((j > a[i]) ? dp[i - 1][j - a[i] - 1] : 0) + MOD) %
MOD;
}
}
cout << dp[n][k];
return 0;
} | [
"expression.operation.binary.remove",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 981,970 | 981,971 | u559507546 | cpp |
p03172 | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> v(n);
for (int i = 0; i < n; ++i)
scanf("%d", &v[i]);
const int M = 1000000007;
vector<vector<int>> dp(n + 1, vector<int>(k + 1));
fill(dp[n].begin(), dp[n].end(), 1);
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j <= k; ++j) {
int l = max(0, j - v[i]);
int r = j;
dp[i][j] = dp[i + 1][r];
if (l) {
dp[i][j] += M - dp[i + 1][l - 1];
if (dp[i][j] >= M)
dp[i][j] -= M;
}
if (j) {
dp[i][j] += dp[i][j - 1];
if (dp[i][j] >= M)
dp[i][j] -= M;
}
}
}
printf("%d\n", dp[0][k] - (k ? dp[0][k - 1] : 0));
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> v(n);
for (int i = 0; i < n; ++i)
scanf("%d", &v[i]);
const int M = 1000000007;
vector<vector<int>> dp(n + 1, vector<int>(k + 1));
fill(dp[n].begin(), dp[n].end(), 1);
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j <= k; ++j) {
int l = max(0, j - v[i]);
int r = j;
dp[i][j] = dp[i + 1][r];
if (l) {
dp[i][j] += M - dp[i + 1][l - 1];
if (dp[i][j] >= M)
dp[i][j] -= M;
}
if (j) {
dp[i][j] += dp[i][j - 1];
if (dp[i][j] >= M)
dp[i][j] -= M;
}
}
}
printf("%d\n", (dp[0][k] - (k ? dp[0][k - 1] : 0) + M) % M);
return 0;
} | [
"call.arguments.change"
] | 981,977 | 981,978 | u423166489 | cpp |
p03172 | #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
int N, K, a;
cin >> N >> K;
vector<int> dp(K + 1);
dp[0] = 1;
for (int i = 0; i < N; i++) {
cin >> a;
vector<int> nx = dp;
for (int j = 1; j <= K; j++) {
if (j > a) {
(nx[j] += nx[j - 1] - dp[j - a - 1] + MOD) %= MOD;
} else {
(nx[j] += nx[j - 1]) %= MOD;
}
}
dp = nx;
}
cout << dp[K] << endl;
}
int main() {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
int N, K, a;
cin >> N >> K;
vector<long> dp(K + 1);
dp[0] = 1;
for (int i = 0; i < N; i++) {
cin >> a;
vector<long> nx = dp;
for (int j = 1; j <= K; j++) {
if (j > a) {
(nx[j] += nx[j - 1] - dp[j - a - 1] + MOD) %= MOD;
} else {
(nx[j] += nx[j - 1]) %= MOD;
}
}
dp = nx;
}
cout << dp[K] << endl;
}
int main() {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change"
] | 981,979 | 981,980 | u344412812 | cpp |
p03172 | #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
int N, K, a;
cin >> N >> K;
vector<int> dp(K + 1);
dp[0] = 1;
for (int i = 0; i < N; i++) {
cin >> a;
vector<int> nx = dp;
for (int j = 1; j <= K; j++) {
if (j > a) {
(nx[j] += nx[j - 1] - dp[j - a - 1]) %= MOD;
} else {
(nx[j] += nx[j - 1]) %= MOD;
}
}
dp = nx;
}
cout << dp[K] << endl;
}
int main() {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
void solve() {
int N, K, a;
cin >> N >> K;
vector<long> dp(K + 1);
dp[0] = 1;
for (int i = 0; i < N; i++) {
cin >> a;
vector<long> nx = dp;
for (int j = 1; j <= K; j++) {
if (j > a) {
(nx[j] += nx[j - 1] - dp[j - a - 1] + MOD) %= MOD;
} else {
(nx[j] += nx[j - 1]) %= MOD;
}
}
dp = nx;
}
cout << dp[K] << endl;
}
int main() {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"assignment.change"
] | 981,981 | 981,980 | u344412812 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
#define ld double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi>
#define str string
#define vs vector<str>
#define vb vector<bool>
#define mii map<int, int>
#define mp make_pair
#define mod 1000000007
#define pii pair<int, int>
#define vpii vector<pii>
#define pb push_back
#define loop(i, s, l, j) for (int i = s; i < l; i += j)
#define rloop(i, s, l, j) for (int i = s; i >= l; i -= j)
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define limit 100005
#define ft first
#define sd second
#define maxval 8.0
#define pi 3.14159265358979323846
int dx[4] = {0, 0, -1, 1}; // u d l r
int dy[4] = {1, -1, 0, 0};
/****************************************************************************/
int main() {
int n, K;
cin >> n >> K;
int a[n + 1];
for (int i = 1; i < n + 1; i++)
cin >> a[i];
int dp[n + 1][K + 1] = {};
for (int j = 0; j < K + 1; j++)
dp[0][j] = 1;
/*
dp[0][0] = 1;
for(int i = 1; i < n+1; i++)
for(int j = 0; j < K+1; j++)
for(int k = 0; k < min(a[i], j)+1; k++)
dp[i][j] += dp[i-1][j-k];
*/
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < K + 1; j++) {
int k = j - min(a[i], j);
dp[i][j] = (dp[i - 1][j] + mod - (k == 0 ? 0 : dp[i - 1][k - 1])) % mod;
}
for (int j = 1; j < K + 1; j++)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
cout << (dp[n][K] - (K == 0 ? 0 : dp[n][K - 1])) << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define ld double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi>
#define str string
#define vs vector<str>
#define vb vector<bool>
#define mii map<int, int>
#define mp make_pair
#define mod 1000000007
#define pii pair<int, int>
#define vpii vector<pii>
#define pb push_back
#define loop(i, s, l, j) for (int i = s; i < l; i += j)
#define rloop(i, s, l, j) for (int i = s; i >= l; i -= j)
#define fastio() \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define limit 100005
#define ft first
#define sd second
#define maxval 8.0
#define pi 3.14159265358979323846
int dx[4] = {0, 0, -1, 1}; // u d l r
int dy[4] = {1, -1, 0, 0};
/****************************************************************************/
int main() {
int n, K;
cin >> n >> K;
int a[n + 1];
for (int i = 1; i < n + 1; i++)
cin >> a[i];
int dp[n + 1][K + 1] = {};
for (int j = 0; j < K + 1; j++)
dp[0][j] = 1;
/*
dp[0][0] = 1;
for(int i = 1; i < n+1; i++)
for(int j = 0; j < K+1; j++)
for(int k = 0; k < min(a[i], j)+1; k++)
dp[i][j] += dp[i-1][j-k];
*/
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < K + 1; j++) {
int k = j - min(a[i], j);
dp[i][j] = (dp[i - 1][j] + mod - (k == 0 ? 0 : dp[i - 1][k - 1])) % mod;
}
for (int j = 1; j < K + 1; j++)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
cout << (dp[n][K] + mod - (K == 0 ? 0 : dp[n][K - 1])) % mod << '\n';
} | [
"expression.operation.binary.add"
] | 981,990 | 981,991 | u908296547 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
int main() {
lli n, k;
cin >> n >> k;
lli i, j, l;
lli a[n + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
lli dp[n + 1][k + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= k; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
lli x[k + 1] = {0};
for (i = 1; i <= n; i++) {
for (j = 0; j <= k; j++) {
if (j == 0)
x[j] = dp[i - 1][j];
else
x[j] = x[j - 1] + dp[i - 1][j];
x[j] %= mod;
}
/*for(j=0;j<=k;j++){
for(l=0;l<=a[i] && j-l>=0;l++){
dp[i][j]+=dp[i-1][j-l];
}
}*/
for (j = 0; j <= k; j++) {
if (j > a[i])
dp[i][j] = dp[i][j] + (x[j] - x[j - a[i] - 1]) % mod;
else
dp[i][j] = dp[i][j] + x[j];
dp[i][j] %= mod;
}
}
cout << dp[n][k] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
int main() {
lli n, k;
cin >> n >> k;
lli i, j, l;
lli a[n + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
lli dp[n + 1][k + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= k; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
lli x[k + 1] = {0};
for (i = 1; i <= n; i++) {
for (j = 0; j <= k; j++) {
if (j == 0)
x[j] = dp[i - 1][j];
else
x[j] = x[j - 1] + dp[i - 1][j];
x[j] %= mod;
}
/*for(j=0;j<=k;j++){
for(l=0;l<=a[i] && j-l>=0;l++){
dp[i][j]+=dp[i-1][j-l];
}
}*/
for (j = 0; j <= k; j++) {
if (j > a[i])
dp[i][j] = dp[i][j] + (x[j] - x[j - a[i] - 1] + mod) % mod;
else
dp[i][j] = dp[i][j] + x[j];
dp[i][j] %= mod;
}
}
cout << dp[n][k] << endl;
return 0;
} | [
"assignment.change"
] | 981,992 | 981,993 | u533093031 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
int main() {
int n, k;
cin >> n >> k;
int i, j, l;
int a[n + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 1][k + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= k; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
lli x[k + 1] = {0};
for (i = 1; i <= n; i++) {
for (j = 0; j <= k; j++) {
if (j == 0)
x[j] = dp[i - 1][j];
else
x[j] = x[j - 1] + dp[i - 1][j];
x[j] %= mod;
}
/*for(j=0;j<=k;j++){
for(l=0;l<=a[i] && j-l>=0;l++){
dp[i][j]+=dp[i-1][j-l];
}
}*/
for (j = 0; j <= k; j++) {
if (j > a[i])
dp[i][j] = dp[i][j] + (x[j] - x[j - a[i] - 1]) % mod;
else
dp[i][j] = dp[i][j] + x[j];
dp[i][j] %= mod;
}
}
cout << dp[n][k] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
int main() {
lli n, k;
cin >> n >> k;
lli i, j, l;
lli a[n + 1];
for (i = 1; i <= n; i++)
cin >> a[i];
lli dp[n + 1][k + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= k; j++) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
lli x[k + 1] = {0};
for (i = 1; i <= n; i++) {
for (j = 0; j <= k; j++) {
if (j == 0)
x[j] = dp[i - 1][j];
else
x[j] = x[j - 1] + dp[i - 1][j];
x[j] %= mod;
}
/*for(j=0;j<=k;j++){
for(l=0;l<=a[i] && j-l>=0;l++){
dp[i][j]+=dp[i-1][j-l];
}
}*/
for (j = 0; j <= k; j++) {
if (j > a[i])
dp[i][j] = dp[i][j] + (x[j] - x[j - a[i] - 1] + mod) % mod;
else
dp[i][j] = dp[i][j] + x[j];
dp[i][j] %= mod;
}
}
cout << dp[n][k] << endl;
return 0;
} | [
"variable_declaration.type.change",
"assignment.change"
] | 981,994 | 981,993 | u533093031 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k] % MOD) % MOD << endl;
return 0;
}
| #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] = (MOD + sum[(i + 1) % 2][j] -
sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k]) % MOD << endl;
return 0;
}
| [
"assignment.change",
"expression.operation.binary.remove"
] | 982,007 | 982,008 | u905715926 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << dp[n % 2][k] % MOD /*+MOD)%MOD*/ << endl;
return 0;
}
| #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] = (MOD + sum[(i + 1) % 2][j] -
sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k]) % MOD << endl;
return 0;
}
| [
"assignment.change"
] | 982,009 | 982,008 | u905715926 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << dp[n % 2][k] % MOD << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] = (MOD + sum[(i + 1) % 2][j] -
sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k]) % MOD << endl;
return 0;
}
| [
"assignment.change"
] | 982,010 | 982,008 | u905715926 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k] % MOD) % MOD << endl;
return 0;
}
| #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k] + MOD) % MOD << endl;
return 0;
} | [
"expression.operator.arithmetic.change",
"io.output.change"
] | 982,007 | 982,011 | u905715926 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << dp[n % 2][k] % MOD /*+MOD)%MOD*/ << endl;
return 0;
}
| #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k] + MOD) % MOD << endl;
return 0;
} | [] | 982,009 | 982,011 | u905715926 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << dp[n % 2][k] % MOD << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k] + MOD) % MOD << endl;
return 0;
} | [] | 982,010 | 982,011 | u905715926 | cpp |
p03172 | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << dp[n % 2][k] % MOD << endl;
return 0;
} | #include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define Yes(hoge) cout << ((hoge) ? "Yes" : "No") << endl;
#define YES(hoge) cout << ((hoge) ? "YES" : "NO") << endl;
using namespace std;
struct Grid {
int x, y, t;
};
struct Edge {
int to, cost;
};
struct Graph {
vector<vector<Edge>> E;
int V;
const ll Inf = llINF;
const int MAX_V = 1010;
vector<ll> d;
Graph(int n) : E(n) {
d.resize(MAX_V);
E.resize(n);
V = n;
}
void init() {
for (int i = 0; i < MAX_V; i++)
d[i] = Inf;
}
void add_edge(int from, int to, int cost) { E[from - 1].pb({to - 1, cost}); }
};
int main() {
int n, k;
cin >> n >> k;
ll dp[2][k + 10];
ll sum[2][k + 10];
for (int i = 0; i < k + 10; i++)
sum[1][i] = sum[0][i] = dp[0][i] = dp[1][i] = 0;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
// cout<<(i+1)%2<<endl;
ll hoge;
cin >> hoge;
sum[(i + 1) % 2][0] = dp[(i + 1) % 2][0] % MOD;
for (ll j = 1; j <= k; j++) {
sum[(i + 1) % 2][j] = sum[(i + 1) % 2][j - 1] + dp[(i + 1) % 2][j];
sum[(i + 1) % 2][j] %= MOD;
// cout<<sum[(i+1)%2][j]<<" ";
}
// sum[(i+1)%2][k+1]=sum[(i+1)%2][k]%MOD;
// cout<<endl;
for (ll j = 0; j <= k; j++) {
if (j == min(j, hoge))
dp[i % 2][j] = sum[(i + 1) % 2][j] % MOD;
else
dp[i % 2][j] =
(sum[(i + 1) % 2][j] - sum[(i + 1) % 2][j - min(hoge, j) - 1]) %
MOD;
// cout<<dp[(i+1)%2][j]<<" ";
}
// cout<<endl;
}
cout << (dp[n % 2][k] % MOD + MOD) % MOD << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 982,010 | 982,012 | u905715926 | cpp |
p03172 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> dp(k + 1, 0);
vector<long long> accum(k + 2, 0);
dp[0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j <= k + 1; j++) {
accum[j] = (accum[j - 1] + dp[j - 1]) % MOD;
}
for (int j = k; j >= 0; j--) {
int lb = max(0, j - a[i]);
dp[j] = (accum[j + 1] - accum[lb]) % MOD;
}
}
cout << dp[k] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> dp(k + 1, 0);
vector<long long> accum(k + 2, 0);
dp[0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 1; j <= k + 1; j++) {
accum[j] = (accum[j - 1] + dp[j - 1]) % MOD;
}
for (int j = k; j >= 0; j--) {
int lb = max(0, j - a[i]);
dp[j] = (accum[j + 1] - accum[lb] + MOD) % MOD;
}
}
cout << dp[k] << endl;
return 0;
} | [
"assignment.change"
] | 982,033 | 982,034 | u120810144 | cpp |
p03172 | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T> void printv(const vector<T> &v) {
int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << v[i] << " \n"[i == sz - 1];
}
}
// add(pos, n): data[pos] += n;
// sum(l, r) : sum [l, r)
template <typename T> class FenwickTree {
const int n;
vector<T> data;
public:
FenwickTree(int count) : n(count), data(count, 0) { ; }
void add(int pos, const T &value) {
assert(0 <= pos && pos < n);
for (int i = pos; i < n; i |= i + 1) {
data[i] += value;
data[i] %= MOD;
}
}
T sum(int pos) const {
assert(0 <= pos && pos <= n);
T res = 0;
for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) {
res += data[i];
res %= MOD;
}
return res;
}
T sum(int l, int r) const {
assert(0 <= l);
assert(l <= r);
assert(r <= n);
return (sum(r) + (-sum(l))) % MOD;
}
using value_type = T;
using update_type = T;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<FenwickTree<ll>> dp(N + 1, FenwickTree<ll>(K + 10));
dp[0].add(0, 1);
for (int i = 1; i <= N; i++) {
int a;
cin >> a;
for (int j = 0; j <= K; j++) {
int mi = max(0, j - a);
dp[i].add(j, dp[i - 1].sum(mi, j + 1));
}
}
cout << dp[N].sum(K, K + 1) << endl;
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T> void printv(const vector<T> &v) {
int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << v[i] << " \n"[i == sz - 1];
}
}
// add(pos, n): data[pos] += n;
// sum(l, r) : sum [l, r)
template <typename T> class FenwickTree {
const int n;
vector<T> data;
public:
FenwickTree(int count) : n(count), data(count, 0) { ; }
void add(int pos, const T &value) {
assert(0 <= pos && pos < n);
for (int i = pos; i < n; i |= i + 1) {
data[i] += value;
data[i] %= MOD;
}
}
T sum(int pos) const {
assert(0 <= pos && pos <= n);
T res = 0;
for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) {
res += data[i];
res %= MOD;
}
return res;
}
T sum(int l, int r) const {
assert(0 <= l);
assert(l <= r);
assert(r <= n);
return (sum(r) + MOD + (-sum(l))) % MOD;
}
using value_type = T;
using update_type = T;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<FenwickTree<ll>> dp(N + 1, FenwickTree<ll>(K + 10));
dp[0].add(0, 1);
for (int i = 1; i <= N; i++) {
int a;
cin >> a;
for (int j = 0; j <= K; j++) {
int mi = max(0, j - a);
dp[i].add(j, dp[i - 1].sum(mi, j + 1));
}
}
cout << dp[N].sum(K, K + 1) << endl;
}
| [
"expression.operation.binary.add"
] | 982,035 | 982,036 | u968834127 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <int MD> struct ModInt {
typedef ModInt M;
int v;
ModInt(int _v = 0) : v(_v) {}
M &operator+=(const M &r) {
if ((v += r.v - MD) < 0)
v += MD;
return *this;
}
M &operator-=(const M &r) {
if ((v -= r.v) < 0)
v += MD;
return *this;
}
M &operator*=(const M &r) {
v = ll(v) * r.v % MD;
return *this;
}
M operator+(const M &r) const { return M(*this) += r; }
M operator-(const M &r) const { return M(*this) -= r; }
M operator*(const M &r) const { return M(*this) *= r; }
M pow(int n) const {
M x = *this, r = 1;
while (n) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return this->pow(MD - 2); }
};
typedef ModInt<1000000007> Mint;
const int MN = 123;
const int MK = 123456;
int n, k;
Mint dp[MN][MK];
Mint fac[MK], ifac[MK];
void first() {
fac[0] = 1;
for (int i = 1; i < MK; i++) {
fac[i] = fac[i - 1] * Mint(i);
}
ifac[MK - 1] = fac[MK - 1].inv();
for (int i = MK - 2; i >= 0; i--) {
ifac[i] = ifac[i + 1] * Mint(i + 1);
}
}
Mint binom(int n, int r) { return fac[n] * ifac[r] * ifac[n - r]; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
first();
cin >> n >> k;
if (k == 0) {
cout << 1 << endl;
return 0;
}
dp[0][k] = 1;
for (int ph = 0; ph < n; ph++) {
int a;
cin >> a;
for (int j = 0; j <= k; j++) {
dp[ph + 1][j] += dp[ph][j];
if (j >= a) {
dp[ph + 1][j - a] -= dp[ph][j];
}
}
}
Mint sm = 0;
for (int i = 0; i <= k; i++) {
sm += binom(i - 1 + n, n - 1) * dp[n][i];
}
cout << sm.v << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <int MD> struct ModInt {
typedef ModInt M;
int v;
ModInt(int _v = 0) : v(_v) {}
M &operator+=(const M &r) {
if ((v += r.v - MD) < 0)
v += MD;
return *this;
}
M &operator-=(const M &r) {
if ((v -= r.v) < 0)
v += MD;
return *this;
}
M &operator*=(const M &r) {
v = ll(v) * r.v % MD;
return *this;
}
M operator+(const M &r) const { return M(*this) += r; }
M operator-(const M &r) const { return M(*this) -= r; }
M operator*(const M &r) const { return M(*this) *= r; }
M pow(int n) const {
M x = *this, r = 1;
while (n) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return this->pow(MD - 2); }
};
typedef ModInt<1000000007> Mint;
const int MN = 123;
const int MK = 123456;
int n, k;
Mint dp[MN][MK];
Mint fac[MK], ifac[MK];
void first() {
fac[0] = 1;
for (int i = 1; i < MK; i++) {
fac[i] = fac[i - 1] * Mint(i);
}
ifac[MK - 1] = fac[MK - 1].inv();
for (int i = MK - 2; i >= 0; i--) {
ifac[i] = ifac[i + 1] * Mint(i + 1);
}
}
Mint binom(int n, int r) { return fac[n] * ifac[r] * ifac[n - r]; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
first();
cin >> n >> k;
if (k == 0) {
cout << 1 << endl;
return 0;
}
dp[0][k] = 1;
for (int ph = 0; ph < n; ph++) {
int a;
cin >> a;
for (int j = 0; j <= k; j++) {
dp[ph + 1][j] += dp[ph][j];
if (j >= a + 1) {
dp[ph + 1][j - a - 1] -= dp[ph][j];
}
}
}
Mint sm = 0;
for (int i = 0; i <= k; i++) {
sm += binom(i - 1 + n, n - 1) * dp[n][i];
}
cout << sm.v << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"assignment.change"
] | 982,041 | 982,042 | u242534780 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <int MD> struct ModInt {
typedef ModInt M;
int v;
ModInt(int _v = 0) : v(_v) {}
M &operator+=(const M &r) {
if ((v += r.v - MD) < 0)
v += MD;
return *this;
}
M &operator-=(const M &r) {
if ((v -= r.v) < 0)
v += MD;
return *this;
}
M &operator*=(const M &r) {
v = ll(v) * r.v % MD;
return *this;
}
M operator+(const M &r) const { return M(*this) += r; }
M operator-(const M &r) const { return M(*this) -= r; }
M operator*(const M &r) const { return M(*this) *= r; }
M pow(int n) const {
M x = *this, r = 1;
while (n) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return this->pow(MD - 2); }
};
typedef ModInt<1000000007> Mint;
const int MN = 123;
const int MK = 123456;
int n, k;
Mint dp[MN][MK];
Mint fac[MK], ifac[MK];
void first() {
fac[0] = 1;
for (int i = 1; i < MK; i++) {
fac[i] = fac[i - 1] * Mint(i);
}
ifac[MK - 1] = fac[MK - 1].inv();
for (int i = MK - 2; i >= 0; i--) {
ifac[i] = ifac[i + 1] * Mint(i + 1);
}
}
Mint binom(int n, int r) { return fac[n] * ifac[r] * ifac[n - r]; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
first();
cin >> n >> k;
if (k == 0) {
cout << 1 << endl;
return 0;
}
dp[0][k] = 1;
for (int ph = 0; ph < n; ph++) {
int a;
cin >> a;
for (int j = 1; j <= k; j++) {
dp[ph + 1][j] += dp[ph][j];
if (j >= a) {
dp[ph + 1][j - a] -= dp[ph][j];
}
}
}
Mint sm = 0;
for (int i = 1; i <= k; i++) {
sm += binom(i - 1 + n, n - 1) * dp[n][i];
}
cout << sm.v << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <int MD> struct ModInt {
typedef ModInt M;
int v;
ModInt(int _v = 0) : v(_v) {}
M &operator+=(const M &r) {
if ((v += r.v - MD) < 0)
v += MD;
return *this;
}
M &operator-=(const M &r) {
if ((v -= r.v) < 0)
v += MD;
return *this;
}
M &operator*=(const M &r) {
v = ll(v) * r.v % MD;
return *this;
}
M operator+(const M &r) const { return M(*this) += r; }
M operator-(const M &r) const { return M(*this) -= r; }
M operator*(const M &r) const { return M(*this) *= r; }
M pow(int n) const {
M x = *this, r = 1;
while (n) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return this->pow(MD - 2); }
};
typedef ModInt<1000000007> Mint;
const int MN = 123;
const int MK = 123456;
int n, k;
Mint dp[MN][MK];
Mint fac[MK], ifac[MK];
void first() {
fac[0] = 1;
for (int i = 1; i < MK; i++) {
fac[i] = fac[i - 1] * Mint(i);
}
ifac[MK - 1] = fac[MK - 1].inv();
for (int i = MK - 2; i >= 0; i--) {
ifac[i] = ifac[i + 1] * Mint(i + 1);
}
}
Mint binom(int n, int r) { return fac[n] * ifac[r] * ifac[n - r]; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
first();
cin >> n >> k;
if (k == 0) {
cout << 1 << endl;
return 0;
}
dp[0][k] = 1;
for (int ph = 0; ph < n; ph++) {
int a;
cin >> a;
for (int j = 0; j <= k; j++) {
dp[ph + 1][j] += dp[ph][j];
if (j >= a + 1) {
dp[ph + 1][j - a - 1] -= dp[ph][j];
}
}
}
Mint sm = 0;
for (int i = 0; i <= k; i++) {
sm += binom(i - 1 + n, n - 1) * dp[n][i];
}
cout << sm.v << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"assignment.change"
] | 982,043 | 982,042 | u242534780 | cpp |
p03172 | #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int a[N];
for (int i = 0; i < N; i++)
cin >> a[i];
long long dp[N + 1][K + 1];
for (int i = 0; i <= N; i++)
for (int j = 0; j <= K; j++)
dp[i][j] = 0;
dp[0][0] = 1;
int mod = 1000000007;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= K; j++) {
dp[i + 1][j] = dp[i][j];
if (j > 0)
dp[i + 1][j] += dp[i + 1][j - 1];
if (j > a[i])
dp[i + 1][j] -= dp[i][j - a[i] - 1];
dp[i + 1][j] %= mod;
// cout << i+1 <<", "<< j << ": " << dp[i+1][j] << endl;
}
}
cout << dp[N][K] << endl;
return 0;
}
| #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
int a[N];
for (int i = 0; i < N; i++)
cin >> a[i];
long long dp[N + 1][K + 1];
for (int i = 0; i <= N; i++)
for (int j = 0; j <= K; j++)
dp[i][j] = 0;
dp[0][0] = 1;
int mod = 1000000007;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= K; j++) {
dp[i + 1][j] = dp[i][j];
if (j > 0)
dp[i + 1][j] += dp[i + 1][j - 1];
if (j > a[i])
dp[i + 1][j] += mod - dp[i][j - a[i] - 1];
dp[i + 1][j] %= mod;
// cout << i+1 <<", "<< j << ": " << dp[i+1][j] << endl;
}
}
cout << dp[N][K] << endl;
return 0;
}
| [
"expression.operator.change",
"assignment.change"
] | 982,044 | 982,045 | u783676040 | cpp |
p03172 | #include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> dp(k + 2);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
vector<int> nxt(k + 2);
for (int j = 0; j <= a[i]; ++j) {
const int l = j, r = min(j + a[i] + 1, k + 1);
(nxt[l] += dp[j]) %= mod;
(nxt[r] += mod - dp[j]) %= mod;
}
for (int j = 0; j <= k; ++j) {
(nxt[j + 1] += nxt[j]) %= mod;
}
dp = move(nxt);
}
cout << dp[k] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> dp(k + 2);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
vector<int> nxt(k + 2);
for (int j = 0; j <= k; ++j) {
const int l = j, r = min(j + a[i] + 1, k + 1);
(nxt[l] += dp[j]) %= mod;
(nxt[r] += mod - dp[j]) %= mod;
}
for (int j = 0; j <= k; ++j) {
(nxt[j + 1] += nxt[j]) %= mod;
}
dp = move(nxt);
}
cout << dp[k] << endl;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 982,054 | 982,055 | u733618878 | cpp |
p03173 | // include
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
//------------------------------------------
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<VB> VVB;
typedef vector<string> VS;
typedef vector<VL> VVL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef pair<string, string> PSS;
//------------------------------------------
// comparison
#define C_MAX(a, b) ((a) > (b) ? (a) : (b))
#define C_MIN(a, b) ((a) < (b) ? (a) : (b))
#define C_ABS(a, b) ((a) < (b) ? (b) - (a) : (a) - (b))
//------------------------------------------
// container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0ll)
#define UB(obj, n) upper_bound((obj).begin(), (obj).end(), n)
#define LB(obj, n) lower_bound((obj).begin(), (obj).end(), n)
#define BS(v, n) binary_search(ALL(v), (n))
#define PB push_back
#define MP make_pair
//------------------------------------------
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FORL(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define RFORL(i, a, b) for (ll i = ll(b) - 1; i >= ll(a); --i)
#define REPL(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREPL(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOREACH(x, v) for (auto &(x) : (v))
#define FORITER(x, v) for (auto(x) = (v).begin(); (x) != (v).end(); ++(x))
//------------------------------------------
// input output
#define GL(s) getline(cin, (s))
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define IN(...) GET_MACRO(__VA_ARGS__, IN3, IN2, IN1)(__VA_ARGS__)
#define IN1(n) std::cin >> (n);
#define IN2(n, m) std::cin >> (n) >> (m);
#define IN3(n, m, l) std::cin >> (n) >> (m) >> (l);
#define OUT(d) std::cout << (d);
#define OUT_L(d) std::cout << (d) << endl;
#define OUT_Y std::cout << "Yes" << endl;
#define OUT_N std::cout << "No" << endl;
#define FOUT(n, d) std::cout << std::fixed << std::setprecision(n) << (d);
#define EL() std::cout << "\n";
//------------------------------------------
// constant
#define MAX 200000
#define MOD 1000000007
#define INF 1 << 29
//------------------------------------------
//数値・文字列
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLongLong(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline VC toVC(string s) {
VC data(s.begin(), s.end());
return data;
}
//------------------------------------------
// extended permutation combination
// possible implementation introduced at
// http://en.cppreference.com/w/cpp/algorithm/rotate with slight modification to
// handle parted ranges
template <typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2) {
if (first1 == last1 || first2 == last2)
return;
FI next = first2;
while (first1 != next) {
std::iter_swap(first1++, next++);
if (first1 == last1)
first1 = first2;
if (next == last2) {
next = first2;
} else if (first1 == first2) {
first2 = next;
}
}
}
template <typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2) {
if (first1 == last1 || first2 == last2)
return false;
auto target = last1;
--target;
auto last_elem = last2;
--last_elem;
// find right-most incrementable element: target
while (target != first1 && !(*target < *last_elem))
--target;
if (target == first1 && !(*target < *last_elem)) {
parted_rotate(first1, last1, first2, last2);
return false;
}
// find the next value to be incremented: *next
auto next = first2;
while (!(*target < *next))
++next;
std::iter_swap(target++, next++);
parted_rotate(target, last1, next, last2);
return true;
}
// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template <typename BI> inline bool next_combination(BI first, BI mid, BI last) {
return next_combination_imp(first, mid, mid, last);
}
// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template <typename BI> inline bool prev_combination(BI first, BI mid, BI last) {
return next_combination_imp(mid, last, first, mid);
}
//------------------------------------------
// other functions
//------------------------------------------
// a^n mod を二分累乗法で計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
long long moddiv(long long a, long long b, long long mod) {
a %= mod;
return a * modinv(b, mod) % mod;
}
//任意の二項係数nCkをO(n)->O(1)で求める
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void nCkinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//最大公約数
template <class T> inline T GCD(const T x, const T y) {
if (x < 0)
return GCD(-x, y);
if (y < 0)
return GCD(x, -y);
return (!y) ? x : GCD(y, x % y);
}
//最小公倍数
template <class T> inline T LCM(const T x, const T y) {
if (x < 0)
return LCM(-x, y);
if (y < 0)
return LCM(x, -y);
return x * (y / GCD(x, y));
}
//探索系
void dfs(VVI &G, VI &O, VI &counter, int u) {
FOREACH(v, G[u]) {
if (counter[v] != -1)
continue;
counter[v] = counter[u] + O[v];
dfs(G, O, counter, v);
}
return;
}
int bfs(VVI &M) {
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int h = M.size(), w = M[0].size();
queue<PI> q;
q.push({0, 0});
while (!q.empty()) {
PI u = q.front();
q.pop();
REP(i, 4) {
PI next = {u.first + dx[i], u.second + dy[i]};
if (next.first < 0 || next.first >= h || next.second < 0 ||
next.second >= w) {
continue;
} else if (M[next.first][next.second] == 0) {
M[next.first][next.second] = M[u.first][u.second] + 1;
q.push(next);
}
}
};
return M[h - 1][w - 1];
}
//-----------------------------------------
// memo-------------------------------------
/*
//尺取り法
//二分法
vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
// index が条件を満たすかどうか
bool isOK(int index, int key) {
if (a[index] >= key) return true;
else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
int ok = (int)a.size(); // 「index =
a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
// ok と ng のどちらが大きいかわからないことを考慮
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key)) ok = mid;
else ng = mid;
}
return ok;
}
//-----------------------------------------
*/
ll rec(vector<VVL> &dp, int i, int j) {
if (dp[i][j - 1][1] != -1)
return dp[i][j - 1][1];
if (dp[i][j - 1][0] == -1) {
dp[i][j - 1][0] = 0;
FOR(k, i, j) dp[i][j - 1][0] += dp[k][k][0];
}
ll mink = MOD;
FOR(k, i + 1, j) {
mink =
min(rec(dp, i, k) + rec(dp, k, j) + dp[i][k - 1][0] + dp[k][j - 1][0],
mink);
}
return dp[i][j - 1][1] = mink;
}
// main code--------------------------------
void _main() {
int n;
IN(n)
vector<VVL> dp(n, VVL(n, VL(2, -1)));
REP(i, n) { IN(dp[i][i][0]) dp[i][i][1] = 0; }
OUT_L(rec(dp, 0, n));
return;
}
int main() {
cout << fixed << setprecision(10);
// nCkinit();
_main();
return 0;
}
| // include
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
//------------------------------------------
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<VB> VVB;
typedef vector<string> VS;
typedef vector<VL> VVL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef pair<string, string> PSS;
//------------------------------------------
// comparison
#define C_MAX(a, b) ((a) > (b) ? (a) : (b))
#define C_MIN(a, b) ((a) < (b) ? (a) : (b))
#define C_ABS(a, b) ((a) < (b) ? (b) - (a) : (a) - (b))
//------------------------------------------
// container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0ll)
#define UB(obj, n) upper_bound((obj).begin(), (obj).end(), n)
#define LB(obj, n) lower_bound((obj).begin(), (obj).end(), n)
#define BS(v, n) binary_search(ALL(v), (n))
#define PB push_back
#define MP make_pair
//------------------------------------------
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FORL(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define RFORL(i, a, b) for (ll i = ll(b) - 1; i >= ll(a); --i)
#define REPL(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREPL(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOREACH(x, v) for (auto &(x) : (v))
#define FORITER(x, v) for (auto(x) = (v).begin(); (x) != (v).end(); ++(x))
//------------------------------------------
// input output
#define GL(s) getline(cin, (s))
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define IN(...) GET_MACRO(__VA_ARGS__, IN3, IN2, IN1)(__VA_ARGS__)
#define IN1(n) std::cin >> (n);
#define IN2(n, m) std::cin >> (n) >> (m);
#define IN3(n, m, l) std::cin >> (n) >> (m) >> (l);
#define OUT(d) std::cout << (d);
#define OUT_L(d) std::cout << (d) << endl;
#define OUT_Y std::cout << "Yes" << endl;
#define OUT_N std::cout << "No" << endl;
#define FOUT(n, d) std::cout << std::fixed << std::setprecision(n) << (d);
#define EL() std::cout << "\n";
//------------------------------------------
// constant
#define MAX 200000
#define MOD 1000000007
#define INF 1 << 29
//------------------------------------------
//数値・文字列
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLongLong(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline VC toVC(string s) {
VC data(s.begin(), s.end());
return data;
}
//------------------------------------------
// extended permutation combination
// possible implementation introduced at
// http://en.cppreference.com/w/cpp/algorithm/rotate with slight modification to
// handle parted ranges
template <typename FI>
void parted_rotate(FI first1, FI last1, FI first2, FI last2) {
if (first1 == last1 || first2 == last2)
return;
FI next = first2;
while (first1 != next) {
std::iter_swap(first1++, next++);
if (first1 == last1)
first1 = first2;
if (next == last2) {
next = first2;
} else if (first1 == first2) {
first2 = next;
}
}
}
template <typename BI>
bool next_combination_imp(BI first1, BI last1, BI first2, BI last2) {
if (first1 == last1 || first2 == last2)
return false;
auto target = last1;
--target;
auto last_elem = last2;
--last_elem;
// find right-most incrementable element: target
while (target != first1 && !(*target < *last_elem))
--target;
if (target == first1 && !(*target < *last_elem)) {
parted_rotate(first1, last1, first2, last2);
return false;
}
// find the next value to be incremented: *next
auto next = first2;
while (!(*target < *next))
++next;
std::iter_swap(target++, next++);
parted_rotate(target, last1, next, last2);
return true;
}
// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template <typename BI> inline bool next_combination(BI first, BI mid, BI last) {
return next_combination_imp(first, mid, mid, last);
}
// INVARIANT: is_sorted(first, mid) && is_sorted(mid, last)
template <typename BI> inline bool prev_combination(BI first, BI mid, BI last) {
return next_combination_imp(mid, last, first, mid);
}
//------------------------------------------
// other functions
//------------------------------------------
// a^n mod を二分累乗法で計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
long long moddiv(long long a, long long b, long long mod) {
a %= mod;
return a * modinv(b, mod) % mod;
}
//任意の二項係数nCkをO(n)->O(1)で求める
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void nCkinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long nCk(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//最大公約数
template <class T> inline T GCD(const T x, const T y) {
if (x < 0)
return GCD(-x, y);
if (y < 0)
return GCD(x, -y);
return (!y) ? x : GCD(y, x % y);
}
//最小公倍数
template <class T> inline T LCM(const T x, const T y) {
if (x < 0)
return LCM(-x, y);
if (y < 0)
return LCM(x, -y);
return x * (y / GCD(x, y));
}
//探索系
void dfs(VVI &G, VI &O, VI &counter, int u) {
FOREACH(v, G[u]) {
if (counter[v] != -1)
continue;
counter[v] = counter[u] + O[v];
dfs(G, O, counter, v);
}
return;
}
int bfs(VVI &M) {
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int h = M.size(), w = M[0].size();
queue<PI> q;
q.push({0, 0});
while (!q.empty()) {
PI u = q.front();
q.pop();
REP(i, 4) {
PI next = {u.first + dx[i], u.second + dy[i]};
if (next.first < 0 || next.first >= h || next.second < 0 ||
next.second >= w) {
continue;
} else if (M[next.first][next.second] == 0) {
M[next.first][next.second] = M[u.first][u.second] + 1;
q.push(next);
}
}
};
return M[h - 1][w - 1];
}
//-----------------------------------------
// memo-------------------------------------
/*
//尺取り法
//二分法
vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
// index が条件を満たすかどうか
bool isOK(int index, int key) {
if (a[index] >= key) return true;
else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
int ok = (int)a.size(); // 「index =
a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
// ok と ng のどちらが大きいかわからないことを考慮
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isOK(mid, key)) ok = mid;
else ng = mid;
}
return ok;
}
//-----------------------------------------
*/
ll rec(vector<VVL> &dp, int i, int j) {
if (dp[i][j - 1][1] != -1)
return dp[i][j - 1][1];
if (dp[i][j - 1][0] == -1) {
dp[i][j - 1][0] = 0;
FOR(k, i, j) dp[i][j - 1][0] += dp[k][k][0];
}
ll mink = pow(10, 15);
FOR(k, i + 1, j) {
mink =
min(rec(dp, i, k) + rec(dp, k, j) + dp[i][k - 1][0] + dp[k][j - 1][0],
mink);
}
return dp[i][j - 1][1] = mink;
}
// main code--------------------------------
void _main() {
int n;
IN(n)
vector<VVL> dp(n, VVL(n, VL(2, -1)));
REP(i, n) { IN(dp[i][i][0]) dp[i][i][1] = 0; }
OUT_L(rec(dp, 0, n));
return;
}
int main() {
cout << fixed << setprecision(10);
// nCkinit();
_main();
return 0;
}
| [
"call.arguments.add"
] | 982,064 | 982,063 | u424621178 | cpp |
p03173 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define el '\n'
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()), ((v).end())
#define clr(v, d) memset(v, d, sizeof(v))
double const EPS = 1e-8, PI = acos(-1);
const int N = 405 + 9, M = 100 + 9, OO = (int)1e9 + 1;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
typedef long long ll;
void OUTPUT() {
cout << fixed << setprecision(12);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
void INPUT() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
}
int n, arr[N];
ll dp[N][N], cum[N];
int main() {
INPUT();
OUTPUT();
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
cum[i] = arr[i] + cum[i - 1] * (i != 0);
}
for (int L = n - 1; L >= 0; L--) {
for (int R = L; R < n; R++) {
if (L == R)
dp[L][R] = 0;
else {
dp[L][R] = INF;
ll s = cum[R];
if (L != 0)
s -= cum[L - 1];
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];
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define el '\n'
#define sz(v) ((int)((v).size()))
#define all(v) ((v).begin()), ((v).end())
#define clr(v, d) memset(v, d, sizeof(v))
double const EPS = 1e-8, PI = acos(-1);
const int N = 405 + 9, M = 100 + 9, OO = (int)1e9 + 1;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
typedef long long ll;
void OUTPUT() {
cout << fixed << setprecision(12);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
void INPUT() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
}
int n, arr[N];
ll dp[N][N], cum[N];
int main() {
// INPUT();
OUTPUT();
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
cum[i] = arr[i] + cum[i - 1] * (i != 0);
}
for (int L = n - 1; L >= 0; L--) {
for (int R = L; R < n; R++) {
if (L == R)
dp[L][R] = 0;
else {
dp[L][R] = INF;
ll s = cum[R];
if (L != 0)
s -= cum[L - 1];
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];
return 0;
}
| [
"call.remove"
] | 982,065 | 982,066 | u018679195 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> A(n), pre(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
pre[i] = i == 0 ? A[i] : pre[i - 1] + A[i];
}
vector<vector<long long>> dp(n, vector<long long>(n, pow(10, 18)));
for (int i = n - 1; i >= 0; i--) {
for (int j = i; j < n; j++) {
if (i == j)
dp[i][j] = 0;
else if (j == i + 1)
dp[i][j] = pre[j] - pre[i] + A[i];
else {
for (int k = i + 1; k < j; k++)
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + pre[j] - pre[i] + A[i]);
}
}
}
cout << dp[0][n - 1];
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> A(n), pre(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
pre[i] = i == 0 ? A[i] : pre[i - 1] + A[i];
}
vector<vector<long long>> dp(n, vector<long long>(n, pow(10, 18)));
for (int i = n - 1; i >= 0; i--) {
for (int j = i; j < n; j++) {
if (i == j)
dp[i][j] = 0;
else if (j == i + 1)
dp[i][j] = pre[j] - pre[i] + A[i];
else {
for (int k = i; k < j; k++)
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + pre[j] - pre[i] + A[i]);
}
}
}
cout << dp[0][n - 1];
}
| [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 982,067 | 982,068 | u155258214 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define it pair<int, pair<int, int>>
#define F first
#define S second
#define fori(p, n) for (int i = p; i < n; i++)
#define forj(q, m) for (int j = q; j < m; j++)
#define fork(r, l) for (int k = r; k < l; k++)
#define revi(h) for (int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout << "DEBUGGING --- " << x << endl;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define input_from_file freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);
vector<int> P(405);
int gets(int l, int r) {
if (l == 0)
return P[r];
return P[r] - P[l - 1];
}
signed main() {
fastio;
// input_from_file;
// output_to_file;
int n;
cin >> n;
vector<int> A(n);
fori(0, n) cin >> A[i];
P[0] = A[0];
fori(1, n) P[i] = P[i - 1] + A[i];
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
fori(0, n) dp[i][i] = 0;
fork(2, n + 1) {
fori(0, n - k + 1) {
int l = i + k - 1;
dp[i][l] = INT_MAX;
forj(i, l) dp[i][l] =
min(dp[i][l], dp[i][j] + dp[j + 1][l] + gets(i, j) + gets(j + 1, l));
}
}
// fori(0, n){
// forj(0, n) cout<<dp[i][j]<<" ";
// cout<<endl;
// }
cout << dp[0][n - 1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define ip pair<int, int>
#define it pair<int, pair<int, int>>
#define F first
#define S second
#define fori(p, n) for (int i = p; i < n; i++)
#define forj(q, m) for (int j = q; j < m; j++)
#define fork(r, l) for (int k = r; k < l; k++)
#define revi(h) for (int i = h; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define PI 3.14159265358
#define debug(x) cout << "DEBUGGING --- " << x << endl;
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define input_from_file freopen("input.txt", "r", stdin);
#define output_to_file freopen("output.txt", "w", stdout);
vector<int> P(405);
int gets(int l, int r) {
if (l == 0)
return P[r];
return P[r] - P[l - 1];
}
signed main() {
fastio;
// input_from_file;
// output_to_file;
int n;
cin >> n;
vector<int> A(n);
fori(0, n) cin >> A[i];
P[0] = A[0];
fori(1, n) P[i] = P[i - 1] + A[i];
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
fori(0, n) dp[i][i] = 0;
fork(2, n + 1) {
fori(0, n - k + 1) {
int l = i + k - 1;
dp[i][l] = LONG_LONG_MAX;
forj(i, l) dp[i][l] =
min(dp[i][l], dp[i][j] + dp[j + 1][l] + gets(i, j) + gets(j + 1, l));
}
}
// fori(0, n){
// forj(0, n) cout<<dp[i][j]<<" ";
// cout<<endl;
// }
cout << dp[0][n - 1] << endl;
} | [
"assignment.value.change",
"identifier.change"
] | 982,075 | 982,076 | u022809468 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[404][404];
ll arr[404];
ll solve(ll l, ll r) {
if (l > r)
return 0;
if (l == r)
return arr[l];
if (dp[l][r] != -1)
return dp[l][r];
// cout<<l<<' '<<r<<'\n';
ll x = arr[l] + min(solve(l + 2, r), solve(l + 1, r - 1));
ll y = arr[r] + min(solve(l, r - 2), solve(l + 1, r - 1));
dp[l][r] = max(x, y);
return dp[l][r];
}
int main() {
ll n, k;
cin >> n;
// memset(dp,-1,sizeof(dp));
ll sum = 0;
for (ll i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
// cout<<"sun "<<i<<' '<<arr[i]<<' '<<sum<<'\n';
}
auto SUM = [&](ll l, ll r) {
ll sum = 0;
for (ll z = l; z <= r; z++) {
sum += arr[z];
}
return sum;
};
// cout<<solve(0,n-1)<<' '<<sum<<'\n';
for (ll l = 0; l <= n - 1; l++) {
for (ll i = 0; i < n - l; i++) {
ll j = i + l;
if (i == j) {
dp[i][j] = 0;
} else {
// ll sum=0;
dp[i][j] = 1000000000;
for (ll k = i + 1; k <= j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k][j] + SUM(i, j)
);
// sum+=arr[k];
// cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j]<<'\n';
}
// dp[i][j]+=sum;
}
}
}
cout << dp[0][n - 1] << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[404][404];
ll arr[404];
ll solve(ll l, ll r) {
if (l > r)
return 0;
if (l == r)
return arr[l];
if (dp[l][r] != -1)
return dp[l][r];
// cout<<l<<' '<<r<<'\n';
ll x = arr[l] + min(solve(l + 2, r), solve(l + 1, r - 1));
ll y = arr[r] + min(solve(l, r - 2), solve(l + 1, r - 1));
dp[l][r] = max(x, y);
return dp[l][r];
}
int main() {
ll n, k;
cin >> n;
// memset(dp,-1,sizeof(dp));
ll sum = 0;
for (ll i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
// cout<<"sun "<<i<<' '<<arr[i]<<' '<<sum<<'\n';
}
auto SUM = [&](ll l, ll r) {
ll sum = 0;
for (ll z = l; z <= r; z++) {
sum += arr[z];
}
return sum;
};
// cout<<solve(0,n-1)<<' '<<sum<<'\n';
for (ll l = 0; l <= n - 1; l++) {
for (ll i = 0; i < n - l; i++) {
ll j = i + l;
if (i == j) {
dp[i][j] = 0;
} else {
// ll sum=0;
dp[i][j] = 10000000000000;
for (ll k = i + 1; k <= j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k][j] + SUM(i, j)
);
// sum+=arr[k];
// cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j]<<'\n';
}
// dp[i][j]+=sum;
}
}
}
cout << dp[0][n - 1] << '\n';
} | [
"literal.number.change",
"assignment.value.change"
] | 982,079 | 982,080 | u408933336 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
long long dp[401][401];
long long sum[401][401];
long long func(long long i, long long j, long long *a) {
if (i == j) {
return 0;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
dp[i][j] = INT_MAX;
for (long long x = i; x < j; x++) {
dp[i][j] = min(func(i, x, a) + func(x + 1, j, a) + sum[i][j], dp[i][j]);
}
return dp[i][j];
}
int main() {
long long n;
cin >> n;
memset(dp, -1, sizeof(dp));
long long a[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
for (long long i = 1; i <= n; i++) {
for (long long j = i; j <= n; j++) {
if (i == j) {
sum[i][j] = a[i];
continue;
}
sum[i][j] = sum[i][j - 1] + a[j];
}
}
cout << func(1, n, a) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long dp[401][401];
long long sum[401][401];
long long func(long long i, long long j, long long *a) {
if (i == j) {
return 0;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
dp[i][j] = LLONG_MAX;
for (long long x = i; x < j; x++) {
dp[i][j] = min(func(i, x, a) + func(x + 1, j, a) + sum[i][j], dp[i][j]);
}
return dp[i][j];
}
int main() {
long long n;
cin >> n;
memset(dp, -1, sizeof(dp));
long long a[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
for (long long i = 1; i <= n; i++) {
for (long long j = i; j <= n; j++) {
if (i == j) {
sum[i][j] = a[i];
continue;
}
sum[i][j] = sum[i][j - 1] + a[j];
}
}
cout << func(1, n, a) << endl;
}
| [
"assignment.value.change",
"identifier.change"
] | 982,081 | 982,082 | u633697116 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> A(N);
vector<ll> sum(N + 1, 0);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
for (int i = 0; i < N; i++)
sum[i + 1] = sum[i] + A[i];
for (int i = 0; i < N; i++)
dp[i][i] = A[i];
for (int w = 2; w < N + 1; w++) {
for (int l = 0; l < N; l++) {
int r = l + w;
if (r > N)
break;
dp[l][r] = INT_MAX;
for (int m = l + 1; m < r; m++) {
dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + sum[r] - sum[l]);
}
}
}
cout << dp[0][N] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> A(N);
vector<ll> sum(N + 1, 0);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 0));
for (int i = 0; i < N; i++)
sum[i + 1] = sum[i] + A[i];
for (int i = 0; i < N; i++)
dp[i][i] = A[i];
for (int w = 2; w < N + 1; w++) {
for (int l = 0; l < N; l++) {
int r = l + w;
if (r > N)
break;
dp[l][r] = LONG_MAX;
for (int m = l + 1; m < r; m++) {
dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + sum[r] - sum[l]);
}
}
}
cout << dp[0][N] << endl;
return 0;
} | [
"assignment.value.change",
"identifier.change"
] | 982,092 | 982,093 | u907512832 | cpp |
p03173 | #include <bits/stdc++.h>
#define loop(i, a, b) for (lli i = a; i <= b; ++i)
#define fast \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define lli long long int
#define p (lli)1e15 + 2
using namespace std;
signed main() {
fast;
lli n;
cin >> n;
lli dp[n + 1][n + 1], pre[n + 1] = {0};
dp[0][0] = 0;
pre[0] = 0;
loop(i, 1, n) {
cin >> pre[i];
pre[i] += pre[i - 1];
dp[i][i] = 0;
}
loop(i, 0, n) loop(j, 0, n) if (i != j) dp[i][j] = p;
loop(len, 1, n) for (lli i = 1; i + len - 1 <= n; i++) loop(k, i, i + len - 1)
dp[i][i + len - 1] =
min(dp[i][i + len - 1], dp[i][k] + dp[k + 1][i + len - 1] +
pre[i + len - 1] - pre[i - 1]);
cout << dp[1][n] << endl;
return 0;
} | #include <bits/stdc++.h>
#define loop(i, a, b) for (lli i = a; i <= b; ++i)
#define fast \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define lli long long int
#define p (lli)1e15 + 2
using namespace std;
signed main() {
fast;
lli n;
cin >> n;
lli dp[n + 1][n + 1], pre[n + 1] = {0};
dp[0][0] = 0;
pre[0] = 0;
loop(i, 1, n) {
cin >> pre[i];
pre[i] += pre[i - 1];
dp[i][i] = 0;
}
loop(i, 0, n) loop(j, 0, n) if (i != j) dp[i][j] = p;
loop(len, 1, n) for (lli i = 1; i + len - 1 <= n; i++) loop(k, i, i + len - 2)
dp[i][i + len - 1] =
min(dp[i][i + len - 1], dp[i][k] + dp[k + 1][i + len - 1] +
pre[i + len - 1] - pre[i - 1]);
cout << dp[1][n] << endl;
return 0;
} | [
"literal.number.change",
"assignment.variable.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 982,097 | 982,098 | u699025659 | cpp |
p03173 | // https://atcoder.jp/contests/dp/tasks/dp_n
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
void helper(const vector<long long> &slimes, vector<vector<long long>> &dp,
int l, int r) {
if (l > r)
return;
if (l == r) {
dp[l][r] = 0;
return;
}
if (dp[l][r] != numeric_limits<long long>::max())
return;
if (r - l == 1) {
dp[l][r] = slimes[l] + slimes[r];
} else {
long long sum = 0;
for (int i = 0; i <= r; i++)
sum += slimes[i];
for (int i = l; i < r; i++) {
helper(slimes, dp, l, i);
helper(slimes, dp, i + 1, r);
dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + sum);
}
}
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
vector<long long> slimes(n);
for (int i = 0; i < n; i++) {
cin >> slimes[i];
}
vector<vector<long long>> dp(
n, vector<long long>(n, numeric_limits<long long>::max()));
helper(slimes, dp, 0, n - 1);
cout << dp[0][n - 1] << endl;
}
| // https://atcoder.jp/contests/dp/tasks/dp_n
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
void helper(const vector<long long> &slimes, vector<vector<long long>> &dp,
int l, int r) {
if (l > r)
return;
if (l == r) {
dp[l][r] = 0;
return;
}
if (dp[l][r] != numeric_limits<long long>::max())
return;
if (r - l == 1) {
dp[l][r] = slimes[l] + slimes[r];
} else {
long long sum = 0;
for (int i = l; i <= r; i++)
sum += slimes[i];
for (int i = l; i < r; i++) {
helper(slimes, dp, l, i);
helper(slimes, dp, i + 1, r);
dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + sum);
}
}
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
vector<long long> slimes(n);
for (int i = 0; i < n; i++) {
cin >> slimes[i];
}
vector<vector<long long>> dp(
n, vector<long long>(n, numeric_limits<long long>::max()));
helper(slimes, dp, 0, n - 1);
cout << dp[0][n - 1] << endl;
}
| [
"variable_declaration.value.change",
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.initializer.change"
] | 982,101 | 982,102 | u184819501 | cpp |
p03173 | #include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const ll INF = 1145141919810893;
int N;
ll dp[400][400];
ll cost[400];
ll ruisekiwa[401]; // idx i ~ idx j (i < j)は [i, j)
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> cost[i];
ruisekiwa[i + 1] = cost[i] + ruisekiwa[i];
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i][j] = INF;
for (int i = 0; i < N; i++)
dp[i][i] = 0;
for (int i = 1; i < N; i++) {
for (int j = 0; j + i < N; j++) {
ll ans = INF;
if (i == 1) {
dp[j][j + i] = ruisekiwa[j + i + 1] - ruisekiwa[j];
} else {
for (int k = j + 1; k <= j + i - 1; k++) {
int ll = j, lr = k, rl = k + 1, rr = j + i;
ans = min(ans, dp[ll][lr] + dp[rl][rr]);
}
ans += ruisekiwa[j + i + 1] - ruisekiwa[j];
dp[j][j + i] = ans;
}
}
}
cout << dp[0][N - 1] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const ll INF = 1145141919810893;
int N;
ll dp[400][400];
ll cost[400];
ll ruisekiwa[401]; // idx i ~ idx j (i < j)は [i, j)
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> cost[i];
ruisekiwa[i + 1] = cost[i] + ruisekiwa[i];
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
dp[i][j] = INF;
for (int i = 0; i < N; i++)
dp[i][i] = 0;
for (int i = 1; i < N; i++) {
for (int j = 0; j + i < N; j++) {
ll ans = INF;
if (i == 1) {
dp[j][j + i] = ruisekiwa[j + i + 1] - ruisekiwa[j];
} else {
for (int k = j; k <= j + i - 1; k++) {
int ll = j, lr = k, rl = k + 1, rr = j + i;
ans = min(ans, dp[ll][lr] + dp[rl][rr]);
}
ans += ruisekiwa[j + i + 1] - ruisekiwa[j];
dp[j][j + i] = ans;
}
}
}
cout << dp[0][N - 1] << endl;
return 0;
} | [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 982,107 | 982,108 | u107077805 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
int n;
long long a[409], sum[409][409], siz[409][409], s[409];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s[i + 1] = s[i] + a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
sum[i][j] = 999999999;
}
for (int i = 0; i < n; i++) {
sum[i][i] = 0;
}
for (int ass = 1; ass <= n; ass++) {
for (int i = 00; i + ass < n; i++) {
for (int j = i; j <= i + ass; j++) {
sum[i][i + ass] =
min(s[i + ass + 1] - s[i - 1 + 1] + sum[i][j] + sum[j + 1][i + ass],
sum[i][i + ass]);
}
}
}
cout << sum[0][n - 1];
}
| #include <bits/stdc++.h>
using namespace std;
int n;
long long a[409], sum[409][409], siz[409][409], s[409];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s[i + 1] = s[i] + a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
sum[i][j] = 99999999999999999;
}
for (int i = 0; i < n; i++) {
sum[i][i] = 0;
}
for (int ass = 1; ass <= n; ass++) {
for (int i = 00; i + ass < n; i++) {
for (int j = i; j <= i + ass; j++) {
sum[i][i + ass] =
min(s[i + ass + 1] - s[i - 1 + 1] + sum[i][j] + sum[j + 1][i + ass],
sum[i][i + ass]);
}
}
}
cout << sum[0][n - 1];
}
| [
"literal.number.change",
"assignment.value.change"
] | 982,110 | 982,111 | u035652615 | cpp |
p03173 | #include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll infl = 10000000; // inflは十分大きい
// N,a[404];入力値、b[404]:b[n]はa[0]からb[n]までの和
int N;
ll a[404], b[404];
// bの初期化
void init_b() {
b[0] = a[0];
for (int i = 1; i < N; i++)
b[i] = a[i] + b[i - 1];
}
// a[L]からa[R]までの総和
ll get(int L, int R) {
ll res = b[R];
if (L)
res -= b[L - 1];
return res;
}
//探索フラグ:Have visted
bool vis[404][404];
//メモ
ll memo[404][404];
//メモ化再帰
ll dp(int L, int R) {
if (vis[L][R] == true)
return memo[L][R];
else if (L == R) {
vis[L][R] = true; //フラグを立てる
return memo[L][R] = 0; //メモしながらリターン
} else {
vis[L][R] = true; //フラグを立てる
ll res = infl; // inflは十分に大きい
// cで二つに区切ってmin全探索
for (int c = L; c < R; c++) {
res = min(res, dp(L, c) + dp(c + 1, R) + get(L, R));
}
return memo[L][R] = res; //メモしながらリターン
}
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> a[i];
init_b();
cout << dp(0, N - 1) << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
ll infl = 100000000000000000000; // inflは十分大きい
// N,a[404];入力値、b[404]:b[n]はa[0]からb[n]までの和
int N;
ll a[404], b[404];
// bの初期化
void init_b() {
b[0] = a[0];
for (int i = 1; i < N; i++)
b[i] = a[i] + b[i - 1];
}
// a[L]からa[R]までの総和
ll get(int L, int R) {
ll res = b[R];
if (L)
res -= b[L - 1];
return res;
}
//探索フラグ:Have visted
bool vis[404][404];
//メモ
ll memo[404][404];
//メモ化再帰
ll dp(int L, int R) {
if (vis[L][R] == true)
return memo[L][R];
else if (L == R) {
vis[L][R] = true; //フラグを立てる
return memo[L][R] = 0; //メモしながらリターン
} else {
vis[L][R] = true; //フラグを立てる
ll res = infl; // inflは十分に大きい
// cで二つに区切ってmin全探索
for (int c = L; c < R; c++) {
res = min(res, dp(L, c) + dp(c + 1, R) + get(L, R));
}
return memo[L][R] = res; //メモしながらリターン
}
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> a[i];
init_b();
cout << dp(0, N - 1) << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 982,112 | 982,113 | u010393289 | cpp |
p03173 | // BROWNIE TK
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define oset \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define osetlli \
tree<lli, null_type, less<lli>, rb_tree_tag, \
tree_order_statistics_node_update>
// member functions :
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;
/*STD fucntions*/
lli power(lli x, lli y, lli p) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y=y/2
x = (x * x) % p;
}
return res;
}
lli gcd(lli a, lli b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
lli lcm(lli a, lli b) { return a * b / gcd(a, b); }
lli modi(lli a, lli m) {
// fermat little thm where m is prime
return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main() {
kira;
lli n;
cin >> n;
lli a[n];
forz(i, n) cin >> a[i];
lli dp[n][n] = {0};
for (int l = n - 1; l >= 0; l--) {
for (int r = l; r < n; r++) {
if (l == r)
dp[l][r] = 0;
else {
dp[l][r] = mod;
lli s = 0;
for (int i = l; i <= r; i++)
s += a[i];
for (int i = l; i <= r - 1; i++) {
dp[l][r] = min(dp[l][r], dp[l][i] + s + dp[i + 1][r]);
}
}
}
}
cout << dp[0][n - 1];
return 0;
} | // BROWNIE TK
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define oset \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define osetlli \
tree<lli, null_type, less<lli>, rb_tree_tag, \
tree_order_statistics_node_update>
// member functions :
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;
/*STD fucntions*/
lli power(lli x, lli y, lli p) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y=y/2
x = (x * x) % p;
}
return res;
}
lli gcd(lli a, lli b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
lli lcm(lli a, lli b) { return a * b / gcd(a, b); }
lli modi(lli a, lli m) {
// fermat little thm where m is prime
return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main() {
kira;
lli n;
cin >> n;
lli a[n];
forz(i, n) cin >> a[i];
lli dp[n][n] = {0};
for (int l = n - 1; l >= 0; l--) {
for (int r = l; r < n; r++) {
if (l == r)
dp[l][r] = 0;
else {
dp[l][r] = 1e18 + 5;
lli s = 0;
for (int i = l; i <= r; i++)
s += a[i];
for (int i = l; i <= r - 1; i++) {
dp[l][r] = min(dp[l][r], dp[l][i] + s + dp[i + 1][r]);
}
}
}
}
cout << dp[0][n - 1];
return 0;
}
| [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"assignment.change"
] | 982,122 | 982,123 | u653959743 | cpp |
p03173 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
register ll i, j, k, x, n, y, t, q, temp, count = 0, f = 0, l;
cin >> n;
ll a[n + 1] = {0}, dp[n + 1][n + 1], pre[n + 1] = {0};
memset(dp, 0, sizeof(dp));
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 0; i <= n; i++) {
dp[i][i] = 0;
pre[i] = pre[i - 1] + a[i];
}
for (l = 2; l <= n; l++) {
for (i = 1; i <= n - l + 1; i++) {
j = i + l - 1;
dp[i][j] = inf;
for (k = i; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + pre[j] - pre[i - 1]);
}
}
}
// for(i=0;i<=n;i++){
// for(j=0;j<=n;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<"\n";
// }
cout << dp[1][n];
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1e17;
const ll MOD = 1000000007;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
register ll i, j, k, x, n, y, t, q, temp, count = 0, f = 0, l;
cin >> n;
ll a[n + 1] = {0}, dp[n + 1][n + 1], pre[n + 1] = {0};
memset(dp, 0, sizeof(dp));
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 0; i <= n; i++) {
dp[i][i] = 0;
pre[i] = pre[i - 1] + a[i];
}
for (l = 2; l <= n; l++) {
for (i = 1; i <= n - l + 1; i++) {
j = i + l - 1;
dp[i][j] = inf;
for (k = i; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + pre[j] - pre[i - 1]);
}
}
}
// for(i=0;i<=n;i++){
// for(j=0;j<=n;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<"\n";
// }
cout << dp[1][n];
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 982,124 | 982,125 | u660054140 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
long long dp[405][405];
int main() {
int n;
cin >> n;
vector<long long> arr(n + 1);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
vector<long long> sum(n);
for (int i = 0; i < n; ++i) {
sum[i] = arr[i];
if (i > 0) {
sum[i] += sum[i - 1];
}
}
for (int len = 2; len <= n; ++len) {
for (int start = 0; start + len <= n; ++start) {
int l = start;
int r = start + len - 1;
dp[start][len] = 1e18;
long long penlty = 0;
for (int k = l + 1; k <= r; ++k) {
if (l == 0) {
penlty = sum[r];
} else {
penlty = sum[r] - sum[l - 1];
}
dp[start][len] =
min(dp[start][len], dp[l][k - l] + dp[k][r - k + 1] + penlty);
}
/*
dp[start][len] = min(
arr[start] + dp[start+1][len-1]
,
dp[start+1][len-1] + arr[start+len-1]
);
*/
}
}
/*
for(int i=0;i<=n;++i){
for(int j=0;j<=n;++j){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
*/
cout << dp[1][n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long dp[405][405];
int main() {
int n;
cin >> n;
vector<long long> arr(n + 1);
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
vector<long long> sum(n);
for (int i = 0; i < n; ++i) {
sum[i] = arr[i];
if (i > 0) {
sum[i] += sum[i - 1];
}
}
for (int len = 2; len <= n; ++len) {
for (int start = 0; start + len <= n; ++start) {
int l = start;
int r = start + len - 1;
dp[start][len] = 1e18;
long long penlty = 0;
for (int k = l + 1; k <= r; ++k) {
if (l == 0) {
penlty = sum[r];
} else {
penlty = sum[r] - sum[l - 1];
}
dp[start][len] =
min(dp[start][len], dp[l][k - l] + dp[k][r - k + 1] + penlty);
}
/*
dp[start][len] = min(
arr[start] + dp[start+1][len-1]
,
dp[start+1][len-1] + arr[start+len-1]
);
*/
}
}
/*
for(int i=0;i<=n;++i){
for(int j=0;j<=n;++j){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
*/
cout << dp[0][n] << endl;
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"io.output.change"
] | 982,146 | 982,147 | u542111796 | cpp |
p03173 | #include <cstdlib>
#include <iostream>
/* run this program using the console pauser or add your own getch,
* system("pause") or input loop */
using namespace std;
int main() {
int cale = 0, mid, len, l, r, i, n;
cin >> n;
int pref[n], a[n], dp[n][n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
pref[0] = a[0];
for (i = 1; i < n; i++) {
pref[i] = pref[i - 1] + a[i];
}
for (len = 1; len <= n; len++) {
for (l = 0; l < n; l++) {
int r = l + len - 1;
if (r == n) {
break;
}
if (len == 1) {
dp[l][l] = 0;
} else {
dp[l][r] = 2e18;
}
for (mid = l; mid < r; mid++) {
if (l == 0) {
cale = dp[l][mid] + dp[mid + 1][r] + pref[r];
dp[l][r] = min(dp[l][r], cale);
} else {
cale = dp[l][mid] + dp[mid + 1][r] + pref[r] - pref[l - 1];
dp[l][r] = min(dp[l][r], cale);
}
}
}
}
cout << dp[0][n - 1];
return 0;
}
| #include <cstdlib>
#include <iostream>
/* run this program using the console pauser or add your own getch,
* system("pause") or input loop */
using namespace std;
int main() {
long long cale = 0, mid, len, l, r, i, n;
cin >> n;
long long pref[n], a[n], dp[n][n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
pref[0] = a[0];
for (i = 1; i < n; i++) {
pref[i] = pref[i - 1] + a[i];
}
for (len = 1; len <= n; len++) {
for (l = 0; l < n; l++) {
int r = l + len - 1;
if (r == n) {
break;
}
if (len == 1) {
dp[l][l] = 0;
} else {
dp[l][r] = 2e18;
}
for (mid = l; mid < r; mid++) {
if (l == 0) {
cale = dp[l][mid] + dp[mid + 1][r] + pref[r];
dp[l][r] = min(dp[l][r], cale);
} else {
cale = dp[l][mid] + dp[mid + 1][r] + pref[r] - pref[l - 1];
dp[l][r] = min(dp[l][r], cale);
}
}
}
}
cout << dp[0][n - 1];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 982,151 | 982,152 | u700270455 | cpp |
p03173 | #include <bits/stdc++.h>
#define DIM 407
#define INF 1000000007
using namespace std;
long long n, a[DIM], p[DIM], d[DIM][DIM];
long long F(int l, int r) {
if (d[l][r] != -1)
return d[l][r];
if (l == r)
return d[l][r] = 0, 0;
d[l][r] = INF;
for (int i = l; i < r; ++i)
d[l][r] = min(d[l][r], F(l, i) + F(i + 1, r) + p[r] - p[l - 1]);
return d[l][r];
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i], p[i] = p[i - 1] + a[i];
memset(d, -1, sizeof(d));
cout << F(1, n);
return 0;
}
| #include <bits/stdc++.h>
#define DIM 407
#define INF 1000000000000000007LL
using namespace std;
long long n, a[DIM], p[DIM], d[DIM][DIM];
long long F(int l, int r) {
if (d[l][r] != -1)
return d[l][r];
if (l == r)
return d[l][r] = 0, 0;
d[l][r] = INF;
for (int i = l; i < r; ++i)
d[l][r] = min(d[l][r], F(l, i) + F(i + 1, r) + p[r] - p[l - 1]);
return d[l][r];
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i], p[i] = p[i - 1] + a[i];
memset(d, -1, sizeof(d));
cout << F(1, n);
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 982,162 | 982,163 | u674071078 | cpp |
p03173 | //** aman**/
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define dl double
#define hell 1000000007
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
int a[405], p[405];
int dp[405][405];
int fun(int l, int r) {
if (l == r)
return 0;
if (dp[l][r] != -1)
return dp[l][r];
int ans = hell;
for (int i = l; i < r; i++) {
ans = min(ans, fun(l, i) + fun(i + 1, r) + p[r] - p[l - 1]);
}
dp[l][r] = ans;
return ans;
}
signed main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
a[0] = 0;
p[0] = 0;
for (int i = 1; i <= n; i++)
p[i] = p[i - 1] + a[i];
// for(int i=1;i<=n;i++)cout<<p[i]<<" ";cout<<endl;
memset(dp, -1, sizeof(dp));
cout << fun(1, n) << endl;
} | //** aman**/
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define dl double
#define hell 1000000007
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
using namespace std;
int a[405], p[405];
int dp[405][405];
int fun(int l, int r) {
if (l == r)
return 0;
if (dp[l][r] != -1)
return dp[l][r];
int ans = 1e17;
for (int i = l; i < r; i++) {
ans = min(ans, fun(l, i) + fun(i + 1, r) + p[r] - p[l - 1]);
}
dp[l][r] = ans;
return ans;
}
signed main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
a[0] = 0;
p[0] = 0;
for (int i = 1; i <= n; i++)
p[i] = p[i - 1] + a[i];
// for(int i=1;i<=n;i++)cout<<p[i]<<" ";cout<<endl;
memset(dp, -1, sizeof(dp));
cout << fun(1, n) << endl;
} | [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 982,173 | 982,174 | u006069211 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 440;
const ll INF = 1e8 + 7;
ll dp[M][M], a[M], pre[M];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
dp[i][j] = INF;
}
for (int i = 1; i <= n; i++)
dp[i][i] = 0;
for (int ln = 2; ln <= n; ln++) {
for (int i = 1; i + ln - 1 <= n; i++) {
int j = i + ln - 1;
if (ln == 2)
dp[i][j] = a[i] + a[j];
else {
ll mn = INF;
for (int k = i; k < j; k++)
mn = min(mn, dp[i][k] + dp[k + 1][j]);
dp[i][j] = mn + pre[j] - pre[i - 1];
}
}
}
cout << dp[1][n];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 440;
const ll INF = 1e18 + 7;
ll dp[M][M], a[M], pre[M];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
dp[i][j] = INF;
}
for (int i = 1; i <= n; i++)
dp[i][i] = 0;
for (int ln = 2; ln <= n; ln++) {
for (int i = 1; i + ln - 1 <= n; i++) {
int j = i + ln - 1;
if (ln == 2)
dp[i][j] = a[i] + a[j];
else {
ll mn = INF;
for (int k = i; k < j; k++)
mn = min(mn, dp[i][k] + dp[k + 1][j]);
dp[i][j] = mn + pre[j] - pre[i - 1];
}
}
}
cout << dp[1][n];
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change"
] | 982,256 | 982,257 | u230002616 | cpp |
p03173 | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int MD = 1e9 + 7;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, r, s;
public:
UnionFind(int N) {
p = r = vi(N);
s = vi(N, 1);
fr(i, N) { p[i] = i; }
}
int find(int i) { return p[i] = p[i] == i ? i : find(p[i]); }
void unite(int a, int b) {
if (r[a = find(a)] > r[b = find(b)]) {
swap(a, b);
}
s[b] += s[a];
r[p[a] = b] += r[a] == r[b];
}
bool same(int a, int b) { return find(a) == find(b); }
int size(int x) { return s[find(x)]; }
};
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) { return pow(x, p - 2, p); }
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
ll f(vl &A, vl &S, vvl &d, int l, int r) {
if (l + 1 == r)
return 0;
if (d[l][r])
return d[l][r];
ll z = 1e18;
foor(i, l + 1, r - 1) { z = min(z, f(A, S, d, l, i) + f(A, S, d, i, r)); }
d[l][r] = z + S[r] - S[l];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vl A(N);
cin >> A;
vl S(N + 1);
fr(i, N) { S[i + 1] = S[i] + A[i]; }
vvl d(N, vl(N + 1));
print(f(A, S, d, 0, N));
return 0;
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int MD = 1e9 + 7;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, r, s;
public:
UnionFind(int N) {
p = r = vi(N);
s = vi(N, 1);
fr(i, N) { p[i] = i; }
}
int find(int i) { return p[i] = p[i] == i ? i : find(p[i]); }
void unite(int a, int b) {
if (r[a = find(a)] > r[b = find(b)]) {
swap(a, b);
}
s[b] += s[a];
r[p[a] = b] += r[a] == r[b];
}
bool same(int a, int b) { return find(a) == find(b); }
int size(int x) { return s[find(x)]; }
};
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) { return pow(x, p - 2, p); }
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
ll f(vl &A, vl &S, vvl &d, int l, int r) {
if (l + 1 == r)
return 0;
if (d[l][r])
return d[l][r];
ll z = 1e18;
foor(i, l + 1, r - 1) { z = min(z, f(A, S, d, l, i) + f(A, S, d, i, r)); }
return d[l][r] = z + S[r] - S[l];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vl A(N);
cin >> A;
vl S(N + 1);
fr(i, N) { S[i + 1] = S[i] + A[i]; }
vvl d(N, vl(N + 1));
print(f(A, S, d, 0, N));
return 0;
}
| [
"control_flow.return.add"
] | 982,271 | 982,272 | u283869437 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
int arr[500];
long long int dp[500][500], pre[420];
int N;
long long int solve(int i, int j) {
if (i == j - 1)
return arr[i] + arr[j];
if (i == j)
return 0;
if (dp[i][j] != 1e9)
return dp[i][j];
for (int low = i; low < j; low++)
dp[i][j] =
min(dp[i][j], solve(i, low) + solve(low + 1, j) + pre[j] - pre[i - 1]);
return dp[i][j];
}
int main() {
cin >> N;
for (int i = 1; i <= N; i++)
cin >> arr[i];
for (int i = 1; i <= N; i++)
pre[i] = pre[i - 1] + arr[i];
for (int i = 0; i <= N; i++)
for (int j = 0; j <= N; j++)
dp[i][j] = 1e9;
cout << solve(1, N);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int arr[500];
long long int dp[500][500], pre[420];
int N;
long long int solve(int i, int j) {
if (i == j - 1)
return arr[i] + arr[j];
if (i == j)
return 0;
if (dp[i][j] != 1e15)
return dp[i][j];
for (int low = i; low < j; low++)
dp[i][j] =
min(dp[i][j], solve(i, low) + solve(low + 1, j) + pre[j] - pre[i - 1]);
return dp[i][j];
}
int main() {
cin >> N;
for (int i = 1; i <= N; i++)
cin >> arr[i];
for (int i = 1; i <= N; i++)
pre[i] = pre[i - 1] + arr[i];
for (int i = 0; i <= N; i++)
for (int j = 0; j <= N; j++)
dp[i][j] = 1e15;
cout << solve(1, N);
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change",
"assignment.value.change"
] | 982,281 | 982,282 | u292217769 | cpp |
p03173 | /*
$$$$$$$\ $$\ $$$$$$$\
$$ __$$\ \__| $$ __$$\
$$ | $$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\
$$$$$$$\ $$$$$$\
$$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ _____|$$$$$$$\ | \____$$\ $$
__$$\ $$ _____|\____$$\
$$ __$$\ $$ / $$ |$$ | \__|$$ |\$$$$$$\ $$ __$$\ $$$$$$$ |$$ |
\__|$$ / $$$$$$$ |
$$ | $$ |$$ | $$ |$$ | $$ | \____$$\ $$ | $$ |$$ __$$ |$$ | $$
| $$ __$$ |
$$$$$$$ |\$$$$$$ |$$ | $$ |$$$$$$$ |$$$$$$$ |\$$$$$$$ |$$ |
\$$$$$$$\\$$$$$$$ |
\_______/ \______/ \__| \__|\_______/ \_______/ \_______|\__|
\_______|\_______|
*/
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define INS insert
#define LB lower_bound
#define UB upper_bound
#define pii pair<int, int>
#define pll pair<long long, long long>
#define si pair<string, int>
#define is pair<int, string>
#define X first
#define Y second
#define _ << " " <<
#define sz(x) (int)x.size()
#define all(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for (int i = (a); i > (b); --i)
#define FORR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FORP(i, a, b) for ((i) = (a); (i) < (b); ++i)
#define FORA(i, x) for (auto &i : x)
#define REP(i, n) FOR(i, 0, n)
#define BITS(x) __builtin_popcount(x)
#define MSET memset
#define MCPY memcpy
#define SQ(a) (a) * (a)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<ll> vll;
typedef vector<pll> vpl;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<si> vsi;
typedef vector<is> vis;
typedef vector<string> vs;
//((float) t)/CLOCKS_PER_SEC
const int MOD = 1e9 + 7;
const int PI = acos(-1);
const int LOG = 20;
const int INF = 1e9 + 10;
const ll INFL = 1e18 + 10;
const int ABC = 30;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dox[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int doy[] = {0, 0, -1, 1, -1, 1, -1, 1};
inline int sum(int a, int b) {
if (a + b >= MOD)
return a + b - MOD;
if (a + b < 0)
return a + b + MOD;
return a + b;
}
inline void add(int &a, int b) { a = sum(a, b); }
inline int pot(ll pot, int n) {
ll ret = 1;
while (n) {
if (n & 1)
ret = (ret * pot) % MOD;
pot = (pot * pot) % MOD;
n >>= 1;
}
return ret;
}
inline int mul(int a, int b) { return (ll)a * (ll)b % MOD; }
inline int sub(int a, int b) { return (a - b + MOD) % MOD; }
inline int divide(int a, int b) { return mul(a, pot(b, MOD - 2)); }
ll lcm(ll a, ll b) { return abs(a * b) / __gcd(a, b); }
inline double ccw(pii A, pii B, pii C) {
return (A.X * B.Y) - (A.Y * B.X) + (B.X * C.Y) - (B.Y * C.X) + (C.X * A.Y) -
(C.Y * A.X);
}
inline int CCW(pii A, pii B, pii C) {
double val = ccw(A, B, C);
double eps = max(max(abs(A.X), abs(A.Y)),
max(max(abs(B.X), abs(B.Y)), max(abs(C.X), abs(C.Y)))) /
1e9;
if (val <= -eps)
return -1;
if (val >= eps)
return 1;
return 0;
}
void to_upper(string &x) {
REP(i, sz(x))
x[i] = toupper(x[i]);
}
void to_lower(string &x) {
REP(i, sz(x))
x[i] = tolower(x[i]);
}
string its(ll x) {
if (x == 0)
return "0";
string ret = "";
while (x > 0) {
ret += (x % 10) + '0';
x /= 10;
}
reverse(all(ret));
return ret;
}
ll sti(string s) {
ll ret = 0;
REP(i, sz(s)) {
ret *= 10;
ret += (s[i] - '0');
}
return ret;
}
const int N = 401;
const int W = 1e5 + 10;
const int OFF = (1 << LOG);
ll n, memo[N][N], pref[N];
vll v;
ll dp(int l, int r) {
if (l == r)
return 0;
if (l + 1 == r)
return v[r] + v[l];
ll &ret = memo[l][r];
if (~ret)
return ret;
ret = INF;
FOR(k, l, r) {
ret = min(ret, dp(l, k) + dp(k + 1, r) + (pref[k] - pref[l - 1]) +
(pref[r] - pref[k]));
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
REP(i, n) {
ll x;
cin >> x;
pref[i] = x;
if (i)
pref[i] += pref[i - 1];
v.PB(x);
}
MSET(memo, -1, sizeof memo);
cout << dp(0, n - 1) << '\n';
return 0;
} | /*
$$$$$$$\ $$\ $$$$$$$\
$$ __$$\ \__| $$ __$$\
$$ | $$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\
$$$$$$$\ $$$$$$\
$$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ _____|$$$$$$$\ | \____$$\ $$
__$$\ $$ _____|\____$$\
$$ __$$\ $$ / $$ |$$ | \__|$$ |\$$$$$$\ $$ __$$\ $$$$$$$ |$$ |
\__|$$ / $$$$$$$ |
$$ | $$ |$$ | $$ |$$ | $$ | \____$$\ $$ | $$ |$$ __$$ |$$ | $$
| $$ __$$ |
$$$$$$$ |\$$$$$$ |$$ | $$ |$$$$$$$ |$$$$$$$ |\$$$$$$$ |$$ |
\$$$$$$$\\$$$$$$$ |
\_______/ \______/ \__| \__|\_______/ \_______/ \_______|\__|
\_______|\_______|
*/
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define INS insert
#define LB lower_bound
#define UB upper_bound
#define pii pair<int, int>
#define pll pair<long long, long long>
#define si pair<string, int>
#define is pair<int, string>
#define X first
#define Y second
#define _ << " " <<
#define sz(x) (int)x.size()
#define all(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORD(i, a, b) for (int i = (a); i > (b); --i)
#define FORR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FORP(i, a, b) for ((i) = (a); (i) < (b); ++i)
#define FORA(i, x) for (auto &i : x)
#define REP(i, n) FOR(i, 0, n)
#define BITS(x) __builtin_popcount(x)
#define MSET memset
#define MCPY memcpy
#define SQ(a) (a) * (a)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<ll> vll;
typedef vector<pll> vpl;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<si> vsi;
typedef vector<is> vis;
typedef vector<string> vs;
//((float) t)/CLOCKS_PER_SEC
const int MOD = 1e9 + 7;
const int PI = acos(-1);
const int LOG = 20;
const int INF = 1e9 + 10;
const ll INFL = 1e18 + 10;
const int ABC = 30;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dox[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int doy[] = {0, 0, -1, 1, -1, 1, -1, 1};
inline int sum(int a, int b) {
if (a + b >= MOD)
return a + b - MOD;
if (a + b < 0)
return a + b + MOD;
return a + b;
}
inline void add(int &a, int b) { a = sum(a, b); }
inline int pot(ll pot, int n) {
ll ret = 1;
while (n) {
if (n & 1)
ret = (ret * pot) % MOD;
pot = (pot * pot) % MOD;
n >>= 1;
}
return ret;
}
inline int mul(int a, int b) { return (ll)a * (ll)b % MOD; }
inline int sub(int a, int b) { return (a - b + MOD) % MOD; }
inline int divide(int a, int b) { return mul(a, pot(b, MOD - 2)); }
ll lcm(ll a, ll b) { return abs(a * b) / __gcd(a, b); }
inline double ccw(pii A, pii B, pii C) {
return (A.X * B.Y) - (A.Y * B.X) + (B.X * C.Y) - (B.Y * C.X) + (C.X * A.Y) -
(C.Y * A.X);
}
inline int CCW(pii A, pii B, pii C) {
double val = ccw(A, B, C);
double eps = max(max(abs(A.X), abs(A.Y)),
max(max(abs(B.X), abs(B.Y)), max(abs(C.X), abs(C.Y)))) /
1e9;
if (val <= -eps)
return -1;
if (val >= eps)
return 1;
return 0;
}
void to_upper(string &x) {
REP(i, sz(x))
x[i] = toupper(x[i]);
}
void to_lower(string &x) {
REP(i, sz(x))
x[i] = tolower(x[i]);
}
string its(ll x) {
if (x == 0)
return "0";
string ret = "";
while (x > 0) {
ret += (x % 10) + '0';
x /= 10;
}
reverse(all(ret));
return ret;
}
ll sti(string s) {
ll ret = 0;
REP(i, sz(s)) {
ret *= 10;
ret += (s[i] - '0');
}
return ret;
}
const int N = 401;
const int W = 1e5 + 10;
const int OFF = (1 << LOG);
ll n, memo[N][N], pref[N];
vll v;
ll dp(int l, int r) {
if (l == r)
return 0;
if (l + 1 == r)
return v[r] + v[l];
ll &ret = memo[l][r];
if (~ret)
return ret;
ret = INFL;
FOR(k, l, r) {
ret = min(ret, dp(l, k) + dp(k + 1, r) + (pref[k] - pref[l - 1]) +
(pref[r] - pref[k]));
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
REP(i, n) {
ll x;
cin >> x;
pref[i] = x;
if (i)
pref[i] += pref[i - 1];
v.PB(x);
}
MSET(memo, -1, sizeof memo);
cout << dp(0, n - 1) << '\n';
return 0;
} | [
"assignment.value.change",
"identifier.change"
] | 982,288 | 982,289 | u604519317 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1000][1000];
ll arr[1000];
ll sum(int i, int j) {
ll ans = 0;
for (int a = i; a <= j; a++) {
ans += arr[a];
}
return ans;
}
ll ans(int i, int j) {
if (i >= j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = INT_MAX;
for (int k = i; k <= j; k++) {
dp[i][j] =
min(dp[i][j], ans(i, k) + ans(k + 1, j) + (sum(i, k) + sum(k + 1, j)));
}
return dp[i][j];
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = -1;
cout << ans(0, n - 1) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[500][500];
ll arr[500];
ll sum(int i, int j) {
ll ans = 0;
for (int a = i; a <= j; a++) {
ans += arr[a];
}
return ans;
}
ll ans(int i, int j) {
if (i >= j)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = 1000000000000000;
for (int k = i; k <= j; k++) {
dp[i][j] =
min(dp[i][j], ans(i, k) + ans(k + 1, j) + (sum(i, k) + sum(k + 1, j)));
}
return dp[i][j];
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = -1;
cout << ans(0, n - 1) << "\n";
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 982,300 | 982,301 | u885151856 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long uLL;
typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<long long, long long> pll;
typedef pair<long long, pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;
int n;
LL a[N];
LL dp[505][505];
LL sum[N];
int getsum(int l, int r) { return (sum[r] - sum[l - 1]); }
LL MCM(int l, int r) {
if (l >= r)
return 0;
if (dp[l][r] != -1)
return dp[l][r];
LL ret = INF;
for (int i = l; i < r; i++) {
int temp = getsum(l, i) + getsum(i + 1, r);
ret = min(ret, MCM(l, i) + MCM(i + 1, r) + temp);
}
return dp[l][r] = ret;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
sum[i] += sum[i - 1] + a[i];
memset(dp, -1, sizeof(dp));
cout << MCM(1, n) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long uLL;
typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<long long, long long> pll;
typedef pair<long long, pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;
int n;
LL a[N];
LL dp[505][505];
LL sum[N];
LL getsum(int l, int r) { return (sum[r] - sum[l - 1]); }
LL MCM(int l, int r) {
if (l >= r)
return 0;
if (dp[l][r] != -1)
return dp[l][r];
LL ret = INF;
for (int i = l; i < r; i++) {
LL temp = getsum(l, i) + getsum(i + 1, r);
ret = min(ret, MCM(l, i) + MCM(i + 1, r) + temp);
}
return dp[l][r] = ret;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
sum[i] += sum[i - 1] + a[i];
memset(dp, -1, sizeof(dp));
cout << MCM(1, n) << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 982,302 | 982,303 | u872217461 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long uLL;
typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<long long, long long> pll;
typedef pair<long long, pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;
int n;
LL a[N];
LL dp[105][105];
LL sum[N];
int getsum(int l, int r) { return (sum[r] - sum[l - 1]); }
LL MCM(int l, int r) {
if (l >= r)
return 0;
if (dp[l][r] != -1)
return dp[l][r];
LL ret = INF;
for (int i = l; i < r; i++) {
int temp = getsum(l, i) + getsum(i + 1, r);
ret = min(ret, MCM(l, i) + MCM(i + 1, r) + temp);
}
return dp[l][r] = ret;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
sum[i] += sum[i - 1] + a[i];
memset(dp, -1, sizeof(dp));
cout << MCM(1, n) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long uLL;
typedef long long int LL;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<long long, long long> pll;
typedef pair<long long, pll> plll;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1000000007;
int n;
LL a[N];
LL dp[505][505];
LL sum[N];
LL getsum(int l, int r) { return (sum[r] - sum[l - 1]); }
LL MCM(int l, int r) {
if (l >= r)
return 0;
if (dp[l][r] != -1)
return dp[l][r];
LL ret = INF;
for (int i = l; i < r; i++) {
LL temp = getsum(l, i) + getsum(i + 1, r);
ret = min(ret, MCM(l, i) + MCM(i + 1, r) + temp);
}
return dp[l][r] = ret;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
sum[i] += sum[i - 1] + a[i];
memset(dp, -1, sizeof(dp));
cout << MCM(1, n) << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.type.change"
] | 982,304 | 982,303 | u872217461 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
constexpr ll INF = 1e9 + 7;
vector<vector<ll>> dp(n, vector<ll>(n, INF));
for (int i = 0; i < n; ++i)
dp[i][i] = 0;
for (int len = 2; len <= n; ++len) {
for (int i = 0; i + len <= n; ++i) {
int j = i + len - 1;
ll tot = 0LL;
for (int k = i; k < j; ++k) {
tot += a[k];
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
}
tot += a[j];
// cout << "tot(" << i << ", " << j << ") = " << tot << '\n';
dp[i][j] += tot;
}
}
/*
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << dp[i][j] << ' ';
}
cout << '\n';
}
*/
cout << dp[0][n - 1] << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
constexpr ll INF = 1e17;
vector<vector<ll>> dp(n, vector<ll>(n, INF));
for (int i = 0; i < n; ++i)
dp[i][i] = 0;
for (int len = 2; len <= n; ++len) {
for (int i = 0; i + len <= n; ++i) {
int j = i + len - 1;
ll tot = 0LL;
for (int k = i; k < j; ++k) {
tot += a[k];
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
}
tot += a[j];
// cout << "tot(" << i << ", " << j << ") = " << tot << '\n';
dp[i][j] += tot;
}
}
/*
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cout << dp[i][j] << ' ';
}
cout << '\n';
}
*/
cout << dp[0][n - 1] << '\n';
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 982,305 | 982,306 | u906129425 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 INF = 1LL << 59;
int N, A[401];
int64 dp[400][400];
int64 getCost(int l, int r) { return A[r + 1] - A[l]; }
int64 rec(int l, int r) {
if (l == r)
return 0;
if (~dp[l][r])
return dp[l][r];
int64 ret = INF;
for (int i = l + 1; i <= r; i++) {
ret = min(ret, rec(l, i - 1) + rec(i, r) + getCost(l, r));
}
return dp[l][r] = ret;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i + 1];
for (int i = 1; i <= N; i++)
A[i] += A[i - 1];
memset(dp, -1, sizeof(dp));
cout << rec(0, N - 1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 INF = 1LL << 59;
int64 N, A[401];
int64 dp[400][400];
int64 getCost(int l, int r) { return A[r + 1] - A[l]; }
int64 rec(int l, int r) {
if (l == r)
return 0;
if (~dp[l][r])
return dp[l][r];
int64 ret = INF;
for (int i = l + 1; i <= r; i++) {
ret = min(ret, rec(l, i - 1) + rec(i, r) + getCost(l, r));
}
return dp[l][r] = ret;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i + 1];
for (int i = 1; i <= N; i++)
A[i] += A[i - 1];
memset(dp, -1, sizeof(dp));
cout << rec(0, N - 1) << endl;
}
| [
"variable_declaration.type.change"
] | 982,321 | 982,322 | u524343822 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3005][3005];
ll a[3005], pre[3005];
ll mini(ll x, ll y) {
if (x >= y)
return y;
return x;
}
int main(void) {
// your code goes here
int n, k, i;
multiset<ll> s;
scanf("%d", &n);
ll ans = 0;
ll x, y;
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
pre[i] = pre[i - 1] + a[i];
}
int j;
for (i = 1; i < n; i++)
dp[i][i + 1] = a[i] + a[i + 1];
int len;
ll hi = 1000000007;
for (len = 3; len <= n; len++) {
for (i = 1; i <= n; i++) {
j = i + len - 1;
dp[i][j] = hi * hi;
for (k = i + 1; k < j; k++) {
dp[i][j] =
mini(dp[i][j], dp[i][k - 1] + dp[k][j] + pre[j] - pre[i - 1]);
}
}
}
printf("%lld\n", dp[1][n]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3005][3005];
ll a[3005], pre[3005];
ll mini(ll x, ll y) {
if (x >= y)
return y;
return x;
}
int main(void) {
// your code goes here
int n, k, i;
multiset<ll> s;
scanf("%d", &n);
ll ans = 0;
ll x, y;
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
pre[i] = pre[i - 1] + a[i];
}
int j;
for (i = 1; i < n; i++)
dp[i][i + 1] = a[i] + a[i + 1];
int len;
ll hi = 1000000007;
for (len = 3; len <= n; len++) {
for (i = 1; i <= n; i++) {
j = i + len - 1;
dp[i][j] = hi * hi;
for (k = i + 1; k <= j; k++) {
dp[i][j] =
mini(dp[i][j], dp[i][k - 1] + dp[k][j] + pre[j] - pre[i - 1]);
}
// printf("%d to %d is %lld\n",i,j,dp[i][j]);
}
}
printf("%lld\n", dp[1][n]);
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 982,331 | 982,332 | u582770155 | cpp |
p03173 | #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define MAXN 405
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n, k, a[MAXN], dp[MAXN][MAXN], sum[MAXN];
int main() {
scanf("%lld", &n);
for (ll i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (ll i = 1; i <= n; i++)
sum[i] = sum[i - 1] + a[i];
for (ll l = 2; l <= n; l++) {
for (ll i = 1; i + l - 1 <= n; i++) {
ll j = i + l - 1;
dp[i][j] = INF;
for (ll k = i; k < j; k++)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1]);
}
}
printf("%lld\n", dp[1][n]);
return 0;
}
| #pragma GCC optimize(3)
#include <bits/stdc++.h>
#define MAXN 405
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n, k, a[MAXN], dp[MAXN][MAXN], sum[MAXN];
int main() {
scanf("%lld", &n);
for (ll i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (ll i = 1; i <= n; i++)
sum[i] = sum[i - 1] + a[i];
for (ll l = 2; l <= n; l++) {
for (ll i = 1; i + l - 1 <= n; i++) {
ll j = i + l - 1;
dp[i][j] = INF;
for (ll k = i; k < j; k++)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[j] - sum[i - 1]);
}
}
printf("%lld\n", dp[1][n]);
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 982,335 | 982,336 | u237254894 | cpp |
p03174 | // by Top1
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x *x
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 4e6 + 111;
using namespace std;
int n, q, dp[maxn], a[25][25];
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
dp[0] = 1;
for (int mask = 0; mask < (1 << n); mask++) {
int k = __builtin_popcount(mask);
// cout << k << endl;
for (int i = 0; i < n; i++)
if (a[k][i] == 1 && (mask & (1 << i)) == 0) {
dp[mask | (1 << i)] += dp[mask];
dp[mask | (1 << i)] %= mask;
}
}
cout << dp[(1 << n) - 1];
}
main() {
boost;
q = 1;
while (q--) {
solve();
}
} | // by Top
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x *x
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 4e6 + 111;
using namespace std;
int n, q, dp[maxn], a[25][25];
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
dp[0] = 1;
for (int mask = 0; mask < (1 << n); mask++) {
int k = __builtin_popcount(mask);
// cout << k << endl;
for (int i = 0; i < n; i++)
if (a[k][i] == 1 && (mask & (1 << i)) == 0) {
dp[mask | (1 << i)] += dp[mask];
dp[mask | (1 << i)] %= mod;
}
}
cout << dp[(1 << n) - 1];
}
main() {
boost;
q = 1;
while (q--) {
solve();
}
} | [
"assignment.value.change",
"identifier.change"
] | 982,190 | 982,191 | u018679195 | cpp |
p03174 | // by Top1
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x *x
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 4e6 + 111;
using namespace std;
int n, q, dp[maxn], a[25][25];
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
dp[0] = 1;
for (int mask = 0; mask < (1 << n); mask++) {
int k = __builtin_popcount(mask);
// cout << k << endl;
for (int i = 0; i < n; i++)
if (a[k][i] == 1 && (mask & (1 << i)) == 0) {
dp[mask | (1 << i)] += dp[mask];
dp[mask | (1 << i)] %= mask;
}
}
cout << dp[(1 << n) - 1];
}
main() {
boost;
q = 1;
while (q--) {
solve();
}
} | // by Top1
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(0), cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x *x
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 4e6 + 111;
using namespace std;
int n, q, dp[maxn], a[25][25];
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
dp[0] = 1;
for (int mask = 0; mask < (1 << n); mask++) {
int k = __builtin_popcount(mask);
// cout << k << endl;
for (int i = 0; i < n; i++)
if (a[k][i] == 1 && (mask & (1 << i)) == 0) {
dp[mask | (1 << i)] += dp[mask];
dp[mask | (1 << i)] %= mod;
}
}
cout << dp[(1 << n) - 1];
}
main() {
boost;
q = 1;
while (q--) {
solve();
}
} | [
"assignment.value.change",
"identifier.change"
] | 982,190 | 982,192 | u018679195 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 3e3 + 5, inf = INT_MAX, mod = 1e9 + 7;
int n, dp[22][(1 << 22)], a[22][22];
int solve(int i, int mask) {
if (i == n)
return 1;
if (dp[i][mask] != -1)
return dp[i][mask];
int ans = 0;
for (int j = 0; j < n; j++) {
if (a[i][j] == 1 && ((1 << j) & mask) == 0)
ans = (ans + solve(i + 1, ((1 << j) | mask))) % mod;
}
return dp[i][mask] = ans;
}
int main() {
// ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i][j] = 1;
// cin >> a[i][j];
cout << solve(0, 0);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 3e3 + 5, inf = INT_MAX, mod = 1e9 + 7;
int n, dp[22][(1 << 22)], a[22][22];
int solve(int i, int mask) {
if (i == n)
return 1;
if (dp[i][mask] != -1)
return dp[i][mask];
int ans = 0;
for (int j = 0; j < n; j++) {
if (a[i][j] == 1 && ((1 << j) & mask) == 0)
ans = (ans + solve(i + 1, ((1 << j) | mask))) % mod;
}
return dp[i][mask] = ans;
}
int main() {
// ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
cout << solve(0, 0);
return 0;
} | [
"assignment.change"
] | 982,201 | 982,202 | u836953711 | cpp |
p03174 | #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n;
cin >> n;
vector<vector<int>> arr(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
vector<int> dp(1LL << n);
dp[0] = 1;
for (int mask = 0; mask < (1LL << n); mask++) {
int a = __builtin_popcount(mask);
for (int b = 0; b < n; b++) {
if (arr[a][b] == 1 && (mask & (1LL << b)) == 0) {
int newmask = mask ^ (1LL << b);
dp[newmask] = (dp[newmask] + dp[mask]) % mod;
}
}
}
cout << dp[(1LL << n) - 1];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
solve();
return 0;
} | #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n;
cin >> n;
vector<vector<int>> arr(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
vector<int> dp(1LL << n);
dp[0] = 1;
for (int mask = 0; mask < (1LL << n) - 1; mask++) {
int a = __builtin_popcount(mask);
for (int b = 0; b < n; b++) {
if (arr[a][b] == 1 && (mask & (1LL << b)) == 0) {
int newmask = mask ^ (1LL << b);
dp[newmask] = (dp[newmask] + dp[mask]) % mod;
}
}
}
cout << dp[(1LL << n) - 1];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
} | [
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 982,226 | 982,227 | u752949890 | cpp |
p03174 | #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n;
cin >> n;
vector<vector<int>> arr(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
vector<int> dp(1LL << n);
dp[0] = 1;
for (int mask = 0; mask < (1LL << n); mask++) {
int a = __builtin_popcount(mask);
for (int b = 0; b < n; b++) {
if (arr[a][b] == 1 && (mask & (1LL << b)) == 0) {
int newmask = mask ^ (1LL << b);
dp[newmask] = (dp[newmask] + dp[mask]) % mod;
}
}
}
cout << dp[(1LL << n) - 1];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
} | #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n;
cin >> n;
vector<vector<int>> arr(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
}
}
vector<int> dp(1LL << n);
dp[0] = 1;
for (int mask = 0; mask < (1LL << n) - 1; mask++) {
int a = __builtin_popcount(mask);
for (int b = 0; b < n; b++) {
if (arr[a][b] == 1 && (mask & (1LL << b)) == 0) {
int newmask = mask ^ (1LL << b);
dp[newmask] = (dp[newmask] + dp[mask]) % mod;
}
}
}
cout << dp[(1LL << n) - 1];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
} | [
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 982,228 | 982,227 | u752949890 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[22][22];
ll n;
const ll m = 1e9 + 7;
ll dp[22][1 << 21];
ll solve(ll index, ll mask) {
if (index == n) {
return 1;
}
if (dp[index][mask] != -1) {
return dp[index][mask];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
if (((mask >> i) & 1) && a[index][i]) {
ans = (ans + solve(index + 1, mask ^ (1 << i))) % m;
}
}
return dp[index][mask] = ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
cout << solve(0, 1 << n - 1) << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[22][22];
ll n;
const ll m = 1e9 + 7;
ll dp[22][1 << 21];
ll solve(ll index, ll mask) {
if (index == n) {
return 1;
}
if (dp[index][mask] != -1) {
return dp[index][mask];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
if (((mask >> i) & 1) && a[index][i]) {
ans = (ans + solve(index + 1, mask ^ (1 << i))) % m;
}
}
return dp[index][mask] = ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
cout << solve(0, (1 << n) - 1) << "\n";
} | [
"call.arguments.change"
] | 982,249 | 982,250 | u217234114 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) \
lower_bound(x.begin(), x.end(), z) - \
lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg) / ((double)360) * 2 * M_PI))
#define rad2deg(rad) ((((double)rad) / (double)2 / M_PI) * (double)360)
#define Find(set, element) set.find(element) != set.end()
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
#define endl "\n"
// debug用
#define PrintVec(x) \
for (auto elementPrintVec : x) { \
cout << elementPrintVec << " "; \
} \
cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
// gcj print用
#define Case(x) printf("Case #%d: ", x);
typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;
int POWINT(int x, int n) {
int ret = 1;
while (n > 0) {
if (n & 1)
ret *= x;
x *= x;
n >>= 1;
}
return ret;
};
ll POWLL(ll x, int n) {
ll ret = 1;
while (n > 0) {
if (n & 1)
ret *= x;
x *= x;
n >>= 1;
}
return ret;
};
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;
};
template <std::int_fast64_t Modulus> class modint {
using i64 = int_fast64_t;
public:
i64 a;
constexpr modint(const i64 x = 0) noexcept {
this->a = x % Modulus;
if (a < 0) {
a += Modulus;
}
}
// constexpr i64 &value() const noexcept {return a;}
constexpr const i64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
i64 a_ = rhs.a, b = Modulus, u = 1, v = 0;
while (b) {
i64 t = a_ / b;
a_ -= t * b;
swap(a_, b);
u -= t * v;
swap(u, v);
}
a = a * u % Modulus;
if (a < 0)
a += Modulus;
return *this;
}
// 自前実装
constexpr bool operator==(const modint rhs) noexcept { return a == rhs.a; }
constexpr bool operator!=(const modint rhs) noexcept { return a != rhs.a; }
constexpr bool operator>(const modint rhs) noexcept { return a > rhs.a; }
constexpr bool operator>=(const modint rhs) noexcept { return a >= rhs.a; }
constexpr bool operator<(const modint rhs) noexcept { return a < rhs.a; }
constexpr bool operator<=(const modint rhs) noexcept { return a <= rhs.a; }
// constexpr modint& operator++() noexcept {
// return (*this) += modint(1);
// }
// constexpr modint operator++(int) {
// modint tmp(*this);
// operator++();
// return tmp;
// }
// constexpr modint& operator--() noexcept {
// return (*this) -= modint(1);
// }
// constexpr modint operator--(int) {
// modint tmp(*this);
// operator--();
// return tmp;
// }
template <typename T>
friend constexpr modint modpow(const modint &mt, T n) noexcept {
if (n < 0) {
modint t = (modint(1) / mt);
return modpow(t, -n);
}
modint res = 1, tmp = mt;
while (n) {
if (n & 1)
res *= tmp;
tmp *= tmp;
n /= 2;
}
return res;
}
};
const ll MOD = 1e9 + 7;
using mint = modint<MOD>;
// 標準入出力対応
std::ostream &operator<<(std::ostream &out, const modint<MOD> &m) {
out << m.a;
return out;
}
std::istream &operator>>(std::istream &in, modint<MOD> &m) {
ll a;
in >> a;
m = mint(a);
return in;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vvi adj(N, vi(N));
rep(i, 0, N) {
rep(j, 0, N) { cin >> adj[i][j]; }
}
vector<mint> dp(1 << N);
dp[0] = mint(1);
rep(S, 1, 1 << N) {
int i = __builtin_popcount(S);
rep(j, 0, N) {
// i番目の男性がj番目の女性とマッチしたときの場合の数を足す
if (bit(S, j) == 1 && adj[i - 1][j] == 1) {
dp[S] += dp[S ^ (1 << j)];
}
}
}
// 配るdp
vector<vector<mint>> dp2(N, vector<mint>(1 << N));
dp2[0][0] = mint(1);
//一見するとO(2^N N^2)だけど……
rep(i, 0, N) {
rep(S, 0, 1 << N) {
if (dp2[i][S] > mint(0)) { //<-ここのif文の枝刈りが効いてO(2^N N)に落ちる
rep(j, 0, N) {
if (bit(S, j) == 0 && adj[i][j] == 1) {
dp2[i + 1][S ^ (1 << j)] += dp2[i][S];
}
}
}
}
}
// cout << dp[(1 << N) - 1] << endl;
cout << dp2[N][(1 << N) - 1] << endl;
return 0;
};
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) \
lower_bound(x.begin(), x.end(), z) - \
lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg) / ((double)360) * 2 * M_PI))
#define rad2deg(rad) ((((double)rad) / (double)2 / M_PI) * (double)360)
#define Find(set, element) set.find(element) != set.end()
#define bit(n, k) ((n >> k) & 1) // nのk bit目
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
#define endl "\n"
// debug用
#define PrintVec(x) \
for (auto elementPrintVec : x) { \
cout << elementPrintVec << " "; \
} \
cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
// gcj print用
#define Case(x) printf("Case #%d: ", x);
typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;
int POWINT(int x, int n) {
int ret = 1;
while (n > 0) {
if (n & 1)
ret *= x;
x *= x;
n >>= 1;
}
return ret;
};
ll POWLL(ll x, int n) {
ll ret = 1;
while (n > 0) {
if (n & 1)
ret *= x;
x *= x;
n >>= 1;
}
return ret;
};
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;
};
template <std::int_fast64_t Modulus> class modint {
using i64 = int_fast64_t;
public:
i64 a;
constexpr modint(const i64 x = 0) noexcept {
this->a = x % Modulus;
if (a < 0) {
a += Modulus;
}
}
// constexpr i64 &value() const noexcept {return a;}
constexpr const i64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
i64 a_ = rhs.a, b = Modulus, u = 1, v = 0;
while (b) {
i64 t = a_ / b;
a_ -= t * b;
swap(a_, b);
u -= t * v;
swap(u, v);
}
a = a * u % Modulus;
if (a < 0)
a += Modulus;
return *this;
}
// 自前実装
constexpr bool operator==(const modint rhs) noexcept { return a == rhs.a; }
constexpr bool operator!=(const modint rhs) noexcept { return a != rhs.a; }
constexpr bool operator>(const modint rhs) noexcept { return a > rhs.a; }
constexpr bool operator>=(const modint rhs) noexcept { return a >= rhs.a; }
constexpr bool operator<(const modint rhs) noexcept { return a < rhs.a; }
constexpr bool operator<=(const modint rhs) noexcept { return a <= rhs.a; }
// constexpr modint& operator++() noexcept {
// return (*this) += modint(1);
// }
// constexpr modint operator++(int) {
// modint tmp(*this);
// operator++();
// return tmp;
// }
// constexpr modint& operator--() noexcept {
// return (*this) -= modint(1);
// }
// constexpr modint operator--(int) {
// modint tmp(*this);
// operator--();
// return tmp;
// }
template <typename T>
friend constexpr modint modpow(const modint &mt, T n) noexcept {
if (n < 0) {
modint t = (modint(1) / mt);
return modpow(t, -n);
}
modint res = 1, tmp = mt;
while (n) {
if (n & 1)
res *= tmp;
tmp *= tmp;
n /= 2;
}
return res;
}
};
const ll MOD = 1e9 + 7;
using mint = modint<MOD>;
// 標準入出力対応
std::ostream &operator<<(std::ostream &out, const modint<MOD> &m) {
out << m.a;
return out;
}
std::istream &operator>>(std::istream &in, modint<MOD> &m) {
ll a;
in >> a;
m = mint(a);
return in;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vvi adj(N, vi(N));
rep(i, 0, N) {
rep(j, 0, N) { cin >> adj[i][j]; }
}
vector<mint> dp(1 << N);
dp[0] = mint(1);
rep(S, 1, 1 << N) {
int i = __builtin_popcount(S);
rep(j, 0, N) {
// i番目の男性がj番目の女性とマッチしたときの場合の数を足す
if (bit(S, j) == 1 && adj[i - 1][j] == 1) {
dp[S] += dp[S ^ (1 << j)];
}
}
}
// 配るdp
vector<vector<mint>> dp2(N + 1, vector<mint>(1 << N));
dp2[0][0] = mint(1);
//一見するとO(2^N N^2)だけど……
rep(i, 0, N) {
rep(S, 0, 1 << N) {
if (dp2[i][S] > mint(0)) { //<-ここのif文の枝刈りが効いてO(2^N N)に落ちる
rep(j, 0, N) {
if (bit(S, j) == 0 && adj[i][j] == 1) {
dp2[i + 1][S ^ (1 << j)] += dp2[i][S];
}
}
}
}
}
// cout << dp[(1 << N) - 1] << endl;
cout << dp2[N][(1 << N) - 1] << endl;
return 0;
};
| [
"assignment.change"
] | 982,347 | 982,348 | u987594251 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 1e7, M = 7 + 1e9;
int n, t;
ll dp[21][N];
vector<int> v[21];
map<int, bool> sorryIhaveaboyfriend;
ll cal(int i, int taken) {
if (i == n)
return 1;
ll &ret = dp[i][taken];
if (~ret)
return ret;
ret = 0;
f(j, 0, v[i].size()) {
if (!sorryIhaveaboyfriend[v[i][j]]) {
sorryIhaveaboyfriend[v[i][j]] = 1;
ret += cal(i + 1, taken | (1 << v[i][j]));
ret %= M;
sorryIhaveaboyfriend[v[i][j]] = 0;
}
}
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n;
f(i, 0, n) {
f(j, 0, n) {
cin >> t;
if (t)
v[i].push_back(j);
}
}
cout << cal(0, 0);
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 1e7, M = 7 + 1e9;
int n, t;
ll dp[21][2097152]; // (1 << 21)-1 the maximum number for the mask
vector<int> v[21];
map<int, bool> sorryIhaveaboyfriend;
ll cal(int i, int taken) {
if (i == n)
return 1;
ll &ret = dp[i][taken];
if (~ret)
return ret;
ret = 0;
f(j, 0, v[i].size()) {
if (!sorryIhaveaboyfriend[v[i][j]]) {
sorryIhaveaboyfriend[v[i][j]] = 1;
ret += cal(i + 1, taken | (1 << v[i][j]));
ret %= M;
sorryIhaveaboyfriend[v[i][j]] = 0;
}
}
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n;
f(i, 0, n) {
f(j, 0, n) {
cin >> t;
if (t)
v[i].push_back(j);
}
}
cout << cal(0, 0);
} | [
"identifier.replace.remove",
"literal.replace.add",
"variable_declaration.array_dimensions.change"
] | 982,349 | 982,350 | u148496542 | cpp |
p03174 | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1LL << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
int N, M, K, T, Q, H, W;
signed main() {
cin >> N;
vector<vector<int>> A(N, vector<int>(N));
rep(i, N) rep(j, N) cin >> A[i][j];
vector<int> B(N, 0);
rep(i, N) rep(j, N) B[i] += A[i][j];
vector<vector<int>> dp(N + 1, vector<int>(1 << N, 0));
dp[0][0] = 1;
rep(i, N) {
rep(b, 1 << N) {
bitset<21> bit(b);
if (bit.count() < i)
continue;
rep(k, N) {
if (!bit[k] && A[k][i]) {
int nb = b | (1 << k);
(dp[i + 1][nb] += dp[i][b]) %= MOD;
}
}
}
}
cout << dp[N][(1 << N) - 1] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1LL << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
int N, M, K, T, Q, H, W;
signed main() {
cin >> N;
vector<vector<int>> A(N, vector<int>(N));
rep(i, N) rep(j, N) cin >> A[i][j];
vector<int> B(N, 0);
rep(i, N) rep(j, N) B[i] += A[i][j];
vector<vector<int>> dp(N + 1, vector<int>(1 << N, 0));
dp[0][0] = 1;
rep(i, N) {
rep(b, 1 << N) {
bitset<21> bit(b);
if (bit.count() != i)
continue;
rep(k, N) {
if (!bit[k] && A[k][i]) {
int nb = b | (1 << k);
(dp[i + 1][nb] += dp[i][b]) %= MOD;
}
}
}
}
cout << dp[N][(1 << N) - 1] << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 982,353 | 982,354 | u537874719 | cpp |
p03174 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define pb push_back
#define size(v) (int)v.size()
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
ll power_mod(ll a, ll x) {
if (x == 0)
return 1;
ll y = power_mod(a, x / 2);
ll ans = (y * y) % mod;
if (x % 2)
ans = (ans * a) % mod;
return ans;
}
ll inv(ll a) { return power_mod(a, mod - 2); }
ll power(ll a, ll x) {
if (x == 0)
return 1;
ll y = power(a, x / 2);
ll ans = (y * y);
if (x % 2)
ans *= a;
return ans;
}
ll dp[(1 << 16) + 3];
int main() {
fast;
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
vector<int> dp(1 << n, 0);
dp[0] = 1;
for (int mask = 0; mask < (1 << n); mask++) {
int count_one = __builtin_popcount(mask);
for (int j = 0; j < n; j++) {
if (a[count_one][j]) {
if (!(mask & (1 << j))) {
dp[mask + (1 << j)] = (dp[mask + (1 << j)] + dp[mask]) % mod;
}
}
}
}
cout << dp[(1 << n) - 1] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v) v.begin(), v.end()
#define pb push_back
#define size(v) (int)v.size()
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
ll power_mod(ll a, ll x) {
if (x == 0)
return 1;
ll y = power_mod(a, x / 2);
ll ans = (y * y) % mod;
if (x % 2)
ans = (ans * a) % mod;
return ans;
}
ll inv(ll a) { return power_mod(a, mod - 2); }
ll power(ll a, ll x) {
if (x == 0)
return 1;
ll y = power(a, x / 2);
ll ans = (y * y);
if (x % 2)
ans *= a;
return ans;
}
ll dp[(1 << 16) + 3];
int main() {
fast;
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
vector<int> dp(1 << n, 0);
dp[0] = 1;
for (int mask = 0; mask < ((1 << n) - 1); mask++) {
int count_one = __builtin_popcount(mask);
for (int j = 0; j < n; j++) {
if (a[count_one][j]) {
if (!(mask & (1 << j))) {
dp[mask + (1 << j)] = (dp[mask + (1 << j)] + dp[mask]) % mod;
}
}
}
}
cout << dp[(1 << n) - 1] << endl;
} | [
"control_flow.loop.for.condition.change"
] | 982,369 | 982,370 | u742642200 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1000000007;
struct Mint {
// typedef long long LL;
LL x;
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 &i, Mint &a) {
i >> a.x;
return i;
}
ostream &operator<<(ostream &o, const Mint &a) {
o << a.x;
return o;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> mask(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int foo;
cin >> foo;
mask[i] |= foo << j;
}
}
vector<Mint> dp(1 << n);
dp[0] = 1;
for (int i = 0; i < (1 << n) - 1; i++) {
int k = __builtin_popcount(i);
for (int j = 0; j < n; j++) {
if ((mask[k] & (1 << j)) && !(i && (1 << j))) {
dp[i | (1 << j)] += dp[i];
}
}
}
cout << dp.back() << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1000000007;
struct Mint {
// typedef long long LL;
LL x;
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 &i, Mint &a) {
i >> a.x;
return i;
}
ostream &operator<<(ostream &o, const Mint &a) {
o << a.x;
return o;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> mask(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int foo;
cin >> foo;
mask[i] |= foo << j;
}
}
vector<Mint> dp(1 << n);
dp[0] = 1;
for (int i = 0; i < (1 << n) - 1; i++) {
int k = __builtin_popcount(i);
for (int j = 0; j < n; j++) {
if ((mask[k] & (1 << j)) && !(i & (1 << j))) {
dp[i | (1 << j)] += dp[i];
}
}
}
cout << dp.back() << '\n';
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 982,375 | 982,376 | u385825353 | cpp |
p03174 | #include <bits/stdc++.h>
typedef int64_t LL;
using namespace std;
const int N = 25;
const int mod = 1e9 + 7;
bool A[N][N];
int n;
int dp[N][1 << 21];
LL solve(int k, int used) {
if (k == n)
return 1LL;
if (dp[k][used] >= 0)
return dp[k][used];
LL res = 0;
for (int i = 0; i < n; i++) {
if (A[k][i] && !((used >> i) & 1)) {
used ^= (1 << i);
res += solve(k + 1, used);
res %= mod;
used ^= (1 << i);
}
}
return dp[k][used] = res;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%d", &A[i][j]);
}
}
memset(dp, sizeof(dp), -1);
int ans = solve(0, 0);
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
typedef int64_t LL;
using namespace std;
const int N = 25;
const int mod = 1e9 + 7;
bool A[N][N];
int n;
int dp[N][1 << 21];
LL solve(int k, int used) {
if (k == n)
return 1LL;
if (dp[k][used] >= 0)
return dp[k][used];
LL res = 0;
for (int i = 0; i < n; i++) {
if (A[k][i] && !((used >> i) & 1)) {
used ^= (1 << i);
res += solve(k + 1, used);
res %= mod;
used ^= (1 << i);
}
}
return dp[k][used] = res;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%d", &A[i][j]);
}
}
memset(dp, -1, sizeof(dp));
int ans = solve(0, 0);
printf("%d\n", ans);
return 0;
} | [
"call.arguments.add",
"call.arguments.change"
] | 982,377 | 982,378 | u385825353 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n;
int a[21];
int cnt[(1 << 21)];
int dp[(1 << 21)];
void builtin_popcount() {
for (int i = 1; i < (1 << 21); ++i) {
cnt[i] = cnt[i & (i - 1)] + 1;
}
}
int main() {
builtin_popcount();
cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int x;
cin >> x;
a[i] |= (x << j);
}
}
int N = (1 << 21) - 1;
dp[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (1 << n); ++j) {
if (cnt[j] != i) {
continue;
}
int k = (j ^ N) & a[i];
for (int l = k; l; l &= (l - 1)) {
int now = l & (-l);
dp[j | now] += dp[j];
if (dp[j | now] > mod) {
dp[j | now] -= mod;
}
}
}
}
cout << dp[N] << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n;
int a[21];
int cnt[(1 << 21)];
int dp[(1 << 21)];
void builtin_popcount() {
for (int i = 1; i < (1 << 21); ++i) {
cnt[i] = cnt[i & (i - 1)] + 1;
}
}
int main() {
builtin_popcount();
cin >> n;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int x;
cin >> x;
a[i] |= (x << j);
}
}
int N = (1 << n) - 1;
dp[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (1 << n); ++j) {
if (cnt[j] != i) {
continue;
}
int k = (j ^ N) & a[i];
for (int l = k; l; l &= (l - 1)) {
int now = l & (-l);
dp[j | now] += dp[j];
if (dp[j | now] > mod) {
dp[j | now] -= mod;
}
}
}
}
cout << dp[N] << '\n';
return 0;
} | [
"identifier.replace.add",
"literal.replace.remove",
"expression.operation.binary.change"
] | 982,379 | 982,380 | u734192058 | cpp |
p03174 | #include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fored(i, l, r) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout << #x << " " << x << el
#define ri(n) scanf("%d", &n)
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<char, int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const ll INF = LONG_LONG_MAX;
const int MAXN = 21;
const int mod = 1e9 + 7;
int can[MAXN][MAXN];
ll dp[int(1 << MAXN)];
int allmask;
int n;
ll go(int mask) {
int idx = __builtin_popcount(mask);
if (idx == n)
return (mask == allmask);
ll &r = dp[mask];
if (r != -1)
return r;
r = 0;
for (int i = 0; i < n; ++i) { // i es mujeres, idx es hombres
if (!((1 << i) & mask) && can[idx][i]) {
r += go(mask | (1 << i));
r %= mod;
}
}
return r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
memset(dp, -1, sizeof dp);
forn(i, n) forn(j, n) ri(can[i][j]);
allmask = (1 << n) - 1;
cout << go(0) << el;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)l; i <= (int)r; ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fored(i, l, r) for (int i = (int)r; i >= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout << #x << " " << x << el
#define ri(n) scanf("%d", &n)
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<char, int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const ll INF = LONG_LONG_MAX;
const int MAXN = 21;
const int mod = 1e9 + 7;
int can[MAXN][MAXN];
ll dp[int(1 << MAXN)];
int allmask;
int n;
ll go(int mask) {
int idx = __builtin_popcount(mask);
if (idx == n)
return (mask == allmask);
ll &r = dp[mask];
if (r != -1)
return r;
r = 0;
for (int i = 0; i < n; ++i) { // i es mujeres, idx es hombres
if (!((1 << i) & mask) && can[idx][i]) {
r += go(mask | (1 << i));
r %= mod;
}
}
return r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
memset(dp, -1, sizeof dp);
forn(i, n) forn(j, n) cin >> can[i][j];
allmask = (1 << n) - 1;
cout << go(0) << el;
}
| [
"call.arguments.change"
] | 982,384 | 982,385 | u440697133 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) \
for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) \
for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
ll dp[25][2101001];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vvll a(n, vll(n));
rep(i, n) rep(j, n) cin >> a[i][j];
dp[0][0] = 1;
rep(i, n) {
rep(s, 1 << n) if (dp[s]) {
rep(j, n) if ((s >> j & 1) == 0) {
if (a[i][j])
(dp[i + 1][s | (1 << j)] += dp[i][s]) %= MOD;
}
}
}
ll ans = dp[n][(1 << n) - 1];
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) \
for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) \
for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
ll dp[25][2101001];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vvll a(n, vll(n));
rep(i, n) rep(j, n) cin >> a[i][j];
dp[0][0] = 1;
rep(i, n) {
rep(s, 1 << n) if (dp[i][s]) {
rep(j, n) if ((s >> j & 1) == 0) {
if (a[i][j])
(dp[i + 1][s | (1 << j)] += dp[i][s]) %= MOD;
}
}
}
ll ans = dp[n][(1 << n) - 1];
cout << ans << endl;
} | [
"control_flow.branch.if.condition.change"
] | 982,408 | 982,409 | u530107518 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define prllarr(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define in(n) scanf("%lld", &n);
#define in2(x, y) scanf("%lld %lld", &(x), &(y));
#define in3(x, y, z) scanf("%lld %lld %lld", &(x), &(y), &(z));
#define out(n) printf("%lld\n", n);
#define out2(x, y) printf("%lld %lld\n", x, y);
#define test(t) \
ll t; \
in(t); \
while (t--)
#define set(arr, n, s) \
for (ll i = 0; i < n; i++) { \
arr[i] = s; \
}
ll power(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1) {
res = (res * x) % p;
}
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInverse(ll a, ll p) {
return power(a, p - 2, p);
} // used with feemat little
ll gcd(ll x, ll y) {
if (x == 0 || y == 0) {
return max(y, x);
}
return gcd(y % x, x);
}
ll gcdExtended(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
} // o(log(b))
;
void prac() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll n;
ll arr[21];
ll dp[1 << 21];
ll solve(ll mask) {
if (mask == (1 << n) - 1) {
return 1;
}
if (mask >= (1 << n))
return 0;
if (dp[mask] != -1)
return dp[mask];
ll index = __builtin_popcount(mask);
// cout<<index;
ll ans = 0;
for (ll i = 0; i < n; i++) {
// cout<<mask<<(1<<i)<<endl;
// cout<<i<<(arr[index]&(1<<i)) <<((mask&(1<<i))==0LL)<<endl;
if (arr[index] & (1 << i) && ((mask & (1 << i)) == 0LL)) {
ans += solve(mask | (1 << i));
ans %= mod;
}
}
dp[mask] = ans;
return ans;
}
int main() {
prac();
in(n)
// for(ll i=0;i<(1<<n);i++)dp[i]=-1;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
ll x;
in(x) if (x) { arr[i] |= (1 << j); }
}
}
dp[0] = 1;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < (1 << n); j++) {
if (__builtin_popcount(j) != i)
continue;
for (ll m = 0; m < n; m++) {
if (arr[i] & (1 << m) && (j & (1 << m)) == 0LL) {
// cout<<i<<" "<<m<<" "<<j<<endl;
dp[j | (1 << m)] += dp[j];
dp[j | (1 << m)] %= mod;
}
}
}
}
// prllarr(arr,7)
out(dp[(1 << n) - 1])
// ll ans=solve(0);
// out(ans)
}
/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
| #include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define prllarr(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define in(n) scanf("%lld", &n);
#define in2(x, y) scanf("%lld %lld", &(x), &(y));
#define in3(x, y, z) scanf("%lld %lld %lld", &(x), &(y), &(z));
#define out(n) printf("%lld\n", n);
#define out2(x, y) printf("%lld %lld\n", x, y);
#define test(t) \
ll t; \
in(t); \
while (t--)
#define set(arr, n, s) \
for (ll i = 0; i < n; i++) { \
arr[i] = s; \
}
ll power(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1) {
res = (res * x) % p;
}
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInverse(ll a, ll p) {
return power(a, p - 2, p);
} // used with feemat little
ll gcd(ll x, ll y) {
if (x == 0 || y == 0) {
return max(y, x);
}
return gcd(y % x, x);
}
ll gcdExtended(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
} // o(log(b))
;
void prac() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll n;
ll arr[21];
ll dp[1 << 21];
ll solve(ll mask) {
if (mask == (1 << n) - 1) {
return 1;
}
if (mask >= (1 << n))
return 0;
if (dp[mask] != -1)
return dp[mask];
ll index = __builtin_popcount(mask);
// cout<<index;
ll ans = 0;
for (ll i = 0; i < n; i++) {
// cout<<mask<<(1<<i)<<endl;
// cout<<i<<(arr[index]&(1<<i)) <<((mask&(1<<i))==0LL)<<endl;
if (arr[index] & (1 << i) && ((mask & (1 << i)) == 0LL)) {
ans += solve(mask | (1 << i));
ans %= mod;
}
}
dp[mask] = ans;
return ans;
}
int main() {
// prac();
in(n)
// for(ll i=0;i<(1<<n);i++)dp[i]=-1;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
ll x;
in(x) if (x) { arr[i] |= (1 << j); }
}
}
dp[0] = 1;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < (1 << n); j++) {
if (__builtin_popcount(j) != i)
continue;
for (ll m = 0; m < n; m++) {
if (arr[i] & (1 << m) && (j & (1 << m)) == 0LL) {
// cout<<i<<" "<<m<<" "<<j<<endl;
dp[j | (1 << m)] += dp[j];
dp[j | (1 << m)] %= mod;
}
}
}
}
// prllarr(arr,7)
out(dp[(1 << n) - 1])
// ll ans=solve(0);
// out(ans)
}
/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
| [
"call.remove"
] | 982,428 | 982,429 | u818356308 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define prllarr(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define in(n) scanf("%lld", &n);
#define in2(x, y) scanf("%lld %lld", &(x), &(y));
#define in3(x, y, z) scanf("%lld %lld %lld", &(x), &(y), &(z));
#define out(n) printf("%lld\n", n);
#define out2(x, y) printf("%lld %lld\n", x, y);
#define test(t) \
ll t; \
in(t); \
while (t--)
#define set(arr, n, s) \
for (ll i = 0; i < n; i++) { \
arr[i] = s; \
}
ll power(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1) {
res = (res * x) % p;
}
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInverse(ll a, ll p) {
return power(a, p - 2, p);
} // used with feemat little
ll gcd(ll x, ll y) {
if (x == 0 || y == 0) {
return max(y, x);
}
return gcd(y % x, x);
}
ll gcdExtended(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
} // o(log(b))
;
void prac() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll n;
ll arr[21];
ll dp[1 << 21];
ll solve(ll mask) {
if (mask == (1 << n) - 1) {
return 1;
}
if (mask >= (1 << n))
return 0;
if (dp[mask] != -1)
return dp[mask];
ll index = __builtin_popcount(mask);
// cout<<index;
ll ans = 0;
for (ll i = 0; i < n; i++) {
// cout<<mask<<(1<<i)<<endl;
// cout<<i<<(arr[index]&(1<<i)) <<((mask&(1<<i))==0LL)<<endl;
if (arr[index] & (1 << i) && ((mask & (1 << i)) == 0LL)) {
ans += solve(mask | (1 << i));
ans %= mod;
}
}
dp[mask] = ans;
return ans;
}
int main() {
prac();
in(n) for (ll i = 0; i < (1 << n); i++) dp[i] = -1;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
ll x;
in(x) if (x) { arr[i] |= (1 << j); }
}
}
ll ans = solve(0);
// prllarr(arr,7)
out(ans)
}
/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
| #include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define prllarr(a, n) \
for (ll i = 0; i < n; i++) \
cout << a[i] << " ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(0);
#define in(n) scanf("%lld", &n);
#define in2(x, y) scanf("%lld %lld", &(x), &(y));
#define in3(x, y, z) scanf("%lld %lld %lld", &(x), &(y), &(z));
#define out(n) printf("%lld\n", n);
#define out2(x, y) printf("%lld %lld\n", x, y);
#define test(t) \
ll t; \
in(t); \
while (t--)
#define set(arr, n, s) \
for (ll i = 0; i < n; i++) { \
arr[i] = s; \
}
ll power(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1) {
res = (res * x) % p;
}
y = y >> 1;
x = (x * x) % p;
}
return res;
}
ll modInverse(ll a, ll p) {
return power(a, p - 2, p);
} // used with feemat little
ll gcd(ll x, ll y) {
if (x == 0 || y == 0) {
return max(y, x);
}
return gcd(y % x, x);
}
ll gcdExtended(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
} // o(log(b))
;
void prac() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll n;
ll arr[21];
ll dp[1 << 21];
ll solve(ll mask) {
if (mask == (1 << n) - 1) {
return 1;
}
if (mask >= (1 << n))
return 0;
if (dp[mask] != -1)
return dp[mask];
ll index = __builtin_popcount(mask);
// cout<<index;
ll ans = 0;
for (ll i = 0; i < n; i++) {
// cout<<mask<<(1<<i)<<endl;
// cout<<i<<(arr[index]&(1<<i)) <<((mask&(1<<i))==0LL)<<endl;
if (arr[index] & (1 << i) && ((mask & (1 << i)) == 0LL)) {
ans += solve(mask | (1 << i));
ans %= mod;
}
}
dp[mask] = ans;
return ans;
}
int main() {
// prac();
in(n) for (ll i = 0; i < (1 << n); i++) dp[i] = -1;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < n; j++) {
ll x;
in(x) if (x) { arr[i] |= (1 << j); }
}
}
ll ans = solve(0);
// prllarr(arr,7)
out(ans)
}
/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/
| [
"call.remove"
] | 982,430 | 982,431 | u818356308 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d", &a)
#define MSB 63 - __builtin_clzll
#define scl(a) scanf("%lld", &a)
#define BITS __builtin_popcountll
#define mem(a, v) memset(a, v, sizeof(a))
#define fastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 55;
const int INF = 1e9 + 77;
const ll INFINF = 1e18 + 1e17;
const double PI = acos(-1.0);
vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll power(ll x, ll y) {
if (y == 0)
return 1;
ll s = power(x, y / 2);
s *= s;
if (y & 1)
s *= x;
return s;
}
int n;
bool x[22][22];
ll dp[10000000][22];
ll solve(int mask, int i) {
if (i == n) {
return 1;
}
ll &res = dp[mask][i];
if (res != -1) {
return res;
}
res = 0;
for (int j = 0; j < n; j++) {
int cur = n - 1 - j;
if (x[i][j] && !(mask & (1 << cur))) {
res += solve(mask + (1 << cur), i + 1) % MOD;
res %= MOD;
}
}
return res % MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt" , "r" , stdin);
// freopen("output.txt" , "w" , stdout);
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> x[i][j];
}
}
mem(dp, -1);
cout << solve(0, 0) % MOD;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define LSB __builtin_ctzll
#define sc(a) scanf("%d", &a)
#define MSB 63 - __builtin_clzll
#define scl(a) scanf("%lld", &a)
#define BITS __builtin_popcountll
#define mem(a, v) memset(a, v, sizeof(a))
#define fastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 55;
const int INF = 1e9 + 77;
const ll INFINF = 1e18 + 1e17;
const double PI = acos(-1.0);
vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ll power(ll x, ll y) {
if (y == 0)
return 1;
ll s = power(x, y / 2);
s *= s;
if (y & 1)
s *= x;
return s;
}
int n;
bool x[22][22];
ll dp[3000000][22];
ll solve(int mask, int i) {
if (i == n) {
return 1;
}
ll &res = dp[mask][i];
if (res != -1) {
return res;
}
res = 0;
for (int j = 0; j < n; j++) {
int cur = n - 1 - j;
if (x[i][j] && !(mask & (1 << cur))) {
res += solve(mask + (1 << cur), i + 1) % MOD;
res %= MOD;
}
}
return res % MOD;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt" , "r" , stdin);
// freopen("output.txt" , "w" , stdout);
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> x[i][j];
}
}
mem(dp, -1);
cout << solve(0, 0) % MOD;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 982,456 | 982,457 | u266944880 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;
const int mod = 1e9 + 7;
void add_self(ll x, ll y) {
x += y;
if (x > mod)
x -= mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<vector<ll>> a(n, vector<ll>(n));
vector<ll> dp(1 << n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cin >> a[i][j];
dp[0] = 1;
for (int mask = 1; mask < (1 << n) - 1; ++mask) {
int idx = __builtin_popcount(mask) - 1;
for (int i = 0; i < n; ++i) {
if (!(mask >> i) & 1 || !a[idx][i])
continue;
add_self(dp[mask], dp[mask - (1 << i)]);
}
}
cout << dp[(1 << n) - 1] << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;
const int mod = 1e9 + 7;
void add_self(ll &x, ll y) {
x += y;
if (x >= mod)
x -= mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<vector<ll>> a(n, vector<ll>(n));
vector<ll> dp(1 << n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cin >> a[i][j];
dp[0] = 1;
for (int mask = 1; mask < (1 << n); ++mask) {
int idx = __builtin_popcount(mask) - 1;
for (int i = 0; i < n; ++i) {
if (!((mask >> i) & 1) || !a[idx][i])
continue;
add_self(dp[mask], dp[mask - (1 << i)]);
}
}
cout << dp[(1 << n) - 1] << '\n';
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 982,458 | 982,459 | u403305794 | cpp |
p03174 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF = 1e+18 + 1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vl dy = {1, -1, 0, 1, -1, 1, 0, -1};
vl dp(1 << 21);
int main() {
dp[0] = 1;
ll n;
cin >> n;
vvl a(n, vl(n));
rep(i, n) { rep(j, n) cin >> a[i][j]; }
for (ll S = 1; S < (1 << 21); S++) {
ll i = __builtin_popcount(S);
rep(j, n) {
if ((S & (1 << j)) && a[i - 1][j])
dp[S] = (dp[S] + dp[S ^ (1 << j)]) % MOD;
}
}
ll ans = dp[(1 << n) - 1];
cout << ans << endl;
}
| //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF = 1e+18 + 1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vl dy = {1, -1, 0, 1, -1, 1, 0, -1};
vl dp(1 << 21);
int main() {
dp[0] = 1;
ll n;
cin >> n;
vvl a(n, vl(n));
rep(i, n) { rep(j, n) cin >> a[i][j]; }
for (ll S = 1; S < (1 << n); S++) {
ll i = __builtin_popcount(S);
rep(j, n) {
if ((S & (1 << j)) && a[i - 1][j])
dp[S] = (dp[S] + dp[S ^ (1 << j)]) % MOD;
}
}
ll ans = dp[(1 << n) - 1];
cout << ans << endl;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 982,460 | 982,461 | u614128939 | cpp |
p03174 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF = 1e+18 + 1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vl dy = {1, -1, 0, 1, -1, 1, 0, -1};
ll dp[1 << 21];
int main() {
dp[0] = 1;
ll n;
cin >> n;
vvl a(n, vl(n));
rep(i, n) { rep(j, n) cin >> a[i][j]; }
for (ll S = 1; S < (1 << 21); S++) {
ll i = __builtin_popcount(S);
rep(j, n) {
if ((S & (1 << j)) && a[i - 1][j])
dp[S] = (dp[S] + dp[S ^ (1 << j)]) % MOD;
}
}
ll ans = dp[(1 << n) - 1];
cout << ans << endl;
}
| //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF = 1e+18 + 1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vl dy = {1, -1, 0, 1, -1, 1, 0, -1};
vl dp(1 << 21);
int main() {
dp[0] = 1;
ll n;
cin >> n;
vvl a(n, vl(n));
rep(i, n) { rep(j, n) cin >> a[i][j]; }
for (ll S = 1; S < (1 << n); S++) {
ll i = __builtin_popcount(S);
rep(j, n) {
if ((S & (1 << j)) && a[i - 1][j])
dp[S] = (dp[S] + dp[S ^ (1 << j)]) % MOD;
}
}
ll ans = dp[(1 << n) - 1];
cout << ans << endl;
}
| [
"variable_declaration.type.change",
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 982,462 | 982,461 | u614128939 | cpp |
p03174 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
template <class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, n) for (int(i) = (a); (i) < (n); ++(i))
#define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); ++(i))
#define rFOR(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define erFOR(i, a, n) for (int(i) = (n); (i) >= (a); --(i))
#define each(i, a) for (auto &i : a)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
#define all(i) (i).begin(), (i).end()
#define out(y, x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n"
#define ENDL(i, n) ((i) == (n)-1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
for (auto &elemnt : v)
is >> elemnt;
return is;
}
template <class T, class U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> inline vector<T> vec(size_t a) { return vector<T>(a); }
template <class T> inline vector<T> defvec(T def, size_t a) {
return vector<T>(a, def);
}
template <class T, class... Ts> inline auto vec(size_t a, Ts... ts) {
return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));
}
template <class T, class... Ts> inline auto defvec(T def, size_t a, Ts... ts) {
return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...));
}
int n;
vector<VI> a;
VL memo;
ll solve(int bit) {
if (bit == (1 << n) - 1)
return 1LL;
if (memo[bit] != -1)
return memo[bit];
int k = 0;
FOR(i, 0, n) if (bit & (1 << i))++ k;
ll ret = 0;
FOR(i, 0, n) {
if (bit & (1 << i))
continue;
if (a[k][i] == 0)
continue;
(ret += solve(bit | (1 << i))) %= mod;
}
return memo[bit] = ret;
}
int main() {
init();
cin >> n;
a = vec<int>(n, n);
cin >> a;
memo.resize(1 << n);
cout << solve(0) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
template <class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, n) for (int(i) = (a); (i) < (n); ++(i))
#define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); ++(i))
#define rFOR(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define erFOR(i, a, n) for (int(i) = (n); (i) >= (a); --(i))
#define each(i, a) for (auto &i : a)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
#define all(i) (i).begin(), (i).end()
#define out(y, x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n"
#define ENDL(i, n) ((i) == (n)-1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
for (auto &elemnt : v)
is >> elemnt;
return is;
}
template <class T, class U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> inline vector<T> vec(size_t a) { return vector<T>(a); }
template <class T> inline vector<T> defvec(T def, size_t a) {
return vector<T>(a, def);
}
template <class T, class... Ts> inline auto vec(size_t a, Ts... ts) {
return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));
}
template <class T, class... Ts> inline auto defvec(T def, size_t a, Ts... ts) {
return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...));
}
int n;
vector<VI> a;
VL memo;
ll solve(int bit) {
if (bit == (1 << n) - 1)
return 1LL;
if (memo[bit] != -1)
return memo[bit];
int k = 0;
FOR(i, 0, n) if (bit & (1 << i))++ k;
ll ret = 0;
FOR(i, 0, n) {
if (bit & (1 << i))
continue;
if (a[k][i] == 0)
continue;
(ret += solve(bit | (1 << i))) %= mod;
}
return memo[bit] = ret;
}
int main() {
init();
cin >> n;
a = vec<int>(n, n);
cin >> a;
memo.resize(1 << n, -1);
cout << solve(0) << "\n";
}
| [
"call.arguments.add"
] | 982,473 | 982,474 | u863044225 | cpp |
p03174 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#define INF 1100000000000
#define MAX 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> p;
typedef pair<pair<int, int>, int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
//__builtin_popcount(S)
ll dp[1 << 22];
int main() {
int N, a[22][22];
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
cin >> a[i][j];
}
dp[0] = 1;
for (int S = 2; S < (1 << N); S++) {
for (int i = 0; i < N; i++) {
if (bit(S, i)) {
int num = __builtin_popcount(S);
num--;
if (a[num][i] == 0)
continue;
dp[S] += dp[S ^ (1 << i)];
dp[S] %= MOD;
}
}
// return 0;
}
// cout<<dp[2]<<endl;
cout << dp[(1 << N) - 1] << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#define INF 1100000000000
#define MAX 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> p;
typedef pair<pair<int, int>, int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
//__builtin_popcount(S)
ll dp[1 << 22];
int main() {
int N, a[22][22];
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
cin >> a[i][j];
}
dp[0] = 1;
for (int S = 1; S < (1 << N); S++) {
for (int i = 0; i < N; i++) {
if (bit(S, i)) {
int num = __builtin_popcount(S);
num--;
if (a[num][i] == 0)
continue;
dp[S] += dp[S ^ (1 << i)];
dp[S] %= MOD;
}
}
// return 0;
}
// cout<<dp[2]<<endl;
cout << dp[(1 << N) - 1] << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 982,483 | 982,484 | u591914971 | cpp |
p03174 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
using namespace std;
int a[22][22];
long long dp[22][2107152];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
dp[0][0] = 1;
int nnn = 1 << n;
for (int i = 0; i < n; i++) {
for (int mask = 0; mask < nnn; mask++) {
if (__builtin_popcount(mask) != n)
continue;
for (int j = 0; j < n; j++) {
if (a[i][j] && (mask & (1 << j)) == 0) {
int newMask = mask | (1 << j);
dp[i + 1][newMask] += dp[i][mask];
if (dp[i + 1][newMask] >= MOD) {
dp[i + 1][newMask] -= MOD;
}
}
}
}
}
cout << dp[n][(1 << n) - 1];
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
using namespace std;
int a[22][22];
long long dp[22][2107152];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
dp[0][0] = 1;
int nnn = 1 << n;
for (int i = 0; i < n; i++) {
for (int mask = 0; mask < nnn; mask++) {
if (__builtin_popcount(mask) != i)
continue;
for (int j = 0; j < n; j++) {
if (a[i][j] && (mask & (1 << j)) == 0) {
int newMask = mask | (1 << j);
dp[i + 1][newMask] += dp[i][mask];
if (dp[i + 1][newMask] >= MOD) {
dp[i + 1][newMask] -= MOD;
}
}
}
}
}
cout << dp[n][(1 << n) - 1];
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 982,488 | 982,489 | u173526104 | cpp |
p03174 | #include <bits/stdc++.h>
#include <iostream>
#define db(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fr(i, a, n) for (int i = a; i <= (n); ++i)
#define rf(i, a, n) for (int i = a; i >= (n); --i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define _ << " " <<
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<int, pair<int, int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
vector<bool> vis;
vvi dp;
ll matching(vvi a, int mask, int n) {
if (n == 0)
return 1;
if (mask == 0)
return 0;
if (dp[n][mask] != -1)
return dp[n][mask];
ll val = 0;
// db(mask);
for (int i = 0; i < a.size(); i++) {
// db2(a[n-1][i],(mask&(1<<i)));
if (a[n - 1][i] && !(mask & (1 << i))) {
// db2(n,mask);
val += matching(a, mask ^ (1 << i), n - 1);
val %= mod;
}
}
dp[n][mask] = val % mod;
// db(val);
return dp[n][mask];
}
int main() {
int n;
cin >> n;
vvi a(n, vi(n, 0));
int mask = 0;
for (int i = 0; i < n; i++) {
mask |= (1 << i);
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
dp.clear();
dp.resize(n + 1, vi(1 << n, -1));
cout << matching(a, mask, n);
// dp.resize(n,vi(n,1e18));
// for(int i=0;i<=n;i++){
// for(int j=0;j<=n;j++){
// if(i==j){
// dp[i][j]=i;
// }
// }
// }
// cout<<dp[0][n-1]<<endl;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#define db(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fr(i, a, n) for (int i = a; i <= (n); ++i)
#define rf(i, a, n) for (int i = a; i >= (n); --i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define _ << " " <<
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<int, pair<int, int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
vector<bool> vis;
vvi dp;
ll matching(vvi &a, int mask, int n) {
if (n == 0)
return 1;
if (mask == 0)
return 0;
if (dp[n][mask] != -1)
return dp[n][mask];
ll val = 0;
// db(mask);
for (int i = 0; i < a.size(); i++) {
// db2(a[n-1][i],(mask&(1<<i)));
if (a[n - 1][i] && (mask & (1 << i))) {
// db2(n,mask);
val += matching(a, mask ^ (1 << i), n - 1);
val %= mod;
}
}
dp[n][mask] = val % mod;
// db(val);
return dp[n][mask];
}
int main() {
int n;
cin >> n;
vvi a(n, vi(n, 0));
int mask = 0;
for (int i = 0; i < n; i++) {
mask |= (1 << i);
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
}
}
dp.clear();
dp.resize(n + 1, vi(1 << n, -1));
cout << matching(a, mask, n);
// dp.resize(n,vi(n,1e18));
// for(int i=0;i<=n;i++){
// for(int j=0;j<=n;j++){
// if(i==j){
// dp[i][j]=i;
// }
// }
// }
// cout<<dp[0][n-1]<<endl;
return 0;
}
| [
"expression.operation.unary.logical.remove",
"control_flow.branch.if.condition.change"
] | 982,494 | 982,493 | u290440425 | cpp |
p03174 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
inline long long po(int n) {
long long ans = 1;
for (int i = 0; i < n; i++) {
ans *= 2;
}
return ans;
}
inline long long bac(vector<bool> ju) {
long long ans = 0;
long long di = 1;
for (int i = 0; i < ju.size(); i++) {
if (ju[i]) {
ans += di;
}
di *= 2;
}
return ans;
}
inline void cha(long long n, vector<bool> &ju) {
for (int i = 0; i < ju.size(); i++) {
ju[i] = n % 2;
n /= 2;
}
}
int main() {
int n;
cin >> n;
vector<vector<int>> da(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> da[i][j];
}
}
vector<long long> mo(n);
mo[0] = 1;
for (int i = 0; i < n - 1; i++) {
mo[i + 1] = mo[i] * 2;
}
int x = po(n);
vector<long long> dp(x, 0);
dp[0] = 1;
for (long long i = 1; i < x; i++) {
vector<bool> ju(n);
cha(i, ju);
int co = -1;
long long me = 0, gg = 0;
for (int j = 0; j < n; j++) {
if (ju[j]) {
gg += mo[j];
co++;
}
}
for (int j = 0; j < n; j++) {
if (ju[j] & da[co][j]) {
me += dp[gg - mo[j]];
}
}
dp[i] = me % 1000000007;
}
printf("%lld", dp[n - 1]);
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
inline long long po(int n) {
long long ans = 1;
for (int i = 0; i < n; i++) {
ans *= 2;
}
return ans;
}
inline long long bac(vector<bool> ju) {
long long ans = 0;
long long di = 1;
for (int i = 0; i < ju.size(); i++) {
if (ju[i]) {
ans += di;
}
di *= 2;
}
return ans;
}
inline void cha(long long n, vector<bool> &ju) {
for (int i = 0; i < ju.size(); i++) {
ju[i] = n % 2;
n /= 2;
}
}
int main() {
int n;
cin >> n;
vector<vector<int>> da(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> da[i][j];
}
}
vector<long long> mo(n);
mo[0] = 1;
for (int i = 0; i < n - 1; i++) {
mo[i + 1] = mo[i] * 2;
}
int x = po(n);
vector<long long> dp(x, 0);
dp[0] = 1;
for (long long i = 1; i < x; i++) {
vector<bool> ju(n);
cha(i, ju);
int co = -1;
long long me = 0, gg = 0;
for (int j = 0; j < n; j++) {
if (ju[j]) {
gg += mo[j];
co++;
}
}
for (int j = 0; j < n; j++) {
if (ju[j] & da[co][j]) {
me += dp[gg - mo[j]];
}
}
dp[i] = me % 1000000007;
}
printf("%lld", dp[x - 1]);
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 982,503 | 982,504 | u057079894 | cpp |
p03174 | #include "bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define MOD 1000000007
int N, a[21][21];
LL dp[21][1 << 21];
LL solve(int now, int state) {
if (now == N)
return 1LL;
if (dp[now][state] != -1)
return dp[now][state];
LL ans = 0;
for (int i = 0; i < N; i++) {
if ((state >> i) & 1 == 0 && a[now][i] == 1)
ans += solve(now + 1, state + (1 << i));
ans %= MOD;
}
return dp[now][state] = ans;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> a[i][j];
}
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = -1;
}
}
cout << solve(0, 0) << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define MOD 1000000007LL
int N, a[21][21];
LL dp[21][1 << 21];
LL solve(int now, int state) {
if (now == N)
return 1LL;
if (dp[now][state] != -1)
return dp[now][state];
LL ans = 0;
for (int i = 0; i < N; i++) {
if ((state >> i) % 2 == 0 && a[now][i] == 1)
ans += solve(now + 1, state + (1 << i));
ans %= MOD;
}
return dp[now][state] = ans;
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> a[i][j];
}
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = -1;
}
}
cout << solve(0, 0) << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change"
] | 982,524 | 982,525 | u422592877 | cpp |
p03174 | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 21
#define MOD 1000000007
int N;
long long dp[MAXN][1 << MAXN];
int m[MAXN][MAXN];
int d(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = 0;
for (int k = 0; k < N; k++) {
if (m[i][k] == 1 && (j & (1 << k))) {
dp[i][j] = (dp[i][j] + dp[i - 1][j ^ (1 << k)]) % MOD;
}
}
return dp[i][j];
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> m[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = -1;
}
}
for (int i = 0; i < (1 << N); i++) {
dp[0][i] = 0;
for (int j = 0; j < N; j++) {
if (m[0][j] == 1 && (i & (1 << j))) {
dp[0][i]++;
}
}
}
cout << d(N - 1, (1 << N) - 1) << endl;
} | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 21
#define MOD 1000000007
int N;
long long dp[MAXN][1 << MAXN];
int m[MAXN][MAXN];
int d(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = 0;
for (int k = 0; k < N; k++) {
if (m[i][k] == 1 && (j & (1 << k))) {
dp[i][j] = (dp[i][j] + d(i - 1, j ^ (1 << k))) % MOD;
}
}
return dp[i][j];
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> m[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = -1;
}
}
for (int i = 0; i < (1 << N); i++) {
dp[0][i] = 0;
for (int j = 0; j < N; j++) {
if (m[0][j] == 1 && (i & (1 << j))) {
dp[0][i]++;
}
}
}
cout << d(N - 1, (1 << N) - 1) << endl;
} | [
"assignment.value.change",
"expression.operation.binary.change"
] | 982,532 | 982,533 | u719290158 | cpp |
p03174 | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 21
#define MOD 1000000007
int N;
long long dp[MAXN][1 << MAXN];
int m[MAXN][MAXN];
int d(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = 0;
for (int k = 0; k < N; k++) {
if (m[i][k] == 1 && (j & (1 << k))) {
dp[i][j] = (dp[i][j] + dp[i - 1][j ^ (1 << k)]) % MOD;
}
}
return dp[i][j];
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> m[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = -1;
}
}
for (int i = 0; i < (1 << N); i++) {
dp[0][i] = 0;
for (int j = 0; j < N; j++) {
if (m[i][j] == 1 && (i & (1 << j))) {
dp[0][i]++;
}
}
}
cout << d(N - 1, (1 << N) - 1) << endl;
} | #include <cmath>
#include <iostream>
using namespace std;
#define MAXN 21
#define MOD 1000000007
int N;
long long dp[MAXN][1 << MAXN];
int m[MAXN][MAXN];
int d(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = 0;
for (int k = 0; k < N; k++) {
if (m[i][k] == 1 && (j & (1 << k))) {
dp[i][j] = (dp[i][j] + d(i - 1, j ^ (1 << k))) % MOD;
}
}
return dp[i][j];
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> m[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < (1 << N); j++) {
dp[i][j] = -1;
}
}
for (int i = 0; i < (1 << N); i++) {
dp[0][i] = 0;
for (int j = 0; j < N; j++) {
if (m[0][j] == 1 && (i & (1 << j))) {
dp[0][i]++;
}
}
}
cout << d(N - 1, (1 << N) - 1) << endl;
} | [
"assignment.value.change",
"expression.operation.binary.change",
"identifier.replace.remove",
"literal.replace.add",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 982,534 | 982,533 | u719290158 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 405;
typedef long long ll;
int A[maxn];
ll ta[maxn], memo[maxn][maxn];
ll solve(int l, int r) {
if (l + 1 == r)
return A[l] + A[r];
if (l == r)
return 0;
if (l > r)
return 0;
ll &ans = memo[l][r];
if (ans != -1)
return ans;
ans = LLONG_MAX;
ll c = ta[r] + ta[l - 1];
for (int k = l + 1; k < r; k++) {
ans = min(ans, solve(l, k) + solve(k + 1, r));
}
return (ans = (ans + c));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen(".in","r",stdin);
int N;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> A[i];
ta[i] = A[i] + ta[i - 1];
}
memset(memo, -1, sizeof memo);
cout << solve(1, N);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 405;
typedef long long ll;
int A[maxn];
ll ta[maxn], memo[maxn][maxn];
ll solve(int l, int r) {
if (l + 1 == r)
return A[l] + A[r];
if (l == r)
return 0;
if (l > r)
return 0;
ll &ans = memo[l][r];
if (ans != -1)
return ans;
ans = LLONG_MAX;
ll c = ta[r] - ta[l - 1];
for (int k = l; k < r; k++) {
ans = min(ans, solve(l, k) + solve(k + 1, r));
}
return (ans = (ans + c));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> A[i];
ta[i] = A[i] + ta[i - 1];
}
memset(memo, -1, sizeof memo);
cout << solve(1, N);
return 0;
}
| [
"misc.opposites",
"expression.operator.arithmetic.change",
"expression.operation.binary.change",
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 982,539 | 982,540 | u303586394 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
const int mx = 405;
typedef long long ll;
const ll INF = 1e18 + 5LL;
ll dp[mx][mx]; // dp[i][j] - min cost to merge range i to j in one slime]
int main() {
int n;
cin >> n;
int a[n], sum[n] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i > 0)
sum[i] = sum[i - 1] + a[i];
else
sum[i] = a[i];
}
for (int i = n - 1; i >= 0; i--) {
for (int j = i; j < n; j++) {
if (i == j)
dp[i][j] = 0;
else {
dp[i][j] = INF;
for (int k = i; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
}
dp[i][j] += sum[j] - ((i > 0) ? sum[i - 1] : 0);
}
}
}
/*
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<dp[i][j]<<" ";
}cout<<"\n";
}
*/
printf("%d\n", dp[0][n - 1]);
} | #include <bits/stdc++.h>
using namespace std;
const int mx = 405;
typedef long long ll;
const ll INF = 1e18 + 5LL;
ll dp[mx][mx]; // dp[i][j] - min cost to merge range i to j in one slime
int main() {
int n;
cin >> n;
ll a[n], sum[n] = {};
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i > 0)
sum[i] = sum[i - 1] + a[i];
else
sum[i] = a[i];
}
for (int i = n - 1; i >= 0; i--) {
for (int j = i; j < n; j++) {
if (i == j)
dp[i][j] = 0;
else {
dp[i][j] = INF;
for (int k = i; k < j; k++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
}
dp[i][j] += sum[j] - ((i > 0) ? sum[i - 1] : 0);
}
}
}
/*
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<dp[i][j]<<" ";
}cout<<"\n";
}
*/
printf("%lld", dp[0][n - 1]);
} | [
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change",
"io.output.change",
"io.output.newline.remove"
] | 982,541 | 982,542 | u446828913 | cpp |
p03173 | #include <iostream>
#include <stdio.h>
using namespace std;
int n;
int main() {
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
long long
dp[n][n]; // for(int i=0; i<n; i++) for(int j=0; j<n; j++) dp[i][j]=1e18;
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i < n; i++)
arr[i] += arr[i - 1];
for (int wid = 2; wid <= n; wid++) {
for (int i = 0; i <= n - wid; i++) {
long long minm = 1e18;
long long cur;
for (int j = i; j < i + wid - 1; j++) {
cur = dp[i][j] + dp[j + 1][i + wid - 1] + arr[i + wid - 1];
if (i > 0)
cur -= arr[i - 1];
minm = min(cur, minm);
}
dp[i][i + wid - 1] = minm;
}
}
cout << dp[0][n - 1] << endl;
}
| #include <iostream>
#include <stdio.h>
using namespace std;
int n;
int main() {
cin >> n;
long long arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
long long
dp[n][n]; // for(int i=0; i<n; i++) for(int j=0; j<n; j++) dp[i][j]=1e18;
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i < n; i++)
arr[i] += arr[i - 1];
for (int wid = 2; wid <= n; wid++) {
for (int i = 0; i <= n - wid; i++) {
long long minm = 1e18;
long long cur;
for (int j = i; j < i + wid - 1; j++) {
cur = dp[i][j] + dp[j + 1][i + wid - 1] + arr[i + wid - 1];
if (i > 0)
cur -= arr[i - 1];
minm = min(cur, minm);
}
dp[i][i + wid - 1] = minm;
}
}
cout << dp[0][n - 1] << endl;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 982,545 | 982,546 | u297798194 | cpp |
p03173 | #include <iostream>
#include <stdio.h>
using namespace std;
int n;
int main() {
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
long long
dp[n][n]; // for(int i=0; i<n; i++) for(int j=0; j<n; j++) dp[i][j]=1e18;
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i < n; i++)
arr[i] += arr[i - 1];
for (int wid = 2; wid <= n; wid++) {
for (int i = 0; i <= n - wid; i++) {
long long minm = 1e18;
long long cur;
for (int j = i; j < i + wid - 1; j++) {
cur = dp[i][j] + dp[j + 1][i + wid - 1] + arr[i + wid - 1];
if (i > 1)
cur -= arr[i - 1];
minm = min(cur, minm);
}
dp[i][i + wid - 1] = minm;
}
}
cout << dp[0][n - 1] << endl;
}
| #include <iostream>
#include <stdio.h>
using namespace std;
int n;
int main() {
cin >> n;
long long arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
long long
dp[n][n]; // for(int i=0; i<n; i++) for(int j=0; j<n; j++) dp[i][j]=1e18;
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i < n; i++)
arr[i] += arr[i - 1];
for (int wid = 2; wid <= n; wid++) {
for (int i = 0; i <= n - wid; i++) {
long long minm = 1e18;
long long cur;
for (int j = i; j < i + wid - 1; j++) {
cur = dp[i][j] + dp[j + 1][i + wid - 1] + arr[i + wid - 1];
if (i > 0)
cur -= arr[i - 1];
minm = min(cur, minm);
}
dp[i][i + wid - 1] = minm;
}
}
cout << dp[0][n - 1] << endl;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 982,547 | 982,546 | u297798194 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
long long f[401][401], sum[401];
int main() {
int i, j, n, s, k;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", &sum[i]);
sum[i] += sum[i - 1];
}
for (s = 1; s < n; s++) {
for (i = 1; i <= n - s; i++) {
j = s + i;
f[i][j] = 0x7fffffffffffffffff;
for (k = i; k < j; k++) {
f[i][j] = min(f[i][j], f[i][k] + sum[j] - sum[i - 1] + f[k + 1][j]);
// printf("---%d %d %d %d\n",i,j,k,f[i][j]);
}
}
}
// for(i=1;i<n;i++)
// for(j=1;j<=n;j++)
// printf("%d %d %d\n",i,j,f[i][j]);
printf("%lld", f[1][n]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long f[401][401], sum[401];
int main() {
int i, j, n, s, k;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", &sum[i]);
sum[i] += sum[i - 1];
}
for (s = 1; s < n; s++) {
for (i = 1; i <= n - s; i++) {
j = s + i;
f[i][j] = 0x7fffffffffffffff;
for (k = i; k < j; k++) {
f[i][j] = min(f[i][j], f[i][k] + sum[j] - sum[i - 1] + f[k + 1][j]);
// printf("---%d %d %d %d\n",i,j,k,f[i][j]);
}
}
}
// for(i=1;i<n;i++)
// for(j=1;j<=n;j++)
// printf("%d %d %d\n",i,j,f[i][j]);
printf("%lld", f[1][n]);
return 0;
} | [
"literal.number.change",
"assignment.value.change"
] | 982,552 | 982,553 | u511639787 | cpp |
p03173 | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 1e9
typedef long long ll;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
ll a[444];
bool flag[444][444];
ll cum[444];
ll dp[444][444];
ll f(int l, int r) {
if (flag[l][r])
return dp[l][r];
flag[l][r] = true;
if (l >= r)
return 0;
ll fans = INF;
REP(i, l, r) { chmin(fans, f(l, i) + f(i + 1, r)); }
return dp[l][r] = fans + cum[r] - cum[l - 1];
}
int main(void) {
int N;
cin >> N;
REP(i, 1, N + 1) { cin >> a[i]; }
cum[0] = 0;
REP(i, 1, N + 1) { cum[i] = cum[i - 1] + a[i]; }
cout << f(1, N) << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 1LL << 55
typedef long long ll;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
ll a[444];
bool flag[444][444];
ll cum[444];
ll dp[444][444];
ll f(int l, int r) {
if (flag[l][r])
return dp[l][r];
flag[l][r] = true;
if (l >= r)
return 0;
ll fans = INF;
REP(i, l, r) { chmin(fans, f(l, i) + f(i + 1, r)); }
return dp[l][r] = fans + cum[r] - cum[l - 1];
}
int main(void) {
int N;
cin >> N;
REP(i, 1, N + 1) { cin >> a[i]; }
cum[0] = 0;
REP(i, 1, N + 1) { cum[i] = cum[i - 1] + a[i]; }
cout << f(1, N) << "\n";
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 982,560 | 982,561 | u245487028 | cpp |
p03173 | #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
typedef long long ll;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
ll a[444];
bool flag[444][444];
ll cum[444];
ll dp[444][444];
ll f(int l, int r) {
if (flag[l][r])
return dp[l][r];
flag[l][r] = true;
if (l == r)
return 0;
ll fans = INF;
REP(i, l, r) { chmin(fans, f(l, i) + f(i + 1, r)); }
return dp[l][r] = fans + cum[r] - cum[l - 1];
}
int main(void) {
int N;
cin >> N;
REP(i, 1, N + 1) { cin >> a[i]; }
cum[0] = 0;
REP(i, 1, N + 1) { cum[i] = cum[i - 1] + a[i]; }
cout << f(1, N) << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(v) v.begin(), v.end()
#define INF 1LL << 55
typedef long long ll;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
ll a[444];
bool flag[444][444];
ll cum[444];
ll dp[444][444];
ll f(int l, int r) {
if (flag[l][r])
return dp[l][r];
flag[l][r] = true;
if (l >= r)
return 0;
ll fans = INF;
REP(i, l, r) { chmin(fans, f(l, i) + f(i + 1, r)); }
return dp[l][r] = fans + cum[r] - cum[l - 1];
}
int main(void) {
int N;
cin >> N;
REP(i, 1, N + 1) { cin >> a[i]; }
cum[0] = 0;
REP(i, 1, N + 1) { cum[i] = cum[i - 1] + a[i]; }
cout << f(1, N) << "\n";
return 0;
}
| [
"preprocessor.define.value.change",
"literal.integer.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 982,563 | 982,561 | u245487028 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;
using ll = long long;
ll mod(ll a, ll b) { return (a % b + b) % b; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void Judge(bool b) { b ? Yes() : No(); }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void JUDGE(bool b) { b ? YES() : NO(); }
ll powMod(ll b, ll e, ll m) {
ll r = 1;
while (e > 0) {
if (e & 1)
r = (r % m) * (b % m) % m;
b = (b % m) * (b % m) % m;
e >>= 1;
}
return r;
}
double distance(ll x1, ll y1, ll x2, ll y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
template <typename T> void ppp(T n) { cout << n << endl; }
ll dp[401][401];
ll sum[401];
ll rec(int l, int r) {
if (dp[l][r] >= 0)
return dp[l][r];
if (l == r)
return 0LL;
ll ans = MOD;
for (int i = l; i < r; ++i) {
ans = min(ans, rec(l, i) + rec(i + 1, r));
}
return dp[l][r] = ans + sum[r] - sum[l - 1];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
fill_n(*dp, 401 * 401, -1);
sum[0] = 0LL;
rep(i, n) {
ll a;
cin >> a;
sum[i + 1] = sum[i] + a;
}
ppp(rec(1, n));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
const char sp = ' ';
const char cmm = ',';
const int MOD = 1000000007;
using ll = long long;
ll mod(ll a, ll b) { return (a % b + b) % b; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void Judge(bool b) { b ? Yes() : No(); }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void JUDGE(bool b) { b ? YES() : NO(); }
ll powMod(ll b, ll e, ll m) {
ll r = 1;
while (e > 0) {
if (e & 1)
r = (r % m) * (b % m) % m;
b = (b % m) * (b % m) % m;
e >>= 1;
}
return r;
}
double distance(ll x1, ll y1, ll x2, ll y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
template <typename T> void ppp(T n) { cout << n << endl; }
ll dp[401][401];
ll sum[401];
ll rec(int l, int r) {
if (dp[l][r] >= 0)
return dp[l][r];
if (l == r)
return 0LL;
ll ans = LLONG_MAX;
for (int i = l; i < r; ++i) {
ans = min(ans, rec(l, i) + rec(i + 1, r));
}
return dp[l][r] = ans + sum[r] - sum[l - 1];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
fill_n(*dp, 401 * 401, -1);
sum[0] = 0LL;
rep(i, n) {
ll a;
cin >> a;
sum[i + 1] = sum[i] + a;
}
ppp(rec(1, n));
return 0;
}
| [
"variable_declaration.value.change",
"identifier.change"
] | 982,564 | 982,565 | u306142032 | cpp |
p03173 | #include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define read() freopen("fibsubseq.in", "r", stdin)
#define write() freopen("fibsubseq.out", "w", stdout)
#define sf(n) scanf("%d", &n)
#define sfd(n) scanf("%lf", &n)
#define sl(x) scanf("%I64d", &x)
#define sfl(n) scanf("%lld", &n)
#define sfc(n) scanf(" %c", &n)
#define sful(n) scanf("%llu", &n)
#define ull unsigned long long int
#define endll printf("\n")
#define pf printf
#define pi acos(-1.0)
#define eps 1e-10
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define xx first
#define yy second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MP make_pair
#define ll long long
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
bool Check(unsigned int N, int pos) { return (bool)(N & (1LL << pos)); }
ll Set(unsigned int N, int pos) { return N = N | (1LL << pos); }
#define cnd tree[idx]
#define lnd tree[idx << 1]
#define rnd tree[(idx << 1) + 1]
#define lndp (idx << 1), (b), ((b + e) >> 1)
#define rndp ((idx << 1) + 1), (((b + e) >> 1) + 1), (e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define mod1 1000000009
#define var int ii, i, j, k, z = 0, c = 0, t, x, y, l, r, mid
// int dx[8]={0,0,1,1,-1,-1,1,-1}; //8 direction
// int dy[8]={1,-1,1,-1,1,-1,0,0};
bool chk(ll x, ll pos) { return (bool)(x & (1 << pos)); }
ll Set(ll x, ll pos) { return x = x | (1 << pos); }
ll clr(ll x, ll pos) { return x = x & ~(1 << pos); }
ll n, m, a[405], dp[405][405];
ll fn(ll l, ll r) {
if (l == r)
return 0;
ll &z = dp[l][r];
if (z != -1)
return z;
z = inf;
for (ll i = l; i < r; i++) {
z = min(z, fn(l, i) + fn(i + 1, r) + a[r] - a[l - 1]);
}
return z;
}
int main() {
ll var;
sfl(n);
mem(dp, -1);
for (i = 1; i <= n; i++) {
sfl(a[i]);
a[i] += a[i - 1];
}
z = fn(1, n);
cout << z << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define read() freopen("fibsubseq.in", "r", stdin)
#define write() freopen("fibsubseq.out", "w", stdout)
#define sf(n) scanf("%d", &n)
#define sfd(n) scanf("%lf", &n)
#define sl(x) scanf("%I64d", &x)
#define sfl(n) scanf("%lld", &n)
#define sfc(n) scanf(" %c", &n)
#define sful(n) scanf("%llu", &n)
#define ull unsigned long long int
#define endll printf("\n")
#define pf printf
#define pi acos(-1.0)
#define eps 1e-10
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define xx first
#define yy second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MP make_pair
#define ll long long
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
bool Check(unsigned int N, int pos) { return (bool)(N & (1LL << pos)); }
ll Set(unsigned int N, int pos) { return N = N | (1LL << pos); }
#define cnd tree[idx]
#define lnd tree[idx << 1]
#define rnd tree[(idx << 1) + 1]
#define lndp (idx << 1), (b), ((b + e) >> 1)
#define rndp ((idx << 1) + 1), (((b + e) >> 1) + 1), (e)
#define inf 1999999999
#define MX 100005
#define mod 1000000007
#define mod1 1000000009
#define var int ii, i, j, k, z = 0, c = 0, t, x, y, l, r, mid
// int dx[8]={0,0,1,1,-1,-1,1,-1}; //8 direction
// int dy[8]={1,-1,1,-1,1,-1,0,0};
bool chk(ll x, ll pos) { return (bool)(x & (1 << pos)); }
ll Set(ll x, ll pos) { return x = x | (1 << pos); }
ll clr(ll x, ll pos) { return x = x & ~(1 << pos); }
ll n, m, a[405], dp[405][405];
ll fn(ll l, ll r) {
if (l == r)
return 0;
ll &z = dp[l][r];
if (z != -1)
return z;
z = LONG_LONG_MAX;
for (ll i = l; i < r; i++) {
z = min(z, fn(l, i) + fn(i + 1, r) + a[r] - a[l - 1]);
}
return z;
}
int main() {
ll var;
sfl(n);
mem(dp, -1);
for (i = 1; i <= n; i++) {
sfl(a[i]);
a[i] += a[i - 1];
}
z = fn(1, n);
cout << z << endl;
}
| [
"assignment.value.change",
"identifier.change"
] | 982,568 | 982,569 | u302781973 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.