Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03176
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define n_l '\n' template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template <size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() { ; } template <typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); } #define dbg(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ dbgm(__VA_ARGS__); \ cout << endl int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> hgt(n), bty(n); for (auto &i : hgt) cin >> i; for (auto &i : bty) cin >> i; set<int> s; map<int, int> m; m[hgt[0]] = bty[0]; s.insert(hgt[0]); int ans = 0; for (int i = 1; i < n; i++) { auto it = s.upper_bound(hgt[i]); it--; if (*it > hgt[i]) m[hgt[i]] = bty[i]; else m[hgt[i]] = m[*it] + bty[i]; ans = max(ans, m[hgt[i]]); s.insert(hgt[i]); auto ut = s.lower_bound(hgt[i]); auto st = ++ut, et = s.end(); vector<int> temp; for (auto at = st; at != s.end(); at++) { if (m[*at] <= m[hgt[i]]) { temp.push_back(*at); } else { break; } } for (auto &j : temp) { m[j] = 0; s.erase(s.find(j)); } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define n_l '\n' template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template <size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() { ; } template <typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); } #define dbg(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ dbgm(__VA_ARGS__); \ cout << endl int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> hgt(n), bty(n); for (auto &i : hgt) cin >> i; for (auto &i : bty) cin >> i; set<int> s; map<int, int> m; m[hgt[0]] = bty[0]; s.insert(hgt[0]); int ans = bty[0]; for (int i = 1; i < n; i++) { auto it = s.upper_bound(hgt[i]); it--; if (*it > hgt[i]) m[hgt[i]] = bty[i]; else m[hgt[i]] = m[*it] + bty[i]; ans = max(ans, m[hgt[i]]); s.insert(hgt[i]); auto ut = s.lower_bound(hgt[i]); auto st = ++ut, et = s.end(); vector<int> temp; for (auto at = st; at != s.end(); at++) { if (m[*at] <= m[hgt[i]]) { temp.push_back(*at); } else { break; } } for (auto &j : temp) { m[j] = 0; s.erase(s.find(j)); } } cout << ans << '\n'; return 0; }
[]
984,128
984,129
u368645334
cpp
p03176
#include <bits/stdc++.h> #define db(x) cout << x << " " #define db1(x) cout << x << '\n' #define db2(x, y) cout << x << " " << y << '\n' #define db3(x, y, z) cout << x << " " << y << " " << z << '\n' #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define pair(a, b) make_pair(a, b) #define pb(a) push_back(a) #define ll long long int #define vi vector<ll> #define pi pair<ll, ll> #define vpi vector<pair<ll, ll>> #define ff first #define ss second #define all(a) a.begin(), a.end() #define mod 1000000007 #define MAX_N using namespace std; // int dx[4] = {1,-1,0,0}; // int dy[4] = {0,0,1,-1}; class Flower { public: int height; int beauty; }; void solve() { ll n; cin >> n; vector<Flower> arr(n); rep(i, n) { cin >> arr[i].height; } rep(i, n) { cin >> arr[i].beauty; } vector<ll> dp(n); dp[0] = arr[0].beauty; map<ll, ll> meaning; meaning[arr[0].height] = arr[0].beauty; repA(i, 1, n - 1) { dp[i] = arr[i].beauty; auto it = meaning.lower_bound(arr[i].height + 1); if (it != meaning.begin()) { it--; dp[i] += it->second; } meaning[arr[i].height] = dp[i]; it = meaning.upper_bound(arr[i].height); while (it != meaning.end() && dp[i] < it->second) { auto temp = it; temp++; meaning.erase(it); it = temp; } } ll ans = 0; rep(i, n) ans = max(ans, dp[i]); db1(ans); } int main() { int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define db(x) cout << x << " " #define db1(x) cout << x << '\n' #define db2(x, y) cout << x << " " << y << '\n' #define db3(x, y, z) cout << x << " " << y << " " << z << '\n' #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define pair(a, b) make_pair(a, b) #define pb(a) push_back(a) #define ll long long int #define vi vector<ll> #define pi pair<ll, ll> #define vpi vector<pair<ll, ll>> #define ff first #define ss second #define all(a) a.begin(), a.end() #define mod 1000000007 #define MAX_N using namespace std; // int dx[4] = {1,-1,0,0}; // int dy[4] = {0,0,1,-1}; class Flower { public: int height; int beauty; }; void solve() { ll n; cin >> n; vector<Flower> arr(n); rep(i, n) { cin >> arr[i].height; } rep(i, n) { cin >> arr[i].beauty; } vector<ll> dp(n); dp[0] = arr[0].beauty; map<ll, ll> meaning; meaning[arr[0].height] = arr[0].beauty; repA(i, 1, n - 1) { dp[i] = arr[i].beauty; auto it = meaning.lower_bound(arr[i].height + 1); if (it != meaning.begin()) { it--; dp[i] += it->second; } meaning[arr[i].height] = dp[i]; it = meaning.upper_bound(arr[i].height); while (it != meaning.end() && dp[i] >= it->second) { auto temp = it; temp++; meaning.erase(it); it = temp; } } ll ans = 0; rep(i, n) ans = max(ans, dp[i]); db1(ans); } int main() { int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
984,130
984,131
u483789716
cpp
p03176
#include <bits/stdc++.h> using namespace std; long long MOD = (long long)(1e9 + 7); vector<int> graph[(int)(1e5 + 7)]; int main() { int n; cin >> n; vector<long long> h(n), a(n); int base = 1; while (base <= n) base *= 2; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { cin >> a[i]; } // sorted heights vector<long long> tree(base + 1); vector<long long> dp((long long)(2e5 + 8), 0); // n^2 // optimise to nlogn int pos; long long ans = 0; dp[0] = a[0]; for (int i = 0; i < n; i++) { long long best = 0; int ind = base + h[i]; // max of dp[i] for i in range (0,h[i]); while (ind > 1) { if (ind % 2 == 1) { best = max(best, tree[ind - 1]); } ind /= 2; } dp[h[i]] = best + a[i]; // update dp[i] for (int j = base + h[i]; j >= 1; j /= 2) { tree[j] = max(tree[j], dp[h[i]]); } } for (int i = 0; i < n; i++) { ans = max(ans, dp[h[i]]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long MOD = (long long)(1e9 + 7); vector<int> graph[(int)(1e5 + 7)]; int main() { int n; cin >> n; vector<long long> h(n), a(n); int base = 1; while (base <= n) base *= 2; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { cin >> a[i]; } // sorted heights vector<long long> tree(2 * base); vector<long long> dp((long long)(2e5 + 8), 0); // n^2 // optimise to nlogn int pos; long long ans = 0; dp[0] = a[0]; for (int i = 0; i < n; i++) { long long best = 0; int ind = base + h[i]; // max of dp[i] for i in range (0,h[i]); while (ind > 1) { if (ind % 2 == 1) { best = max(best, tree[ind - 1]); } ind /= 2; } dp[h[i]] = best + a[i]; // update dp[i] for (int j = base + h[i]; j >= 1; j /= 2) { tree[j] = max(tree[j], dp[h[i]]); } } for (int i = 0; i < n; i++) { ans = max(ans, dp[h[i]]); } cout << ans << endl; }
[ "expression.operation.binary.remove" ]
984,132
984,133
u552024502
cpp
p03177
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 1LL << 61; ll m; vec mul(vec &dp, mat &mt) { vec ret(m); for (ll i = 0; i < m; i++) { for (ll j = 0; j < m; j++) { ret[i] = (ret[i] + mt[i][j] * dp[j]) % mod; } } return ret; } mat matmul(mat &a, mat &b) { mat res(m, vec(m, 0)); for (ll i = 0; i < m; i++) { for (ll j = 0; j < m; j++) { for (ll k = 0; k < m; k++) { (res[i][j] += a[i][k] * b[k][j]) %= mod; } } } return res; } mat update(mat &mt) { mat ret(m, vec(m)); for (ll i = 0; i < m; i++) { for (ll j = 0; j < m; j++) { for (ll k = 0; k < m; k++) { ret[i][j] = (ret[i][j] + mt[i][k] * mt[k][j]) % mod; } } } return ret; } void vmpow(vec &dp, mat &mt, ll k) { ll m = dp.size(); while (k) { if (k & 1) dp = mul(dp, mt); mt = update(mt); k /= 2; } } mat matpow(mat a, ll k) { mat res(m, vec(m, 0)); for (ll i = 0; i < m; i++) { res[i][i] = 1; } while (k > 0) { if (k & 1) res = matmul(res, a); a = matmul(a, a); k >>= 1; } return res; } int main() { ll k; cin >> m >> k; mat dp(m, vec(m)); for (ll i = 0; i < m; i++) for (ll j = 0; j < m; j++) cin >> dp[i][j]; dp = matpow(dp, k); ll ans = 0; for (ll i = 0; i < m; i++) for (ll j = 0; j < m; j++) ans += dp[i][j]; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 1LL << 61; ll m; vec mul(vec &dp, mat &mt) { vec ret(m); for (ll i = 0; i < m; i++) { for (ll j = 0; j < m; j++) { ret[i] = (ret[i] + mt[i][j] * dp[j]) % mod; } } return ret; } mat matmul(mat &a, mat &b) { mat res(m, vec(m, 0)); for (ll i = 0; i < m; i++) { for (ll j = 0; j < m; j++) { for (ll k = 0; k < m; k++) { (res[i][j] += a[i][k] * b[k][j]) %= mod; } } } return res; } mat update(mat &mt) { mat ret(m, vec(m)); for (ll i = 0; i < m; i++) { for (ll j = 0; j < m; j++) { for (ll k = 0; k < m; k++) { ret[i][j] = (ret[i][j] + mt[i][k] * mt[k][j]) % mod; } } } return ret; } void vmpow(vec &dp, mat &mt, ll k) { ll m = dp.size(); while (k) { if (k & 1) dp = mul(dp, mt); mt = update(mt); k /= 2; } } mat matpow(mat a, ll k) { mat res(m, vec(m, 0)); for (ll i = 0; i < m; i++) { res[i][i] = 1; } while (k > 0) { if (k & 1) res = matmul(res, a); a = matmul(a, a); k >>= 1; } return res; } int main() { ll k; cin >> m >> k; mat dp(m, vec(m)); for (ll i = 0; i < m; i++) for (ll j = 0; j < m; j++) cin >> dp[i][j]; dp = matpow(dp, k); ll ans = 0; for (ll i = 0; i < m; i++) for (ll j = 0; j < m; j++) (ans += dp[i][j]) %= mod; cout << ans << endl; }
[ "assignment.change" ]
984,153
984,154
u718758485
cpp
p03177
#include <algorithm> #include <cassert> #include <cstdio> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> using namespace std; const int mod = 1e9 + 7; using VL = vector<long long>; using VVL = vector<VL>; using VVVL = vector<VVL>; int n; void show(VVL &vv) { for (auto v : vv) { for (auto x : v) { printf("%3lld ", x); } printf("\n"); } } VVL prod(const VVL &a, const VVL &b) { VVL ret(n, VL(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { ret[i][j] += a[i][k] * b[k][j]; } ret[i][j] %= mod; } } return ret; } int main() { long long dist; cin >> n >> dist; const int maxi = 61; VVVL a(maxi, VVL(n, VL(n, 0))); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[0][i][j]; } } for (int bit = 1; bit < maxi; bit++) { a[bit] = prod(a[bit - 1], a[bit - 1]); } int bit = 0; VVL mat(n, VL(n, 0)); for (int i = 0; i < n; i++) { mat[i][i] = 1; } while (dist > 0) { if (dist & 1) { mat = prod(mat, a[bit]); } bit++; dist >>= 1; } // for (int i = 0; i < maxi; i++) { // printf("i %d ------\n", i); // show(a[i]); // } // show(mat); long long ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans += mat[i][j]; } } ans %= mod; cout << ans << endl; return 0; }
#include <algorithm> #include <cassert> #include <cstdio> #include <iostream> #include <numeric> #include <string> #include <utility> #include <vector> using namespace std; const int mod = 1e9 + 7; using VL = vector<long long>; using VVL = vector<VL>; using VVVL = vector<VVL>; int n; void show(VVL &vv) { for (auto v : vv) { for (auto x : v) { printf("%3lld ", x); } printf("\n"); } } VVL prod(const VVL &a, const VVL &b) { VVL ret(n, VL(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { ret[i][j] += a[i][k] * b[k][j]; ret[i][j] %= mod; } } } return ret; } int main() { long long dist; cin >> n >> dist; const int maxi = 61; VVVL a(maxi, VVL(n, VL(n, 0))); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[0][i][j]; } } for (int bit = 1; bit < maxi; bit++) { a[bit] = prod(a[bit - 1], a[bit - 1]); } int bit = 0; VVL mat(n, VL(n, 0)); for (int i = 0; i < n; i++) { mat[i][i] = 1; } while (dist > 0) { if (dist & 1) { mat = prod(mat, a[bit]); } bit++; dist >>= 1; } // for (int i = 0; i < maxi; i++) { // printf("i %d ------\n", i); // show(a[i]); // } // show(mat); long long ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans += mat[i][j]; } } ans %= mod; cout << ans << endl; return 0; }
[]
984,155
984,156
u590241855
cpp
p03177
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define input \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); ll mat[55][55]; ll temp[55][55]; ll n; auto addmod(ll a, ll b) { ll res = (a % mod + b % mod) % mod; if (res < 0) res += mod; return res % mod; } auto mulmod(ll a, ll b) { ll res = (a % mod * b % mod) % mod; if (res < 0) res += mod; return res % mod; } void multiply(ll A[55][55], ll B[55][55]) { ll c[55][55]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { c[i][j] = 0; for (ll k = 0; k < n; k++) { c[i][j] = addmod(c[i][j], mulmod(A[i][k], B[k][j])); } } } for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) A[i][j] = c[i][j]; } } int main() { fast; input; ll k; cin >> n >> k; for (ll i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> mat[i][j]; // mat[i][j]; if (i == j) temp[i][j] = 1; else temp[i][j] = 0; } } while (k) { if (k & 1) { multiply(temp, mat); } k >>= 1; multiply(mat, mat); } ll res = 0; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { res = addmod(res, temp[i][j]); } } cout << res % mod << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define input \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); ll mat[55][55]; ll temp[55][55]; ll n; auto addmod(ll a, ll b) { ll res = (a % mod + b % mod) % mod; if (res < 0) res += mod; return res % mod; } auto mulmod(ll a, ll b) { ll res = (a % mod * b % mod) % mod; if (res < 0) res += mod; return res % mod; } void multiply(ll A[55][55], ll B[55][55]) { ll c[55][55]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { c[i][j] = 0; for (ll k = 0; k < n; k++) { c[i][j] = addmod(c[i][j], mulmod(A[i][k], B[k][j])); } } } for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) A[i][j] = c[i][j]; } } int main() { fast; // input; ll k; cin >> n >> k; for (ll i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> mat[i][j]; // mat[i][j]; if (i == j) temp[i][j] = 1; else temp[i][j] = 0; } } while (k) { if (k & 1) { multiply(temp, mat); } k >>= 1; multiply(mat, mat); } ll res = 0; for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { res = addmod(res, temp[i][j]); } } cout << res % mod << endl; }
[]
984,159
984,160
u424211710
cpp
p03177
// ysh_gpta #include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> // using multiInt = boost::multiprecision::cpp_int; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; #define bit(x, i) (x & (1 << i)) // select the bit of position i of x #define IN(i, l, r) (l < i && i < r) // the next for are for checking bound #define LINR(i, l, r) (l <= i && i <= r) #define LIN(i, l, r) (l <= i && i < r) #define INR(i, l, r) (l < i && i <= r) #define repf(i, L, R) \ for (int i = L; i < R; i++) // next four are for "for loops" #define repfe(i, L, R) for (int i = L; i <= R; i++) #define repb(i, L, R) for (int i = L; i > R; i--) #define repbe(i, L, R) for (int i = L; i >= R; i--) typedef long long ll; #define cerr \ if (false) \ cerr #define vb vector<bool> #define vi vector<ll> #define vvi vector<vi> #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define mkp make_pair #define pb push_back #define INF 1000000000000000 #define MOD 1000000007 #define ff first #define ss second #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define watch(x) cerr << (#x) << " is " << (x) << endl; #define FastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll ncr(ll n, ll r) { ll ans = 1; r = min(r, n - r); for (int i = 1; i <= r; i++) { ans *= (n - r + i); ans /= i; } return ans; } vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; ll n, k; vvi m(55, vi(55)); vvi matmul(vvi &a, vvi &b) { vvi c(n, vi(n, 0)); repf(row, 0, n) { repf(col, 0, n) { repf(k, 0, n) { c[row][col] += a[row][k] * b[k][col]; } c[row][col] %= MOD; } } return c; } vvi power(vvi m, ll e) { if (e == 1) return m; vvi a = power(m, e / 2); vvi ans = matmul(a, a); if (e % 2 == 1) ans = matmul(ans, m); return ans; } int main() { FastIO cin >> n >> k; repf(i, 0, n) repf(j, 0, n) cin >> m[i][j]; vvi res = power(m, k); ll sum = 0; repf(i, 0, n) repf(j, 0, n) sum = (sum + res[i][j]) % MOD; cout << sum; return 0; }
// ysh_gpta #include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> // using multiInt = boost::multiprecision::cpp_int; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; #define bit(x, i) (x & (1 << i)) // select the bit of position i of x #define IN(i, l, r) (l < i && i < r) // the next for are for checking bound #define LINR(i, l, r) (l <= i && i <= r) #define LIN(i, l, r) (l <= i && i < r) #define INR(i, l, r) (l < i && i <= r) #define repf(i, L, R) \ for (int i = L; i < R; i++) // next four are for "for loops" #define repfe(i, L, R) for (int i = L; i <= R; i++) #define repb(i, L, R) for (int i = L; i > R; i--) #define repbe(i, L, R) for (int i = L; i >= R; i--) typedef long long ll; #define cerr \ if (false) \ cerr #define vb vector<bool> #define vi vector<ll> #define vvi vector<vi> #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define mkp make_pair #define pb push_back #define INF 1000000000000000 #define MOD 1000000007 #define ff first #define ss second #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define watch(x) cerr << (#x) << " is " << (x) << endl; #define FastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll ncr(ll n, ll r) { ll ans = 1; r = min(r, n - r); for (int i = 1; i <= r; i++) { ans *= (n - r + i); ans /= i; } return ans; } vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0}; vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0}; ll n, k; vvi m(55, vi(55)); vvi matmul(vvi &a, vvi &b) { vvi c(n, vi(n, 0)); repf(row, 0, n) { repf(col, 0, n) { repf(k, 0, n) { c[row][col] += a[row][k] * b[k][col]; c[row][col] %= MOD; } } } return c; } vvi power(vvi m, ll e) { if (e == 1) return m; vvi a = power(m, e / 2); vvi ans = matmul(a, a); if (e % 2 == 1) ans = matmul(ans, m); return ans; } int main() { FastIO cin >> n >> k; repf(i, 0, n) repf(j, 0, n) cin >> m[i][j]; vvi res = power(m, k); ll sum = 0; repf(i, 0, n) repf(j, 0, n) sum = (sum + res[i][j]) % MOD; cout << sum; return 0; }
[]
984,176
984,177
u898771121
cpp
p03177
#include <bits/stdc++.h> #define ll long long #define X first #define Y second #define MP make_pair using namespace std; const int N = 123; const ll mod = 1e9 + 7; int n; struct mtx { int a[N][N], len = n; mtx() { memset(a, 0, sizeof(a)); } void operator*=(mtx b) { int res[N][N]; memset(res, 0, sizeof(res)); for (int i = 1; i <= len; i++) { for (int j = 1; j <= len; j++) { for (int k = 1; k <= len; k++) { res[i][j] = (res[i][j] + a[i][k] * b.a[k][j]) % mod; } } } for (int i = 1; i <= len; i++) { for (int j = 1; j <= len; j++) { a[i][j] = res[i][j]; } } } }; mtx bin_pow(mtx x, ll y) { mtx res; for (int i = 1; i <= n; i++) { res.a[i][i] = 1; } while (y) { if (y & 1LL) res *= x; /* for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ cout << res.a[i][j] << " "; } cout << "\n"; } */ x *= x; y >>= 1LL; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k; cin >> n >> k; mtx z; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> z.a[i][j]; // z *= z; z = bin_pow(z, k); ll res = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { // cout << z.a[i][j] << " "; res += z.a[i][j], res %= mod; } // cout << "\n"; } cout << res; }
#include <bits/stdc++.h> #define ll long long #define X first #define Y second #define MP make_pair using namespace std; const int N = 123; const ll mod = 1e9 + 7; int n; struct mtx { ll a[N][N], len = n; mtx() { memset(a, 0, sizeof(a)); } void operator*=(mtx b) { int res[N][N]; memset(res, 0, sizeof(res)); for (int i = 1; i <= len; i++) { for (int j = 1; j <= len; j++) { for (int k = 1; k <= len; k++) { res[i][j] = (res[i][j] + a[i][k] * b.a[k][j]) % mod; } } } for (int i = 1; i <= len; i++) { for (int j = 1; j <= len; j++) { a[i][j] = res[i][j]; } } } }; mtx bin_pow(mtx x, ll y) { mtx res; for (int i = 1; i <= n; i++) { res.a[i][i] = 1; } while (y) { if (y & 1LL) res *= x; /* for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ cout << res.a[i][j] << " "; } cout << "\n"; } */ x *= x; y >>= 1LL; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll k; cin >> n >> k; mtx z; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> z.a[i][j]; // z *= z; z = bin_pow(z, k); ll res = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { // cout << z.a[i][j] << " "; res += z.a[i][j], res %= mod; } // cout << "\n"; } cout << res; }
[]
984,212
984,213
u816631826
cpp
p03177
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep1(i, n) for (int i = (n); i > 0; i--) #define ll long long #define pi pair<int, int> #define pll pair<ll, ll> #define MOD 1000000007 #define INF 1000000000000000LL using namespace std; #define MAXN 51 // dp[k][i][j]:ノードiからノードjにk手番で到達できるパス数 ll dp[MAXN + 1][MAXN + 1]; int n; struct Matrix { ll val[MAXN + 1][MAXN + 1]; Matrix() { rep(i, n) rep(j, n) val[i][j] = 0; } }; Matrix operator*(Matrix a, Matrix b) { Matrix c; rep(i, n) rep(j, n) rep(k, n) { c.val[i][j] += a.val[i][k] * b.val[k][j]; c.val[i][j] %= MOD; } return c; } Matrix I; Matrix matrix_power(Matrix a, int b) { if (b == 0) return I; Matrix res = matrix_power(a, b / 2); res = res * res; if (b % 2) res = res * a; return res; } int main() { ll k; cin >> n >> k; Matrix a; rep(i, n) rep(j, n) cin >> a.val[i][j]; rep(i, n) I.val[i][i] = 1; a = matrix_power(a, k); ll result = 0; rep(i, n) rep(j, n) { result += a.val[i][j]; result %= MOD; } cout << result << endl; return 0; rep(i, n) { rep(j, n) cout << a.val[i][j] << ' '; cout << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define rrep1(i, n) for (int i = (n); i > 0; i--) #define ll long long #define pi pair<int, int> #define pll pair<ll, ll> #define MOD 1000000007 #define INF 1000000000000000LL using namespace std; #define MAXN 51 // dp[k][i][j]:ノードiからノードjにk手番で到達できるパス数 ll dp[MAXN + 1][MAXN + 1]; int n; struct Matrix { ll val[MAXN + 1][MAXN + 1]; Matrix() { rep(i, n) rep(j, n) val[i][j] = 0; } }; Matrix operator*(Matrix a, Matrix b) { Matrix c; rep(i, n) rep(j, n) rep(k, n) { c.val[i][j] += a.val[i][k] * b.val[k][j]; c.val[i][j] %= MOD; } return c; } Matrix I; Matrix matrix_power(Matrix a, ll b) { if (b == 0) return I; Matrix res = matrix_power(a, b / 2); res = res * res; if (b % 2) res = res * a; return res; } int main() { ll k; cin >> n >> k; Matrix a; rep(i, n) rep(j, n) cin >> a.val[i][j]; rep(i, n) I.val[i][i] = 1; a = matrix_power(a, k); ll result = 0; rep(i, n) rep(j, n) { result += a.val[i][j]; result %= MOD; } cout << result << endl; return 0; rep(i, n) { rep(j, n) cout << a.val[i][j] << ' '; cout << endl; } return 0; }
[]
984,228
984,229
u021358975
cpp
p03177
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; const ll MAX_N = 50 + 1; const ll MOD_M = 1000000000 + 7; auto matrix_product_mod(vector<vector<ll>> &mat_a, vector<vector<ll>> &mat_b, ll m, ll N) { vector<vector<ll>> mat_res(N, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { ll temp = 0; for (ll k = 0; k < N; k++) temp += mat_a[i][k] * mat_b[k][j]; temp %= m; mat_res[i][j] = temp; } } return mat_res; } auto matrix_binpow_mod(vector<vector<ll>> &mat_a, ll n, ll m, ll N) { vector<vector<ll>> mat_res(N, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { if (i == j) mat_res[i][j] = 1; else mat_res[i][j] = 0; } } while (n > 0) { if (n & 1) mat_res = matrix_product_mod(mat_res, mat_a, m, N); mat_a = matrix_product_mod(mat_a, mat_a, m, N); n = n >> 1; } return mat_res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; vector<vector<ll>> A(N, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { cin >> A[i][j]; } } vector<vector<ll>> mat_res(N, vector<ll>(N)); mat_res = matrix_binpow_mod(A, K, MOD_M, N); ll ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { ans += mat_res[i][j]; ans %= MOD_M; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; const ll MAX_N = 50 + 1; const ll MOD_M = 1000000000 + 7; auto matrix_product_mod(vector<vector<ll>> &mat_a, vector<vector<ll>> &mat_b, ll m, ll N) { vector<vector<ll>> mat_res(N, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { ll temp = 0; for (ll k = 0; k < N; k++) { temp += mat_a[i][k] * mat_b[k][j]; temp %= m; } mat_res[i][j] = temp; } } return mat_res; } auto matrix_binpow_mod(vector<vector<ll>> &mat_a, ll n, ll m, ll N) { vector<vector<ll>> mat_res(N, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { if (i == j) mat_res[i][j] = 1; else mat_res[i][j] = 0; } } while (n > 0) { if (n & 1) mat_res = matrix_product_mod(mat_res, mat_a, m, N); mat_a = matrix_product_mod(mat_a, mat_a, m, N); n = n >> 1; } return mat_res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; vector<vector<ll>> A(N, vector<ll>(N)); for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { cin >> A[i][j]; } } vector<vector<ll>> mat_res(N, vector<ll>(N)); mat_res = matrix_binpow_mod(A, K, MOD_M, N); ll ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { ans += mat_res[i][j]; ans %= MOD_M; } } cout << ans << endl; return 0; }
[]
984,230
984,231
u367713721
cpp
p03177
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); #define int long long int using namespace std; const int MAXN = 100, MOD = 1e9 + 7; int n, k, base[MAXN][MAXN]; struct matrix { int n, m; int mx[MAXN][MAXN]; matrix(int n = 0, int m = 0) : n(n), m(m) { memset(mx, 0, sizeof(mx)); } matrix operator*(matrix a) const { matrix ans(n, a.m); for (int i = 0; i < n; i++) for (int j = 0; j < a.m; j++) for (int k = 0; k < m; k++) { ans.mx[i][j] += mx[i][k] * a.mx[k][j]; ans.mx[i][j] %= MOD; } return ans; } }; main() { fastio; cin >> n >> k; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> base[i][j]; matrix b(n, n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { b.mx[i][j] = base[i][j]; } } matrix ans(n, n); for (int i = 0; i < n; i++) { ans.mx[i][i] = 1; } for (int i = 64; i >= 0; i--) { ans = ans * ans; if (k & 1LL << i) ans = ans * b; } int resp = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans.mx[i][j] %= MOD; resp += ans.mx[i][j]; resp %= MOD; } } cout << resp << endl; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); #define int long long int using namespace std; const int MAXN = 100, MOD = 1e9 + 7; int n, k, base[MAXN][MAXN]; struct matrix { int n, m; int mx[MAXN][MAXN]; matrix(int n = 0, int m = 0) : n(n), m(m) { memset(mx, 0, sizeof(mx)); } matrix operator*(matrix a) const { matrix ans(n, a.m); for (int i = 0; i < n; i++) for (int j = 0; j < a.m; j++) for (int k = 0; k < m; k++) { ans.mx[i][j] += mx[i][k] * a.mx[k][j]; ans.mx[i][j] %= MOD; } return ans; } }; main() { fastio; cin >> n >> k; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> base[i][j]; matrix b(n, n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { b.mx[i][j] = base[i][j]; } } matrix ans(n, n); for (int i = 0; i < n; i++) { ans.mx[i][i] = 1; } for (int i = 62; i >= 0; i--) { ans = ans * ans; if (k & 1LL << i) ans = ans * b; } int resp = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans.mx[i][j] %= MOD; resp += ans.mx[i][j]; resp %= MOD; } } cout << resp << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
984,232
984,233
u408388726
cpp
p03177
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod = (ll)1e9 + 7; void multiply(ll first[][50], ll second[][50], ll n) { ll i, j, k, tmp[n][50]; memset(tmp, 0, sizeof(tmp)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) tmp[i][j] += first[i][k] * second[k][j]; for (i = 0; i < n; i++) for (j = 0; j < n; j++) first[i][j] = tmp[i][j] % mod; } void power(ll arr[][50], ll m, ll n) { ll tmp[n][50]; memset(tmp, 0, sizeof(tmp)); for (ll i = 0; i < n; i++) tmp[i][i] = 1; while (m) { if (m & 1) multiply(tmp, arr, n); m >>= 1; multiply(arr, arr, n); } ll ans = 0; for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) (ans += tmp[i][j]) %= mod; cout << ans; } int main() { ll i, n, j, m; cin >> n >> m; ll arr[n][50]; for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> arr[i][j]; power(arr, m, n); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod = (ll)1e9 + 7; void multiply(ll first[][50], ll second[][50], ll n) { ll i, j, k, tmp[n][50]; memset(tmp, 0, sizeof(tmp)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) for (k = 0; k < n; k++) (tmp[i][j] += first[i][k] * second[k][j]) %= mod; for (i = 0; i < n; i++) for (j = 0; j < n; j++) first[i][j] = tmp[i][j] % mod; } void power(ll arr[][50], ll m, ll n) { ll tmp[n][50]; memset(tmp, 0, sizeof(tmp)); for (ll i = 0; i < n; i++) tmp[i][i] = 1; while (m) { if (m & 1) multiply(tmp, arr, n); m >>= 1; multiply(arr, arr, n); } ll ans = 0; for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) (ans += tmp[i][j]) %= mod; cout << ans; } int main() { ll i, n, j, m; cin >> n >> m; ll arr[n][50]; for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> arr[i][j]; power(arr, m, n); }
[ "assignment.change" ]
984,245
984,246
u341555499
cpp
p03177
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define fir first #define sec second #define sz(s) (s).size(); #define pb push_back #define get(n) scanf("%d", &n); #define gets(s) \ string s; \ cin >> (s); #define prfi(n) printf("%d", &n); #define prfd(n) printf("%lf", &n); #define All(s) (s).begin(), (s).end() #define rep(i, j, k) for (int(i) = (j); (i) <= (k); (i)++) #define rep0(i, j) for (int(i) = 0; (i) < (j); (i)++) #define repdown(i, j, k) for (int(i) = (j); (i) >= (k); (i)--) #define repdown0(i, j) for (int(i) = (j); i >= 0; i--) #define dump(x) std::cout << #x << " = " << (x) << std::endl; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using ll = long long; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vd = std::vector<double>; using vvd = std::vector<vd>; using qi = std::queue<int>; using vpii = std::vector<std::pair<int, int>>; using namespace std; const int Mod = (1e9) + 7; const int max_n = 3 * (1e5) + 1; const int max_m = 83 * (1e5) + 1; const int INF = 10241024; // const ll INFL = (1ll << 63) - 1; //_____________________________________Templates_________________________________________// template <class T1, class T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <class T1, class T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } // mainly use for dynamic prog template <class T1, class T2> void update(T1 &a, T2 b) { a += b; if (a > Mod) a %= Mod; } inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } inline void OUT(void) { cout << "\n"; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } //_____________________array calc____________________________________// vvll mul(vvll &A, vvll &B) { vvll C(A.size(), vll(B[0].size())); rep0(i, A.size()) { rep0(j, B.size()) { rep0(k, B[0].size()) { C[i][j] += (C[i][j] + A[i][k] * B[k][j]) % Mod; } } } return C; } vvll pow(vvll A, ll n) { vvll B(A.size(), vll(A.size())); rep0(i, A.size()) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } //_____________________Bynary Indexed Tree __________________________// /* const max_st = (1 << 15) - 1; int bit[max_st]; int sum (int i){ int s = 0; while(i > 0){ s += bit[i]; i -= i & -i; } return s; } void add(int i, int x){ while(i <= n){ bit[i] += x; i += i & -i; } } */ //____________________RMQ____________________________// /* struct RMQ{ #define s (1 << 20) ll dat[s]; int n; void init(){ memset(dat, -1e10, sizeof(dat)); } void upd(int k, ll a){ k += s/2 - 1; dat[k] = a; while(k > 0){ k = (k -1) /2; dat[k] = max(dat[k*2+1], dat[k*2+2]); } } ll query(int a, int b, int k, int l, int r){ if(r <= a || b <= l) return -1e8; if( a <= l && r <= b)return dat[k]; else { ll vl = query(a, b, k*2+1, l, (l+r)/2); ll vr = query(a, b, k*2+2, (l+r)/2, r); return max(vl, vr); } } void Debug(int a){ a += s/2 - 1; rep(i,s/2 - 1,a){ dump(dat[i]); } } }; */ //_____________________ following sorce code_________________________// int n, m, k, x, y; vvll dp(50, vll(50)); vvll v(50, vll(50)); ll ans = 0ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll z; IN(n, z); rep0(i, n) { rep0(j, n) { int a; IN(a); v[i][j] = a; } } dp = pow(v, z); rep0(i, n) { rep0(j, n) { ans += dp[i][j]; ans %= Mod; } } OUT(ans); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define fir first #define sec second #define sz(s) (s).size(); #define pb push_back #define get(n) scanf("%d", &n); #define gets(s) \ string s; \ cin >> (s); #define prfi(n) printf("%d", &n); #define prfd(n) printf("%lf", &n); #define All(s) (s).begin(), (s).end() #define rep(i, j, k) for (int(i) = (j); (i) <= (k); (i)++) #define rep0(i, j) for (int(i) = 0; (i) < (j); (i)++) #define repdown(i, j, k) for (int(i) = (j); (i) >= (k); (i)--) #define repdown0(i, j) for (int(i) = (j); i >= 0; i--) #define dump(x) std::cout << #x << " = " << (x) << std::endl; #define debug(x) \ cout << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using ll = long long; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vd = std::vector<double>; using vvd = std::vector<vd>; using qi = std::queue<int>; using vpii = std::vector<std::pair<int, int>>; using namespace std; const int Mod = (1e9) + 7; const int max_n = 3 * (1e5) + 1; const int max_m = 83 * (1e5) + 1; const int INF = 10241024; // const ll INFL = (1ll << 63) - 1; //_____________________________________Templates_________________________________________// template <class T1, class T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <class T1, class T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } // mainly use for dynamic prog template <class T1, class T2> void update(T1 &a, T2 b) { a += b; if (a > Mod) a %= Mod; } inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } inline void OUT(void) { cout << "\n"; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest) { cout << first << " "; OUT(rest...); return; } //_____________________array calc____________________________________// vvll mul(vvll &A, vvll &B) { vvll C(A.size(), vll(B[0].size())); rep0(i, A.size()) { rep0(j, B.size()) { rep0(k, B[0].size()) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % Mod; } } } return C; } vvll pow(vvll A, ll n) { vvll B(A.size(), vll(A.size())); rep0(i, A.size()) { B[i][i] = 1; } while (n > 0) { if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } //_____________________Bynary Indexed Tree __________________________// /* const max_st = (1 << 15) - 1; int bit[max_st]; int sum (int i){ int s = 0; while(i > 0){ s += bit[i]; i -= i & -i; } return s; } void add(int i, int x){ while(i <= n){ bit[i] += x; i += i & -i; } } */ //____________________RMQ____________________________// /* struct RMQ{ #define s (1 << 20) ll dat[s]; int n; void init(){ memset(dat, -1e10, sizeof(dat)); } void upd(int k, ll a){ k += s/2 - 1; dat[k] = a; while(k > 0){ k = (k -1) /2; dat[k] = max(dat[k*2+1], dat[k*2+2]); } } ll query(int a, int b, int k, int l, int r){ if(r <= a || b <= l) return -1e8; if( a <= l && r <= b)return dat[k]; else { ll vl = query(a, b, k*2+1, l, (l+r)/2); ll vr = query(a, b, k*2+2, (l+r)/2, r); return max(vl, vr); } } void Debug(int a){ a += s/2 - 1; rep(i,s/2 - 1,a){ dump(dat[i]); } } }; */ //_____________________ following sorce code_________________________// int n, m, k, x, y; vvll dp(50, vll(50)); vvll v(50, vll(50)); ll ans = 0ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll z; IN(n, z); rep0(i, n) { rep0(j, n) { int a; IN(a); v[i][j] = a; } } dp = pow(v, z); rep0(i, n) { rep0(j, n) { ans += dp[i][j]; ans %= Mod; } } OUT(ans); return 0; }
[ "assignment.value.change" ]
984,249
984,250
u264405855
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0)); // i番目までにj個の飴を配る場合の数 dp[0][0] = 1; for (int i = 0; i < n; i++) { vector<int> b(k + 2, 0); //累積和 for (int j = 0; j <= k; j++) { b[j + 1] += b[j] + dp[i][j]; b[j + 1] %= MOD; } for (int j = 0; j <= k; j++) { dp[i + 1][j] += b[j + 1] - b[max(0LL, j - a[i])]; dp[i + 1][j] %= MOD; } } cout << dp[n][k] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1e9 + 7; signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0)); // i番目までにj個の飴を配る場合の数 dp[0][0] = 1; for (int i = 0; i < n; i++) { vector<int> b(k + 2, 0); //累積和 for (int j = 0; j <= k; j++) { b[j + 1] += b[j] + dp[i][j]; b[j + 1] %= MOD; } for (int j = 0; j <= k; j++) { dp[i + 1][j] += b[j + 1] - b[max(0LL, j - a[i])] + MOD; dp[i + 1][j] %= MOD; } } cout << dp[n][k] << endl; return 0; }
[ "assignment.change" ]
984,255
984,256
u344122377
cpp
p03172
#include <bits/stdc++.h> typedef int ll; using namespace std; int dp[102][100004]; int pref[102][100004]; int main() { ios::sync_with_stdio(false); int n, k; int a[102]; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int mod = 1e9 + 7; memset(dp, 0, sizeof dp); memset(pref, 0, sizeof pref); dp[0][0] = 1; for (int i = 1; i <= n; i++) { pref[i - 1][0] = dp[i - 1][0]; for (int j = 1; j <= k; j++) { pref[i - 1][j] = dp[i - 1][j]; pref[i - 1][j] %= mod; pref[i - 1][j] += pref[i - 1][j - 1]; pref[i - 1][j] %= mod; } for (int j = 0; j <= k; j++) { if (j - a[i] - 1 >= 0) dp[i][j] = (pref[i - 1][j] - pref[i - 1][j - a[i] - 1]); else dp[i][j] = pref[i - 1][j]; } } cout << dp[n][k] << endl; return 0; }
#include <bits/stdc++.h> typedef int ll; using namespace std; int dp[102][100004]; int pref[102][100004]; int main() { ios::sync_with_stdio(false); int n, k; int a[102]; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; int mod = 1e9 + 7; memset(dp, 0, sizeof dp); memset(pref, 0, sizeof pref); dp[0][0] = 1; for (int i = 1; i <= n; i++) { pref[i - 1][0] = dp[i - 1][0]; for (int j = 1; j <= k; j++) { pref[i - 1][j] = dp[i - 1][j]; pref[i - 1][j] %= mod; pref[i - 1][j] += pref[i - 1][j - 1]; pref[i - 1][j] %= mod; } for (int j = 0; j <= k; j++) { if (j - a[i] - 1 >= 0) dp[i][j] = (pref[i - 1][j] - pref[i - 1][j - a[i] - 1] + mod) % mod; else dp[i][j] = pref[i - 1][j]; } } cout << dp[n][k] << endl; return 0; }
[ "assignment.change" ]
984,262
984,263
u758866199
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) typedef long long ll; const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(k + 2, 0)); dp[0][k] = 1; rep(i, n) { for (int j = k; j >= 0; j--) { dp[i + 1][j] = (dp[i + 1][j + 1] + dp[i][j]) % mod; if (j + a[i] + 1 <= k) (dp[i + 1][j] -= dp[i][j + a[i] + 1]) %= mod; } } cout << dp[n][0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) typedef long long ll; const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(k + 2, 0)); dp[0][k] = 1; rep(i, n) { for (int j = k; j >= 0; j--) { dp[i + 1][j] = (dp[i + 1][j + 1] + dp[i][j]) % mod; if (j + a[i] + 1 <= k) (dp[i + 1][j] += -dp[i][j + a[i] + 1] + mod) %= mod; } } cout << dp[n][0] << endl; return 0; }
[ "expression.operator.change", "expression.operation.unary.add", "assignment.change" ]
984,266
984,267
u970690920
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) typedef long long ll; const ll mod = 1e9 + 7; int main() { int n, k; cin >> n >> k; int a[n]; rep(i, n) cin >> a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(k + 2, 0)); dp[0][k] = 1; rep(i, n) { for (int j = k; j >= 0; j--) { dp[i + 1][j] = (dp[i + 1][j + 1] + dp[i][j]) % mod; if (j + a[i] + 1 <= k) (dp[i + 1][j] -= dp[i][j + a[i] + 1]) %= mod; } } cout << dp[n][0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) typedef long long ll; const ll mod = 1e9 + 7; int main() { ll n, k; cin >> n >> k; ll a[n]; rep(i, n) cin >> a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(k + 2, 0)); dp[0][k] = 1; rep(i, n) { for (int j = k; j >= 0; j--) { dp[i + 1][j] = (dp[i + 1][j + 1] + dp[i][j]) % mod; if (j + a[i] + 1 <= k) (dp[i + 1][j] += -dp[i][j + a[i] + 1] + mod) %= mod; } } cout << dp[n][0] << endl; return 0; }
[ "variable_declaration.type.change", "expression.operator.change", "expression.operation.unary.add", "assignment.change" ]
984,268
984,267
u970690920
cpp
p03172
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long dp[n + 1][k + 1]; 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 = 0; i <= k; i++) { if (i <= a[1]) dp[1][i] = 1; else dp[1][i] = 0; } for (long long i = 1; i <= n; i++) { dp[i][0] = 1; } for (long long i = 2; i <= n; i++) { for (long long j = 1; j <= k; j++) { if (j <= a[i]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % 1000000007; } else { dp[i][j] = (dp[i][j - 1] - dp[i - 1][j - a[i] - 1] + dp[i - 1][j]) % 1000000007; } } } cout << dp[n][k]; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long dp[n + 1][k + 1]; 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 = 0; i <= k; i++) { if (i <= a[1]) dp[1][i] = 1; else dp[1][i] = 0; } for (long long i = 1; i <= n; i++) { dp[i][0] = 1; } for (long long i = 2; i <= n; i++) { for (long long j = 1; j <= k; j++) { if (j <= a[i]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % 1000000007; } else { dp[i][j] = (dp[i][j - 1] - dp[i - 1][j - a[i] - 1] + dp[i - 1][j] + 1000000007) % 1000000007; } } } cout << dp[n][k]; }
[]
984,271
984,272
u633697116
cpp
p03172
#include <algorithm> #include <iostream> #include <vector> #define mod 1e9 + 5 using namespace std; using ll = long long; void add_self(int &a, int b) { a += b; a -= a >= mod ? mod : 0; } void sub_self(int &a, int b) { a -= b; a += a < 0 ? mod : 0; } int main() { int n, k; scanf("%d%d", &n, &k); vector<int> dp(k + 1); dp[0] = 1; while (n--) { int up_to; scanf("%d", &up_to); vector<int> fake(k + 1); for (int used = k; used >= 0; used--) { int l = used + 1; int r = used + min(up_to, k - used); int tmp = dp[used]; if (l <= r) { add_self(fake[l], tmp); if (r + 1 <= k) { sub_self(fake[r + 1], tmp); } } } int prefixe_sum = 0; for (int i = 0; i <= k; i++) { add_self(prefixe_sum, fake[i]); add_self(dp[i], prefixe_sum); } } printf("%d\n", dp[k]); }
#include <algorithm> #include <iostream> #include <vector> #define mod 1e9 + 7 using namespace std; using ll = long long; void add_self(int &a, int b) { a += b; a -= a >= mod ? mod : 0; } void sub_self(int &a, int b) { a -= b; a += a < 0 ? mod : 0; } int main() { int n, k; scanf("%d%d", &n, &k); vector<int> dp(k + 1); dp[0] = 1; while (n--) { int up_to; scanf("%d", &up_to); vector<int> fake(k + 1); for (int used = k; used >= 0; used--) { int l = used + 1; int r = used + min(up_to, k - used); int tmp = dp[used]; if (l <= r) { add_self(fake[l], tmp); if (r + 1 <= k) { sub_self(fake[r + 1], tmp); } } } int prefixe_sum = 0; for (int i = 0; i <= k; i++) { add_self(prefixe_sum, fake[i]); add_self(dp[i], prefixe_sum); } } printf("%d\n", dp[k]); }
[ "preprocessor.define.value.change", "literal.integer.change" ]
984,277
984,278
u236288355
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ll long long int #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { off; int n, k; cin >> n >> k; ll arr[n]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } ll dp[n][k + 1]; dp[0][0] = 1; for (int i = 1; i <= k; ++i) { dp[0][i] = dp[0][i - 1]; if (i <= arr[0]) dp[0][i]++; } for (int i = 1; i < n; ++i) { for (int j = 0; j <= k; ++j) { ll temp = max(j - arr[i], 0LL); if (temp < 1) dp[i][j] = dp[i - 1][j]; else dp[i][j] = dp[i - 1][j] - dp[i - 1][temp - 1]; } for (int j = 1; j <= k; ++j) { dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD; } } if (k) cout << dp[n - 1][k] - dp[n - 1][k - 1]; else cout << dp[n - 1][k]; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ll long long int #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { off; int n, k; cin >> n >> k; ll arr[n]; for (int i = 0; i < n; ++i) { cin >> arr[i]; } ll dp[n][k + 1]; dp[0][0] = 1; for (int i = 1; i <= k; ++i) { dp[0][i] = dp[0][i - 1]; if (i <= arr[0]) dp[0][i]++; } for (int i = 1; i < n; ++i) { for (int j = 0; j <= k; ++j) { ll temp = max(j - arr[i], 0LL); if (temp < 1) dp[i][j] = dp[i - 1][j]; else dp[i][j] = dp[i - 1][j] - dp[i - 1][temp - 1]; } for (int j = 1; j <= k; ++j) { dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD; } } if (k) cout << (dp[n - 1][k] - dp[n - 1][k - 1] + MOD) % MOD; else cout << dp[n - 1][k]; return 0; }
[ "expression.operation.binary.add" ]
984,290
984,291
u540942722
cpp
p03172
#include <iostream> #include <vector> using namespace std; int MAX = 1e9 + 7; int dispatch(int total, vector<int> &criterias) { if (total == 0) return 1; int n = criterias.size(); vector<vector<int>> records = vector<vector<int>>(total + 1, vector<int>(n + 1, 0)); records[0][0] = 1; for (int candies = 1; candies <= total; candies++) records[candies][0] = records[candies - 1][0]; for (int people = 1; people <= n; people++) records[0][people] = 1; for (int people = 1; people <= n; people++) { for (int candies = 1; candies <= total; candies++) { int low = (candies - criterias[people - 1] - 1 >= 0) ? records[candies - criterias[people - 1] - 1][people - 1] : 0; int sum = (records[candies][people - 1] - low) % MAX; records[candies][people] = (records[candies - 1][people] + sum) % MAX; // cout << "candies=" << candies << " people=" << people << " // result=" << // records[candies][people]-records[candies-1][people] << // "\n"; } } return (records[total][n] - records[total - 1][n] + MAX * 2) % MAX; } int main() { int n, k; cin >> n >> k; vector<int> criterias = vector<int>(n); for (int i = 0; i < n; i++) cin >> criterias[i]; int result = dispatch(k, criterias); cout << result << "\n"; return 0; }
#include <iostream> #include <vector> using namespace std; int MAX = 1e9 + 7; int dispatch(int total, vector<int> &criterias) { if (total == 0) return 1; int n = criterias.size(); vector<vector<int>> records = vector<vector<int>>(total + 1, vector<int>(n + 1, 0)); records[0][0] = 1; for (int candies = 1; candies <= total; candies++) records[candies][0] = records[candies - 1][0]; for (int people = 1; people <= n; people++) records[0][people] = 1; for (int people = 1; people <= n; people++) { for (int candies = 1; candies <= total; candies++) { int low = (candies - criterias[people - 1] - 1 >= 0) ? records[candies - criterias[people - 1] - 1][people - 1] : 0; int sum = (records[candies][people - 1] - low) % MAX; records[candies][people] = (records[candies - 1][people] + sum) % MAX; // cout << "candies=" << candies << " people=" << people << " // result=" << // records[candies][people]-records[candies-1][people] << // "\n"; } } return (records[total][n] - records[total - 1][n] + MAX * 2ll) % MAX; } int main() { int n, k; cin >> n >> k; vector<int> criterias = vector<int>(n); for (int i = 0; i < n; i++) cin >> criterias[i]; int result = dispatch(k, criterias); cout << result << "\n"; return 0; }
[ "function.return_value.change" ]
984,292
984,293
u729714874
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define pu push #define pp pop_back #define in insert #define ld long double #define endl '\n' #define debug cout << "Hold right there sparky.....\n"; #define forn(low, high, i) for (i = low; i < high; i++) #define forrev(high, low, i) for (i = high; i >= low; i--) #define trace(x) cerr << #x << ": " << x << " " << endl; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; const ll mod = 1e9 + 7; int main() { IOS ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; ll dp[k + 1][n], dp1[k + 1][n]; memset(dp, 0, sizeof(dp)); memset(dp1, 0, sizeof(dp1)); for (ll i = 0; i < n; i++) { dp[0][i] = 1; dp1[0][i] = 1; } for (ll i = 1; i <= k; i++) { for (ll j = 0; j < n; j++) { if (j == 0) { dp[i][j] = i == a[j] ? 1 : 0; dp1[i][j] = dp1[i - 1][j] + dp[i][j]; dp1[i][j] %= mod; } else { dp[i][j] = a[j] < i ? dp1[i][j - 1] - dp1[i - a[j] - 1][j - 1] + mod : dp1[i][j - 1]; dp[i][j] %= mod; dp1[i][j] = dp1[i - 1][j] + dp[i][j]; dp1[i][j] %= mod; /*for(ll m=0;m<=min(a[j],i);m++) dp[i][j]+=dp[i-m][j-1];*/ } // cout<<dp1[i][j]<<" "; } /*cout<<endl; for(ll j=0;j<n;j++) cout<<dp[i][j]<<" "; cout<<endl;*/ } cout << dp[k][n - 1] << endl; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define pu push #define pp pop_back #define in insert #define ld long double #define endl '\n' #define debug cout << "Hold right there sparky.....\n"; #define forn(low, high, i) for (i = low; i < high; i++) #define forrev(high, low, i) for (i = high; i >= low; i--) #define trace(x) cerr << #x << ": " << x << " " << endl; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; const ll mod = 1e9 + 7; int main() { IOS ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) cin >> a[i]; ll dp[k + 1][n], dp1[k + 1][n]; memset(dp, 0, sizeof(dp)); memset(dp1, 0, sizeof(dp1)); for (ll i = 0; i < n; i++) { dp[0][i] = 1; dp1[0][i] = 1; } for (ll i = 1; i <= k; i++) { for (ll j = 0; j < n; j++) { if (j == 0) { dp[i][j] = i <= a[j] ? 1 : 0; dp1[i][j] = dp1[i - 1][j] + dp[i][j]; dp1[i][j] %= mod; } else { dp[i][j] = a[j] < i ? dp1[i][j - 1] - dp1[i - a[j] - 1][j - 1] + mod : dp1[i][j - 1]; dp[i][j] %= mod; dp1[i][j] = dp1[i - 1][j] + dp[i][j]; dp1[i][j] %= mod; /*for(ll m=0;m<=min(a[j],i);m++) dp[i][j]+=dp[i-m][j-1];*/ } // cout<<dp1[i][j]<<" "; } /*cout<<endl; for(ll j=0;j<n;j++) cout<<dp[i][j]<<" "; cout<<endl;*/ } cout << dp[k][n - 1] << endl; }
[ "expression.operator.compare.change", "assignment.value.change", "control_flow.branch.if.condition.change" ]
984,294
984,295
u859541564
cpp
p03172
// https://atcoder.jp/contests/dp/tasks/dp_m #include <algorithm> #include <array> #include <iomanip> #include <iostream> #include <queue> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main(int argc, char *argv[]) { int n, k; cin >> n >> k; vector<int> max_candies(n); for (int i = 0; i < n; i++) { cin >> max_candies[i]; } // dp[kid index][candies distributed] = number of patterns to distribute // candies up to kid index vector<vector<long long>> dp(n, vector<long long>(k + 1)); for (int i = 0; i <= min(k, max_candies[0]); i++) { dp[0][i] = 1; } for (int i = 1; i < n; i++) { long long patterns = 0; int window_size = min(max_candies[i], k) + 1; for (int total_c = 0; total_c <= k; total_c++) { if (total_c - window_size >= 0) { patterns = (patterns - dp[i - 1][total_c - window_size]) % 1000000007; } patterns = (patterns + dp[i - 1][total_c]) % 1000000007; dp[i][total_c] = patterns; } } cout << dp.back().back() << endl; }
// https://atcoder.jp/contests/dp/tasks/dp_m #include <algorithm> #include <array> #include <iomanip> #include <iostream> #include <queue> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main(int argc, char *argv[]) { int n, k; cin >> n >> k; vector<int> max_candies(n); for (int i = 0; i < n; i++) { cin >> max_candies[i]; } // dp[kid index][candies distributed] = number of patterns to distribute // candies up to kid index vector<vector<long long>> dp(n, vector<long long>(k + 1)); for (int i = 0; i <= min(k, max_candies[0]); i++) { dp[0][i] = 1; } for (int i = 1; i < n; i++) { long long patterns = 0; int window_size = min(max_candies[i], k) + 1; for (int total_c = 0; total_c <= k; total_c++) { if (total_c - window_size >= 0) { patterns = (patterns - dp[i - 1][total_c - window_size] + 1000000007) % 1000000007; } patterns = (patterns + dp[i - 1][total_c]) % 1000000007; dp[i][total_c] = patterns; } } cout << dp.back().back() << endl; }
[ "assignment.change" ]
984,296
984,297
u184819501
cpp
p03172
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned int uint; using namespace std; ll mod = 1000000007LL; int main() { cin.sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll dp[n + 1][k + 1]; fill(dp[0], dp[n] + k + 1, 0LL); dp[0][0] = 1LL; for (int i = 1; i <= n; i++) { dp[i][0] = 1LL; for (int j = 1; j <= k; j++) { if (j <= a[i - 1]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod; } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - a[i - 1] - 1]) % mod; } } } cout << dp[n][k] << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned int uint; using namespace std; ll mod = 1000000007LL; int main() { cin.sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll dp[n + 1][k + 1]; fill(dp[0], dp[n] + k + 1, 0LL); dp[0][0] = 1LL; for (int i = 1; i <= n; i++) { dp[i][0] = 1LL; for (int j = 1; j <= k; j++) { if (j <= a[i - 1]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod; } else { dp[i][j] = ((dp[i][j - 1] + dp[i - 1][j]) % mod + mod - dp[i - 1][j - a[i - 1] - 1]) % mod; } } } cout << dp[n][k] << "\n"; return 0; }
[ "assignment.change" ]
984,300
984,301
u334624175
cpp
p03172
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned int uint; using namespace std; ll mod = 1000000007LL; int main() { cin.sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll dp[n + 1][k + 1]; fill(dp[0], dp[n] + k + 1, 0LL); dp[0][0] = 1LL; for (int i = 1; i <= n; i++) { dp[i][0] = 1LL; for (int j = 1; j <= k; j++) { if (j <= a[i - 1]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod; } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - a[i - 1] - 1]) % mod; } } } cout << dp[n][k] << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned int uint; using namespace std; ll mod = 1000000007LL; int main() { cin.sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll dp[n + 1][k + 1]; fill(dp[0], dp[n] + k + 1, 0LL); dp[0][0] = 1LL; for (int i = 1; i <= n; i++) { dp[i][0] = 1LL; for (int j = 1; j <= k; j++) { if (j <= a[i - 1]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod; } else { dp[i][j] = ((dp[i][j - 1] + dp[i - 1][j]) % mod + mod - dp[i - 1][j - a[i - 1] - 1]) % mod; } } } cout << dp[n][k] << "\n"; return 0; }
[ "assignment.change" ]
984,302
984,301
u334624175
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define all(v) v.begin(), v.end() #define allarr(a) a, a + n #define ll long long #define ull unsigned long long #define pb push_back #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<int, pi> trp; typedef vector<pi> vpi; typedef vector<pll> vpll; // int ab (int x ) { return (x>0?x:-x); } const int F = 3e5 + 5; const ll mod = 1e9 + 7; ll dp[105][F]; int a[105]; int main() { 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++) { for (int j = 0; j <= k; j++) { dp[i + 1][j] += dp[i][j]; // dp[i+1][j]%=mod; // if(j+a[i]<=k){ dp[i + 1][j + a[i] + 1] -= dp[i][j]; // dp[i+1][j+a[i]+1]%=mod; } dp[i + 1][0] %= mod; for (int j = 1; j <= k; j++) dp[i + 1][j] += dp[i + 1][j - 1], assert(dp[i + 1][j] >= 0), dp[i + 1][j] %= mod; } // for(int i = 1 ; i <= n ; i++ ){for(int j = 0 ; j <= k ; j++ )cout << // dp[i][j]<<" " ; cout<<endl; } cout << dp[n][k] << endl; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define all(v) v.begin(), v.end() #define allarr(a) a, a + n #define ll long long #define ull unsigned long long #define pb push_back #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<int, pi> trp; typedef vector<pi> vpi; typedef vector<pll> vpll; // int ab (int x ) { return (x>0?x:-x); } const int F = 3e5 + 5; const ll mod = 1e9 + 7; ll dp[105][F]; int a[105]; int main() { 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++) { for (int j = 0; j <= k; j++) { dp[i + 1][j] += dp[i][j]; // dp[i+1][j]%=mod; // if(j+a[i]<=k){ dp[i + 1][j + a[i] + 1] -= dp[i][j]; // dp[i+1][j+a[i]+1]%=mod; } dp[i + 1][0] %= mod; for (int j = 1; j <= k; j++) dp[i + 1][j] += dp[i + 1][j - 1] + mod, assert(dp[i + 1][j] >= 0), dp[i + 1][j] %= mod; } // for(int i = 1 ; i <= n ; i++ ){for(int j = 0 ; j <= k ; j++ )cout << // dp[i][j]<<" " ; cout<<endl; } cout << dp[n][k] << endl; }
[ "assignment.change" ]
984,303
984,304
u179395482
cpp
p03172
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; using ll = long long; using ull = unsigned long long; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vs = V<string>; using qll = queue<ll>; using qpl = queue<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; #define int ll #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define emp empty() #define fr front() #define bk back() #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ string __VA_ARGS__; \ Input(__VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInput(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInput(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size, args...); REP(i, size) vInputNum(i, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.assign(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n, k); vli(n, a); vvll dp(n, vll(k + 1, 1)); REP(i, k + 1) { dp[0][i] = a[0] >= i; } REP1(i, n - 1) { REP1(j, k) { if (j - 1 - a[i] >= 0) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1 - a[i]]; } else { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } dp[i][j] %= MOD; } } cout << dp[n - 1][k]; }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class S, class T> using P = pair<S, T>; using ll = long long; using ull = unsigned long long; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vs = V<string>; using qll = queue<ll>; using qpl = queue<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; #define int ll #define fi first #define se second #define mp make_pair #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define emp empty() #define fr front() #define bk back() #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ string __VA_ARGS__; \ Input(__VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInput(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInput(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const string alp = "abcdefghijklmnopqrstuvwxyz"; const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInputNum(ll num) {} template <class T, class... Args> void vInputNum(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNum(num, args...); } void vInput(ll size) {} template <class... Args> void vInput(ll size, Args &...args) { vInit(size, args...); REP(i, size) vInputNum(i, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.assign(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n, k); vli(n, a); vvll dp(n, vll(k + 1, 1)); REP(i, k + 1) { dp[0][i] = a[0] >= i; } REP1(i, n - 1) { REP1(j, k) { if (j - 1 - a[i] >= 0) { dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1 - a[i]] + MOD; } else { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } dp[i][j] %= MOD; } } cout << dp[n - 1][k]; }
[ "assignment.change" ]
984,320
984,321
u172929647
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define forn(i, n) for (ll i = 0; i < n; i++) #define fore(i, a, b) for (ll i = a; i <= b; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define fi first #define se second #define endl "\n" #define all(a) a.begin(), a.end() #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265 /*************************************************************************************/ void file() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } /*************************************************************************************/ const ll maxn = 2e5 + 1, mod = 1e9 + 7; int main() { sync // file(); int n, k; cin >> n >> k; vector<ll> dp(k + 1); dp[0] = 1; forn(i, n) { int x; cin >> x; vector<int> fake(k + 1); for (int j = k; j >= 0; --j) { int l = j + 1; int r = j + min(x, k - j) + 1; if (l < r && l <= k) { fake[l] += dp[j]; fake[l] %= mod; fake[r] -= dp[j]; fake[r] += mod; fake[r] %= mod; } } ll pre = 0; fore(lel, 0, k) { pre += fake[lel]; pre %= mod; dp[lel] += pre; dp[lel] %= mod; } } cout << dp[k] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define forn(i, n) for (ll i = 0; i < n; i++) #define fore(i, a, b) for (ll i = a; i <= b; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define fi first #define se second #define endl "\n" #define all(a) a.begin(), a.end() #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265 /*************************************************************************************/ void file() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } /*************************************************************************************/ const ll maxn = 2e5 + 1, mod = 1e9 + 7; int main() { sync // file(); int n, k; cin >> n >> k; vector<ll> dp(k + 1); dp[0] = 1; forn(i, n) { int x; cin >> x; vector<int> fake(k + 2); for (int j = k; j >= 0; --j) { int l = j + 1; int r = j + min(x, k - j) + 1; if (l < r && l <= k) { fake[l] += dp[j]; fake[l] %= mod; // if(r<=k){ fake[r] -= dp[j]; fake[r] += mod; fake[r] %= mod; // } } } ll pre = 0; fore(lel, 0, k) { pre += fake[lel]; pre %= mod; dp[lel] += pre; dp[lel] %= mod; } } cout << dp[k] << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
984,324
984,325
u576115185
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define forn(i, n) for (ll i = 0; i < n; i++) #define fore(i, a, b) for (ll i = a; i <= b; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define fi first #define se second #define endl "\n" #define all(a) a.begin(), a.end() #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265 /*************************************************************************************/ void file() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } /*************************************************************************************/ const ll maxn = 2e5 + 1, mod = 1e9 + 7; int main() { sync // file(); int n, k; cin >> n >> k; vector<ll> dp(k + 1); dp[0] = 1; forn(i, n) { int x; cin >> x; vector<int> fake(k + 1); for (int j = k; j >= 0; --j) { int l = j + 1; int r = j + min(x, k - j) + 1; if (l < r) { fake[l] += dp[j]; fake[l] %= mod; fake[r] -= dp[j]; fake[r] += mod; fake[r] %= mod; } } ll pre = 0; fore(lel, 0, k) { pre += fake[lel]; pre %= mod; dp[lel] += pre; dp[lel] %= mod; } } cout << dp[k] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define mp make_pair #define forn(i, n) for (ll i = 0; i < n; i++) #define fore(i, a, b) for (ll i = a; i <= b; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define fi first #define se second #define endl "\n" #define all(a) a.begin(), a.end() #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265 /*************************************************************************************/ void file() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } /*************************************************************************************/ const ll maxn = 2e5 + 1, mod = 1e9 + 7; int main() { sync // file(); int n, k; cin >> n >> k; vector<ll> dp(k + 1); dp[0] = 1; forn(i, n) { int x; cin >> x; vector<int> fake(k + 2); for (int j = k; j >= 0; --j) { int l = j + 1; int r = j + min(x, k - j) + 1; if (l < r && l <= k) { fake[l] += dp[j]; fake[l] %= mod; // if(r<=k){ fake[r] -= dp[j]; fake[r] += mod; fake[r] %= mod; // } } } ll pre = 0; fore(lel, 0, k) { pre += fake[lel]; pre %= mod; dp[lel] += pre; dp[lel] %= mod; } } cout << dp[k] << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
984,326
984,325
u576115185
cpp
p03172
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int a[N], dp[K + 1][N]; // intでは若干ケタが足らずWAが出る for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; long int a[N], dp[K + 1][N]; // intでは若干ケタが足らずWAが出る for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
984,329
984,330
u543181229
cpp
p03172
// M - Candies https://atcoder.jp/contests/dp/tasks/dp_m /* 入力例 3 4 1 2 3 // →出力 5 // 横軸子供、縦軸アメのナップザック的2次元DP // 各セルには左のセルの個数と上からのセルの個数の和から上からのセルから満杯になってものを引いた値が入る。 // 左からのセル(i, j-1)の個数は、そのセル j列の子供が0個持つことを意味し // 上からのセル(i-1, j)の個数は、そのセル j列の子供が(i-1, j)に一つ加えたアメを持つことを意味する。そのためj列の子が持ちきれなくたった分を引かないといけないが // その個数は、DP表を考えると、dp[i - 1 - a[j]][j - 1]であらわされる。 // // WAがひどかった。(理由)1000000007で割るとえらく小さい値なる可能性があり、それから値を引いたとき、負の数になってしまって想定外のことがおこってしまう。 // 引き算がある場合は、この解答のように割る前に1000000007を足しておかないといけない。 */ #include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int a[N], dp[K + 1][N]; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; long int a[N], dp[K + 1][N]; // intでは若干ケタが足らずWAが出る for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
984,331
984,330
u543181229
cpp
p03172
// M - Candies https://atcoder.jp/contests/dp/tasks/dp_m /* 入力例 3 4 1 2 3 // →出力 5 // 横軸子供、縦軸アメのナップザック的2次元DP // 各セルには左のセルの個数と上からのセルの個数の和から上からのセルから満杯になってものを引いた値が入る。 // 左からのセル(i, j-1)の個数は、そのセル j列の子供が0個持つことを意味し // 上からのセル(i-1, j)の個数は、そのセル j列の子供が(i-1, j)に一つ加えたアメを持つことを意味する。そのためj列の子が持ちきれなくたった分を引かないといけないが // その個数は、DP表を考えると、dp[i - 1 - a[j]][j - 1]であらわされる。 // // WAがひどかった。(理由)1000000007で割るとえらく小さい値なる可能性があり、それから値を引いたとき、負の数になってしまって想定外のことがおこってしまう。 // 引き算がある場合は、この解答のように割る前に1000000007を足しておかないといけない。 */ #include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int a[N], dp[K + 1][N]; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; unsigned int a[N], dp[K + 1][N]; // intでは若干ケタが足らずWAが出る for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
[ "variable_declaration.type.widen.change", "expression.operation.binary.remove" ]
984,331
984,332
u543181229
cpp
p03172
// M - Candies https://atcoder.jp/contests/dp/tasks/dp_m /* 入力例 3 4 1 2 3 // →出力 5 // 横軸子供、縦軸アメのナップザック的2次元DP // 各セルには左のセルの個数と上からのセルの個数の和から上からのセルから満杯になってものを引いた値が入る。 // 左からのセル(i, j-1)の個数は、そのセル j列の子供が0個持つことを意味し // 上からのセル(i-1, j)の個数は、そのセル j列の子供が(i-1, j)に一つ加えたアメを持つことを意味する。そのためj列の子が持ちきれなくたった分を引かないといけないが // その個数は、DP表を考えると、dp[i - 1 - a[j]][j - 1]であらわされる。 // // WAがひどかった。(理由)1000000007で割るとえらく小さい値なる可能性があり、それから値を引いたとき、負の数になってしまって想定外のことがおこってしまう。 // 引き算がある場合は、この解答のように割る前に1000000007を足しておかないといけない。 */ #include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int a[N], dp[K + 1][N]; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; unsigned int a[N], dp[K + 1][N]; // intでは若干ケタが足らずWAが出る for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
984,331
984,333
u543181229
cpp
p03172
// M - Candies https://atcoder.jp/contests/dp/tasks/dp_m /* 入力例 3 4 1 2 3 // →出力 5 // 横軸子供、縦軸アメのナップザック的2次元DP // 各セルには左のセルの個数と上からのセルの個数の和から上からのセルから満杯になってものを引いた値が入る。 // 左からのセル(i, j-1)の個数は、そのセル j列の子供が0個持つことを意味し // 上からのセル(i-1, j)の個数は、そのセル j列の子供が(i-1, j)に一つ加えたアメを持つことを意味する。そのためj列の子が持ちきれなくたった分を引かないといけないが // その個数は、DP表を考えると、dp[i - 1 - a[j]][j - 1]であらわされる。 // // WAがひどかった。(理由)1000000007で割るとえらく小さい値なる可能性があり、それから値を引いたとき、負の数になってしまって想定外のことがおこってしまう。 // 引き算がある場合は、この解答のように割る前に1000000007を足しておかないといけない。 */ #include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; int a[N], dp[K + 1][N]; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
// M - Candies https://atcoder.jp/contests/dp/tasks/dp_m /* 入力例 3 4 1 2 3 // →出力 5 // 横軸子供、縦軸アメのナップザック的2次元DP // 各セルには左のセルの個数と上からのセルの個数の和から上からのセルから満杯になってものを引いた値が入る。 // 左からのセル(i, j-1)の個数は、そのセル j列の子供が0個持つことを意味し // 上からのセル(i-1, j)の個数は、そのセル j列の子供が(i-1, j)に一つ加えたアメを持つことを意味する。そのためj列の子が持ちきれなくたった分を引かないといけないが // その個数は、DP表を考えると、dp[i - 1 - a[j]][j - 1]であらわされる。 // // WAがひどかった。(理由)1000000007で割るとえらく小さい値なる可能性があり、それから値を引いたとき、負の数になってしまって想定外のことがおこってしまう。 // 引き算がある場合は、この解答のように割る前に1000000007を足しておかないといけない。 */ #include <bits/stdc++.h> using namespace std; int main(void) { int N, K; cin >> N >> K; unsigned int a[N], dp[K + 1][N]; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int j = 0; j < N; j++) { dp[0][j] = 1; } for (int i = 1; i <= K; i++) { if (i <= a[0]) { dp[i][0] = 1; } else { dp[i][0] = 0; } for (int j = 1; j < N; j++) { if (a[j] == 0) { dp[i][j] = dp[i][j - 1]; } else { if (i <= a[j]) { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007); } else { dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007); } } } } cout << dp[K][N - 1] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
984,331
984,334
u543181229
cpp
p03172
// // ///// /// // // // // // // // // // // // // //// // // // // // // // // ///////// // // // // // // // // ///// // // #include <bits/stdc++.h> using namespace std; #define forstl(i, v) for (auto &i : v) #define forn(i, e) for (int i = 0; i < e; i++) #define forsn(i, s, e) for (int i = s; i < e; i++) #define rforn(i, s) for (int i = s; i >= 0; i--) #define rforsn(i, s, e) for (int i = s; i >= e; i--) #define iter(it, a, b) for (a::iterator it = b.begin(); it != b.end(); ++it) #define clz(a) __builtin_clz(a) // count leading zeroes #define ctz(a) __builtin_ctz(a) // count trailing zeroes #define popc(a) \ __builtin_popcount( \ a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll) #define ln "\n" #define dbg(x) cerr << #x << " = " << x << endl #define dbg2(x, y) \ cerr << #x << " = " << x << " & " << #y << " = " << y << endl; #define dbgstl32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it << ln; \ } \ cerr << endl #define dbgstlp32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it.fi << " , " \ << it.se << ln; \ } \ cerr << endl #define dbgarr(v, s, e) \ cerr << #v << " = "; \ forsn(i, s, e) cerr << v[i] << ", "; \ cerr << endl #define mp make_pair #define pb push_back #define fi first #define se second #define all(n) n.begin(), n.end() #define tfi first.first #define tse first.second #define tth second typedef long long ll; typedef long double ld; typedef pair<int, int> p32; typedef pair<ll, ll> p64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int>> vv32; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef map<int, int> m32; typedef pair<pair<int, int>, int> tri; typedef vector<bool> vbool; typedef priority_queue<p32> pq32; typedef priority_queue<p32, vector<p32>, greater<p32>> pq32l; #pragma GCC optimize("-O2") const ll LIM = 2e5 + 5; const ll MOD = 1e9 + 7; const ll inf = 1e10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll dp[n + 1][k + 1]; forn(i, k + 1) dp[0][i] = 0; forn(i, n + 1) dp[i][0] = 1; forn(i, n) { forn(j, k) { if (j >= a[i]) dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j - a[i]]) % MOD; else dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD; } } cout << setprecision(20) << dp[n][k]; }
// // ///// /// // // // // // // // // // // // // //// // // // // // // // // ///////// // // // // // // // // ///// // // #include <bits/stdc++.h> using namespace std; #define forstl(i, v) for (auto &i : v) #define forn(i, e) for (int i = 0; i < e; i++) #define forsn(i, s, e) for (int i = s; i < e; i++) #define rforn(i, s) for (int i = s; i >= 0; i--) #define rforsn(i, s, e) for (int i = s; i >= e; i--) #define iter(it, a, b) for (a::iterator it = b.begin(); it != b.end(); ++it) #define clz(a) __builtin_clz(a) // count leading zeroes #define ctz(a) __builtin_ctz(a) // count trailing zeroes #define popc(a) \ __builtin_popcount( \ a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll) #define ln "\n" #define dbg(x) cerr << #x << " = " << x << endl #define dbg2(x, y) \ cerr << #x << " = " << x << " & " << #y << " = " << y << endl; #define dbgstl32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it << ln; \ } \ cerr << endl #define dbgstlp32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it.fi << " , " \ << it.se << ln; \ } \ cerr << endl #define dbgarr(v, s, e) \ cerr << #v << " = "; \ forsn(i, s, e) cerr << v[i] << ", "; \ cerr << endl #define mp make_pair #define pb push_back #define fi first #define se second #define all(n) n.begin(), n.end() #define tfi first.first #define tse first.second #define tth second typedef long long ll; typedef long double ld; typedef pair<int, int> p32; typedef pair<ll, ll> p64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int>> vv32; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef map<int, int> m32; typedef pair<pair<int, int>, int> tri; typedef vector<bool> vbool; typedef priority_queue<p32> pq32; typedef priority_queue<p32, vector<p32>, greater<p32>> pq32l; #pragma GCC optimize("-O2") const ll LIM = 2e5 + 5; const ll MOD = 1e9 + 7; const ll inf = 1e10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll dp[n + 1][k + 1]; forn(i, k + 1) dp[0][i] = 0; forn(i, n + 1) dp[i][0] = 1; forn(i, n) { forn(j, k) { if (j >= a[i]) dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j - a[i]] + MOD) % MOD; else dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD; } } cout << setprecision(20) << dp[n][k]; }
[ "assignment.change" ]
984,343
984,344
u416198344
cpp
p03172
// // ///// /// // // // // // // // // // // // // //// // // // // // // // // ///////// // // // // // // // // ///// // // #include <bits/stdc++.h> using namespace std; #define forstl(i, v) for (auto &i : v) #define forn(i, e) for (int i = 0; i < e; i++) #define forsn(i, s, e) for (int i = s; i < e; i++) #define rforn(i, s) for (int i = s; i >= 0; i--) #define rforsn(i, s, e) for (int i = s; i >= e; i--) #define iter(it, a, b) for (a::iterator it = b.begin(); it != b.end(); ++it) #define clz(a) __builtin_clz(a) // count leading zeroes #define ctz(a) __builtin_ctz(a) // count trailing zeroes #define popc(a) \ __builtin_popcount( \ a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll) #define ln "\n" #define dbg(x) cerr << #x << " = " << x << endl #define dbg2(x, y) \ cerr << #x << " = " << x << " & " << #y << " = " << y << endl; #define dbgstl32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it << ln; \ } \ cerr << endl #define dbgstlp32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it.fi << " , " \ << it.se << ln; \ } \ cerr << endl #define dbgarr(v, s, e) \ cerr << #v << " = "; \ forsn(i, s, e) cerr << v[i] << ", "; \ cerr << endl #define mp make_pair #define pb push_back #define fi first #define se second #define all(n) n.begin(), n.end() #define tfi first.first #define tse first.second #define tth second typedef long long ll; typedef long double ld; typedef pair<int, int> p32; typedef pair<ll, ll> p64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int>> vv32; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef map<int, int> m32; typedef pair<pair<int, int>, int> tri; typedef vector<bool> vbool; typedef priority_queue<p32> pq32; typedef priority_queue<p32, vector<p32>, greater<p32>> pq32l; #pragma GCC optimize("-O2") const ll LIM = 2e5 + 5; const ll MOD = 1e9 + 7; const ll inf = 1e10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll dp[n + 1][k + 1]; forn(i, k + 1) dp[0][i] = 0; forn(i, n + 1) dp[i][0] = 1; forn(i, n) { forn(j, k) { if (j >= a[i]) dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i + 1][j - a[i]]) % MOD; else dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD; } } cout << setprecision(20) << dp[n][k]; }
// // ///// /// // // // // // // // // // // // // //// // // // // // // // // ///////// // // // // // // // // ///// // // #include <bits/stdc++.h> using namespace std; #define forstl(i, v) for (auto &i : v) #define forn(i, e) for (int i = 0; i < e; i++) #define forsn(i, s, e) for (int i = s; i < e; i++) #define rforn(i, s) for (int i = s; i >= 0; i--) #define rforsn(i, s, e) for (int i = s; i >= e; i--) #define iter(it, a, b) for (a::iterator it = b.begin(); it != b.end(); ++it) #define clz(a) __builtin_clz(a) // count leading zeroes #define ctz(a) __builtin_ctz(a) // count trailing zeroes #define popc(a) \ __builtin_popcount( \ a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll) #define ln "\n" #define dbg(x) cerr << #x << " = " << x << endl #define dbg2(x, y) \ cerr << #x << " = " << x << " & " << #y << " = " << y << endl; #define dbgstl32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it << ln; \ } \ cerr << endl #define dbgstlp32(v) \ cerr << #v << " = \n"; \ { \ int c = 0; \ forstl(it, v) cerr << " Term " << ++c << " = " << it.fi << " , " \ << it.se << ln; \ } \ cerr << endl #define dbgarr(v, s, e) \ cerr << #v << " = "; \ forsn(i, s, e) cerr << v[i] << ", "; \ cerr << endl #define mp make_pair #define pb push_back #define fi first #define se second #define all(n) n.begin(), n.end() #define tfi first.first #define tse first.second #define tth second typedef long long ll; typedef long double ld; typedef pair<int, int> p32; typedef pair<ll, ll> p64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int>> vv32; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef map<int, int> m32; typedef pair<pair<int, int>, int> tri; typedef vector<bool> vbool; typedef priority_queue<p32> pq32; typedef priority_queue<p32, vector<p32>, greater<p32>> pq32l; #pragma GCC optimize("-O2") const ll LIM = 2e5 + 5; const ll MOD = 1e9 + 7; const ll inf = 1e10; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll dp[n + 1][k + 1]; forn(i, k + 1) dp[0][i] = 0; forn(i, n + 1) dp[i][0] = 1; forn(i, n) { forn(j, k) { if (j >= a[i]) dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j - a[i]] + MOD) % MOD; else dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD; } } cout << setprecision(20) << dp[n][k]; }
[ "expression.operation.binary.remove", "assignment.change" ]
984,345
984,344
u416198344
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; signed main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int dp[N + 1][K + 1]; for (int i = 0; i < N + 1; i++) { for (int j = 0; j < K + 1; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 1; i < N + 1; i++) { vector<int> cs(K + 2); for (int k = 0; k < K + 1; k++) { cs[k + 1] = (cs[k] + dp[i - 1][k]) % mod; } for (int j = 0; j < K + 1; j++) { dp[i][j] = (cs[j + 1] - cs[max(j - A[i - 1], 0LL) + mod]) % mod; } } cout << dp[N][K] << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; signed main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int dp[N + 1][K + 1]; for (int i = 0; i < N + 1; i++) { for (int j = 0; j < K + 1; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 1; i < N + 1; i++) { vector<int> cs(K + 2); for (int k = 0; k < K + 1; k++) { cs[k + 1] = (cs[k] + dp[i - 1][k]) % mod; } for (int j = 0; j < K + 1; j++) { dp[i][j] = (cs[j + 1] - cs[max(j - A[i - 1], 0LL)] + mod) % mod; } } cout << dp[N][K] << endl; }
[]
984,350
984,351
u983918956
cpp
p03172
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; signed main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int dp[N + 1][K + 1]; for (int i = 0; i < N + 1; i++) { for (int j = 0; j < K + 1; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 1; i < N + 1; i++) { vector<int> cs(K + 2); for (int k = 0; k < K + 1; k++) { cs[k + 1] = (cs[k] + dp[i - 1][k]) % mod; } for (int j = 0; j < K + 1; j++) { dp[i][j] = (cs[j + 1] - cs[max(j - A[i - 1], 0LL)]) % mod; } } cout << dp[N][K] << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; signed main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int dp[N + 1][K + 1]; for (int i = 0; i < N + 1; i++) { for (int j = 0; j < K + 1; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 1; i < N + 1; i++) { vector<int> cs(K + 2); for (int k = 0; k < K + 1; k++) { cs[k + 1] = (cs[k] + dp[i - 1][k]) % mod; } for (int j = 0; j < K + 1; j++) { dp[i][j] = (cs[j + 1] - cs[max(j - A[i - 1], 0LL)] + mod) % mod; } } cout << dp[N][K] << endl; }
[ "assignment.change" ]
984,352
984,351
u983918956
cpp
p03172
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unistd.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vvb> vvvb; typedef vector<vvvb> vvvvb; typedef vector<string> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> vp; typedef vector<PL> vpl; typedef vector<vector<P>> vvp; typedef vector<vector<PL>> vvpl; const int INF = 1001001001; const ll LINF = 1e17; const double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for (ll i = (a); i < b; i++) #define RFOR(i, a, b) for (ll i = (a); i > b; i--) #define REP(i, n) for (ll i = 0; i < n; i++) #define RREP(i, n) for (ll i = n - 1; i > -1; i--) #define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back #define epb emplace_back template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; }; bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; }; bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; }; bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; }; template <typename T> vector<T> uniquen(vector<T> vec) { vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll N, K; cin >> N >> K; vl A(N); REP(i, N) cin >> A[i]; const ll mod = 1e9 + 7; vvl dp(N + 1, vl(K + 1, 0)); dp[0][0] = 1; REP(i, N) { vl sum(K + 2, 0); REP(j, K + 1) { sum[j + 1] = (sum[j] + dp[i][j]) % mod; } REP(j, K + 1) { if (j < A[i]) dp[i + 1][j] = sum[j + 1]; else dp[i + 1][j] = sum[j + 1] - sum[j - A[i]]; } } cout << dp[N][K] << endstr; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unistd.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<vvb> vvvb; typedef vector<vvvb> vvvvb; typedef vector<string> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> vp; typedef vector<PL> vpl; typedef vector<vector<P>> vvp; typedef vector<vector<PL>> vvpl; const int INF = 1001001001; const ll LINF = 1e17; const double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for (ll i = (a); i < b; i++) #define RFOR(i, a, b) for (ll i = (a); i > b; i--) #define REP(i, n) for (ll i = 0; i < n; i++) #define RREP(i, n) for (ll i = n - 1; i > -1; i--) #define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back #define epb emplace_back template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; }; bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; }; bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; }; bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; }; template <typename T> vector<T> uniquen(vector<T> vec) { vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll N, K; cin >> N >> K; vl A(N); REP(i, N) cin >> A[i]; const ll mod = 1e9 + 7; vvl dp(N + 1, vl(K + 1, 0)); dp[0][0] = 1; REP(i, N) { vl sum(K + 2, 0); REP(j, K + 1) { sum[j + 1] = (sum[j] + dp[i][j]) % mod; } REP(j, K + 1) { if (j < A[i]) dp[i + 1][j] = sum[j + 1]; else dp[i + 1][j] = (sum[j + 1] - sum[j - A[i]] + mod) % mod; } } cout << dp[N][K] << endstr; return 0; }
[ "assignment.change" ]
984,355
984,356
u159208574
cpp
p03172
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unistd.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> vp; typedef vector<PL> vpl; typedef vector<vector<P>> vvp; typedef vector<vector<PL>> vvpl; const int INF = 1001001001; const ll LINF = 1e12; const double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for (ll i = (a); i < b; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; }; bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; }; bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; }; bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; }; template <typename T> vector<T> uniquen(vector<T> vec) { vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } const ll mod = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vl a(N); REP(i, N) cin >> a[i]; vvl dp(N + 1, vl(K + 1, 0)); REP(i, K + 1) if (i <= a[0]) dp[1][i] = 1; FOR(i, 1, N) { vl sum(K + 1, 0); REP(j, K + 1) sum[j + 1] = (sum[j] + dp[i][j]) % mod; REP(l, K + 1) { dp[i + 1][l] = (sum[l + 1] - sum[max(l - a[i], 0ll)] + mod) % mod; } } cout << dp[N][K] % mod << endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unistd.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> vp; typedef vector<PL> vpl; typedef vector<vector<P>> vvp; typedef vector<vector<PL>> vvpl; const int INF = 1001001001; const ll LINF = 1e12; const double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for (ll i = (a); i < b; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; }; bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; }; bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; }; bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; }; template <typename T> vector<T> uniquen(vector<T> vec) { vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } const ll mod = 1e9 + 7; int main() { ll N, K; cin >> N >> K; vl a(N); REP(i, N) cin >> a[i]; vvl dp(N + 1, vl(K + 1, 0)); REP(i, K + 1) if (i <= a[0]) dp[1][i] = 1; FOR(i, 1, N) { vl sum(K + 2, 0); REP(j, K + 1) sum[j + 1] = (sum[j] + dp[i][j]) % mod; REP(l, K + 1) { dp[i + 1][l] = (sum[l + 1] - sum[max(l - a[i], 0ll)] + mod) % mod; } } cout << dp[N][K] % mod << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
984,357
984,358
u159208574
cpp
p03172
#include <stdio.h> #include <stdlib.h> #include <string.h> //#include <math.h> //#include <algorithm> #include <vector> #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) using namespace std; #define MOD 1000000007 int main(int argc, char *argv[]) { long n, k; scanf("%ld %ld", &n, &k); long a[101] = {0}; vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, 0)); long i, j; for (i = 0; i < n; i++) { scanf("%ld", &(a[i])); } for (i = 0; i <= n; i++) { dp[i][0] = 1; } for (i = 0; i < n; i++) { for (j = 1; j <= k; j++) { if (j - 1 - a[i] >= 0) { dp[i + 1][j] = (dp[i][j] + dp[i + 1][j - 1] - dp[i][j - 1 - a[i]]) % MOD; } else { dp[i + 1][j] = (dp[i][j] + dp[i + 1][j - 1]) % MOD; } } } printf("%lld\n", dp[n][k]); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> //#include <math.h> //#include <algorithm> #include <vector> #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) using namespace std; #define MOD 1000000007 int main(int argc, char *argv[]) { long n, k; scanf("%ld %ld", &n, &k); long a[101] = {0}; vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, 0)); long i, j; for (i = 0; i < n; i++) { scanf("%ld", &(a[i])); } for (i = 0; i <= n; i++) { dp[i][0] = 1; } for (i = 0; i < n; i++) { for (j = 1; j <= k; j++) { if (j - 1 - a[i] >= 0) { dp[i + 1][j] = (dp[i][j] + dp[i + 1][j - 1] - dp[i][j - 1 - a[i]] + MOD) % MOD; } else { dp[i + 1][j] = (dp[i][j] + dp[i + 1][j - 1]) % MOD; } } } printf("%lld\n", dp[n][k]); return 0; }
[ "assignment.change" ]
984,359
984,360
u209713918
cpp
p03172
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <utility> #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> rest(N); rest[N - 1] = 0; for (int i = N - 2; i >= 0; i--) { rest[i] = rest[i + 1] + a[i + 1]; } vector<long long> before(K + 2, 1); vector<long long> next(K + 2); before[0] = 0; next[0] = 0; for (int i = 0; i < N; i++) { int temp = a[i]; int lower = max(0, K - rest[i]); for (int j = 0; j < lower; j++) { next[j + 1] = 0; } for (int j = lower; j <= K; j++) { next[j + 1] = (next[j] + (before[j + 1] - before[max(0, j - temp)])) % MOD; } // for(int j = 0; j < K + 2; j++){ // cout << next[j] << " "; // } // cout << endl; swap(before, next); } cout << before[K + 1] << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <utility> #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> rest(N); rest[N - 1] = 0; for (int i = N - 2; i >= 0; i--) { rest[i] = rest[i + 1] + a[i + 1]; } vector<long long> before(K + 2, 1); vector<long long> next(K + 2); before[0] = 0; next[0] = 0; for (int i = 0; i < N; i++) { int temp = a[i]; int lower = max(0, K - rest[i]); for (int j = 0; j < lower; j++) { next[j + 1] = 0; } for (int j = lower; j <= K; j++) { next[j + 1] = (next[j] + (before[j + 1] - before[max(0, j - temp)] + MOD)) % MOD; } // for(int j = 0; j < K + 2; j++){ // cout << next[j] << " "; // } // cout << endl; swap(before, next); } cout << before[K + 1] << endl; return 0; }
[ "assignment.change" ]
984,361
984,362
u048945791
cpp
p03172
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <utility> #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> rest(N); rest[N - 1] = 0; for (int i = N - 2; i >= 0; i--) { rest[i] = rest[i + 1] + a[i + 1]; } vector<int> before(K + 2, 1); vector<int> next(K + 2); before[0] = 0; next[0] = 0; for (int i = 0; i < N; i++) { int temp = a[i]; int lower = max(0, K - rest[i]); for (int j = 0; j < lower; j++) { next[j + 1] = 0; } for (int j = lower; j <= K; j++) { next[j + 1] = (next[j] + (before[j + 1] - before[max(0, j - temp)])) % MOD; } // for(int j = 0; j < K + 2; j++){ // cout << next[j] << " "; // } // cout << endl; swap(before, next); } cout << before[K + 1] << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <numeric> #include <string> #include <utility> #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> rest(N); rest[N - 1] = 0; for (int i = N - 2; i >= 0; i--) { rest[i] = rest[i + 1] + a[i + 1]; } vector<long long> before(K + 2, 1); vector<long long> next(K + 2); before[0] = 0; next[0] = 0; for (int i = 0; i < N; i++) { int temp = a[i]; int lower = max(0, K - rest[i]); for (int j = 0; j < lower; j++) { next[j + 1] = 0; } for (int j = lower; j <= K; j++) { next[j + 1] = (next[j] + (before[j + 1] - before[max(0, j - temp)] + MOD)) % MOD; } // for(int j = 0; j < K + 2; j++){ // cout << next[j] << " "; // } // cout << endl; swap(before, next); } cout << before[K + 1] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "assignment.change" ]
984,363
984,362
u048945791
cpp
p03172
#include <bits/stdc++.h> #define ll long long #define MAX 300005 #define pp pair<int, pair<int, int>> #define pb push_back #define mod 1000000007 using namespace std; /* * author: Kruti_20 */ ll power(ll x, ll y); ll gcd(ll a, ll b); ll dp[105][MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; ll a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= a[1]; i++) dp[1][i] = i + 1; for (int i = a[1] + 1; i <= k; i++) dp[1][i] = dp[1][a[1]]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= k; j++) { dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; if (j > 0) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; if (j > a[i]) dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - a[i] - 1] + 10 * mod) % mod; } } cout << (dp[n][k] - dp[n][k - 1] + mod) % mod << "\n"; return 0; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
#include <bits/stdc++.h> #define ll long long #define MAX 300005 #define pp pair<int, pair<int, int>> #define pb push_back #define mod 1000000007 using namespace std; /* * author: Kruti_20 */ ll power(ll x, ll y); ll gcd(ll a, ll b); ll dp[105][MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; ll a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 0; i <= a[1]; i++) dp[1][i] = i + 1; for (int i = a[1] + 1; i <= k; i++) dp[1][i] = dp[1][a[1]]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= k; j++) { dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; if (j > 0) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; if (j > a[i]) dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - a[i] - 1]) % mod; } } cout << (dp[n][k] - dp[n][k - 1] + mod) % mod << "\n"; return 0; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
[ "expression.operation.binary.remove" ]
984,364
984,365
u352059674
cpp
p03172
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORALL(i, m) for (auto i = m.begin(); i != m.end(); ++i) #define INF 2e9 #define ALL(v) v.begin(), v.end() #define TM_T template <class T> using namespace std; typedef long long ll; TM_T T inp() { T it; cin >> it; return it; } ll N, K; vector<ll> li; vector<ll> dp; vector<ll> dp2; int input() { cin >> N >> K; REP(i, N) li.push_back(inp<ll>()); } int main() { input(); REP(i, K + 1) dp.push_back(0); REP(i, K + 1) dp2.push_back(0); dp[0] = 1; REP(i, N) { REP(j, K + 1) dp2[j] = 0; REP(j, K + 1) { dp2[j] = dp[j]; if (j > 0) dp2[j] += dp2[j - 1]; if (j - li[i] > 0) dp2[j] += -dp[j - li[i] - 1] + (1000000007 * 9); } REP(j, K + 1) dp[j] = dp2[j] % (1000000007); } cout << dp[K] << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORALL(i, m) for (auto i = m.begin(); i != m.end(); ++i) #define INF 2e9 #define ALL(v) v.begin(), v.end() #define TM_T template <class T> using namespace std; typedef long long ll; TM_T T inp() { T it; cin >> it; return it; } ll N, K; vector<ll> li; vector<ll> dp; vector<ll> dp2; int input() { cin >> N >> K; REP(i, N) li.push_back(inp<ll>()); } int main() { input(); REP(i, K + 1) dp.push_back(0); REP(i, K + 1) dp2.push_back(0); dp[0] = 1; REP(i, N) { REP(j, K + 1) dp2[j] = 0; REP(j, K + 1) { dp2[j] = dp[j]; if (j > 0) dp2[j] += dp2[j - 1]; if (j - li[i] > 0) dp2[j] += -dp[j - li[i] - 1] + (1000000007l * 9l); } REP(j, K + 1) dp[j] = dp2[j] % (1000000007l); } cout << dp[K] << endl; }
[]
984,373
984,374
u649373416
cpp
p03172
// // main.cpp // atcoder-candies // // Created by r on 6/1/19. // Copyright © 2019 r. All rights reserved. // #include <algorithm> #include <assert.h> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //#define RDEBUG 1 #ifdef RDEBUG #define D(x) x #else #define D(x) #endif #define inf 0x7fffffff #define MOD 1000000007 long long N, K; long long pref[200010]; long long currpref[200010]; long long dp[210][200010]; long long a[200010]; int main() { ios_base ::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K; for (long long i = 1; i <= N; i++) { cin >> a[i]; a[i] %= MOD; } dp[0][0] = 1; for (long long i = 0; i <= K; i++) { pref[i + 1] = (pref[i + 1] + pref[i]) % MOD; pref[i + 1] = (pref[i + 1] + dp[0][i]) % MOD; } for (long long i = 1; i <= N; i++) { for (long long j = 0; j <= K; j++) { dp[i][j] = (pref[j + 1] - pref[max((long long)0, j - a[i])]) % MOD; currpref[j + 1] = (currpref[j + 1] + currpref[j]) % MOD; currpref[j + 1] = (currpref[j + 1] + dp[i][j]) % MOD; } for (int j = 0; j <= K + 1; j++) { pref[j] = currpref[j]; currpref[j] = 0; } } cout << dp[N][K] % MOD << endl; return 0; }
#include <algorithm> #include <assert.h> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //#define RDEBUG 1 #ifdef RDEBUG #define D(x) x #else #define D(x) #endif #define inf 0x7fffffff #define MOD 1000000007 long long N, K; long long pref[200010]; long long currpref[200010]; long long dp[210][200010]; long long a[200010]; int main() { ios_base ::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K; for (long long i = 1; i <= N; i++) { cin >> a[i]; a[i] %= MOD; } dp[0][0] = 1; for (long long i = 0; i <= K; i++) { pref[i + 1] = (pref[i + 1] + pref[i]) % MOD; pref[i + 1] = (pref[i + 1] + dp[0][i]) % MOD; } for (long long i = 1; i <= N; i++) { for (long long j = 0; j <= K; j++) { dp[i][j] = (pref[j + 1] - pref[max((long long)0, j - a[i])] + MOD) % MOD; currpref[j + 1] = (currpref[j + 1] + currpref[j]) % MOD; currpref[j + 1] = (currpref[j + 1] + dp[i][j]) % MOD; } for (int j = 0; j <= K + 1; j++) { pref[j] = currpref[j]; currpref[j] = 0; } } cout << dp[N][K] % MOD << endl; return 0; }
[ "assignment.change" ]
984,375
984,376
u707204861
cpp
p03172
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; /*BigInteger #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> namespace xxx = boost::multiprecision; using Bint = xxx::cpp_int; using Real = xxx::number<xxx::cpp_dec_float<1024>>; */ #define int long long #define pb(x) push_back(x) #define m0(x) memset((x), 0LL, sizeof(x)) #define mm(x) memset((x), -1LL, sizeof(x)) // container #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end()); #define PERM(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) // debug #define GET_VAR_NAME(variable) #variable #define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl; // bit_macro #define Bit(n) (1LL << (n)) #define Bitset(a, b) (a) |= (1LL << (b)) #define Bitunset(a, b) (a) &= ~(1LL << (b)) #define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL) #define Bitcount(a) __builtin_popcountll((a)) // typedef typedef long long lint; typedef unsigned long long ull; typedef complex<long double> Complex; typedef pair<int, int> P; typedef tuple<int, int, int> TP; typedef vector<int> vec; typedef vector<vec> mat; // constant constexpr int INF = (int)1e18; constexpr int MOD = (int)1e9 + 7; constexpr double PI = (double)acos(-1); constexpr double EPS = (double)1e-10; constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1}; constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1}; // template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } // inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // struct Accelerate_Cin { Accelerate_Cin() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } Accelerate_Cin; signed main() { int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; static int dp[110][101010]; m0(dp); dp[0][0] = 1; for (int i = 0; i < N; i++) { vector<int> sum(K + 1); for (int j = 0; j <= K + 1; j++) { if (j == 0) { sum[j] = dp[0][0]; } else { sum[j] = (sum[j - 1] + dp[i][j - 1]) % MOD; } } for (int k = 0; k <= K; k++) { dp[i + 1][k] = ((sum[k + 1] - sum[max(0LL, k - a[i])]) % MOD + MOD) % MOD; } } cout << dp[N][K] << endl; return 0; }
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; /*BigInteger #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/rational.hpp> namespace xxx = boost::multiprecision; using Bint = xxx::cpp_int; using Real = xxx::number<xxx::cpp_dec_float<1024>>; */ #define int long long #define pb(x) push_back(x) #define m0(x) memset((x), 0LL, sizeof(x)) #define mm(x) memset((x), -1LL, sizeof(x)) // container #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end()); #define PERM(c) \ sort(ALL(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c))) // debug #define GET_VAR_NAME(variable) #variable #define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl; // bit_macro #define Bit(n) (1LL << (n)) #define Bitset(a, b) (a) |= (1LL << (b)) #define Bitunset(a, b) (a) &= ~(1LL << (b)) #define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL) #define Bitcount(a) __builtin_popcountll((a)) // typedef typedef long long lint; typedef unsigned long long ull; typedef complex<long double> Complex; typedef pair<int, int> P; typedef tuple<int, int, int> TP; typedef vector<int> vec; typedef vector<vec> mat; // constant constexpr int INF = (int)1e18; constexpr int MOD = (int)1e9 + 7; constexpr double PI = (double)acos(-1); constexpr double EPS = (double)1e-10; constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1}; constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1}; // template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } // inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // struct Accelerate_Cin { Accelerate_Cin() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } Accelerate_Cin; signed main() { int N, K; cin >> N >> K; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; static int dp[110][101010]; m0(dp); dp[0][0] = 1; for (int i = 0; i < N; i++) { vector<int> sum(K + 10); for (int j = 0; j <= K + 1; j++) { if (j == 0) { sum[j] = dp[0][0]; } else { sum[j] = (sum[j - 1] + dp[i][j - 1]) % MOD; } } for (int k = 0; k <= K; k++) { dp[i + 1][k] = (sum[k + 1] - sum[max(0LL, k - a[i])] + MOD) % MOD; } } cout << dp[N][K] << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
984,387
984,388
u876978301
cpp
p03177
#include <bits/stdc++.h> using namespace std; long long n; typedef struct node { long long a[51][51]; long long scale; struct node operator*(const struct node &tmp) { struct node ret; long long i, j, k; ret.scale = scale; memset(ret.a, 0, sizeof(ret.a)); for (k = 1; k <= scale; k++) for (i = 1; i <= scale; i++) for (j = 1; j <= scale; j++) if (a[i][k] && tmp.a[k][j]) ret.a[i][j] = (ret.a[i][j] + (long long)a[i][k] * tmp.a[k][j]) % 1000000007; return ret; } } NODE, *PNODE; NODE g, ans; int main() { long long s = 0, flag = 0; long long i, j, k, q, w; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%lld", &g.a[i][j]); } } g.scale = n; while (k) { if (k % 2) { if (!flag) { ans = g; flag = 1; } else ans = ans * g; } g = g * g; k /= 2; } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { s += ans.a[i][j] % 1000000007; } } printf("%lld", s); return 0; }
#include <bits/stdc++.h> using namespace std; long long n; typedef struct node { long long a[51][51]; long long scale; struct node operator*(const struct node &tmp) { struct node ret; long long i, j, k; ret.scale = scale; memset(ret.a, 0, sizeof(ret.a)); for (k = 1; k <= scale; k++) for (i = 1; i <= scale; i++) for (j = 1; j <= scale; j++) if (a[i][k] && tmp.a[k][j]) ret.a[i][j] = (ret.a[i][j] + (long long)a[i][k] * tmp.a[k][j]) % 1000000007; return ret; } } NODE, *PNODE; NODE g, ans; int main() { long long s = 0, flag = 0; long long i, j, k, q, w; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%lld", &g.a[i][j]); } } g.scale = n; while (k) { if (k % 2) { if (!flag) { ans = g; flag = 1; } else ans = ans * g; } g = g * g; k /= 2; } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { s = (s + ans.a[i][j]) % 1000000007; } } printf("%lld", s); return 0; }
[ "assignment.value.change" ]
984,402
984,403
u963399321
cpp
p03177
#include <bits/stdc++.h> using namespace std; long long n; typedef struct node { long long a[51][51]; long long scale; struct node operator*(const struct node &tmp) { struct node ret; long long i, j, k; ret.scale = scale; memset(ret.a, 0, sizeof(ret.a)); for (k = 1; k <= scale; k++) for (i = 1; i <= scale; i++) for (j = 1; j <= scale; j++) if (a[i][k] && tmp.a[k][j]) ret.a[i][j] = (ret.a[i][j] + (long long)a[i][k] * tmp.a[k][j]) % 1000000007; return ret; } } NODE, *PNODE; NODE g, ans; int main() { long long s = 0, flag = 0; long long i, j, k, q, w; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%lld", &g.a[i][j]); } } g.scale = n; while (k) { if (k % 2) { if (!flag) { ans = g; flag = 1; } else ans = ans * g; } g = g * g; k /= 2; } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { s += (s + ans.a[i][j]) % 1000000007; } } printf("%lld", s); return 0; }
#include <bits/stdc++.h> using namespace std; long long n; typedef struct node { long long a[51][51]; long long scale; struct node operator*(const struct node &tmp) { struct node ret; long long i, j, k; ret.scale = scale; memset(ret.a, 0, sizeof(ret.a)); for (k = 1; k <= scale; k++) for (i = 1; i <= scale; i++) for (j = 1; j <= scale; j++) if (a[i][k] && tmp.a[k][j]) ret.a[i][j] = (ret.a[i][j] + (long long)a[i][k] * tmp.a[k][j]) % 1000000007; return ret; } } NODE, *PNODE; NODE g, ans; int main() { long long s = 0, flag = 0; long long i, j, k, q, w; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%lld", &g.a[i][j]); } } g.scale = n; while (k) { if (k % 2) { if (!flag) { ans = g; flag = 1; } else ans = ans * g; } g = g * g; k /= 2; } for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { s = (s + ans.a[i][j]) % 1000000007; } } printf("%lld", s); return 0; }
[ "assignment.value.change" ]
984,404
984,403
u963399321
cpp
p03177
#include <bits/stdc++.h> using namespace std; long long n, k; typedef struct node { long long a[51][51]; struct node operator*(const struct node &tmp) { int i, j, K; struct node ret; memset(ret.a, 0, sizeof(ret.a)); for (K = 1; K <= n; K++) { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (a[i][K] && tmp.a[K][j]) ret.a[i][j] = ((long long)a[i][K] * tmp.a[K][j] + ret.a[i][j]) % 100000007; } } } return ret; } } NODE, *PNODE; NODE ans, g; int main() { int flag = 0, i, j; long long a; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%lld", &g.a[i][j]); } } while (k) { if (k % 2) { if (!flag) { ans = g; flag = 1; } else ans = ans * g; } g = g * g; k /= 2; } a = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { a = ((long long)a + ans.a[i][j]) % 1000000007; } } printf("%lld", a); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, k; typedef struct node { long long a[51][51]; struct node operator*(const struct node &tmp) { int i, j, K; struct node ret; memset(ret.a, 0, sizeof(ret.a)); for (K = 1; K <= n; K++) { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (a[i][K] && tmp.a[K][j]) ret.a[i][j] = ((long long)a[i][K] * tmp.a[K][j] + ret.a[i][j]) % 1000000007; } } } return ret; } } NODE, *PNODE; NODE ans, g; int main() { int flag = 0, i, j; long long a; scanf("%lld %lld", &n, &k); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { scanf("%lld", &g.a[i][j]); } } while (k) { if (k % 2) { if (!flag) { ans = g; flag = 1; } else ans = ans * g; } g = g * g; k /= 2; } a = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { a = ((long long)a + ans.a[i][j]) % 1000000007; } } printf("%lld", a); return 0; }
[ "assignment.value.change", "expression.operation.binary.change" ]
984,405
984,406
u356929542
cpp
p03177
#include <bits/stdc++.h> using namespace std; #define oo 666666666 #define ll long long #define ld long double vector<vector<ll>> Mul(vector<vector<ll>> A, vector<vector<ll>> B, ll mod) { int n = A.size(); vector<vector<ll>> ats(n, vector<ll>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) ats[i][j] = (ats[i][j] + A[i][k] * B[k][j]) % mod; return ats; } vector<vector<ll>> Pow(vector<vector<ll>> A, ll n, ll mod) { if (n <= 1) return A; if (n & 1) return Mul(A, Pow(A, n - 1, mod), mod); return Pow(Mul(A, A, mod), n / 2, mod); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, k, mod = 1e9 + 7; cin >> n >> k; vector<vector<ll>> A(n, vector<ll>(n)); for (auto &r : A) for (auto &c : r) cin >> c; A = Pow(A, k, mod); ll ats = 0; for (auto &r : A) for (auto &c : r) ats = ats + c % mod; cout << ats; }
#include <bits/stdc++.h> using namespace std; #define oo 666666666 #define ll long long #define ld long double vector<vector<ll>> Mul(vector<vector<ll>> A, vector<vector<ll>> B, ll mod) { int n = A.size(); vector<vector<ll>> ats(n, vector<ll>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) ats[i][j] = (ats[i][j] + A[i][k] * B[k][j]) % mod; return ats; } vector<vector<ll>> Pow(vector<vector<ll>> A, ll n, ll mod) { if (n <= 1) return A; if (n & 1) return Mul(A, Pow(A, n - 1, mod), mod); return Pow(Mul(A, A, mod), n / 2, mod); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, k, mod = 1e9 + 7; cin >> n >> k; vector<vector<ll>> A(n, vector<ll>(n)); for (auto &r : A) for (auto &c : r) cin >> c; A = Pow(A, k, mod); ll ats = 0; for (auto &r : A) for (auto &c : r) ats = (ats + c) % mod; cout << ats; }
[]
984,409
984,410
u847400794
cpp
p03177
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define INF 2000000000000000000LL #define EPS 1e-9 #define debug(a) cerr << #a << "=" << (a) << "\n" #define FastSlowInput \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); typedef long long ll; typedef unsigned long long ull; typedef complex<double> cd; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; const double PI = acos(-1); struct matrix { int mat[50][50]; int sz; void identity() { memset(mat, 0, sizeof mat); for (int i = 0; i < sz; ++i) mat[i][i] = 1; } matrix operator*(const matrix ot) { matrix res; res.sz = sz; for (int i = 0; i < sz; ++i) { for (int j = 0; j < sz; ++j) { res.mat[i][j] = 0; for (int k = 0; k < sz; ++k) { res.mat[i][j] += 1LL * mat[i][k] * ot.mat[k][j] % mod; res.mat[i][j] %= mod; } } } return res; } int sum() { int res = 0; for (int i = 0; i < sz; ++i) { for (int j = 0; j < sz; ++j) { res += mat[i][j]; res %= mod; } } return res; } void print() { cout << "print:" << endl; for (int i = 0; i < sz; ++i) { for (int j = 0; j < sz; ++j) { cout << mat[i][j] << " "; } cout << endl; } } }; int n, i, j, k, t; ll p; matrix mat; matrix pp[32]; int main() { scanf("%d %lld", &n, &p); mat.sz = n; for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { scanf("%d", &mat.mat[i][j]); } } pp[0] = mat; for (i = 1; i < 32; ++i) { pp[i] = pp[i - 1] * pp[i - 1]; } matrix res; res.sz = n; res.identity(); for (i = 0; p; ++i) { if (p & 1) { res = res * pp[i]; } p >>= 1; } printf("%d\n", res.sum()); return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define INF 2000000000000000000LL #define EPS 1e-9 #define debug(a) cerr << #a << "=" << (a) << "\n" #define FastSlowInput \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); typedef long long ll; typedef unsigned long long ull; typedef complex<double> cd; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; const double PI = acos(-1); struct matrix { int mat[50][50]; int sz; void identity() { memset(mat, 0, sizeof mat); for (int i = 0; i < sz; ++i) mat[i][i] = 1; } matrix operator*(const matrix ot) { matrix res; res.sz = sz; for (int i = 0; i < sz; ++i) { for (int j = 0; j < sz; ++j) { res.mat[i][j] = 0; for (int k = 0; k < sz; ++k) { res.mat[i][j] += 1LL * mat[i][k] * ot.mat[k][j] % mod; res.mat[i][j] %= mod; } } } return res; } int sum() { int res = 0; for (int i = 0; i < sz; ++i) { for (int j = 0; j < sz; ++j) { res += mat[i][j]; res %= mod; } } return res; } void print() { cout << "print:" << endl; for (int i = 0; i < sz; ++i) { for (int j = 0; j < sz; ++j) { cout << mat[i][j] << " "; } cout << endl; } } }; int n, i, j, k, t; ll p; matrix mat; matrix pp[64]; int main() { scanf("%d %lld", &n, &p); mat.sz = n; for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { scanf("%d", &mat.mat[i][j]); } } pp[0] = mat; for (i = 1; i < 64; ++i) { pp[i] = pp[i - 1] * pp[i - 1]; } matrix res; res.sz = n; res.identity(); for (i = 0; p; ++i) { if (p & 1) { res = res * pp[i]; } p >>= 1; } printf("%d\n", res.sum()); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
984,417
984,418
u069951049
cpp
p03177
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; //#define int ll typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<short> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<ld> vld; typedef vector<vld> vvld; typedef vector<vvld> vvvld; typedef vector<string> vst; typedef vector<vst> vvst; typedef pair<ld, ld> pld; typedef complex<double> base; #define inmin(a, b) a = min(a, (b)) #define inmax(a, b) a = max(a, (b)) #define mp(a, b) make_pair(a, b) #define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b)) #define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b)) #define modmultiply(a, b) (((a) * (b)) % M) #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define sqr(x) ((x) * (x)) #define fori(i, n) for (int i = 0; i < int(n); ++i) #define cint const int & #define SZ(a) ((int)((a).size())) #define watch(x) cout << (#x) << " = " << (x) << endl; const double PI = 2 * acos(0.0); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; inline void transpose(vector<string> &a) { int n = a.size(); if (n == 0) return; int m = a[0].size(); vector<string> b(m, string(n, ' ')); fori(i, n) fori(j, m) b[j][i] = a[i][j]; a = b; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) { out << "{"; fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)]; return out; } void smain(); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef MAX_HOME freopen("input.txt", "r", stdin); clock_t start = clock(); #define cerr cout #endif cout << setprecision(12) << fixed; smain(); #ifdef MAX_HOME cout << "\n\n\n\n"; cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl; #endif } const ll M = 1e9 + 7; vvl operator*(const vvl &a, const vvl &b) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) fori(j, n) fori(k, n) ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % M; return ret; } vvl mat_pow(vvl a, ll p) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) ret[i][i] = 1; while (p) { if (p & 1) ret = ret * a; a = a * a; p >>= 1; } return ret; } void smain() { int n, m; cin >> n >> m; vvl a(n, vl(n, 0)); fori(i, n) fori(j, n) cin >> a[i][j]; a = mat_pow(a, m); ll ans = 0; fori(i, n) fori(j, n) ans = (ans + a[i][j]) % M; cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; //#define int ll typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<short> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<ld> vld; typedef vector<vld> vvld; typedef vector<vvld> vvvld; typedef vector<string> vst; typedef vector<vst> vvst; typedef pair<ld, ld> pld; typedef complex<double> base; #define inmin(a, b) a = min(a, (b)) #define inmax(a, b) a = max(a, (b)) #define mp(a, b) make_pair(a, b) #define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b)) #define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b)) #define modmultiply(a, b) (((a) * (b)) % M) #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define sqr(x) ((x) * (x)) #define fori(i, n) for (int i = 0; i < int(n); ++i) #define cint const int & #define SZ(a) ((int)((a).size())) #define watch(x) cout << (#x) << " = " << (x) << endl; const double PI = 2 * acos(0.0); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; inline void transpose(vector<string> &a) { int n = a.size(); if (n == 0) return; int m = a[0].size(); vector<string> b(m, string(n, ' ')); fori(i, n) fori(j, m) b[j][i] = a[i][j]; a = b; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) { out << "{"; fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)]; return out; } void smain(); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef MAX_HOME freopen("input.txt", "r", stdin); clock_t start = clock(); #define cerr cout #endif cout << setprecision(12) << fixed; smain(); #ifdef MAX_HOME cout << "\n\n\n\n"; cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl; #endif } const ll M = 1e9 + 7; vvl operator*(const vvl &a, const vvl &b) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) fori(j, n) fori(k, n) ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % M; return ret; } vvl mat_pow(vvl a, ll p) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) ret[i][i] = 1; while (p) { if (p & 1) ret = ret * a; a = a * a; p >>= 1; } return ret; } void smain() { ll n, m; cin >> n >> m; vvl a(n, vl(n, 0)); fori(i, n) fori(j, n) cin >> a[i][j]; a = mat_pow(a, m); ll ans = 0; fori(i, n) fori(j, n) ans = (ans + a[i][j]) % M; cout << ans; }
[ "variable_declaration.type.change" ]
984,422
984,423
u443685186
cpp
p03177
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; //#define int ll typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<short> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<ld> vld; typedef vector<vld> vvld; typedef vector<vvld> vvvld; typedef vector<string> vst; typedef vector<vst> vvst; typedef pair<ld, ld> pld; typedef complex<double> base; #define inmin(a, b) a = min(a, (b)) #define inmax(a, b) a = max(a, (b)) #define mp(a, b) make_pair(a, b) #define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b)) #define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b)) #define modmultiply(a, b) (((a) * (b)) % M) #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define sqr(x) ((x) * (x)) #define fori(i, n) for (int i = 0; i < int(n); ++i) #define cint const int & #define SZ(a) ((int)((a).size())) #define watch(x) cout << (#x) << " = " << (x) << endl; const double PI = 2 * acos(0.0); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; inline void transpose(vector<string> &a) { int n = a.size(); if (n == 0) return; int m = a[0].size(); vector<string> b(m, string(n, ' ')); fori(i, n) fori(j, m) b[j][i] = a[i][j]; a = b; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) { out << "{"; fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)]; return out; } void smain(); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef MAX_HOME freopen("input.txt", "r", stdin); clock_t start = clock(); #define cerr cout #endif cout << setprecision(12) << fixed; smain(); #ifdef MAX_HOME cout << "\n\n\n\n"; cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl; #endif } const ll M = 1e9 + 7; vvl operator*(const vvl &a, const vvl &b) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) fori(j, n) fori(k, n) ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % M; return ret; } vvl mat_pow(vvl a, ll p) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) ret[i][i] = 1; while (n) { if (n & 1) ret = ret * a; a = a * a; n >>= 1; } return ret; } void smain() { int n, m; cin >> n >> m; vvl a(n, vl(n, 0)); fori(i, n) fori(j, n) cin >> a[i][j]; a = mat_pow(a, m); ll ans = 0; fori(i, n) fori(j, n) ans = (ans + a[i][j]); cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; //#define int ll typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<short> vs; typedef vector<vs> vvs; typedef vector<vvs> vvvs; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<ld> vld; typedef vector<vld> vvld; typedef vector<vvld> vvvld; typedef vector<string> vst; typedef vector<vst> vvst; typedef pair<ld, ld> pld; typedef complex<double> base; #define inmin(a, b) a = min(a, (b)) #define inmax(a, b) a = max(a, (b)) #define mp(a, b) make_pair(a, b) #define modsum(a, b) ((a) + (b) >= M ? (a) + (b)-M : (a) + (b)) #define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b)) #define modmultiply(a, b) (((a) * (b)) % M) #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define sqr(x) ((x) * (x)) #define fori(i, n) for (int i = 0; i < int(n); ++i) #define cint const int & #define SZ(a) ((int)((a).size())) #define watch(x) cout << (#x) << " = " << (x) << endl; const double PI = 2 * acos(0.0); const string DIGITS = "0123456789"; const string ALPH = "abcdefghijklmnopqrstuvwxyz"; inline void transpose(vector<string> &a) { int n = a.size(); if (n == 0) return; int m = a[0].size(); vector<string> b(m, string(n, ' ')); fori(i, n) fori(j, m) b[j][i] = a[i][j]; a = b; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) { out << "{"; fori(i, SZ(a)) out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)]; return out; } void smain(); signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef MAX_HOME freopen("input.txt", "r", stdin); clock_t start = clock(); #define cerr cout #endif cout << setprecision(12) << fixed; smain(); #ifdef MAX_HOME cout << "\n\n\n\n"; cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl; #endif } const ll M = 1e9 + 7; vvl operator*(const vvl &a, const vvl &b) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) fori(j, n) fori(k, n) ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % M; return ret; } vvl mat_pow(vvl a, ll p) { int n = a.size(); vvl ret(n, vl(n, 0)); fori(i, n) ret[i][i] = 1; while (p) { if (p & 1) ret = ret * a; a = a * a; p >>= 1; } return ret; } void smain() { ll n, m; cin >> n >> m; vvl a(n, vl(n, 0)); fori(i, n) fori(j, n) cin >> a[i][j]; a = mat_pow(a, m); ll ans = 0; fori(i, n) fori(j, n) ans = (ans + a[i][j]) % M; cout << ans; }
[ "identifier.change", "control_flow.loop.condition.change", "control_flow.branch.if.condition.change", "assignment.variable.change", "variable_declaration.type.change", "assignment.change" ]
984,424
984,423
u443685186
cpp
p03176
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define inf1 INT_MAX #define inf2 LLONG_MAX #define ll long long #define ld long double #define pb push_back #define mp make_pair #define sbit __builtin_popcount #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) #define rit(it, x) for (auto it = x.begin(); it != x.end(); it++) #define cases(t) \ int t; \ cin >> t; \ rep(casn, 1, t + 1) #define fill(a, b) memset(a, b, sizeof(a)) #define dbg(x) cerr << #x << " " << x << endl; #define dbga(arr, n) \ cerr << #arr << ": "; \ rep(tt, 0, n) cerr << arr[tt] << " "; \ cerr << endl; #define infile \ ifstream fin; \ fin.open("input.txt") #define outfile \ ofstream fout; \ fout.open("output.txt") #define vec vector<int> #define pii pair<int, int> #define plii pair<ll, int> #define pll pair<ll, ll> #define p_queue priority_queue<plii, vector<plii>, greater<plii>> #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define sp(x) setprecision(x) #define si(x) scanf("%d", &x) #define sc(x) scanf("%c", &x) #define sl(x) scanf("%lld", &x) #define sst(x) scanf("%s", x) #define pl(x) printf("%lld\n", x) #define pi(x) printf("%d\n", x) #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define bs binary_search #define mex 200005 int tree[8 * mex], h[mex]; ll arr[mex], aux[mex]; inline void upd(int u, int s, int e, int idx, ll val) { if (s == e) { tree[u] = val; return; } int m = (s + e) / 2; if (idx <= m) upd(2 * u + 1, s, m, idx, val); else upd(2 * u + 2, m + 1, e, idx, val); tree[u] = max(tree[2 * u + 1], tree[2 * u + 2]); } inline ll que(int u, int s, int e, int l, int r) { if (s > r || e < l) return -1; if (s >= l && e <= r) return tree[u]; int m = (s + e) / 2; return max(que(2 * u + 1, s, m, l, r), que(2 * u + 2, m + 1, e, l, r)); } inline ll solve(int n) { fill(tree, -1); repr(i, n - 1, 0) { ll temp = que(0, 0, n - 1, h[i], n - 1); if (temp != -1) upd(0, 0, n - 1, h[i], temp + arr[i]), aux[h[i]] = temp + arr[i]; else upd(0, 0, n - 1, h[i], arr[i]), aux[h[i]] = arr[i]; } return tree[0]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; rep(i, 0, n) { cin >> h[i]; h[i]--; } rep(i, 0, n) cin >> arr[i]; cout << solve(n) << endl; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define inf1 INT_MAX #define inf2 LLONG_MAX #define ll long long #define ld long double #define pb push_back #define mp make_pair #define sbit __builtin_popcount #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) #define rit(it, x) for (auto it = x.begin(); it != x.end(); it++) #define cases(t) \ int t; \ cin >> t; \ rep(casn, 1, t + 1) #define fill(a, b) memset(a, b, sizeof(a)) #define dbg(x) cerr << #x << " " << x << endl; #define dbga(arr, n) \ cerr << #arr << ": "; \ rep(tt, 0, n) cerr << arr[tt] << " "; \ cerr << endl; #define infile \ ifstream fin; \ fin.open("input.txt") #define outfile \ ofstream fout; \ fout.open("output.txt") #define vec vector<int> #define pii pair<int, int> #define plii pair<ll, int> #define pll pair<ll, ll> #define p_queue priority_queue<plii, vector<plii>, greater<plii>> #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define sp(x) setprecision(x) #define si(x) scanf("%d", &x) #define sc(x) scanf("%c", &x) #define sl(x) scanf("%lld", &x) #define sst(x) scanf("%s", x) #define pl(x) printf("%lld\n", x) #define pi(x) printf("%d\n", x) #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define bs binary_search #define mex 200005 ll tree[8 * mex], h[mex], arr[mex], aux[mex]; inline void upd(int u, int s, int e, int idx, ll val) { if (s == e) { tree[u] = val; return; } int m = (s + e) / 2; if (idx <= m) upd(2 * u + 1, s, m, idx, val); else upd(2 * u + 2, m + 1, e, idx, val); tree[u] = max(tree[2 * u + 1], tree[2 * u + 2]); } inline ll que(int u, int s, int e, int l, int r) { if (s > r || e < l) return -1; if (s >= l && e <= r) return tree[u]; int m = (s + e) / 2; return max(que(2 * u + 1, s, m, l, r), que(2 * u + 2, m + 1, e, l, r)); } inline ll solve(int n) { fill(tree, -1); repr(i, n - 1, 0) { ll temp = que(0, 0, n - 1, h[i], n - 1); // dbg(temp); if (temp != -1) upd(0, 0, n - 1, h[i], temp + arr[i]), aux[h[i]] = temp + arr[i]; else upd(0, 0, n - 1, h[i], arr[i]), aux[h[i]] = arr[i]; } return tree[0]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; rep(i, 0, n) { cin >> h[i]; h[i]--; } rep(i, 0, n) cin >> arr[i]; cout << solve(n) << endl; }
[ "variable_declaration.type.change" ]
984,426
984,427
u663862781
cpp
p03176
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define emp emplace using namespace std; using ll = long long int; using ii = pair<int, int>; const int MOD = 1000 * 1000 * 1000 + 7; const int N = 2 * 100000; int tree[2 * N + N]; void build(int index, int l, int r) { if (l == r) { tree[index] = 0; } else { int mid = (l + r) / 2; build(2 * index + 1, l, mid); build(2 * index + 2, mid + 1, r); tree[index] = 0; } } void update(int node, int l, int r, int index, int val) { if (l > index || r < index) return; if (l == r) tree[node] = val; else { int mid = (l + r) / 2; update(2 * node + 1, l, mid, index, val); update(2 * node + 2, mid + 1, r, index, val); tree[node] = max(tree[2 * node + 1], tree[2 * node + 2]); } } int query(int index, int start, int end, int l, int r) { if (start > r || end < l) return 0; if (start >= l && end <= r) return tree[index]; else { int mid = (start + end) / 2; return max(query(2 * index + 1, start, mid, l, r), query(2 * index + 2, mid + 1, end, l, r)); } } int main() { int n; cin >> n; int height[n]; int beauty[n]; for (int i = 0; i < n; ++i) { cin >> height[i]; } for (int i = 0; i < n; ++i) { cin >> beauty[i]; } for (int i = n - 1; i >= 0; --i) { int mx = query(0, 0, n - 1, height[i], n - 1) + beauty[i]; update(0, 0, n - 1, height[i] - 1, mx); } cout << query(0, 0, n - 1, 0, n - 1); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define emp emplace using namespace std; using ll = long long int; using ii = pair<int, int>; const int MOD = 1000 * 1000 * 1000 + 7; const int N = 2 * 100000; ll tree[2 * N + N]; void build(int index, int l, int r) { if (l == r) { tree[index] = 0; } else { int mid = (l + r) / 2; build(2 * index + 1, l, mid); build(2 * index + 2, mid + 1, r); tree[index] = 0; } } void update(int node, int l, int r, int index, ll val) { if (l > index || r < index) return; if (l == r) tree[node] = val; else { int mid = (l + r) / 2; update(2 * node + 1, l, mid, index, val); update(2 * node + 2, mid + 1, r, index, val); tree[node] = max(tree[2 * node + 1], tree[2 * node + 2]); } } ll query(int index, int start, int end, int l, int r) { if (start > r || end < l) return 0; if (start >= l && end <= r) return tree[index]; else { int mid = (start + end) / 2; return max(query(2 * index + 1, start, mid, l, r), query(2 * index + 2, mid + 1, end, l, r)); } } int main() { int n; cin >> n; int height[n]; ll beauty[n]; for (int i = 0; i < n; ++i) { cin >> height[i]; } for (int i = 0; i < n; ++i) { cin >> beauty[i]; } for (int i = n - 1; i >= 0; --i) { ll mx = query(0, 0, n - 1, height[i], n - 1) + beauty[i]; update(0, 0, n - 1, height[i] - 1, mx); } cout << query(0, 0, n - 1, 0, n - 1); return 0; }
[ "variable_declaration.type.change" ]
984,436
984,437
u540942722
cpp
p03176
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define int long long using namespace std; typedef pair<int, int> P; template <typename T, typename E> // SegmentTree((要素数) int n_,(演算) F // f,(更新) G g,(初期値) T d1) struct SegmentTree { typedef function<T(T, T)> F; typedef function<T(T, E)> G; int n; F f; G g; T d1; E d0; vector<T> dat; SegmentTree(){}; SegmentTree(int n_, F f, G g, T d1, vector<T> v = vector<T>()) : f(f), g(g), d1(d1) { init(n_); if (n_ == (int)v.size()) build(n_, v); } void init(int n_) { n = 1; while (n < n_) n *= 2; dat.clear(); dat.resize(2 * n - 1, d1); } void build(int n_, vector<T> v) { for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]); } void update(int k, E a) { k += n - 1; dat[k] = g(dat[k], a); while (k > 0) { k = (k - 1) / 2; dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]); } } inline T query(int a, int b) { T vl = d1, vr = d1; for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, dat[(l++) - 1]); if (r & 1) vr = f(dat[(--r) - 1], vr); } return f(vl, vr); } }; signed main() { int N; cin >> N; vector<int> h(N); REP(i, N) cin >> h[i]; vector<int> a(N); REP(i, N) cin >> a[i]; vector<int> dp(N + 1, 0); SegmentTree<int, int> seg( N, [](int x, int y) { return max(x, y); }, [](int x, int y) { return x + y; }, 0); REP(i, N) { dp[h[i]] = max(dp[h[i]], seg.query(0, h[i]) + a[i]); seg.update(h[i], dp[h[i]]); } int ans = 0; REP(i, N + 1) ans = max(ans, dp[i]); cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define int long long using namespace std; typedef pair<int, int> P; template <typename T, typename E> // SegmentTree((要素数) int n_,(演算) F // f,(更新) G g,(初期値) T d1) struct SegmentTree { typedef function<T(T, T)> F; typedef function<T(T, E)> G; int n; F f; G g; T d1; E d0; vector<T> dat; SegmentTree(){}; SegmentTree(int n_, F f, G g, T d1, vector<T> v = vector<T>()) : f(f), g(g), d1(d1) { init(n_); if (n_ == (int)v.size()) build(n_, v); } void init(int n_) { n = 1; while (n < n_) n *= 2; dat.clear(); dat.resize(2 * n - 1, d1); } void build(int n_, vector<T> v) { for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]); } void update(int k, E a) { k += n - 1; dat[k] = g(dat[k], a); while (k > 0) { k = (k - 1) / 2; dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]); } } inline T query(int a, int b) { T vl = d1, vr = d1; for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, dat[(l++) - 1]); if (r & 1) vr = f(dat[(--r) - 1], vr); } return f(vl, vr); } }; signed main() { int N; cin >> N; vector<int> h(N); REP(i, N) cin >> h[i]; vector<int> a(N); REP(i, N) cin >> a[i]; vector<int> dp(N + 1, 0); SegmentTree<int, int> seg( N + 1, [](int x, int y) { return max(x, y); }, [](int x, int y) { return x + y; }, 0); REP(i, N) { dp[h[i]] = max(dp[h[i]], seg.query(0, h[i]) + a[i]); seg.update(h[i], dp[h[i]]); } int ans = 0; REP(i, N + 1) ans = max(ans, dp[i]); cout << ans << endl; }
[ "assignment.change" ]
984,440
984,441
u203033720
cpp
p03176
//* AuThOr GaRyMr *// #include <bits/stdc++.h> #define rb(a, b, c) for (int a = b; a <= c; ++a) #define rl(a, b, c) for (int a = b; a >= c; --a) #define niv vector<int> #define LL long long #define IT iterator #define PB(a) push_back(a) #define II(a, b) make_pair(a, b) #define FIR first #define SEC second #define FREO freopen("check.out", "w", stdout) #define rep(a, b) for (int a = 0; a < b; ++a) using namespace std; const int INF = 0x3f3f3f3f; typedef pair<int, int> mp; typedef pair<mp, mp> superpair; // dp[i]=max(dp[i-1],dp[j](1<=j<i)+a[i]) int n, treen; LL seg_tree[200000 * 8]; LL dp[200000 + 10]; int h[200000 + 10], a[200000 + 10]; LL query(int now, int l, int r, int a, int b) { if (l >= a && r <= b) { return seg_tree[now]; } if (l >= b || r <= a) { return -INF; } int mid = (l + r) >> 1; return max(query(now << 1, l, mid, a, b), query((now << 1) + 1, mid, r, a, b)); } LL maxi(int l, int r) { if (l == r) return 0; return query(1, 1, treen + 1, l, r); } void change(int pos, LL val) { pos += treen - 1; seg_tree[pos] = val; pos >>= 1; while (pos) { seg_tree[pos] = max(seg_tree[pos << 1], seg_tree[(pos << 1) + 1]); pos >>= 1; } } int main() { scanf("%d", &n); rb(i, 1, n) scanf("%d", &h[i]); rb(i, 1, n) scanf("%d", &a[i]); treen = int(ceil(log2(double(n)))); treen = 1 << treen; LL res = 0; rb(i, 1, n) { dp[i] = maxi(1, h[i]) + (LL)(a[i]), change(h[i], dp[i]), res = max(res, dp[i]); } printf("%I64d\n", res); return 0; }
//* AuThOr GaRyMr *// #include <bits/stdc++.h> #define rb(a, b, c) for (int a = b; a <= c; ++a) #define rl(a, b, c) for (int a = b; a >= c; --a) #define niv vector<int> #define LL long long #define IT iterator #define PB(a) push_back(a) #define II(a, b) make_pair(a, b) #define FIR first #define SEC second #define FREO freopen("check.out", "w", stdout) #define rep(a, b) for (int a = 0; a < b; ++a) using namespace std; const int INF = 0x3f3f3f3f; typedef pair<int, int> mp; typedef pair<mp, mp> superpair; // dp[i]=max(dp[i-1],dp[j](1<=j<i)+a[i]) int n, treen; LL seg_tree[200000 * 8]; LL dp[200000 + 10]; int h[200000 + 10], a[200000 + 10]; LL query(int now, int l, int r, int a, int b) { if (l >= a && r <= b) { return seg_tree[now]; } if (l >= b || r <= a) { return -INF; } int mid = (l + r) >> 1; return max(query(now << 1, l, mid, a, b), query((now << 1) + 1, mid, r, a, b)); } LL maxi(int l, int r) { if (l == r) return 0; return query(1, 1, treen + 1, l, r); } void change(int pos, LL val) { pos += treen - 1; seg_tree[pos] = val; pos >>= 1; while (pos) { seg_tree[pos] = max(seg_tree[pos << 1], seg_tree[(pos << 1) + 1]); pos >>= 1; } } int main() { scanf("%d", &n); rb(i, 1, n) scanf("%d", &h[i]); rb(i, 1, n) scanf("%d", &a[i]); treen = int(ceil(log2(double(n)))); treen = 1 << treen; LL res = 0; rb(i, 1, n) { dp[i] = maxi(1, h[i]) + (LL)(a[i]), change(h[i], dp[i]), res = max(res, dp[i]); } printf("%lld\n", res); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
984,442
984,443
u751730221
cpp
p03176
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; class SegTree { public: // Range Max Query vector<int> ar; int length; SegTree(int n) { length = 1; while (n > length) length *= 2; ar.resize(2 * length - 1); for (int i = 0; i < 2 * length - 1; i++) ar[i] = 0; } void update(int k, int a) { // k番目をaにする k += length - 1; ar[k] = a; while (k > 0) { k = (k - 1) / 2; ar[k] = max(ar[2 * k + 1], ar[2 * k + 2]); } } int getval(int a, int b, int k, int l, int r) { //[a, b)を求める if (r <= a || b <= l) return 0; else if (a <= l && r <= b) return ar[k]; else { int v1, v2; v1 = getval(a, b, 2 * k + 1, l, (l + r) / 2); v2 = getval(a, b, 2 * k + 2, (l + r) / 2, r); return max(v1, v2); } } }; int N; ll dp[200001]; // dp[i]:=高さiで終わる際の美しさの和の最大値 ll H[200001], I[200001]; ll pos1[200001]; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> H[i]; pos1[H[i]] = i; } for (int i = 1; i <= N; i++) { cin >> I[i]; } SegTree st(N + 1); dp[0] = 0; for (int i = 1; i <= N; i++) { dp[i] = st.getval(0, pos1[i], 0, 0, st.length) + I[pos1[i]]; //[0, i)の中の最大値をlog //nで求める。0番は便宜上の配置であり、実際は1,2...番の順にデータが格納される st.update(pos1[i], dp[i]); } ll ans = 0; for (int i = 1; i <= N; i++) { ans = max(ans, dp[i]); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; class SegTree { public: // Range Max Query vector<ll> ar; int length; SegTree(int n) { length = 1; while (n > length) length *= 2; ar.resize(2 * length - 1); for (int i = 0; i < 2 * length - 1; i++) ar[i] = 0; } void update(int k, ll a) { // k番目をaにする k += length - 1; ar[k] = a; while (k > 0) { k = (k - 1) / 2; ar[k] = max(ar[2 * k + 1], ar[2 * k + 2]); } } ll getval(int a, int b, int k, int l, int r) { //[a, b)を求める if (r <= a || b <= l) return 0; else if (a <= l && r <= b) return ar[k]; else { ll v1, v2; v1 = getval(a, b, 2 * k + 1, l, (l + r) / 2); v2 = getval(a, b, 2 * k + 2, (l + r) / 2, r); return max(v1, v2); } } }; int N; ll dp[200001]; // dp[i]:=高さiで終わる際の美しさの和の最大値 ll H[200001], I[200001]; ll pos1[200001]; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> H[i]; pos1[H[i]] = i; } for (int i = 1; i <= N; i++) { cin >> I[i]; } SegTree st(N + 1); dp[0] = 0; for (int i = 1; i <= N; i++) { dp[i] = st.getval(0, pos1[i], 0, 0, st.length) + I[pos1[i]]; //[0, i)の中の最大値をlog //nで求める。0番は便宜上の配置であり、実際は1,2...番の順にデータが格納される st.update(pos1[i], dp[i]); } ll ans = 0; for (int i = 1; i <= N; i++) { ans = max(ans, dp[i]); ; } cout << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
984,453
984,454
u107077805
cpp
p03176
#include <bits/stdc++.h> #define ll long long #define pb push_back #define c(P) cout << P << "\n" #define dbg(P) cout << P << " " #define pii pair<ll, ll> #define mi map<ll, ll> #define mii map<pii, ll> #define F first #define S second #define mem(a, val) memset(a, val, sizeof(a)) #define fr(i, x, n) for (ll i = x; i < n; i++) #define frr(i, x, n) for (ll i = n - 1; i >= x; i--) const ll N = 200005; const ll mod = 1e9 + 7; using namespace std; vector<ll> bit(N + 4); void update(ll x, ll val) { for (; x <= N; x += (x & -x)) { bit[x] = max(val, bit[x]); } } ll query(ll x) { ll res = 0; for (; x > 0; x -= (x & x)) { res = max(res, bit[x]); } return res; } void solve() { // string s; ll n, m, k, x = 0, y = 0, c = 0, q, ans = 0; cin >> n; ll a[n], h[n]; for (ll i = 0; i < n; ++i) { cin >> h[i]; } for (ll i = 0; i < n; ++i) { cin >> a[i]; x = query(h[i] - 1) + a[i]; ans = max(ans, x); update(h[i], x); } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define c(P) cout << P << "\n" #define dbg(P) cout << P << " " #define pii pair<ll, ll> #define mi map<ll, ll> #define mii map<pii, ll> #define F first #define S second #define mem(a, val) memset(a, val, sizeof(a)) #define fr(i, x, n) for (ll i = x; i < n; i++) #define frr(i, x, n) for (ll i = n - 1; i >= x; i--) const ll N = 200005; const ll mod = 1e9 + 7; using namespace std; vector<ll> bit(N + 4); void update(ll x, ll val) { for (; x <= N; x += (x & -x)) { bit[x] = max(val, bit[x]); } } ll query(ll x) { ll res = 0; for (; x > 0; x -= (x & -x)) { res = max(res, bit[x]); } return res; } void solve() { // string s; ll n, m, k, x = 0, y = 0, c = 0, q, ans = 0; cin >> n; ll a[n], h[n]; for (ll i = 0; i < n; ++i) { cin >> h[i]; } for (ll i = 0; i < n; ++i) { cin >> a[i]; x = query(h[i] - 1) + a[i]; ans = max(ans, x); update(h[i], x); } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
[ "expression.operation.unary.add" ]
984,455
984,456
u305721160
cpp
p03176
#include <bits/stdc++.h> #define ll long long #define pb push_back #define c(P) cout << P << "\n" #define dbg(P) cout << P << " " #define pii pair<ll, ll> #define mi map<ll, ll> #define mii map<pii, ll> #define F first #define S second #define mem(a, val) memset(a, val, sizeof(a)) #define fr(i, x, n) for (ll i = x; i < n; i++) #define frr(i, x, n) for (ll i = n - 1; i >= x; i--) const ll N = 500005; const ll mod = 1e9 + 7; using namespace std; vector<ll> bit(N); void update(ll x, ll val) { for (; x <= N; x += (x & -x)) { bit[x] = max(val, bit[x]); } } ll query(ll x) { ll res = 0; for (; x > 0; x -= (x & x)) { res = max(res, bit[x]); } return res; } void solve() { // string s; ll n, m, k, x = 0, y = 0, c = 0, q, ans = 0; cin >> n; ll a[n], h[n]; for (ll i = 0; i < n; ++i) { cin >> h[i]; } for (ll i = 0; i < n; ++i) { cin >> a[i]; x = query(h[i] - 1) + a[i]; ans = max(ans, x); update(h[i], x); } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define c(P) cout << P << "\n" #define dbg(P) cout << P << " " #define pii pair<ll, ll> #define mi map<ll, ll> #define mii map<pii, ll> #define F first #define S second #define mem(a, val) memset(a, val, sizeof(a)) #define fr(i, x, n) for (ll i = x; i < n; i++) #define frr(i, x, n) for (ll i = n - 1; i >= x; i--) const ll N = 200005; const ll mod = 1e9 + 7; using namespace std; vector<ll> bit(N + 4); void update(ll x, ll val) { for (; x <= N; x += (x & -x)) { bit[x] = max(val, bit[x]); } } ll query(ll x) { ll res = 0; for (; x > 0; x -= (x & -x)) { res = max(res, bit[x]); } return res; } void solve() { // string s; ll n, m, k, x = 0, y = 0, c = 0, q, ans = 0; cin >> n; ll a[n], h[n]; for (ll i = 0; i < n; ++i) { cin >> h[i]; } for (ll i = 0; i < n; ++i) { cin >> a[i]; x = query(h[i] - 1) + a[i]; ans = max(ans, x); update(h[i], x); } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll T = 1; // cin>>T; while (T--) { solve(); } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.unary.add" ]
984,457
984,456
u305721160
cpp
p03176
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; /* * Supports range sum queries on a mutable array of Ts. * Requires that T's + operator is associative and that T() is the * additive identity: T() + t = t = t + T() for any T t. */ template <typename T> struct segment_tree { int S; vector<T> table; segment_tree<T>(int _S) : S(_S) { table.resize(2 * S); } segment_tree<T>(auto begin, auto end) : segment_tree(distance(begin, end)) { copy(begin, end, table.begin() + S); for (int i = S - 1; i > 0; i--) table[i] = table[2 * i] + table[2 * i + 1]; } // Replaces the element at index i with v void replace(int i, T v) { table[i += S] = v; for (i /= 2; i > 0; i /= 2) { table[i] = table[2 * i] + table[2 * i + 1]; } } // Returns the value of the element at index i const T &operator()(int i) const { return table[S + i]; } // Returns the sum of the elements at indices in [i, j) T operator()(int i, int j) const { T left{}, right{}; for (i += S, j += S; i < j; i /= 2, j /= 2) { if (i & 1) left = left + table[i++]; if (j & 1) right = table[--j] + right; } return left + right; } }; struct max_ll { ll val; max_ll() : val(0) {} max_ll(int val) : val(val) {} max_ll operator+(const max_ll &other) const { return max_ll(max(val, other.val)); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vi H(N); vll A(N); for (int i = 0; i < N; i++) cin >> H[i]; for (int i = 0; i < N; i++) cin >> A[i]; segment_tree<max_ll> segtree(N); for (int i = 0; i < N; i++) { int h = H[i] - 1; ll cur = A[i]; if (h > 0) cur += segtree(0, h).val; segtree.replace(h, cur); } ll ans = segtree(0, N).val; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vd = vector<double>; using vs = vector<string>; /* * Supports range sum queries on a mutable array of Ts. * Requires that T's + operator is associative and that T() is the * additive identity: T() + t = t = t + T() for any T t. */ template <typename T> struct segment_tree { int S; vector<T> table; segment_tree<T>(int _S) : S(_S) { table.resize(2 * S); } segment_tree<T>(auto begin, auto end) : segment_tree(distance(begin, end)) { copy(begin, end, table.begin() + S); for (int i = S - 1; i > 0; i--) table[i] = table[2 * i] + table[2 * i + 1]; } // Replaces the element at index i with v void replace(int i, T v) { table[i += S] = v; for (i /= 2; i > 0; i /= 2) { table[i] = table[2 * i] + table[2 * i + 1]; } } // Returns the value of the element at index i const T &operator()(int i) const { return table[S + i]; } // Returns the sum of the elements at indices in [i, j) T operator()(int i, int j) const { T left{}, right{}; for (i += S, j += S; i < j; i /= 2, j /= 2) { if (i & 1) left = left + table[i++]; if (j & 1) right = table[--j] + right; } return left + right; } }; struct max_ll { ll val; max_ll() : val(0) {} max_ll(ll val) : val(val) {} max_ll operator+(const max_ll &other) const { return max_ll(max(val, other.val)); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vi H(N); vll A(N); for (int i = 0; i < N; i++) cin >> H[i]; for (int i = 0; i < N; i++) cin >> A[i]; segment_tree<max_ll> segtree(N); for (int i = 0; i < N; i++) { int h = H[i] - 1; ll cur = A[i]; if (h > 0) cur += segtree(0, h).val; segtree.replace(h, cur); } ll ans = segtree(0, N).val; cout << ans << endl; return 0; }
[]
984,460
984,461
u695197008
cpp
p03176
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int N = (int)2e5 + 10; struct node { int l, r; node *left, *right; ll val; node(int L, int R) { val = 0, l = L, r = R; if (l == r) return; int m = l + r >> 1; left = new node(l, m); right = new node(m + 1, r); } int query_max(int L, int R) { if (r < L || l > R) return 0; if (L <= l && r <= R) return val; return max(left->query_max(L, R), right->query_max(L, R)); } void update(int i, ll x) { if (r < i || i < l) return; if (l == r) { val = x; return; } left->update(i, x); right->update(i, x); val = max(left->val, right->val); } }; int n; int a[N], h[N]; node *st; void solve() { cin >> n; st = new node(1, n); for (int i = 1; i <= n; ++i) { cin >> h[i]; } for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { int height = h[i]; int max_val = st->query_max(1, height); ll cur = max_val + a[i]; st->update(height, cur); } cout << st->query_max(1, n) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(20); cout << fixed; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int N = (int)2e5 + 10; struct node { int l, r; node *left, *right; ll val; node(int L, int R) { val = 0, l = L, r = R; if (l == r) return; int m = l + r >> 1; left = new node(l, m); right = new node(m + 1, r); } ll query_max(int L, int R) { if (r < L || l > R) return 0; if (L <= l && r <= R) return val; return max(left->query_max(L, R), right->query_max(L, R)); } void update(int i, ll x) { if (r < i || i < l) return; if (l == r) { val = x; return; } left->update(i, x); right->update(i, x); val = max(left->val, right->val); } }; int n; int a[N], h[N]; node *st; void solve() { cin >> n; st = new node(1, n); for (int i = 1; i <= n; ++i) { cin >> h[i]; } for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { int height = h[i]; ll max_val = st->query_max(1, height); ll cur = max_val + a[i]; st->update(height, cur); } cout << st->query_max(1, n) << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(20); cout << fixed; solve(); return 0; }
[ "variable_declaration.type.change" ]
984,466
984,467
u013023508
cpp
p03176
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x, n) \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> Pll; typedef vector<ll> vll; const ll INF = LLONG_MAX / 10; const ll MOD = 1e9 + 7; template <typename T> struct SegmentTree { using F = function<T(T, T)>; int n; F f; T ti; vector<T> dat; SegmentTree(){}; SegmentTree(F f, T ti) : f(f), ti(ti) {} void init(int n_) { n = 1; while (n < n_) n <<= 1; dat.assign(n << 1, ti); } void build(const vector<T> &v) { int n_ = v.size(); init(n_); for (int i = 0; i < n_; i++) dat[n + i] = v[i]; for (int i = n - 1; i; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } void set_val(int k, T x) { dat[k += n] = x; while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]); } //[a,b) T query(int a, int b) { T vl = ti, vr = ti; for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, dat[l++]); if (r & 1) vr = f(dat[--r], vr); } return f(vl, vr); } }; ll dp[20010]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; vll h(N); for (ll i = 0; i < N; i++) { cin >> h[i]; h[i]--; } vll A(N); for (ll i = 0; i < N; i++) cin >> A[i]; SegmentTree<ll> seg([](ll a, ll b) { return max(a, b); }, 0ll); seg.init(N); for (ll i = 0; i < N; i++) { dp[i] = seg.query(0, h[i]) + A[i]; seg.set_val(h[i] + 1, dp[i]); } cout << seg.query(0, N) << endl; return 0; }
#include <bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x, n) \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> Pll; typedef vector<ll> vll; const ll INF = LLONG_MAX / 10; const ll MOD = 1e9 + 7; template <typename T> struct SegmentTree { using F = function<T(T, T)>; int n; F f; T ti; vector<T> dat; SegmentTree(){}; SegmentTree(F f, T ti) : f(f), ti(ti) {} void init(int n_) { n = 1; while (n < n_) n <<= 1; dat.assign(n << 1, ti); } void build(const vector<T> &v) { int n_ = v.size(); init(n_); for (int i = 0; i < n_; i++) dat[n + i] = v[i]; for (int i = n - 1; i; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } void set_val(int k, T x) { dat[k += n] = x; while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]); } //[a,b) T query(int a, int b) { T vl = ti, vr = ti; for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, dat[l++]); if (r & 1) vr = f(dat[--r], vr); } return f(vl, vr); } }; ll dp[200010]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; vll h(N); for (ll i = 0; i < N; i++) { cin >> h[i]; h[i]--; } vll A(N); for (ll i = 0; i < N; i++) cin >> A[i]; SegmentTree<ll> seg([](ll a, ll b) { return max(a, b); }, 0ll); seg.init(N); for (ll i = 0; i < N; i++) { dp[i] = seg.query(0, h[i] + 1) + A[i]; seg.set_val(h[i], dp[i]); } cout << seg.query(0, N) << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "assignment.change", "expression.operation.binary.remove" ]
984,482
984,481
u120143737
cpp
p03176
/*DavitMarg*/ #include <algorithm> #include <cassert> #include <cmath> #include <cstring> #include <ctype.h>> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; vector<LL> t(4 * 200005); void add(int v, int l, int r, int pos, LL val) { if (l == r) { t[v] = val; return; } int m = (l + r) >> 1; if (pos <= m) add(v * 2, l, m, pos, val); else add(v * 2 + 1, m + 1, r, pos, val); t[v] = max(t[v * 2], t[v * 2 + 1]); } LL get(int v, int l, int r, int pos) { if (l == r) return t[v]; int m = (l + r) >> 1; if (pos <= m) return get(v * 2, l, m, pos); else return max(t[v * 2], get(v * 2 + 1, m + 1, r, pos)); } int n, h[200005]; LL a[200005], ans; int main() { cin >> n; for (int i = 0; i < n; i++) scanf("%d", h + i); for (int i = 0; i < n; i++) scanf("%lld", a + i); for (int i = 0; i < n; i++) { a[i] += get(0, 0, n, h[i] - 1); ans = max(ans, a[i]); add(0, 0, n, h[i], a[i]); } cout << ans << endl; return 0; } /* */
/*DavitMarg*/ #include <algorithm> #include <cassert> #include <cmath> #include <cstring> #include <ctype.h>> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; vector<LL> t(4 * 200005); void add(int v, int l, int r, int pos, LL val) { if (l == r) { t[v] = val; return; } int m = (l + r) >> 1; if (pos <= m) add(v * 2, l, m, pos, val); else add(v * 2 + 1, m + 1, r, pos, val); t[v] = max(t[v * 2], t[v * 2 + 1]); } LL get(int v, int l, int r, int pos) { if (l == r) return t[v]; int m = (l + r) >> 1; if (pos <= m) return get(v * 2, l, m, pos); else return max(t[v * 2], get(v * 2 + 1, m + 1, r, pos)); } int n, h[200005]; LL a[200005], ans; int main() { cin >> n; for (int i = 0; i < n; i++) scanf("%d", h + i); for (int i = 0; i < n; i++) scanf("%lld", a + i); for (int i = 0; i < n; i++) { a[i] += get(1, 0, n, h[i] - 1); ans = max(ans, a[i]); add(1, 0, n, h[i], a[i]); } cout << ans << endl; return 0; } /* */
[ "literal.number.change", "assignment.value.change", "call.arguments.change" ]
984,492
984,493
u921233745
cpp
p03176
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a); i <= (b); i++) #define PER(i, a, b) for (int i = (a); i >= (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pf push_front #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; const int MAX = 2e5 + 5; int N, h[MAX], a[MAX]; ll b[MAX]; void update(int i, ll v) { for (; i <= N; i += i & -i) b[i] = max(b[i], v); } ll query(int i) { ll ans = 0; for (; i; i -= i & -i) ans = max(ans, b[i]); return ans; } int main(int argc, char **argv) { scanf("%d", &N); REP(i, 1, N) scanf("%d", &h[i]); REP(i, 1, N) scanf("%d", &a[i]); REP(i, 1, N) update(h[i], query(h[i]) + a[i]); printf("%I64d\n", query(N)); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a); i <= (b); i++) #define PER(i, a, b) for (int i = (a); i >= (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pf push_front #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; const int MAX = 2e5 + 5; int N, h[MAX], a[MAX]; ll b[MAX]; void update(int i, ll v) { for (; i <= N; i += i & -i) b[i] = max(b[i], v); } ll query(int i) { ll ans = 0; for (; i; i -= i & -i) ans = max(ans, b[i]); return ans; } int main(int argc, char **argv) { scanf("%d", &N); REP(i, 1, N) scanf("%d", &h[i]); REP(i, 1, N) scanf("%d", &a[i]); REP(i, 1, N) update(h[i], query(h[i] - 1) + a[i]); printf("%lld\n", query(N)); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
984,496
984,497
u991534398
cpp
p03176
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a); i <= (b); i++) #define PER(i, a, b) for (int i = (a); i >= (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pf push_front #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; const int MAX = 2e5 + 5; int N, h[MAX], a[MAX]; ll b[MAX]; void update(int i, ll v) { for (; i <= N; i += i & -i) b[i] = max(b[i], v); } ll query(int i) { ll ans = 0; for (; i; i -= i & -i) ans = max(ans, b[i]); return ans; } int main(int argc, char **argv) { scanf("%d", &N); REP(i, 1, N) scanf("%d", &h[i]); REP(i, 1, N) scanf("%d", &a[i]); REP(i, 1, N) update(h[i], query(h[i] - 1) + a[i]); printf("%I64d\n", query(N)); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a); i <= (b); i++) #define PER(i, a, b) for (int i = (a); i >= (b); i--) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(S) (S).begin(), (S).end() #define pf push_front #define pb push_back #define mk make_pair #define S second #define F first typedef long long ll; typedef long double lf; typedef pair<int, int> ii; const int MAX = 2e5 + 5; int N, h[MAX], a[MAX]; ll b[MAX]; void update(int i, ll v) { for (; i <= N; i += i & -i) b[i] = max(b[i], v); } ll query(int i) { ll ans = 0; for (; i; i -= i & -i) ans = max(ans, b[i]); return ans; } int main(int argc, char **argv) { scanf("%d", &N); REP(i, 1, N) scanf("%d", &h[i]); REP(i, 1, N) scanf("%d", &a[i]); REP(i, 1, N) update(h[i], query(h[i] - 1) + a[i]); printf("%lld\n", query(N)); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
984,498
984,497
u991534398
cpp
p03176
#include <bits/stdc++.h> #define ld long double #define sf scanf #define pf printf #define pb push_back #define mp make_pair #define PI (acos(-1.0)) #define IN freopen("input.txt", "r", stdin) #define OUT freopen("output.txt", "w", stdout) #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 INF 1000000000 #define ll long long int #define eps (1e-8) #define sq(x) ((x) * (x)) #define all(x) x.begin(), x.end() #define flog2(n) 64 - __builtin_clzll(n) - 1 #define popcnt(n) __builtin_popcountll(n) using namespace std; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll st[4 * 200005]; ll h[200005], a[200005]; void update(int id, int l, int r, int u, int v) { if (l == r) { st[id] = v; return; } int mid = (l + r) / 2; if (u <= mid) update(id * 2, l, mid, u, v); else update(id * 2 + 1, mid + 1, r, u, v); st[id] = max(st[id * 2], st[id * 2 + 1]); } ll getMax(int id, int l, int r, int u, int v) { if (v < l || r < u) return 0; if (u <= l && r <= v) return st[id]; int mid = (l + r) / 2; return max(getMax(id * 2, l, mid, u, v), getMax(id * 2 + 1, mid + 1, r, u, v)); } ll d[200005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; FOR(i, 1, n) { cin >> h[i]; } FOR(i, 1, n) { cin >> a[i]; } d[1] = a[1]; update(1, 1, n, h[1], d[1]); ll res = d[1]; FOR(i, 2, n) { d[i] = getMax(1, 1, n, 1, h[i]) + a[i]; update(1, 1, n, h[i], d[i]); // FOR (j, 1, n) cout << getMax(1, 1, n, j, j) << " "; cout << endl; res = max(res, d[i]); } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define ld long double #define sf scanf #define pf printf #define pb push_back #define mp make_pair #define PI (acos(-1.0)) #define IN freopen("input.txt", "r", stdin) #define OUT freopen("output.txt", "w", stdout) #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 INF 1000000000 #define ll long long int #define eps (1e-8) #define sq(x) ((x) * (x)) #define all(x) x.begin(), x.end() #define flog2(n) 64 - __builtin_clzll(n) - 1 #define popcnt(n) __builtin_popcountll(n) using namespace std; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll st[4 * 200005]; ll h[200005], a[200005]; void update(int id, int l, int r, int u, ll v) { if (l == r) { st[id] = v; return; } int mid = (l + r) / 2; if (u <= mid) update(id * 2, l, mid, u, v); else update(id * 2 + 1, mid + 1, r, u, v); st[id] = max(st[id * 2], st[id * 2 + 1]); } ll getMax(int id, int l, int r, int u, int v) { if (v < l || r < u) return 0; if (u <= l && r <= v) return st[id]; int mid = (l + r) / 2; return max(getMax(id * 2, l, mid, u, v), getMax(id * 2 + 1, mid + 1, r, u, v)); } ll d[200005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; FOR(i, 1, n) { cin >> h[i]; } FOR(i, 1, n) { cin >> a[i]; } d[1] = a[1]; update(1, 1, n, h[1], d[1]); ll res = d[1]; FOR(i, 2, n) { d[i] = getMax(1, 1, n, 1, h[i]) + a[i]; update(1, 1, n, h[i], d[i]); // FOR (j, 1, n) cout << getMax(1, 1, n, j, j) << " "; cout << endl; res = max(res, d[i]); } cout << res << endl; return 0; }
[]
984,523
984,524
u274856119
cpp
p03176
#include <iostream> #define mid (l + r) / 2 #define ll long long using namespace std; const int N = 2e5 + 55; ll tree[N * 4]; int h[N]; ll a[N]; void update(int l, int r, int node, int ind, int val) { if (l == r) { tree[node] = val; return; } if (ind <= mid) update(l, mid, node * 2, ind, val); else update(mid + 1, r, node * 2 + 1, ind, val); tree[node] = max(tree[node * 2], tree[node * 2 + 1]); } ll query(int l, int r, int node, int x, int y) { if (l > y || r < x) return 0; if (x <= l && r <= y) return tree[node]; return max(query(l, mid, node * 2, x, y), query(mid + 1, r, node * 2 + 1, x, y)); } int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> a[i]; ll ans = 0; ll x = 0; for (int i = 0; i < n; i++) { x = query(0, n - 1, 1, 0, h[i] - 1) + a[i]; ans = max(ans, x); update(0, n - 1, 1, h[i], x); } cout << ans << endl; return 0; }
#include <iostream> #define mid (l + r) / 2 #define ll long long using namespace std; const int N = 2e5 + 55; ll tree[N * 4]; int h[N]; ll a[N]; void update(int l, int r, int node, int ind, ll val) { if (l == r) { tree[node] = val; return; } if (ind <= mid) update(l, mid, node * 2, ind, val); else update(mid + 1, r, node * 2 + 1, ind, val); tree[node] = max(tree[node * 2], tree[node * 2 + 1]); } ll query(int l, int r, int node, int x, int y) { if (l > y || r < x) return 0; if (x <= l && r <= y) return tree[node]; return max(query(l, mid, node * 2, x, y), query(mid + 1, r, node * 2 + 1, x, y)); } int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> a[i]; ll ans = 0; ll x = 0; for (int i = 0; i < n; i++) { x = query(0, n - 1, 1, 1, h[i]) + a[i]; ans = max(ans, x); update(0, n - 1, 1, h[i], x); } cout << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
984,525
984,526
u083991297
cpp
p03176
// csjosh #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> //required // #include <ext/pb_ds/tree_policy.hpp> //required // using namespace __gnu_pbds; //required using namespace std; #define ll long long #define loop(x) for (int i = 0; i < x; i++) #define llu unsigned long long #define pb push_back #define sc(x) scanf("%lld", &x) #define pr(x) printf("%lld\n", x) #define dd fflush(stdout) #define what_is(x) cerr << #x << " is " << x << endl; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mt make_tuple // use tie #define eb emplace_back typedef tuple<int, int, int> State; // use in dijkstra // ll mod=1e9+7; // ll power(ll x,ll y,ll mod){ // ll ans=1; // while(y>0){ // if(y&1){ // ans=ans*x; // } // x=x*x; // y=y/2; // } // return ans; // } // typedef tree< // pair<int, int>, // null_type, // less<pair<int, int>>, // rb_tree_tag, // tree_order_statistics_node_update> ordered_set; int h[300005]; ll a[300006]; ll bit[566000]; int n; ll get(int x) { ll ans = 0; for (int i = x; i > 0; i = i - (i & -i)) ans = max(bit[i], ans); return ans; } void update(int x, ll y) { for (int i = x; i <= n; i += (i & -i)) { bit[i] = max(bit[i], y); } } int main() { IOS; cin >> n; memset(bit, 0, sizeof bit); loop(n) cin >> h[i + 1]; loop(n) cin >> a[i + 1]; // first use of BIT ll dp[n + 3]; for (int i = 1; i <= n; i++) { dp[i] = get(h[i] - 1) + a[i]; update(h[i], dp[i]); } cout << dp[n] << endl; }
// csjosh #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> //required // #include <ext/pb_ds/tree_policy.hpp> //required // using namespace __gnu_pbds; //required using namespace std; #define ll long long #define loop(x) for (int i = 0; i < x; i++) #define llu unsigned long long #define pb push_back #define sc(x) scanf("%lld", &x) #define pr(x) printf("%lld\n", x) #define dd fflush(stdout) #define what_is(x) cerr << #x << " is " << x << endl; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mt make_tuple // use tie #define eb emplace_back typedef tuple<int, int, int> State; // use in dijkstra // ll mod=1e9+7; // ll power(ll x,ll y,ll mod){ // ll ans=1; // while(y>0){ // if(y&1){ // ans=ans*x; // } // x=x*x; // y=y/2; // } // return ans; // } // typedef tree< // pair<int, int>, // null_type, // less<pair<int, int>>, // rb_tree_tag, // tree_order_statistics_node_update> ordered_set; ll h[300005]; ll a[300006]; ll bit[566000]; int n; ll get(int x) { ll ans = 0; for (int i = x; i > 0; i = i - (i & -i)) ans = max(bit[i], ans); return ans; } void update(int x, ll y) { for (int i = x; i <= n; i += (i & -i)) { bit[i] = max(bit[i], y); } } int main() { IOS; cin >> n; memset(bit, 0, sizeof bit); loop(n) cin >> h[i + 1]; loop(n) cin >> a[i + 1]; // first use of BIT ll dp[n + 3]; for (int i = 1; i <= n; i++) { dp[i] = get(h[i] - 1) + a[i]; update(h[i], dp[i]); } cout << get(n) << endl; }
[ "variable_declaration.type.change", "io.output.change" ]
984,533
984,534
u353116207
cpp
p03176
#include <bits/stdc++.h> using namespace std; long long t[600000]; int h[200001]; long long query(int index, int lb, int rb, int lq, int rq) { if (lb == rb || (lq == lb && rb == rq)) return t[index]; int mid = (lb + rb) / 2; if (lq > mid) return query(index * 2 + 1, mid + 1, rb, lq, rq); else if (rq <= mid) return query(index * 2, lb, mid, lq, rq); else return max(query(index * 2, lb, mid, lq, mid), query(index * 2 + 1, mid + 1, rb, mid + 1, rq)); } long long update(int index, int lb, int rb, int leaf_id, long long value) { if (lb == rb && lb == leaf_id) t[index] = value; int mid = (lb + rb) / 2; if (leaf_id <= mid) return t[index] = max(t[index], update(index * 2, lb, mid, leaf_id, value)); else return t[index] = max(t[index], update(index * 2 + 1, mid + 1, rb, leaf_id, value)); } int main() { int i, n, a; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &h[i]); for (i = 1; i <= n; i++) { scanf("%d", &a); update(1, 1, n, h[i], query(1, 1, n, 1, h[i] - 1) + a); } printf("%lld", t[1]); return 0; }
#include <bits/stdc++.h> using namespace std; long long t[600000]; int h[200001]; long long query(int index, int lb, int rb, int lq, int rq) { if (lb == rb || (lq == lb && rb == rq)) return t[index]; int mid = (lb + rb) / 2; if (lq > mid) return query(index * 2 + 1, mid + 1, rb, lq, rq); else if (rq <= mid) return query(index * 2, lb, mid, lq, rq); else return max(query(index * 2, lb, mid, lq, mid), query(index * 2 + 1, mid + 1, rb, mid + 1, rq)); } long long update(int index, int lb, int rb, int leaf_id, long long value) { if (lb == rb && lb == leaf_id) return t[index] = value; int mid = (lb + rb) / 2; if (leaf_id <= mid) return t[index] = max(t[index], update(index * 2, lb, mid, leaf_id, value)); else return t[index] = max(t[index], update(index * 2 + 1, mid + 1, rb, leaf_id, value)); } int main() { int i, n, a; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &h[i]); for (i = 1; i <= n; i++) { scanf("%d", &a); update(1, 1, n, h[i], query(1, 1, n, 1, h[i] - 1) + a); } printf("%lld", t[1]); return 0; }
[ "control_flow.return.add" ]
984,537
984,538
u511639787
cpp
p03176
#include <bits/stdc++.h> using namespace std; long long c[200001]; int h[200001]; long long max_v; int n; int lowbit(int x) { return x & -x; } void updatemax(int index, long long value) { while (index <= 200001) { c[index] = max(c[index], value); index += lowbit(index); } } int maxrange(int index) { long long ret = 0; while (index) { ret = max(ret, c[index]); index -= lowbit(index); } return ret; } int main() { int i; long long a, t; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &h[i]); for (i = 1; i <= n; i++) { scanf("%lld", &a); t = maxrange(h[i]) + a; updatemax(h[i], t); max_v = max(max_v, t); } printf("%lld", max_v); return 0; }
#include <bits/stdc++.h> using namespace std; long long c[200001]; int h[200001]; long long max_v; int n; int lowbit(int x) { return x & -x; } void updatemax(int index, long long value) { while (index <= n) { c[index] = max(c[index], value); index += lowbit(index); } } long long maxrange(int index) { long long ret = 0; while (index) { ret = max(ret, c[index]); index -= lowbit(index); } return ret; } int main() { int i; long long a, t; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &h[i]); for (i = 1; i <= n; i++) { scanf("%lld", &a); t = maxrange(h[i] - 1) + a; updatemax(h[i], t); max_v = max(max_v, t); } printf("%lld", max_v); return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.condition.change", "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "assignment.change" ]
984,539
984,540
u511639787
cpp
p03176
#include "bits/stdc++.h" #define N 200001 #define ZERO 0 using namespace std; int n; long long maxn = ZERO; long long c[N]; int h[N]; int lowbit(int x) { return x & (-x); } void updatemax(int index, long long value) { while (index <= n) { c[index] = max(c[index], value); index += lowbit(index); } } long long maxrange(int index) { long long cnt = 0; while (index) { cnt = max(cnt, c[index]); index -= lowbit(index); } return cnt; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) { long long a; scanf("%lld", &a); long long t = maxrange(h[i] - 1) + a; maxn = max(maxn, t); updatemax(h[i], i); } printf("%lld", maxn); return 0; }
#include "bits/stdc++.h" #define N 200001 #define ZERO 0 using namespace std; int n; long long maxn = ZERO; long long c[N]; int h[N]; int lowbit(int x) { return x & (-x); } void updatemax(int index, long long value) { while (index <= n) { c[index] = max(c[index], value); index += lowbit(index); } } long long maxrange(int index) { long long cnt = 0; while (index) { cnt = max(cnt, c[index]); index -= lowbit(index); } return cnt; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) { long long a; scanf("%lld", &a); long long t = maxrange(h[i] - 1) + a; maxn = max(maxn, t); updatemax(h[i], t); } printf("%lld", maxn); return 0; }
[ "identifier.change", "call.arguments.change" ]
984,543
984,544
u226709380
cpp
p03176
#include <bits/stdc++.h> using namespace std; long long int st[800005]; long long int query(int node, int be, int en, int l, int r) { if (be >= l && en <= r) return st[node]; if (be > r || en < l) return 0; int mid = (be + en) >> 1; long long int p1 = query(2 * node, be, mid, l, r); long long int p2 = query(2 * node + 1, mid + 1, en, l, r); return max(p1, p2); } void update(int node, int be, int en, int pos, int value) { if (be == en) { st[node] = value; return; } int mid = (be + en) >> 1; if (pos <= mid) update(2 * node, be, mid, pos, value); else update(2 * node + 1, mid + 1, en, pos, value); st[node] = max(st[2 * node], st[2 * node + 1]); return; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; int a[n], h[n]; vector<long long int> dp(n + 1, 0); // dp[i] -> max beauty that can be obtained if last flower selected has height // i for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int flower = 1; flower <= n; ++flower) { dp[h[flower]] = query(1, 1, n, 1, h[flower]) + a[flower]; update(1, 1, n, h[flower], dp[h[flower]]); } long long int mx = 0; for (int i = 0; i <= n; ++i) { mx = max(mx, dp[i]); } cout << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int st[800005]; long long int query(int node, int be, int en, int l, int r) { if (be >= l && en <= r) return st[node]; if (be > r || en < l) return 0; int mid = (be + en) >> 1; long long int p1 = query(2 * node, be, mid, l, r); long long int p2 = query(2 * node + 1, mid + 1, en, l, r); return max(p1, p2); } void update(int node, int be, int en, int pos, long long int value) { if (be == en) { st[node] = value; return; } int mid = (be + en) >> 1; if (pos <= mid) update(2 * node, be, mid, pos, value); else update(2 * node + 1, mid + 1, en, pos, value); st[node] = max(st[2 * node], st[2 * node + 1]); return; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; long long int a[n], h[n]; vector<long long int> dp(n + 1, 0); // dp[i] -> max beauty that can be obtained if last flower selected has height // i for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int flower = 1; flower <= n; ++flower) { dp[h[flower]] = query(1, 1, n, 1, h[flower]) + a[flower]; update(1, 1, n, h[flower], dp[h[flower]]); } long long int mx = 0; for (int i = 0; i <= n; ++i) { mx = max(mx, dp[i]); } cout << mx << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
984,549
984,550
u792036618
cpp
p03176
/* Author - linpaws07 */ #include <bits/stdc++.h> using namespace std; using namespace std::chrono; #define mod 1000000007 #define mp make_pair #define pb push_back #define inf (int)1e9 #define f first #define s second #define eps 1e-9 #define PI 3.1415926535897932384626433832795 #define scd(t) scanf("%d", &t) #define sclld(t) scanf("%lld", &t) #define scc(t) scanf("%c", &t) #define scs(t) scanf("%s", t) #define scf(t) scanf("%f", &t) #define sclf(t) scanf("%lf", &t) #define memst(a, b) memset(a, (b), sizeof(a)) typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define rp(i, n) for (int i = 0; i < (n); i++) #define fr(i, a, b) for (int i = (a); i < (b); i++) #define fre(i, a, b) for (int i = (a); i <= (b); i++) #define frd(i, a, b) for (int i = (a); i >= (b); i--) inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; } inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int &n, int b) { n |= two(b); } inline void unset_bit(int &n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } auto start = high_resolution_clock::now(); inline void measure(); int64 h[200002], a[200002]; int64 dp[200002], hans[200002]; void update(int i, int64 v) { for (int k = i; k < 200002; k += (k & (-k))) { dp[k] = max(dp[i], v); } } int64 query(int i) { int64 ans = 0; for (int k = i; k > 0; k -= (k & (-k))) { ans = max(dp[k], ans); } return ans; } int main() { FAST // Do awesome things here int n; cin >> n; rp(i, n) { cin >> h[i]; } rp(i, n) { cin >> a[i]; } rp(i, n) { int64 ans = query(h[i] - 1); update(h[i], ans + a[i]); hans[i] = ans + a[i]; } int64 ans = -1; rp(i, 200002) { ans = max(ans, hans[i]); } cout << ans << endl; return 0; } inline void measure() { auto stop = high_resolution_clock::now(); auto duration = duration_cast<milliseconds>(stop - start); cout << duration.count() << endl; }
/* Author - linpaws07 */ #include <bits/stdc++.h> using namespace std; using namespace std::chrono; #define mod 1000000007 #define mp make_pair #define pb push_back #define inf (int)1e9 #define f first #define s second #define eps 1e-9 #define PI 3.1415926535897932384626433832795 #define scd(t) scanf("%d", &t) #define sclld(t) scanf("%lld", &t) #define scc(t) scanf("%c", &t) #define scs(t) scanf("%s", t) #define scf(t) scanf("%f", &t) #define sclf(t) scanf("%lf", &t) #define memst(a, b) memset(a, (b), sizeof(a)) typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define rp(i, n) for (int i = 0; i < (n); i++) #define fr(i, a, b) for (int i = (a); i < (b); i++) #define fre(i, a, b) for (int i = (a); i <= (b); i++) #define frd(i, a, b) for (int i = (a); i >= (b); i--) inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; } inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int &n, int b) { n |= two(b); } inline void unset_bit(int &n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } auto start = high_resolution_clock::now(); inline void measure(); int64 h[200002], a[200002]; int64 dp[200002], hans[200002]; void update(int i, int64 v) { for (int k = i; k < 200002; k += (k & (-k))) { dp[k] = max(dp[k], v); } } int64 query(int i) { int64 ans = 0; for (int k = i; k > 0; k -= (k & (-k))) { ans = max(dp[k], ans); } return ans; } int main() { FAST // Do awesome things here int n; cin >> n; rp(i, n) { cin >> h[i]; } rp(i, n) { cin >> a[i]; } rp(i, n) { int64 ans = query(h[i] - 1); update(h[i], ans + a[i]); hans[i] = ans + a[i]; } int64 ans = -1; rp(i, n) { ans = max(ans, hans[i]); } cout << ans << endl; return 0; } inline void measure() { auto stop = high_resolution_clock::now(); auto duration = duration_cast<milliseconds>(stop - start); cout << duration.count() << endl; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
984,555
984,556
u445244358
cpp
p03176
#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 namespace std; using ll = long long; template <class T, T monoid> class RMQ { public: vector<T> dat; int _n; RMQ(int size) : _n{1} { while (size > _n) _n *= 2; dat.resize(2 * _n - 1, monoid); } void update(int k, int a) { k += _n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, _n); } const T operator[](int i) const { assert(i >= 0 && i < _n); return dat[i + _n - 1]; } private: T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return monoid; } if (a <= l && r <= b) { return dat[k]; } else { T v1 = _query(a, b, k * 2 + 1, l, (l + r) / 2); T v2 = _query(a, b, k * 2 + 2, (l + r) / 2, r); return max(v1, v2); } } }; int main() { int n; cin >> n; int h[n], a[n]; REP(i, n) cin >> h[i]; REP(i, n) cin >> a[i]; RMQ<ll, 0LL> rmq(n + 1); REP(i, n) { ll be = rmq.query(0, h[i]); rmq.update(h[i], be + a[i]); } cout << rmq.query(0, n + 1) << 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 namespace std; using ll = long long; template <class T, T monoid> class RMQ { public: vector<T> dat; int _n; RMQ(int size) : _n{1} { while (size > _n) _n *= 2; dat.resize(2 * _n - 1, monoid); } void update(int k, T a) { k += _n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, _n); } const T operator[](int i) const { assert(i >= 0 && i < _n); return dat[i + _n - 1]; } private: T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return monoid; } if (a <= l && r <= b) { return dat[k]; } else { T v1 = _query(a, b, k * 2 + 1, l, (l + r) / 2); T v2 = _query(a, b, k * 2 + 2, (l + r) / 2, r); return max(v1, v2); } } }; int main() { int n; cin >> n; int h[n], a[n]; REP(i, n) cin >> h[i]; REP(i, n) cin >> a[i]; RMQ<ll, 0LL> rmq(n + 1); REP(i, n) { ll be = rmq.query(0, h[i]); rmq.update(h[i], be + a[i]); } cout << rmq.query(0, n + 1) << endl; return 0; }
[]
984,568
984,569
u772304668
cpp
p03176
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1000000007; typedef long long ll; int n; int dp[200005]; // dp[i] end with i's best solution int a[200005], h[200005]; struct BIT { ll data[200005]; void modify(int x, ll y) { while (x <= n) { data[x] = max(data[x], y); x += x & -x; } } ll get(int x) { ll ret = 0; while (x) { ret = max(ret, data[x]); x &= x - 1; } return ret; } } bit; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { dp[i] = bit.get(h[i]) + a[i]; bit.modify(h[i], dp[i]); } printf("%lld\n", *max_element(dp + 1, dp + n + 1)); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1000000007; typedef long long ll; int n; ll dp[200005]; // dp[i] end with i's best solution int a[200005], h[200005]; struct BIT { ll data[200005]; void modify(int x, ll y) { while (x <= n) { data[x] = max(data[x], y); x += x & -x; } } ll get(int x) { ll ret = 0; while (x) { ret = max(ret, data[x]); x &= x - 1; } return ret; } } bit; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { dp[i] = bit.get(h[i]) + a[i]; bit.modify(h[i], dp[i]); } printf("%lld\n", *max_element(dp + 1, dp + n + 1)); return 0; }
[ "variable_declaration.type.change" ]
984,576
984,577
u588911593
cpp
p03176
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1000000007; typedef long long ll; int n; int dp[100005]; // dp[i] end with i's best solution int a[100005], h[100005]; struct BIT { ll data[100005]; void modify(int x, ll y) { while (x <= n) { data[x] = max(data[x], y); x += x & -x; } } ll get(int x) { ll ret = 0; while (x) { ret = max(ret, data[x]); x &= x - 1; } return ret; } } bit; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { dp[i] = bit.get(h[i]) + a[i]; bit.modify(h[i], dp[i]); } printf("%lld\n", *max_element(dp + 1, dp + n + 1)); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int mod = 1000000007; typedef long long ll; int n; ll dp[200005]; // dp[i] end with i's best solution int a[200005], h[200005]; struct BIT { ll data[200005]; void modify(int x, ll y) { while (x <= n) { data[x] = max(data[x], y); x += x & -x; } } ll get(int x) { ll ret = 0; while (x) { ret = max(ret, data[x]); x &= x - 1; } return ret; } } bit; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &h[i]); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { dp[i] = bit.get(h[i]) + a[i]; bit.modify(h[i], dp[i]); } printf("%lld\n", *max_element(dp + 1, dp + n + 1)); return 0; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
984,578
984,577
u588911593
cpp
p03176
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; long long n, f[MAX], dp[MAX], a[MAX], h[MAX]; long long get(long long idx) { long long res = 0; for (; idx; idx -= (idx & (-idx))) res = max(res, f[idx]); return res; } void modify(long long idx, long long val) { for (; idx < MAX; idx += (idx & (-idx))) { f[idx] = max(f[idx], val); } } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> a[i]; long long ans = 0; for (int i = 1; i <= n; i++) { dp[i] = get(h[i]) + a[i]; ans = max(dp[i], ans); modify(h[i], a[i]); } cout << ans; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; long long n, f[MAX], dp[MAX], a[MAX], h[MAX]; long long get(long long idx) { long long res = 0; for (; idx; idx -= (idx & (-idx))) res = max(res, f[idx]); return res; } void modify(long long idx, long long val) { for (; idx < MAX; idx += (idx & (-idx))) { f[idx] = max(f[idx], val); } } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> a[i]; long long ans = 0; for (int i = 1; i <= n; i++) { dp[i] = get(h[i]) + a[i]; ans = max(dp[i], ans); modify(h[i], dp[i]); } cout << ans; }
[ "identifier.change", "call.arguments.change" ]
984,579
984,580
u573738515
cpp
p03176
#include <bits/stdc++.h> using namespace std; const int MAXN = 300001; typedef long long ll; #define f first #define s second const ll mod = 1e9 + 7; ll nums[MAXN]; ll tree[MAXN]; void update(int pos, ll val) { for (; pos < MAXN; pos += pos & -pos) { tree[pos] = max(tree[pos], val); } } ll query(int pos) { ll res = 0; for (; pos > 0; pos -= pos & -pos) res = max(res, tree[pos]); return res; } int main() { int N; scanf("%d", &N); int arr[N], arr2[N]; for (int i = 0; i < N; i++) { scanf("%lld", &arr[i]); arr2[i] = arr[i]; } for (int i = 0; i < N; i++) { scanf("%lld", &nums[i]); } sort(arr2, arr2 + N); for (int i = 0; i < N; i++) { arr[i] = upper_bound(arr2, arr2 + N, arr[i]) - arr2 + 1; } ll ans = 0; for (int i = 0; i < N; i++) { ll cur = query(arr[i] + 1); ans = max(ans, cur + nums[i]); update(arr[i], cur + nums[i]); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 300001; typedef long long ll; #define f first #define s second const ll mod = 1e9 + 7; ll nums[MAXN]; ll tree[MAXN]; void update(int pos, ll val) { for (; pos < MAXN; pos += pos & -pos) { tree[pos] = max(tree[pos], val); } } ll query(int pos) { ll res = 0; for (; pos > 0; pos -= pos & -pos) res = max(res, tree[pos]); return res; } int main() { int N; scanf("%d", &N); int arr[N], arr2[N]; for (int i = 0; i < N; i++) { scanf("%lld", &arr[i]); arr2[i] = arr[i]; } for (int i = 0; i < N; i++) { scanf("%lld", &nums[i]); } sort(arr2, arr2 + N); for (int i = 0; i < N; i++) { arr[i] = upper_bound(arr2, arr2 + N, arr[i]) - arr2 + 1; } ll ans = 0; for (int i = 0; i < N; i++) { ll cur = query(arr[i]); ans = max(ans, cur + nums[i]); update(arr[i] + 1, cur + nums[i]); } printf("%lld\n", ans); }
[ "expression.operation.binary.remove" ]
984,610
984,611
u693463436
cpp
p03176
#include <bits/stdc++.h> using namespace std; long s[1 << 19]; int n; void update(int p, int x, int k = 0, int l = 0, int r = n) { if (r - l < 2) { s[k] = x; return; } int m = (l + r) / 2; if (p < m) update(p, x, 2 * k + 1, l, m); else update(p, x, 2 * k + 2, m, r); s[k] = max(s[2 * k + 1], s[2 * k + 2]); } long query(int a, int b, int k = 0, int l = 0, int r = n) { if (a >= r || b <= l) return 0; if (a <= l && r <= b) return s[k]; int m = (l + r) / 2; return max(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r)); } int main() { cin >> n; vector<pair<int, int>> p(n); for (int i = 0; i < n; ++i) { int t; cin >> t; p[i] = {t, i}; } vector<int> a(n); for (auto &e : a) cin >> e; sort(begin(p), end(p)); for (auto &e : p) { int i = e.second; auto x = query(0, i); update(i, x + a[i]); } cout << query(0, n) << endl; }
#include <bits/stdc++.h> using namespace std; long s[1 << 19]; int n; void update(int p, long x, int k = 0, int l = 0, int r = n) { if (r - l < 2) { s[k] = x; return; } int m = (l + r) / 2; if (p < m) update(p, x, 2 * k + 1, l, m); else update(p, x, 2 * k + 2, m, r); s[k] = max(s[2 * k + 1], s[2 * k + 2]); } long query(int a, int b, int k = 0, int l = 0, int r = n) { if (a >= r || b <= l) return 0; if (a <= l && r <= b) return s[k]; int m = (l + r) / 2; return max(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r)); } int main() { cin >> n; vector<pair<int, int>> p(n); for (int i = 0; i < n; ++i) { int t; cin >> t; p[i] = {t, i}; } vector<int> a(n); for (auto &e : a) cin >> e; sort(begin(p), end(p)); for (auto &e : p) { int i = e.second; auto x = query(0, i); update(i, x + a[i]); } cout << query(0, n) << endl; }
[ "variable_declaration.type.primitive.change" ]
984,634
984,635
u503549962
cpp
p03177
#include <cstring> #include <iostream> using namespace std; const int MAX = 51; const int MOD = 1e9 + 7; using namespace std; int main() { int N, K; cin >> N >> K; long long G[MAX][MAX]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> G[i][j]; } } long long ans[MAX][MAX]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { ans[i][j] = 0; } ans[i][i] = 1; } int exp = K; while (exp > 0) { if (exp % 2 == 1) { // ans *= G; // <=> // prod = ans * G; // ans = prod; long long prod[MAX][MAX]; for (int begin = 0; begin < N; begin++) { for (int end = 0; end < N; end++) { prod[begin][end] = 0; for (int j = 0; j < N; j++) { prod[begin][end] += ans[begin][j] * G[j][end] % MOD; } prod[begin][end] %= MOD; } } memcpy(ans, prod, sizeof(prod)); } // G *= G; // <=> // prod = G * G; // G = prod; long long prod[MAX][MAX]; for (int begin = 0; begin < N; begin++) { for (int end = 0; end < N; end++) { prod[begin][end] = 0; for (int j = 0; j < N; j++) { prod[begin][end] += G[begin][j] * G[j][end] % MOD; } prod[begin][end] %= MOD; } } memcpy(G, prod, sizeof(prod)); exp /= 2; } long long answer = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { answer += ans[i][j]; } } answer %= MOD; cout << answer << '\n'; return 0; }
#include <cstring> #include <iostream> using namespace std; const int MAX = 51; const int MOD = 1e9 + 7; using namespace std; int main() { long long N, K; cin >> N >> K; long long G[MAX][MAX]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> G[i][j]; } } long long ans[MAX][MAX]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { ans[i][j] = 0; } ans[i][i] = 1; } long long exp = K; while (exp > 0) { if (exp % 2 == 1) { // ans *= G; // <=> // prod = ans * G; // ans = prod; long long prod[MAX][MAX]; for (int begin = 0; begin < N; begin++) { for (int end = 0; end < N; end++) { prod[begin][end] = 0; for (int j = 0; j < N; j++) { prod[begin][end] += ans[begin][j] * G[j][end] % MOD; } prod[begin][end] %= MOD; } } memcpy(ans, prod, sizeof(prod)); } // G *= G; // <=> // prod = G * G; // G = prod; long long prod[MAX][MAX]; for (int begin = 0; begin < N; begin++) { for (int end = 0; end < N; end++) { prod[begin][end] = 0; for (int j = 0; j < N; j++) { prod[begin][end] += G[begin][j] * G[j][end] % MOD; } prod[begin][end] %= MOD; } } memcpy(G, prod, sizeof(prod)); exp /= 2; } long long answer = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { answer += ans[i][j]; } } answer %= MOD; cout << answer << '\n'; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
984,696
984,697
u879680955
cpp
p03177
#include <bits/stdc++.h> #define DIM 57 #define modulo 1000000007 using namespace std; struct matrix { long long n, a[DIM][DIM]; void mul(matrix b) { matrix am = *this; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { a[i][j] = 0; for (int k = 1; k <= n; ++k) a[i][j] = (a[i][j] + am.a[i][k] * b.a[k][j]) % modulo; } } void power(long long k) { matrix c = (*this); k--; while (k) { if (k & 1) mul(c); c.mul(c); k >>= 2; } } }; int main() { matrix a; long long k; cin >> a.n >> k; for (int i = 1; i <= a.n; ++i) for (int j = 1; j <= a.n; ++j) cin >> a.a[i][j]; a.power(k); long long res = 0; for (int i = 1; i <= a.n; ++i) for (int j = 1; j <= a.n; ++j) { res += a.a[i][j]; res %= modulo; } cout << res; return 0; }
#include <bits/stdc++.h> #define DIM 57 #define modulo 1000000007 using namespace std; struct matrix { long long n, a[DIM][DIM]; void mul(matrix b) { matrix am = *this; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { a[i][j] = 0; for (int k = 1; k <= n; ++k) a[i][j] = (a[i][j] + am.a[i][k] * b.a[k][j]) % modulo; } } void power(long long k) { matrix c = (*this); k--; while (k) { if (k & 1) mul(c); c.mul(c); k >>= 1; } } }; int main() { matrix a; long long k; cin >> a.n >> k; for (int i = 1; i <= a.n; ++i) for (int j = 1; j <= a.n; ++j) cin >> a.a[i][j]; a.power(k); long long res = 0; for (int i = 1; i <= a.n; ++i) for (int j = 1; j <= a.n; ++j) { res += a.a[i][j]; res %= modulo; } cout << res; return 0; }
[ "literal.number.change", "assignment.value.change" ]
984,729
984,730
u674071078
cpp
p03177
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<long long, long long> pl; const int MOD = 1e9 + 7; const ll INF = 1e18; const double EPS = 1e-6; const int MAX_N = 55; struct Matrix { long long **mat; int a, b; Matrix() { a = b = 0; } Matrix(int a, int b) { this->a = a, this->b = b; mat = new long long *[a]; for (int i = 0; i < a; ++i) { mat[i] = new long long[b]; for (int j = 0; j < b; ++j) mat[i][j] = 0; } } Matrix(vector<vector<int>> v) : Matrix(v.size(), v[0].size()) { for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) mat[i][j] = v[i][j]; } void print() { for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) cout << mat[i][j] << " "; cout << "\n"; } cout << "------------\n"; } Matrix operator+(const Matrix &m) { Matrix ret(a, b); for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) ret.mat[i][j] = (mat[i][j] + m.mat[i][j]) % MOD; return ret; } Matrix operator*(const Matrix &m) { Matrix ret(a, m.b); for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) for (int k = 0; k < m.b; ++k) ret.mat[i][k] = (ret.mat[i][k] + mat[i][j] * m.mat[j][k] % MOD) % MOD; return ret; } Matrix operator^(ll pow) { Matrix ret(a, a), base(*this); for (int i = 0; i < a; ++i) ret.mat[i][i] = 1; while (pow) { if (pow & 1) ret = ret * base; base = base * base; pow /= 2; } return ret; } }; int N, K; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> K; Matrix adjMat(N, N); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cin >> adjMat.mat[i][j]; } } adjMat = adjMat ^ K; ll total = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { total = (total + adjMat.mat[i][j]) % MOD; } } cout << total << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<long long, long long> pl; const int MOD = 1e9 + 7; const ll INF = 1e18; const double EPS = 1e-6; const int MAX_N = 55; struct Matrix { long long **mat; int a, b; Matrix() { a = b = 0; } Matrix(int a, int b) { this->a = a, this->b = b; mat = new long long *[a]; for (int i = 0; i < a; ++i) { mat[i] = new long long[b]; for (int j = 0; j < b; ++j) mat[i][j] = 0; } } Matrix(vector<vector<int>> v) : Matrix(v.size(), v[0].size()) { for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) mat[i][j] = v[i][j]; } void print() { for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) cout << mat[i][j] << " "; cout << "\n"; } cout << "------------\n"; } Matrix operator+(const Matrix &m) { Matrix ret(a, b); for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) ret.mat[i][j] = (mat[i][j] + m.mat[i][j]) % MOD; return ret; } Matrix operator*(const Matrix &m) { Matrix ret(a, m.b); for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) for (int k = 0; k < m.b; ++k) ret.mat[i][k] = (ret.mat[i][k] + mat[i][j] * m.mat[j][k] % MOD) % MOD; return ret; } Matrix operator^(ll pow) { Matrix ret(a, a), base(*this); for (int i = 0; i < a; ++i) ret.mat[i][i] = 1; while (pow) { if (pow & 1) ret = ret * base; base = base * base; pow /= 2; } return ret; } }; int N; ll K; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> K; Matrix adjMat(N, N); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cin >> adjMat.mat[i][j]; } } adjMat = adjMat ^ K; ll total = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { total = (total + adjMat.mat[i][j]) % MOD; } } cout << total << '\n'; return 0; }
[]
984,741
984,742
u738069880
cpp
p03177
#include <algorithm> #include <iostream> #include <stdio.h> #include <vector> using namespace std; long long MM = 1e9 + 7; typedef vector<vector<long long>> mat; mat mm(const mat &A, const mat &B, int N) { mat rl(N, vector<long long>(N, 0)); for (auto i = 0; i < N; i++) for (auto j = 0; j < N; j++) for (auto k = 0; k < N; k++) rl[i][j] = (rl[i][j] + A[i][k] * B[k][j]) % MM; return rl; } int main() { long long N, K; cin >> N >> K; vector<vector<long long>> A(N + 1, vector<long long>(N + 1)); for (auto i = 0; i < N; i++) for (auto j = 0; j < N; j++) cin >> A[i][j]; mat F = A; vector<vector<long long>> ans(N + 1, vector<long long>(N + 1, 0)); for (auto i = 0; i < N; i++) ans[i][i] = 1; while (K != 0) { if (K & 1) ans = mm(ans, F, N); F = mm(F, F, N); K = K >> 1; } long long int myans; for (auto i = 0; i < N; i++) for (auto j = 0; j < N; j++) myans = (myans + ans[i][j]) % MM; cout << myans << endl; return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <vector> using namespace std; long long MM = 1e9 + 7; typedef vector<vector<long long>> mat; mat mm(const mat &A, const mat &B, int N) { mat rl(N, vector<long long>(N, 0)); for (auto i = 0; i < N; i++) for (auto j = 0; j < N; j++) for (auto k = 0; k < N; k++) rl[i][j] = (rl[i][j] + A[i][k] * B[k][j]) % MM; return rl; } int main() { long long N, K; cin >> N >> K; vector<vector<long long>> A(N + 1, vector<long long>(N + 1)); for (auto i = 0; i < N; i++) for (auto j = 0; j < N; j++) cin >> A[i][j]; mat F = A; vector<vector<long long>> ans(N + 1, vector<long long>(N + 1, 0)); for (auto i = 0; i < N; i++) ans[i][i] = 1; while (K != 0) { if (K & 1) ans = mm(ans, F, N); F = mm(F, F, N); K = K >> 1; } long long int myans = 0; for (auto i = 0; i < N; i++) for (auto j = 0; j < N; j++) myans = (myans + ans[i][j]) % MM; cout << myans << endl; return 0; }
[ "variable_declaration.value.change" ]
984,743
984,744
u993688697
cpp
p03177
/* if you can't see the repay Why not just work step by step rubbish is relaxed to ljq */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdlib.h> #include <vector> using namespace std; #define dbg(x) cout << #x << " = " << (x) << endl #define dbg2(x1, x2) \ cout << #x1 << " = " << x1 << " " << #x2 << " = " << x2 << endl #define dbg3(x1, x2, x3) \ cout << #x1 << " = " << x1 << " " << #x2 << " = " << x2 << " " << #x3 \ << " = " << x3 << endl #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define lc (rt << 1) #define rc (rt << 11) #define mid ((l + r) >> 1) typedef pair<int, int> pll; typedef long long ll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll _INF = 0xc0c0c0c0c0c0c0c0; const ll mod = (int)1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll ksm(ll a, ll b, ll mod) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } ll inv2(ll a, ll mod) { return ksm(a, mod - 2, mod); } void exgcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, y, x, d); y -= x * (a / b); } } // printf("%lld*a + %lld*b = %lld\n", x, y, d); ll mo(ll x, ll y) { return x + y >= mod ? x + y - mod : x + y; } int n; struct mat { ll jz[50][50]; }; mat mat_mul(mat x, mat y) { mat res; memset(res.jz, 0, sizeof(res.jz)); for (int i = 0; i < n; ++i) for (int k = 0; k < n; ++k) for (int j = 0; j < n; ++j) res.jz[i][j] = (res.jz[i][j] + x.jz[i][k] * y.jz[k][j] + mod) % mod; return res; } ll power_mod(ll P, mat res) { mat ans; for (int i = 0; i < n; ++i) ans.jz[i][i] = 1; while (P > 0) { if (P & 1) ans = mat_mul(ans, res); P = P >> 1; res = mat_mul(res, res); } ll tmp = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { tmp += ans.jz[i][j]; if (tmp >= mod) tmp -= mod; } return tmp; } int main() { // ios::sync_with_stdio(false); // freopen("a.txt","r",stdin); // freopen("b.txt","w",stdout); ll k; mat res; scanf("%d%lld", &n, &k); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf("%d", &res.jz[i][j]); printf("%lld\n", power_mod(k, res)); // fclose(stdin); // fclose(stdout); // cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << // endl; return 0; }
/* if you can't see the repay Why not just work step by step rubbish is relaxed to ljq */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdlib.h> #include <vector> using namespace std; #define dbg(x) cout << #x << " = " << (x) << endl #define dbg2(x1, x2) \ cout << #x1 << " = " << x1 << " " << #x2 << " = " << x2 << endl #define dbg3(x1, x2, x3) \ cout << #x1 << " = " << x1 << " " << #x2 << " = " << x2 << " " << #x3 \ << " = " << x3 << endl #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define lc (rt << 1) #define rc (rt << 11) #define mid ((l + r) >> 1) typedef pair<int, int> pll; typedef long long ll; const int inf = 0x3f3f3f3f; const int _inf = 0xc0c0c0c0; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll _INF = 0xc0c0c0c0c0c0c0c0; const ll mod = (int)1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll ksm(ll a, ll b, ll mod) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } ll inv2(ll a, ll mod) { return ksm(a, mod - 2, mod); } void exgcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a; x = 1; y = 0; } else { exgcd(b, a % b, y, x, d); y -= x * (a / b); } } // printf("%lld*a + %lld*b = %lld\n", x, y, d); ll mo(ll x, ll y) { return x + y >= mod ? x + y - mod : x + y; } int n; struct mat { ll jz[50][50]; }; mat mat_mul(mat x, mat y) { mat res; memset(res.jz, 0, sizeof(res.jz)); for (int i = 0; i < n; ++i) for (int k = 0; k < n; ++k) for (int j = 0; j < n; ++j) res.jz[i][j] = (res.jz[i][j] + x.jz[i][k] * y.jz[k][j] + mod) % mod; return res; } ll power_mod(ll P, mat res) { mat ans; for (int i = 0; i < n; ++i) ans.jz[i][i] = 1; while (P > 0) { if (P & 1) ans = mat_mul(ans, res); P = P >> 1; res = mat_mul(res, res); } ll tmp = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { tmp += ans.jz[i][j]; if (tmp >= mod) tmp -= mod; } return tmp; } int main() { // ios::sync_with_stdio(false); // freopen("a.txt","r",stdin); // freopen("b.txt","w",stdout); ll k; mat res; scanf("%d%lld", &n, &k); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf("%lld", &res.jz[i][j]); printf("%lld\n", power_mod(k, res)); // fclose(stdin); // fclose(stdout); // cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << // endl; return 0; }
[ "literal.string.change", "call.arguments.change" ]
984,745
984,746
u536451615
cpp
p03178
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int dp[10002][102][2]; string s; int d; int fun(int idx, int cur, bool gr) { if (idx == s.size()) return !cur; int &ret = dp[idx][cur][gr]; if (~ret) return ret; ret = 0; if (!gr) { for (int i = 0; i < s[idx] - '0'; i++) ret += fun(idx + 1, (cur + i) % d, 1) % mod; ret += fun(idx + 1, (cur + s[idx] - '0') % d, 0) % mod; } else { for (int i = 0; i <= 9; i++) ret += fun(idx + 1, (cur + i) % d, 1) % mod; } ret %= mod; return ret; } int main() { memset(dp, -1, sizeof dp); cin >> s >> d; cout << (fun(0, 0, 0) + mod - 1) % mod << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; int dp[10002][102][2]; string s; int d; int fun(int idx, int cur, bool gr) { if (idx == s.size()) return !cur; int &ret = dp[idx][cur][gr]; if (~ret) return ret; ret = 0; if (!gr) { for (int i = 0; i < s[idx] - '0'; i++) ret += fun(idx + 1, (cur + i) % d, 1) % mod; ret += fun(idx + 1, (cur + s[idx] - '0') % d, 0) % mod; } else { for (int i = 0; i <= 9; i++) ret += fun(idx + 1, (cur + i) % d, 1) % mod; } ret %= mod; return ret; } signed main() { memset(dp, -1, sizeof dp); cin >> s >> d; cout << (fun(0, 0, 0) + mod - 1) % mod << endl; }
[ "variable_declaration.type.primitive.change" ]
984,767
984,768
u839354257
cpp
p03178
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<ll, ll, ll> T; const long long INF = 1LL << 60; const int MOD = 1000000000 + 7; #define rev(s) (string((s).rbegin(), (s).rend())) template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; // cout << fixed << setprecision(10) << ans << endl; 有効桁数指定 // *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max // int dx[8]={1,1,0,-1,-1,-1,0,1}; // int dy[8]={0,1,1,1,0,-1,-1,-1}; // int dx[4]={1,0,-1,0}; // int dy[4]={0,1,0,-1}; // ~ は、-1の時だけfalse // struct Edge { // int to, id; // Edge(int a, int b): to(a), id(b) {} // }; ll dp[10010][2][110]; int main(int argc, char const *argv[]) { string s; int d; cin >> s >> d; int n = (int)s.size(); dp[0][0][0] = 1; rep(i, n) { rep(j, 2) { rep(k, d) { int e = s[i] - '0'; if (j == 0) { dp[i + 1][0][(k + e) % d] += dp[i][j][k]; dp[i + 1][0][(k + e) % d] %= MOD; if (e >= 1) { rep(l, e) { dp[i + 1][1][(k + l) % d] += dp[i][j][k]; dp[i + 1][1][(k + l) % d] %= MOD; } } } else { rep(l, 10) { dp[i + 1][1][(k + l) % d] += dp[i][j][k]; dp[i + 1][1][(k + l) % d] %= MOD; } } } } } cout << (dp[n][0][0] + dp[n][1][0]) % MOD << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<ll, ll, ll> T; const long long INF = 1LL << 60; const int MOD = 1000000000 + 7; #define rev(s) (string((s).rbegin(), (s).rend())) template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; // cout << fixed << setprecision(10) << ans << endl; 有効桁数指定 // *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max // int dx[8]={1,1,0,-1,-1,-1,0,1}; // int dy[8]={0,1,1,1,0,-1,-1,-1}; // int dx[4]={1,0,-1,0}; // int dy[4]={0,1,0,-1}; // ~ は、-1の時だけfalse // struct Edge { // int to, id; // Edge(int a, int b): to(a), id(b) {} // }; ll dp[10010][2][110]; int main(int argc, char const *argv[]) { string s; int d; cin >> s >> d; int n = (int)s.size(); dp[0][0][0] = 1; rep(i, n) { rep(j, 2) { rep(k, d) { int e = s[i] - '0'; if (j == 0) { dp[i + 1][0][(k + e) % d] += dp[i][j][k]; dp[i + 1][0][(k + e) % d] %= MOD; if (e >= 1) { rep(l, e) { dp[i + 1][1][(k + l) % d] += dp[i][j][k]; dp[i + 1][1][(k + l) % d] %= MOD; } } } else { rep(l, 10) { dp[i + 1][1][(k + l) % d] += dp[i][j][k]; dp[i + 1][1][(k + l) % d] %= MOD; } } } } } cout << (dp[n][0][0] + dp[n][1][0] - 1 + MOD) % MOD << endl; return 0; }
[ "expression.operation.binary.add" ]
984,771
984,772
u895393304
cpp
p03178
#include <bits/stdc++.h> using namespace std; #define ll long long int #define endl "\n" #define pb push_back #define w(x) \ int x; \ cin >> x; \ while (x--) #define f(i, n) for (ll i = 0; i < n; i++) #define f1(i, n) for (ll i = 1; i <= n; i++) #define ff first #define ss second #define vi vector<ll> #define vvi vector<vector<ll>> #define me max_element const int mod = 1e9 + 7; void ganekasar() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void add_self(ll &a, ll b) { a += b; if (a > mod) a -= mod; } int main() { string k; cin >> k; ll D; cin >> D; ll len = k.length(); vvi dp(D, vi(2)); dp[0][0] = 1; for (int here = 0; here < len; here++) { vvi new_dp(D, vi(2)); for (int sum = 0; sum < D; sum++) { for (bool sm_already : {false, true}) { for (ll digit = 0; digit < 10; digit++) { if (digit > k[here - '0'] && !sm_already) break; add_self( new_dp[(sum + digit) % D][sm_already || (digit < k[here] - '0')], dp[sum][sm_already]); } } } dp = new_dp; } ll answer = (dp[0][false] + dp[0][true]) % mod; answer--; if (answer == -1) answer = mod - 1; cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define endl "\n" #define pb push_back #define w(x) \ int x; \ cin >> x; \ while (x--) #define f(i, n) for (ll i = 0; i < n; i++) #define f1(i, n) for (ll i = 1; i <= n; i++) #define ff first #define ss second #define vi vector<ll> #define vvi vector<vector<ll>> #define me max_element const int mod = 1e9 + 7; void ganekasar() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } void add_self(ll &a, ll b) { a += b; if (a > mod) a -= mod; } int main() { string k; cin >> k; ll D; cin >> D; ll len = k.length(); vvi dp(D, vi(2)); dp[0][0] = 1; for (int here = 0; here < len; here++) { vvi new_dp(D, vi(2)); for (int sum = 0; sum < D; sum++) { for (bool sm_already : {false, true}) { for (ll digit = 0; digit < 10; digit++) { if (digit > k[here] - '0' && !sm_already) break; add_self( new_dp[(sum + digit) % D][sm_already || (digit < k[here] - '0')], dp[sum][sm_already]); } } } dp = new_dp; } ll answer = (dp[0][false] + dp[0][true]) % mod; answer--; if (answer == -1) answer = mod - 1; cout << answer << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
984,776
984,777
u193875150
cpp
p03178
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); string K; cin >> K; int n = K.size(); int D; cin >> D; vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(D, vector<ll>(2, 0))); dp[0][0][1] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < D; j++) { for (int b = 0; b < 2; b++) { for (int k = 0; k < 10; k++) { int ni = (i + 1) % 2, nj = (j + k) % D, nb = 0; int curNum = K[i] - '0'; if (b) { if (k > curNum) { break; } else if (k == curNum) { nb = 1; } } dp[ni][nj][nb] += dp[(i % 2)][j][b]; dp[ni][nj][nb] %= mod; } dp[i][j][b] = 0; } } } ll ans = dp[(n % 2)][0][0] + dp[(n % 2)][0][1]; ans %= mod; ans--; ans %= mod; if (ans < 0) { ans += mod; } cout << ans << '\n'; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); string K; cin >> K; int n = K.size(); int D; cin >> D; vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(D, vector<ll>(2, 0))); dp[0][0][1] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < D; j++) { for (int b = 0; b < 2; b++) { for (int k = 0; k < 10; k++) { int ni = (i + 1) % 2, nj = (j + k) % D, nb = 0; int curNum = K[i] - '0'; if (b) { if (k > curNum) { break; } else if (k == curNum) { nb = 1; } } dp[ni][nj][nb] += dp[(i % 2)][j][b]; dp[ni][nj][nb] %= mod; } dp[i % 2][j][b] = 0; } } } ll ans = dp[(n % 2)][0][0] + dp[(n % 2)][0][1]; ans %= mod; ans--; ans %= mod; if (ans < 0) { ans += mod; } cout << ans << '\n'; }
[ "assignment.change" ]
984,778
984,779
u270654502
cpp
p03178
#include <bits/stdc++.h> using namespace std; // look at 0 - K and subtract 1. string k; int n, d; const int MOD = 1e9 + 7; // dp[i][j]: if we have i 0-9 choices and we want j mod d, how many ways? int dp[10002][101]; // solve: int i is the first letter index of the suffix we look at. left is the // modulus mod D we want. long long solve(int i, int left) { if (i == n) { // base case return (left == 0); } long long ret = 0; // take the first char ret += solve(i + 1, ((left - (k[i] - '0')) % d + d) % d); for (int c = 0; c < (k[i] - '0'); c++) { ret += dp[n - i - 1][((left - c) % d + d) % d]; ret %= MOD; } ret %= MOD; return ret; } int main() { cin >> k >> d; n = k.length(); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < d; j++) { int ret = 0; for (int c = 0; c < 10; c++) { ret += dp[i - 1][((j - c) % d + d) % d]; ret %= MOD; } dp[i][j] = ret; } } cout << ((solve(0, 0) - (d != 1)) % MOD + MOD) % MOD << endl; }
#include <bits/stdc++.h> using namespace std; // look at 0 - K and subtract 1. string k; int n, d; const int MOD = 1e9 + 7; // dp[i][j]: if we have i 0-9 choices and we want j mod d, how many ways? int dp[10002][101]; // solve: int i is the first letter index of the suffix we look at. left is the // modulus mod D we want. long long solve(int i, int left) { if (i == n) { // base case return (left == 0); } long long ret = 0; // take the first char ret += solve(i + 1, ((left - (k[i] - '0')) % d + d) % d); for (int c = 0; c < (k[i] - '0'); c++) { ret += dp[n - i - 1][((left - c) % d + d) % d]; ret %= MOD; } ret %= MOD; return ret; } int main() { cin >> k >> d; n = k.length(); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < d; j++) { int ret = 0; for (int c = 0; c < 10; c++) { ret += dp[i - 1][((j - c) % d + d) % d]; ret %= MOD; } dp[i][j] = ret; } } cout << ((solve(0, 0) - 1) % MOD + MOD) % MOD << endl; }
[]
984,820
984,821
u117022482
cpp
p03178
#include <bits/stdc++.h> using namespace std; // look at 0 - K and subtract 1. string k; int n, d; const int MOD = 1e9 + 7; // dp[i][j]: if we have i 0-9 choices and we want j mod d, how many ways? int dp[10001][101]; // solve: int i is the first letter index of the suffix we look at. left is the // modulus mod D we want. long long solve(int i, int left) { if (i == n) { // base case return 0; } long long ret = 0; // take the first char ret += solve(i + 1, ((left - (k[i] - '0')) % d + d) % d); for (int c = 0; c < (k[i] - '0'); c++) { ret += dp[n - i - 1][((left - c) % d + d) % d]; ret %= MOD; } ret %= MOD; return ret; } int main() { cin >> k >> d; n = k.length(); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < d; j++) { int ret = 0; for (int c = 0; c < 10; c++) { ret += dp[i - 1][((j - c) % d + d) % d]; ret %= MOD; } dp[i][j] = ret; } } cout << ((solve(0, 0) - 1) % MOD + MOD) % MOD << endl; }
#include <bits/stdc++.h> using namespace std; // look at 0 - K and subtract 1. string k; int n, d; const int MOD = 1e9 + 7; // dp[i][j]: if we have i 0-9 choices and we want j mod d, how many ways? int dp[10002][101]; // solve: int i is the first letter index of the suffix we look at. left is the // modulus mod D we want. long long solve(int i, int left) { if (i == n) { // base case return (left == 0); } long long ret = 0; // take the first char ret += solve(i + 1, ((left - (k[i] - '0')) % d + d) % d); for (int c = 0; c < (k[i] - '0'); c++) { ret += dp[n - i - 1][((left - c) % d + d) % d]; ret %= MOD; } ret %= MOD; return ret; } int main() { cin >> k >> d; n = k.length(); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < d; j++) { int ret = 0; for (int c = 0; c < 10; c++) { ret += dp[i - 1][((j - c) % d + d) % d]; ret %= MOD; } dp[i][j] = ret; } } cout << ((solve(0, 0) - 1) % MOD + MOD) % MOD << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "function.return_value.change" ]
984,822
984,821
u117022482
cpp
p03178
#include <bits/stdc++.h> #define int long long #define counter(m) for (int i = 0; i < m; i++) #define gcd __gcd #define endl "\n" #define pb emplace_back #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define deci(x, y) fixed << setprecision(y) << x #define w(t) \ int t; \ cin >> t; \ while (t--) #define nitin \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define PI 3.141592653589793238 using namespace std; int dp[10001][2][101]; int d; int solve(string &s, int idx, int n, int sum, bool isSmalled, int num) { if (idx == n) { // if(sum%d==0) // cout<<num<<" "<<sum<<endl; return sum % d == 0; } if (dp[idx][isSmalled][sum] != -1) return dp[idx][isSmalled][sum]; int ans = 0; if (isSmalled) { for (int i = 0; i < 10; i++) { ans += solve(s, idx + 1, n, (sum + i) % d, true, num * 10 + i); ans = ans % mod; } } else { int Num = s[idx] - '0'; for (int i = 0; i < Num; i++) { ans += solve(s, idx + 1, n, (sum + i) % d, true, num * 10 + i); ans %= mod; } ans += solve(s, idx + 1, n, (sum + num) % d, false, num * 10 + Num); ans %= mod; } return dp[idx][isSmalled][sum] = ans; } int32_t main() { nitin; string s; cin >> s; for (int i = 0; i <= 10000; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 101; k++) dp[i][j][k] = -1; } } int n = s.length(); cin >> d; cout << (solve(s, 0, n, 0, false, 0) - 1 + mod) % mod; return 0; }
#include <bits/stdc++.h> #define int long long #define counter(m) for (int i = 0; i < m; i++) #define gcd __gcd #define endl "\n" #define pb emplace_back #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define deci(x, y) fixed << setprecision(y) << x #define w(t) \ int t; \ cin >> t; \ while (t--) #define nitin \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define PI 3.141592653589793238 using namespace std; int dp[10001][2][101]; int d; int solve(string &s, int idx, int n, int sum, bool isSmalled, int num) { if (idx == n) { // if(sum%d==0) // cout<<num<<" "<<sum<<endl; return sum % d == 0; } if (dp[idx][isSmalled][sum] != -1) return dp[idx][isSmalled][sum]; int ans = 0; if (isSmalled) { for (int i = 0; i < 10; i++) { ans += solve(s, idx + 1, n, (sum + i) % d, true, num * 10 + i); ans = ans % mod; } } else { int Num = s[idx] - '0'; for (int i = 0; i < Num; i++) { ans += solve(s, idx + 1, n, (sum + i) % d, true, num * 10 + i); ans %= mod; } ans += solve(s, idx + 1, n, (sum + Num) % d, false, num * 10 + Num); ans %= mod; } return dp[idx][isSmalled][sum] = ans; } int32_t main() { nitin; string s; cin >> s; for (int i = 0; i <= 10000; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 101; k++) dp[i][j][k] = -1; } } int n = s.length(); cin >> d; cout << (solve(s, 0, n, 0, false, 0) - 1 + mod) % mod; return 0; }
[ "assignment.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
984,828
984,829
u052649041
cpp
p03178
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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 int mod = 1e9 + 7; const int INF = 1001001001; int dp[1000005][5][105]; int main() { string S; int D; cin >> S >> D; int N = S.size(); dp[0][0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < D; k++) { if (dp[i][j][k] == 0) { continue; } int lim = j ? 9 : S[i] - '0'; for (int d = 0; d < lim + 1; d++) { (dp[i + 1][j || (d < lim)][(d + k) % D] += dp[i][j][k]) %= mod; } } } } cout << (dp[N][0][0] + dp[N][1][0] - 1) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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 int mod = 1e9 + 7; const int INF = 1001001001; int64_t dp[100005][5][105]; int main() { string S; int D; cin >> S >> D; int N = S.size(); dp[0][0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < D; k++) { if (dp[i][j][k] == 0) { continue; } int lim = j ? 9 : S[i] - '0'; for (int d = 0; d < lim + 1; d++) { (dp[i + 1][j || (d < lim)][(d + k) % D] += dp[i][j][k]) %= mod; } } } } cout << (dp[N][0][0] + dp[N][1][0] - 1 + mod) % mod << endl; return 0; }
[ "variable_declaration.type.primitive.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
984,832
984,831
u209457657
cpp
p03178
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; ll dp[1001][101][2]; ll solve(int i, string &s, int m, int d, bool tight) { if (i == s.length()) { if (m == 0) { return 1; } return 0; } if (dp[i][m][tight] != -1) return dp[i][m][tight]; int en = (tight) ? (s[i] - '0') : 9; ll ans = 0; for (int j = 0; j <= en; j++) { int newm = (m + j) % d; ans = ans + solve(i + 1, s, newm, d, tight & (j == en)); } return dp[i][m][tight] = ans; } int main() { string k; cin >> k; memset(dp, -1, sizeof dp); int d; cin >> d; cout << (mod + -1 + solve(0, k, 0, d, true)) % mod; return 0; }
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; ll dp[10001][101][2]; ll solve(int i, string &s, int m, int d, bool tight) { if (i == s.length()) { if (m == 0) { return 1; } return 0; } if (dp[i][m][tight] != -1) return dp[i][m][tight]; int en = (tight) ? (s[i] - '0') : 9; ll ans = 0; for (int j = 0; j <= en; j++) { int newm = (m + j) % d; ans = (ans + solve(i + 1, s, newm, d, tight & (j == en))) % mod; } return dp[i][m][tight] = ans; } int main() { string k; cin >> k; memset(dp, -1, sizeof dp); int d; cin >> d; cout << (mod + -1 + solve(0, k, 0, d, true)) % mod; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "assignment.change" ]
984,838
984,837
u746113754
cpp
p03178
#include <bits/stdc++.h> #include <math.h> using namespace std; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" typedef long long ll; #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define ff first #define ld long double #define ss second #define vi vector<int> #define vll vector<ll> #define pb push_back #define pf push_front #define PI 3.1415926535897932384626 #define INF 0x3f3f3f3f #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i >= b; i--) const int mod = 1'000'000'007; int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } #define INFF 200 int main() { fastio; ll ttt = 1; // cin >> t; rep(tt, 1, ttt + 1) { ll d; string k; cin >> k >> d; // deb(k); vll dp(d), dp1(d), dp1old(d); dp[0] = 1; dp1old[0] = 1; ll now = 1; repr(i, k.size() - 1, 0) { rep(j, 0, 10) { rep(ii, 0, d) { dp1[((j * now) % d + ii) % d] += dp1old[ii]; dp1[((j * now) % d + ii) % d] %= mod; } } vll dpnew(d); rep(ii, 0, d) { ll val = k[i] - '0'; dpnew[((val * now) % d + ii) % d] += dp[ii]; dpnew[((val * now) % d + ii) % d] %= mod; } rep(j, 0, k[i] - '0') { rep(ii, 0, d) { dpnew[((j * now) % d + ii) % d] += dp1old[ii]; dpnew[((j * now) % d + ii) % d] %= mod; } } dp1old = dp1; dp = dpnew; dp1 = vector<ll>(d, 0); } cout << (dp[0] - 1 + d) % d << endl; } return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" typedef long long ll; #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define ff first #define ld long double #define ss second #define vi vector<int> #define vll vector<ll> #define pb push_back #define pf push_front #define PI 3.1415926535897932384626 #define INF 0x3f3f3f3f #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i >= b; i--) const int mod = 1'000'000'007; int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } #define INFF 200 int main() { fastio; ll ttt = 1; // cin >> t; rep(tt, 1, ttt + 1) { ll d; string k; cin >> k >> d; // deb(k); vll dp(d), dp1(d), dp1old(d); dp[0] = 1; dp1old[0] = 1; ll now = 1; repr(i, k.size() - 1, 0) { rep(j, 0, 10) { rep(ii, 0, d) { dp1[((j * now) % d + ii) % d] += dp1old[ii]; dp1[((j * now) % d + ii) % d] %= mod; } } vll dpnew(d); rep(ii, 0, d) { ll val = k[i] - '0'; dpnew[((val * now) % d + ii) % d] += dp[ii]; dpnew[((val * now) % d + ii) % d] %= mod; } rep(j, 0, k[i] - '0') { rep(ii, 0, d) { dpnew[((j * now) % d + ii) % d] += dp1old[ii]; dpnew[((j * now) % d + ii) % d] %= mod; } } dp1old = dp1; dp = dpnew; dp1 = vector<ll>(d, 0); } cout << (dp[0] - 1 + mod) % mod << endl; } return 0; }
[ "identifier.change", "io.output.change" ]
984,843
984,844
u129079689
cpp
p03178
#include <bits/stdc++.h> #define l long #define ll long long #define ld long double #define MOD 1000000007 #define MAX_N 10004 #define f first #define s second #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; const ll inf = 1e18; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll dig_dp[MAX_N][60]; l x = 0, d, y; string num; cin >> num; cin >> d; for (l i = 0; i < MAX_N; i++) { for (l j = 0; j < 10; j++) { dig_dp[i][j] = 0; } } for (l i = 0; i < MAX_N; i++) { for (l j = 0; j < d; j++) { if (i == 0) { for (l dig = 0; dig < 10; dig++) { if ((dig - j) % d == 0) dig_dp[i][j]++; } } else { for (l dig = 0; dig < 10; dig++) { x = (j - dig) % d; if (x < 0) x += d; dig_dp[i][j] = (dig_dp[i][j] + dig_dp[i - 1][x]) % MOD; } } } } x = 0; ll ans = 0; reverse(num.begin(), num.end()); for (l i = num.size() - 1; i >= 0; i--) { for (l j = 0; j < num[i] - '0'; j++) { y = (d - x - j) % d; if (y < 0) y += d; if (i > 0) ans = (ans + dig_dp[i - 1][y]) % MOD; else if (y == 0) ans = (ans + 1) % MOD; } x = (x + num[i] - '0') % d; if (x < 0) x += d; } if (x != 0) ans = (ans - 1) % MOD; if (ans < 0) ans += MOD; cout << ans << endl; }
#include <bits/stdc++.h> #define l long #define ll long long #define ld long double #define MOD 1000000007 #define MAX_N 10004 #define f first #define s second #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; const ll inf = 1e18; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll dig_dp[MAX_N][100]; l x = 0, d, y; string num; cin >> num; cin >> d; for (l i = 0; i < MAX_N; i++) { for (l j = 0; j < 100; j++) { dig_dp[i][j] = 0; } } for (l i = 0; i < MAX_N; i++) { for (l j = 0; j < d; j++) { if (i == 0) { for (l dig = 0; dig < 10; dig++) { if ((dig - j) % d == 0) dig_dp[i][j]++; } } else { for (l dig = 0; dig < 10; dig++) { x = (j - dig) % d; if (x < 0) x += d; dig_dp[i][j] = (dig_dp[i][j] + dig_dp[i - 1][x]) % MOD; } } } } x = 0; ll ans = 0; reverse(num.begin(), num.end()); for (l i = num.size() - 1; i >= 0; i--) { for (l j = 0; j < num[i] - '0'; j++) { y = (d - x - j) % d; if (y < 0) y += d; if (i > 0) ans = (ans + dig_dp[i - 1][y]) % MOD; else if (y == 0) ans = (ans + 1) % MOD; } x = (x + num[i] - '0') % d; if (x < 0) x += d; } if (x != 0) ans = (ans - 1) % MOD; if (ans < 0) ans += MOD; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
984,846
984,847
u474855599
cpp
p03178
/* ___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat. ___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat. ___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb. ___az dast o zabane ke barayad ? ___kaz ohdeye shokrash be dar ayad ! ___man be to dami gharar natvanam kard ___va ehsane to ra shomar natvanam kard #################### ___gar bar tane man zaban shavad har moyee ___yek shokre to az hezar natvanam kard */ #include <bits/stdc++.h> #define pb push_back #define SALI main #define left(x) ((x)*2) #define right(x) (((x)*2) + 1) #define fuck(x) cout << #x << " : " << x << endl; #define findLowVec(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define findUpVec(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define findLowArr(a, n, x) (lower_bound(a, a + n, x) - a) #define findUpArr(a, n, x) (upper_bound(a, a + n, x) - a) #define int long long using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &p) { return out << "(" << p.first << ", " << p.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &v) { out << "["; for (int i = 0; i < v.size(); i++) { if (i) out << ", "; out << v[i]; } return out << "]"; } template <class A, class B> ostream &operator<<(ostream &out, const set<A, B> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } template <class A> ostream &operator<<(ostream &out, const set<A> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } const int mod = 1e9 + 7; int32_t SALI() { string s; int n, d; cin >> s >> d; n = s.size(); int dp[n + 2][d]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i < n; i++) { // i raghami for (int dg = 0; dg < 10; dg++) { for (int j = 0; j < d; j++) { // k mod= j - dg dp[i][j] += dp[i - 1][((((j - dg) % d) + d) % d)]; dp[i][j] %= mod; } } } int ans = 0; int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < s[i] - '0'; j++) { // x + sum + j mod= 0 ans += dp[n - i - 1][(((-1 * (sum + j)) % d) + d) % d]; ans %= mod; } sum += s[i] - '0'; } if (d != 1) ans = (ans - 1 + mod) % mod; if (sum % d == 0) ans = (ans + 1) % mod; cout << ans << endl; } /**< WRITEN BY ALI ADELKHAH */
/* ___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat. ___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat. ___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb. ___az dast o zabane ke barayad ? ___kaz ohdeye shokrash be dar ayad ! ___man be to dami gharar natvanam kard ___va ehsane to ra shomar natvanam kard #################### ___gar bar tane man zaban shavad har moyee ___yek shokre to az hezar natvanam kard */ #include <bits/stdc++.h> #define pb push_back #define SALI main #define left(x) ((x)*2) #define right(x) (((x)*2) + 1) #define fuck(x) cout << #x << " : " << x << endl; #define findLowVec(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define findUpVec(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define findLowArr(a, n, x) (lower_bound(a, a + n, x) - a) #define findUpArr(a, n, x) (upper_bound(a, a + n, x) - a) #define int long long using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &p) { return out << "(" << p.first << ", " << p.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &v) { out << "["; for (int i = 0; i < v.size(); i++) { if (i) out << ", "; out << v[i]; } return out << "]"; } template <class A, class B> ostream &operator<<(ostream &out, const set<A, B> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } template <class A> ostream &operator<<(ostream &out, const set<A> &s) { out << "["; for (auto i = s.begin(); i != s.end(); i++) { out << ", "; out << *i; } return out << "]"; } const int mod = 1e9 + 7; int32_t SALI() { string s; int n, d; cin >> s >> d; n = s.size(); int dp[n + 2][d]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i < n; i++) { // i raghami for (int dg = 0; dg < 10; dg++) { for (int j = 0; j < d; j++) { // k mod= j - dg dp[i][j] += dp[i - 1][((((j - dg) % d) + d) % d)]; dp[i][j] %= mod; } } } int ans = 0; int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < s[i] - '0'; j++) { // x + sum + j mod= 0 ans += dp[n - i - 1][(((-1 * (sum + j)) % d) + d) % d]; ans %= mod; } sum += s[i] - '0'; } if (d != 1) ans = (ans - 1 + mod) % mod; if (sum % d == 0 && d != 1) ans = (ans + 1) % mod; cout << ans << endl; } /**< WRITEN BY ALI ADELKHAH */
[ "control_flow.branch.if.condition.change" ]
984,850
984,851
u232873057
cpp
p03178
#include <bits/stdc++.h> #define int long long #define maxn 10005 #define maxc 105 using namespace std; const int mod = 1e9 + 7; // len sum last int dp[maxn][maxc][10] = {}; string s; int n, k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> k; reverse(begin(s), end(s)); n = s.size(); s = "@" + s; for (int i = 0; i < 10; i++) { dp[1][i % k][i] = 1; } for (int len = 2; len <= n; len++) { for (int sum = 0; sum < k; sum++) { for (int last = 0; last < 10; last++) { int prev = (sum - last + 10 * k) % k; for (int i = 0; i < 10; i++) dp[len][sum][last] += dp[len - 1][prev][i]; dp[len][sum][last] %= mod; } } } int ans = 0, cnt = 0; for (int i = n; i > 0; i--) { for (int j = 0; j < (s[i] - '0'); j++) { int prev = (k - cnt + 10 * k) % k; ans += dp[i][prev][j]; } ans %= mod; cnt += s[i] - '0'; } ans = (ans - 1 + mod) % mod; if (cnt % k == 0) ans = (ans + 1) % mod; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define int long long #define maxn 10005 #define maxc 105 using namespace std; const int mod = 1e9 + 7; // len sum last int dp[maxn][maxc][10] = {}; string s; int n, k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> k; reverse(begin(s), end(s)); n = s.size(); s = "@" + s; for (int i = 0; i < 10; i++) { dp[1][i % k][i] = 1; } for (int len = 2; len <= n; len++) { for (int sum = 0; sum < k; sum++) { for (int last = 0; last < 10; last++) { int prev = (sum - last + 10 * k) % k; for (int i = 0; i < 10; i++) dp[len][sum][last] += dp[len - 1][prev][i]; dp[len][sum][last] %= mod; } } } int ans = 0, cnt = 0; for (int i = n; i > 0; i--) { for (int j = 0; j < (s[i] - '0'); j++) { int prev = (k - cnt + 10000000LL * k) % k; ans += dp[i][prev][j]; } ans %= mod; cnt += s[i] - '0'; } ans = (ans - 1 + mod) % mod; if (cnt % k == 0) ans = (ans + 1) % mod; cout << ans << '\n'; return 0; }
[ "literal.number.change", "expression.operation.binary.change", "literal.number.type.widen.change" ]
984,869
984,870
u635731706
cpp
p03178
#include <bits/stdc++.h> #define int long long #define maxn 10005 #define maxc 105 using namespace std; const int mod = 1e9 + 7; // len sum last int dp[maxn][maxc][10] = {}; string s; int n, k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> k; reverse(begin(s), end(s)); n = s.size(); s = "@" + s; for (int i = 0; i < 10; i++) { dp[1][i % k][i] = 1; } for (int len = 2; len <= n; len++) { for (int sum = 0; sum < k; sum++) { for (int last = 0; last < 10; last++) { int prev = (sum - last + k) % k; for (int i = 0; i < 10; i++) dp[len][sum][last] += dp[len - 1][prev][i]; dp[len][sum][last] %= mod; } } } int ans = 0, cnt = 0; for (int i = n; i > 0; i--) { for (int j = 0; j < (s[i] - '0'); j++) { int prev = (k - cnt + k) % k; ans += dp[i][prev][j]; } ans %= mod; cnt += s[i] - '0'; } ans = (ans - 1 + mod) % mod; if (cnt % k == 0) ans = (ans + 1) % mod; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define int long long #define maxn 10005 #define maxc 105 using namespace std; const int mod = 1e9 + 7; // len sum last int dp[maxn][maxc][10] = {}; string s; int n, k; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> k; reverse(begin(s), end(s)); n = s.size(); s = "@" + s; for (int i = 0; i < 10; i++) { dp[1][i % k][i] = 1; } for (int len = 2; len <= n; len++) { for (int sum = 0; sum < k; sum++) { for (int last = 0; last < 10; last++) { int prev = (sum - last + 10 * k) % k; for (int i = 0; i < 10; i++) dp[len][sum][last] += dp[len - 1][prev][i]; dp[len][sum][last] %= mod; } } } int ans = 0, cnt = 0; for (int i = n; i > 0; i--) { for (int j = 0; j < (s[i] - '0'); j++) { int prev = (k - cnt + 10000000LL * k) % k; ans += dp[i][prev][j]; } ans %= mod; cnt += s[i] - '0'; } ans = (ans - 1 + mod) % mod; if (cnt % k == 0) ans = (ans + 1) % mod; cout << ans << '\n'; return 0; }
[ "assignment.change" ]
984,871
984,870
u635731706
cpp