problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; const int nax = 1e5 + 10; ll d[nax]; ll maxi(int k) { ll s = 0; while (k > 0) { s = max(d[k], s); k -= k & -k; } return s; } void add(int k, ll x) { while (k <= n) { d[k] = max(d[k], x); k += k & -k; } } int main() { cin >> n; ll h[n]; ll b[n]; for (int i = 0; i < n; ++i) cin >> h[i]; for (int i = 0; i < n; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) { ll t = maxi(h[i] - 1); add(h[i], t + b[i]); } cout << maxi(n); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; const int nax = 2e5 + 10; ll d[nax]; ll maxi(int k) { ll s = 0; while (k > 0) { s = max(d[k], s); k -= k & -k; } return s; } void add(int k, ll x) { while (k <= n) { d[k] = max(d[k], x); k += k & -k; } } int main() { cin >> n; ll h[n]; ll b[n]; for (int i = 0; i < n; ++i) cin >> h[i]; for (int i = 0; i < n; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) { ll t = maxi(h[i] - 1); add(h[i], t + b[i]); } cout << maxi(n); }
replace
6
7
6
7
0
p03176
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <unordered_map> using namespace std; #define fs first #define sc second typedef long long ll; typedef pair<int, int> P; const ll mod = 1e9 + 7; ll fact[200200]; ll invfact[200200]; inline ll take_mod(ll a) { return (a % mod + mod) % mod; } inline ll add(ll a, ll b) { return take_mod(a + b); } inline ll sub(ll a, ll b) { return take_mod(a - b); } inline ll mul(ll a, ll b) { return take_mod(a * b); } inline ll pow(ll x, ll n) { ll res = 1LL; while (n > 0) { if (n & 1) res = mul(res, x); x = mul(x, x); n >>= 1; } return res; } ll mod_inv(ll x) { return pow(x, mod - 2); } // nは上限 void make_fact(ll n) { fact[0] = 1; ll res = 1; for (int i = 1; i <= n; i++) { fact[i] = res; res = mul(res, i + 1); } } // nは上限 void make_invfact(ll n) { invfact[0] = 1; invfact[n] = mod_inv(fact[n]); for (int i = n - 1; i >= 1; i--) { invfact[i] = mul(invfact[i + 1], i + 1); } } ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); } ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); } #define MAX_N 210000 template <typename T> class SegTree { public: // セグメント木を持つグローバル変数 int n; T dat[2 * MAX_N - 1]; void init(int n_, T init_num) { n = 1; while (n < n_) n *= 2; for (int i = 0; i < 2 * n - 1; i++) { dat[i] = init_num; } } // k番目の値(0-indexed)をaに変更 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]); } } // [a, b)の最小値を求める。 // kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。 // query(a, b, 0, 0, n)で外からは呼び出す。 private: T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return 0; } 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); } } // [a, b)の最小値を求める。 public: T query(int a, int b) { return query(a, b, 0, 0, this->n); } }; int main() { int N, h[210000]; ll a[210000]; cin >> N; h[0] = 0; a[0] = 0; for (int i = 1; i <= N; i++) { cin >> h[i]; } for (int i = 1; i <= N; i++) { cin >> a[i]; } SegTree<ll> seg; seg.init(N + 1, 0); ll res = 0; for (int i = 1; i <= N; i++) { ll tmp = seg.query(0, h[i]) + a[i]; seg.update(h[i], tmp); res = max(res, tmp); } cout << res << endl; return 0; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <unordered_map> using namespace std; #define fs first #define sc second typedef long long ll; typedef pair<int, int> P; const ll mod = 1e9 + 7; ll fact[200200]; ll invfact[200200]; inline ll take_mod(ll a) { return (a % mod + mod) % mod; } inline ll add(ll a, ll b) { return take_mod(a + b); } inline ll sub(ll a, ll b) { return take_mod(a - b); } inline ll mul(ll a, ll b) { return take_mod(a * b); } inline ll pow(ll x, ll n) { ll res = 1LL; while (n > 0) { if (n & 1) res = mul(res, x); x = mul(x, x); n >>= 1; } return res; } ll mod_inv(ll x) { return pow(x, mod - 2); } // nは上限 void make_fact(ll n) { fact[0] = 1; ll res = 1; for (int i = 1; i <= n; i++) { fact[i] = res; res = mul(res, i + 1); } } // nは上限 void make_invfact(ll n) { invfact[0] = 1; invfact[n] = mod_inv(fact[n]); for (int i = n - 1; i >= 1; i--) { invfact[i] = mul(invfact[i + 1], i + 1); } } ll perm(ll n, ll k) { return mul(fact[n], invfact[n - k]); } ll comb(ll n, ll k) { return mul(mul(fact[n], invfact[n - k]), invfact[k]); } #define MAX_N 410000 template <typename T> class SegTree { public: // セグメント木を持つグローバル変数 int n; T dat[2 * MAX_N - 1]; void init(int n_, T init_num) { n = 1; while (n < n_) n *= 2; for (int i = 0; i < 2 * n - 1; i++) { dat[i] = init_num; } } // k番目の値(0-indexed)をaに変更 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]); } } // [a, b)の最小値を求める。 // kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。 // query(a, b, 0, 0, n)で外からは呼び出す。 private: T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return 0; } 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); } } // [a, b)の最小値を求める。 public: T query(int a, int b) { return query(a, b, 0, 0, this->n); } }; int main() { int N, h[210000]; ll a[210000]; cin >> N; h[0] = 0; a[0] = 0; for (int i = 1; i <= N; i++) { cin >> h[i]; } for (int i = 1; i <= N; i++) { cin >> a[i]; } SegTree<ll> seg; seg.init(N + 1, 0); ll res = 0; for (int i = 1; i <= N; i++) { ll tmp = seg.query(0, h[i]) + a[i]; seg.update(h[i], tmp); res = max(res, tmp); } cout << res << endl; return 0; }
replace
66
67
66
67
0
p03176
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define F first #define S second #define show(x) cout << #x << " " << x << " "; #define f(i, j, k) for (int i = j; i <= k; i++) #define fr(i, j, k) for (int i = j; i >= k; i--) #define ll long long #define all(A) A.begin(), A.end() #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const int MSIZE = 1e5 + 5; const int MOD = 1e9 + 7; int arr[MSIZE], ht[MSIZE]; map<int, ll> m; ll dp[MSIZE]; ll solve(int &n) { dp[0] = arr[0]; m[ht[0]] = dp[0]; f(i, 1, n - 1) { dp[i] = arr[i]; auto it = m.lower_bound(ht[i]); if (it != m.begin()) dp[i] += (--it)->second; m[ht[i]] = dp[i]; it = m.upper_bound(ht[i]); while (it != m.end() && (it->second) <= dp[i]) { auto t = it; it++; m.erase(t); } } return *max_element(dp, dp + n); } int main() { FIO int n; cin >> n; f(i, 0, n - 1) cin >> ht[i]; f(i, 0, n - 1) cin >> arr[i]; cout << solve(n) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define F first #define S second #define show(x) cout << #x << " " << x << " "; #define f(i, j, k) for (int i = j; i <= k; i++) #define fr(i, j, k) for (int i = j; i >= k; i--) #define ll long long #define all(A) A.begin(), A.end() #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const int MSIZE = 2e5 + 5; const int MOD = 1e9 + 7; int arr[MSIZE], ht[MSIZE]; map<int, ll> m; ll dp[MSIZE]; ll solve(int &n) { dp[0] = arr[0]; m[ht[0]] = dp[0]; f(i, 1, n - 1) { dp[i] = arr[i]; auto it = m.lower_bound(ht[i]); if (it != m.begin()) dp[i] += (--it)->second; m[ht[i]] = dp[i]; it = m.upper_bound(ht[i]); while (it != m.end() && (it->second) <= dp[i]) { auto t = it; it++; m.erase(t); } } return *max_element(dp, dp + n); } int main() { FIO int n; cin >> n; f(i, 0, n - 1) cin >> ht[i]; f(i, 0, n - 1) cin >> arr[i]; cout << solve(n) << endl; return 0; }
replace
12
13
12
13
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(rng(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(rng(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vs = vector<string>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; typedef vector<pii> vp; typedef vector<tiii> vt; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1 << 30) - 1; const ll INFLL = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int MAX_N = 250005; // セグメント木を持つグローバル配列(n2は要素数を2のべき乗にするから) int n2, dat[2 * MAX_N - 1]; void init(int n_) { n2 = 1; while (n2 < n_) n2 *= 2; for (int i = 0; i < 2 * n2 - 1; i++) dat[i] = -INFLL; } // k番目の値(0-indexed)をaに変更 void update(int k, int a) { // 葉の節点 k += n2 - 1; dat[k] = a; // 登りながら更新 while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // 区間max: [a,b)の最大値を求める(k: // 節点の番号、l、rはその節点が[l,r)に対応づいていることを表す // query(a,b,0,0,n2)と呼ぶ int query(int a, int b, int k = 0, int l = 0, int r = n2) { if (r <= a || b <= l) return -INFLL; if (a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } /* int main () { int n; n = 6; vi a = {1,3,6,6,4,2}; n2 = n; init(n2); rep(i,n2) update(i,a[i]); showt(dat,6); show(query(0,1)); return 0; } */ signed main() { int n; cin >> n; vi h(n); rep(i, n) cin >> h[i]; vi a(n); rep(i, n) cin >> a[i]; init(n + 1); update(0, 0); rep(i, n) { int temp = query(0, h[i]); update(h[i], temp + a[i]); } // show2(n,n2); // show2(MAX_N,2*MAX_N - 1); int ans = query(0, n + 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(rng(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(rng(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vs = vector<string>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; typedef vector<pii> vp; typedef vector<tiii> vt; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1 << 30) - 1; const ll INFLL = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int MAX_N = 263005; // セグメント木を持つグローバル配列(n2は要素数を2のべき乗にするから) int n2, dat[2 * MAX_N - 1]; void init(int n_) { n2 = 1; while (n2 < n_) n2 *= 2; for (int i = 0; i < 2 * n2 - 1; i++) dat[i] = -INFLL; } // k番目の値(0-indexed)をaに変更 void update(int k, int a) { // 葉の節点 k += n2 - 1; dat[k] = a; // 登りながら更新 while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // 区間max: [a,b)の最大値を求める(k: // 節点の番号、l、rはその節点が[l,r)に対応づいていることを表す // query(a,b,0,0,n2)と呼ぶ int query(int a, int b, int k = 0, int l = 0, int r = n2) { if (r <= a || b <= l) return -INFLL; if (a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } /* int main () { int n; n = 6; vi a = {1,3,6,6,4,2}; n2 = n; init(n2); rep(i,n2) update(i,a[i]); showt(dat,6); show(query(0,1)); return 0; } */ signed main() { int n; cin >> n; vi h(n); rep(i, n) cin >> h[i]; vi a(n); rep(i, n) cin >> a[i]; init(n + 1); update(0, 0); rep(i, n) { int temp = query(0, h[i]); update(h[i], temp + a[i]); } // show2(n,n2); // show2(MAX_N,2*MAX_N - 1); int ans = query(0, n + 1); cout << ans << endl; return 0; }
replace
91
92
91
92
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(rng(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(rng(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vs = vector<string>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; typedef vector<pii> vp; typedef vector<tiii> vt; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1 << 30) - 1; const ll INFLL = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int MAX_N = 210005; // セグメント木を持つグローバル配列(n2は要素数を2のべき乗にするから) int n2, dat[2 * MAX_N - 1]; void init(int n_) { n2 = 1; while (n2 < n_) n2 *= 2; for (int i = 0; i < 2 * n2 - 1; i++) dat[i] = -INFLL; } // k番目の値(0-indexed)をaに変更 void update(int k, int a) { // 葉の節点 k += n2 - 1; dat[k] = a; // 登りながら更新 while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // 区間max: [a,b)の最大値を求める(k: // 節点の番号、l、rはその節点が[l,r)に対応づいていることを表す // query(a,b,0,0,n2)と呼ぶ int query(int a, int b, int k = 0, int l = 0, int r = n2) { if (r <= a || b <= l) return -INFLL; if (a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } /* int main () { int n; n = 6; vi a = {1,3,6,6,4,2}; n2 = n; init(n2); rep(i,n2) update(i,a[i]); showt(dat,6); show(query(0,1)); return 0; } */ signed main() { int n; cin >> n; vi h(n); rep(i, n) cin >> h[i]; vi a(n); rep(i, n) cin >> a[i]; init(n + 1); update(0, 0); rep(i, n) { int temp = query(0, h[i]); update(h[i], temp + a[i]); } // show2(n,n2); // show2(MAX_N,2*MAX_N - 1); int ans = query(0, n + 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(x) (x).begin(), (x).end() #define rrng(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(rng(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(rng(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vs = vector<string>; using pii = pair<int, int>; using tiii = tuple<int, int, int>; typedef vector<pii> vp; typedef vector<tiii> vt; const int mod = 1000000007; const double EPS = 1e-9; const int INF = (1 << 30) - 1; const ll INFLL = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int MAX_N = 300005; // セグメント木を持つグローバル配列(n2は要素数を2のべき乗にするから) int n2, dat[2 * MAX_N - 1]; void init(int n_) { n2 = 1; while (n2 < n_) n2 *= 2; for (int i = 0; i < 2 * n2 - 1; i++) dat[i] = -INFLL; } // k番目の値(0-indexed)をaに変更 void update(int k, int a) { // 葉の節点 k += n2 - 1; dat[k] = a; // 登りながら更新 while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // 区間max: [a,b)の最大値を求める(k: // 節点の番号、l、rはその節点が[l,r)に対応づいていることを表す // query(a,b,0,0,n2)と呼ぶ int query(int a, int b, int k = 0, int l = 0, int r = n2) { if (r <= a || b <= l) return -INFLL; if (a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } /* int main () { int n; n = 6; vi a = {1,3,6,6,4,2}; n2 = n; init(n2); rep(i,n2) update(i,a[i]); showt(dat,6); show(query(0,1)); return 0; } */ signed main() { int n; cin >> n; vi h(n); rep(i, n) cin >> h[i]; vi a(n); rep(i, n) cin >> a[i]; init(n + 1); update(0, 0); rep(i, n) { int temp = query(0, h[i]); update(h[i], temp + a[i]); } // show2(n,n2); // show2(MAX_N,2*MAX_N - 1); int ans = query(0, n + 1); cout << ans << endl; return 0; }
replace
91
92
91
92
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sz(a) a.size() #define all(a) a.begin(), a.end() #define F first #define S second #define pb push_back #define eb emplace_back #define ll long long #define vi vector<int> #define pi pair<int, int> #define mp make_pair string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char ch) { return string("'") + ch + string("'"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <class InputIterator> string to_string(InputIterator first, InputIterator last) { bool start = true; string res = "{"; while (first != last) { if (!start) { res += ", "; } start = false; res += to_string(*first); ++first; } res += "}"; return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } template <typename A, typename B> istream &operator>>(istream &input, pair<A, B> &x) { input >> x.F >> x.S; return input; } template <typename A> istream &operator>>(istream &input, vector<A> &x) { for (auto &i : x) input >> i; return input; } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define int ll const int mod = 1e9 + 7; int mul(int a, int b) { return ((a)*1ll * (b)) % mod; } void add(int &a, int b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } int powz(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); b /= 2; a = mul(a, a); } return res; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 200005; int t[N]; int n; int sum(int v, int tl, int tr, int l, int r) { if (l > r) return 0; if (l == tl && r == tr) { return t[v]; } int tm = (tl + tr) / 2; return max(sum(v * 2, tl, tm, l, min(r, tm)), sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)); } void update(int v, int tl, int tr, int pos, int new_val) { if (tl == tr) { if (t[v] < new_val) t[v] = new_val; } else { int tm = (tl + tr) / 2; if (pos <= tm) update(v * 2, tl, tm, pos, new_val); else update(v * 2 + 1, tm + 1, tr, pos, new_val); t[v] = max(t[v * 2], t[v * 2 + 1]); } } void solve() { cin >> n; vi a(n); cin >> a; vi b(n); cin >> b; ll ans = 0; for (int i = 0; i < n; i++) { ll sm = sum(1, 1, n, 1, a[i] - 1); ans = max(ans, sm + b[i]); update(1, 1, n, a[i], sm + b[i]); } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc = 1; // cin>>tc; for (int i = 0; i < tc; i++) { // cout<<"Case #"<<i+1<<": "; solve(); } } /* Intuition > Logic * If you are not confident please dont submit * When you feel like Quitting: Remember why you started * Game Theory == Skip * If n== 1e18 apply binary or Matrix expo * I see those tears in your eyes I feel so helpless inside Oh love, there's no need to hide Just let me love you when your heart is tired Cold hands, red eyes Packed your bags at midnight They've been there for weeks You don't know what goodbye means Just roll up a cigarette Just forget about this mess Waiting on the sidelines From the sidelines */
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sz(a) a.size() #define all(a) a.begin(), a.end() #define F first #define S second #define pb push_back #define eb emplace_back #define ll long long #define vi vector<int> #define pi pair<int, int> #define mp make_pair string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char ch) { return string("'") + ch + string("'"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <class InputIterator> string to_string(InputIterator first, InputIterator last) { bool start = true; string res = "{"; while (first != last) { if (!start) { res += ", "; } start = false; res += to_string(*first); ++first; } res += "}"; return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } template <typename A, typename B> istream &operator>>(istream &input, pair<A, B> &x) { input >> x.F >> x.S; return input; } template <typename A> istream &operator>>(istream &input, vector<A> &x) { for (auto &i : x) input >> i; return input; } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define int ll const int mod = 1e9 + 7; int mul(int a, int b) { return ((a)*1ll * (b)) % mod; } void add(int &a, int b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } int powz(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); b /= 2; a = mul(a, a); } return res; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 200005; int t[4 * N]; int n; int sum(int v, int tl, int tr, int l, int r) { if (l > r) return 0; if (l == tl && r == tr) { return t[v]; } int tm = (tl + tr) / 2; return max(sum(v * 2, tl, tm, l, min(r, tm)), sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)); } void update(int v, int tl, int tr, int pos, int new_val) { if (tl == tr) { if (t[v] < new_val) t[v] = new_val; } else { int tm = (tl + tr) / 2; if (pos <= tm) update(v * 2, tl, tm, pos, new_val); else update(v * 2 + 1, tm + 1, tr, pos, new_val); t[v] = max(t[v * 2], t[v * 2 + 1]); } } void solve() { cin >> n; vi a(n); cin >> a; vi b(n); cin >> b; ll ans = 0; for (int i = 0; i < n; i++) { ll sm = sum(1, 1, n, 1, a[i] - 1); ans = max(ans, sm + b[i]); update(1, 1, n, a[i], sm + b[i]); } cout << ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc = 1; // cin>>tc; for (int i = 0; i < tc; i++) { // cout<<"Case #"<<i+1<<": "; solve(); } } /* Intuition > Logic * If you are not confident please dont submit * When you feel like Quitting: Remember why you started * Game Theory == Skip * If n== 1e18 apply binary or Matrix expo * I see those tears in your eyes I feel so helpless inside Oh love, there's no need to hide Just let me love you when your heart is tired Cold hands, red eyes Packed your bags at midnight They've been there for weeks You don't know what goodbye means Just roll up a cigarette Just forget about this mess Waiting on the sidelines From the sidelines */
replace
114
115
114
115
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < b; i++) typedef long long ll; const int MAX_N = 2e5 + 1010; const int def = 0; // セグメント木を持つグローバル配列 ll n, dat[2 * MAX_N - 1]; // 初期化 void init(ll n_) { // 簡単のため、要素数を2のべき乗に n = 1; while (n < n_) n *= 2; // 全ての値をINT_MAXに for (int i = 0; i < 2 * n - 1; i++) dat[i] = def; } // k番目の値(0-indexed)をaに変更 void update(ll k, ll 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]); } } // [a,b)の最小値を求める // 後ろの方の引数は、計算の簡単のための引数 // kは節点の番号、1,rはその接点が[1,r)に対応づいていることを表す // したがって、外からはquery(a, b, 0, 0, n)として呼ぶ ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = n) { //[a,b)と[l,r)が交差しなければ、INT_MAX if (r <= a || b <= l) return def; //[a,b)が[l,r)を完全に含んでいれば、この節点の値 if (a <= l && r <= b) return dat[k]; else { // そうでなければ、2つの子が必要 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); } } int main() { ll N; cin >> N; vector<ll> h(N), a(N); rep(i, 0, N) cin >> h[i]; rep(i, 0, N) cin >> a[i]; init(N); rep(i, 0, N) { update(h[i] - 1, query(0, h[i] - 1) + a[i]); } cout << query(0, N) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < b; i++) typedef long long ll; const int MAX_N = 1 << 18; const int def = 0; // セグメント木を持つグローバル配列 ll n, dat[2 * MAX_N - 1]; // 初期化 void init(ll n_) { // 簡単のため、要素数を2のべき乗に n = 1; while (n < n_) n *= 2; // 全ての値をINT_MAXに for (int i = 0; i < 2 * n - 1; i++) dat[i] = def; } // k番目の値(0-indexed)をaに変更 void update(ll k, ll 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]); } } // [a,b)の最小値を求める // 後ろの方の引数は、計算の簡単のための引数 // kは節点の番号、1,rはその接点が[1,r)に対応づいていることを表す // したがって、外からはquery(a, b, 0, 0, n)として呼ぶ ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = n) { //[a,b)と[l,r)が交差しなければ、INT_MAX if (r <= a || b <= l) return def; //[a,b)が[l,r)を完全に含んでいれば、この節点の値 if (a <= l && r <= b) return dat[k]; else { // そうでなければ、2つの子が必要 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); } } int main() { ll N; cin >> N; vector<ll> h(N), a(N); rep(i, 0, N) cin >> h[i]; rep(i, 0, N) cin >> a[i]; init(N); rep(i, 0, N) { update(h[i] - 1, query(0, h[i] - 1) + a[i]); } cout << query(0, N) << endl; }
replace
5
6
5
6
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-ffloat-store") // to restrict undesirable precision #pragma GCC optimize( \ "-fno-defer-pop") // to pop argument of function as soon as it returns #define all(a) a.begin(), a.end() #define ll long long int #define ld long double ll power(ll a, ll b, ll m) { if (b == 0) return 1; if (b == 1) return a % m; ll t = power(a, b / 2, m) % m; t = (t * t) % m; if (b & 1) t = ((t % m) * (a % m)) % m; return t; } ll modInverse(ll a, ll m) { return power(a, m - 2, m); } #define ps push_back #define fs first #define sc second #define takeline cin.ignore(); #define iactive cout.flush(); #define N 100005 #define endl "\n" #define mod 1000000007 #define PI 3.141592653589793 //((1.0l)*BIG MULTIPLY MAGIC?) // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); //----------------------------------------------- ll n, ar[N + 1], st[4 * N + 1], ht[N + 1], dp[N + 1]; ll query(ll node, ll nl, ll nr, ll ql, ll qr) { if (ql > nr || nl > qr) return 0; if (nl >= ql && nr <= qr) return st[node]; ll a, b; a = query(2 * node, nl, (nl + nr) / 2, ql, qr); b = query(2 * node + 1, (nl + nr) / 2 + 1, nr, ql, qr); return max(a, b); } void update(ll node, ll nl, ll nr, ll idx, ll val) { if (idx < nl || idx > nr) return; if (nl == idx && nl == nr) { st[node] = st[node] + val; return; } update(2 * node, nl, (nl + nr) / 2, idx, val); update(2 * node + 1, (nl + nr) / 2 + 1, nr, idx, val); st[node] = max(st[2 * node], st[2 * node + 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll i, j, k, l; cin >> n; for (i = 1; i <= n; i++) { cin >> ht[i]; } for (i = 1; i <= n; i++) { cin >> ar[i]; } dp[1] = ar[1]; update(1, 1, N, ht[1], ar[1]); for (i = 2; i <= n; i++) { ll mx = query(1, 1, N, 0, ht[i] - 1); dp[i] = mx + ar[i]; update(1, 1, N, ht[i], dp[i]); } ll an = 0; for (i = 1; i <= n; i++) { an = max(an, dp[i]); } cout << an << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-ffloat-store") // to restrict undesirable precision #pragma GCC optimize( \ "-fno-defer-pop") // to pop argument of function as soon as it returns #define all(a) a.begin(), a.end() #define ll long long int #define ld long double ll power(ll a, ll b, ll m) { if (b == 0) return 1; if (b == 1) return a % m; ll t = power(a, b / 2, m) % m; t = (t * t) % m; if (b & 1) t = ((t % m) * (a % m)) % m; return t; } ll modInverse(ll a, ll m) { return power(a, m - 2, m); } #define ps push_back #define fs first #define sc second #define takeline cin.ignore(); #define iactive cout.flush(); #define N 200005 #define endl "\n" #define mod 1000000007 #define PI 3.141592653589793 //((1.0l)*BIG MULTIPLY MAGIC?) // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); //----------------------------------------------- ll n, ar[N + 1], st[4 * N + 1], ht[N + 1], dp[N + 1]; ll query(ll node, ll nl, ll nr, ll ql, ll qr) { if (ql > nr || nl > qr) return 0; if (nl >= ql && nr <= qr) return st[node]; ll a, b; a = query(2 * node, nl, (nl + nr) / 2, ql, qr); b = query(2 * node + 1, (nl + nr) / 2 + 1, nr, ql, qr); return max(a, b); } void update(ll node, ll nl, ll nr, ll idx, ll val) { if (idx < nl || idx > nr) return; if (nl == idx && nl == nr) { st[node] = st[node] + val; return; } update(2 * node, nl, (nl + nr) / 2, idx, val); update(2 * node + 1, (nl + nr) / 2 + 1, nr, idx, val); st[node] = max(st[2 * node], st[2 * node + 1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll i, j, k, l; cin >> n; for (i = 1; i <= n; i++) { cin >> ht[i]; } for (i = 1; i <= n; i++) { cin >> ar[i]; } dp[1] = ar[1]; update(1, 1, N, ht[1], ar[1]); for (i = 2; i <= n; i++) { ll mx = query(1, 1, N, 0, ht[i] - 1); dp[i] = mx + ar[i]; update(1, 1, N, ht[i], dp[i]); } ll an = 0; for (i = 1; i <= n; i++) { an = max(an, dp[i]); } cout << an << endl; return 0; }
replace
27
28
27
28
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) { for (ll i = 0; i < v.size(); ++i) x << v[i] << " "; return x; } template <typename X> ostream &operator<<(ostream &x, const set<X> &v) { for (auto it : v) x << it << " "; return x; } template <typename X, typename Y> ostream &operator<<(ostream &x, const pair<X, Y> &v) { x << v.ff << " " << v.ss; return x; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; } struct pair_hash { inline std::size_t operator()(const std::pair<ll, ll> &v) const { return v.first * 31 + v.second; } }; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define speed \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define pb push_back #define fr first #define sc second #define prnt(m) \ for (auto it = m.begin(); it != m.end(); ++it) { \ cout << *it << endl; \ } #define tra(it, m) for (auto it = m.begin(); it != m.end(); ++it) #define DBG(x) cout << "# # # " << x << '\n'; #define fri(i, s, n) for (long long i = s; i < n; i++) #define mod 1000000007LL #define mod2 998244353 #define vct2 vector<vector<ll>> #define vct vector<ll> #define pll pair<ll, ll> #define rz(n) resize(n) #define all(v) v.begin(), v.end() #define mkp make_pair #define arrin(a, n) \ for (ll i = 0; i < n; i++) { \ cin >> a[i]; \ } #define arrout(a, n) \ for (ll i = 0; i < n; i++) { \ cout << a[i] << " "; \ } #define ex(s) cout << s << endl, exit(0); #define infy 2e18 #define five 100005; #define six 1000005; #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; //___________________________________________________________________________________________________________________________________________________________ const int N = five; ll seg[4 * N]; void update(int ind, int rl, int rr, int idx, ll val) { if (rl == rr) { seg[ind] = val; return; } int mid = (rl + rr) / 2; if (idx <= mid && idx >= rl) { update(2 * ind, rl, mid, idx, val); } else { update(2 * ind + 1, mid + 1, rr, idx, val); } seg[ind] = max(seg[2 * ind], seg[2 * ind + 1]); } ll q(int ind, int rl, int rr, int ql, int qr) { if (ql > rr || rl > qr) { return 0; } if (rl >= ql && rr <= qr) { return seg[ind]; } int mid = (rl + rr) / 2; return max(q(2 * ind, rl, mid, ql, qr), q(2 * ind + 1, mid + 1, rr, ql, qr)); } int main() { memset(seg, 0, sizeof seg); int n; cin >> n; ll h[n]; ll a[n]; arrin(h, n); arrin(a, n); fri(i, 0, n) { h[i]--; } ll ans[n]; ll maxi = 0; fri(i, 0, n) { ll qq = q(1, 0, n - 1, 0, h[i]); ans[i] = qq + a[i]; update(1, 0, n - 1, h[i], ans[i]); maxi = max(maxi, ans[i]); } cout << maxi << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) { for (ll i = 0; i < v.size(); ++i) x << v[i] << " "; return x; } template <typename X> ostream &operator<<(ostream &x, const set<X> &v) { for (auto it : v) x << it << " "; return x; } template <typename X, typename Y> ostream &operator<<(ostream &x, const pair<X, Y> &v) { x << v.ff << " " << v.ss; return x; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; } struct pair_hash { inline std::size_t operator()(const std::pair<ll, ll> &v) const { return v.first * 31 + v.second; } }; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define speed \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define pb push_back #define fr first #define sc second #define prnt(m) \ for (auto it = m.begin(); it != m.end(); ++it) { \ cout << *it << endl; \ } #define tra(it, m) for (auto it = m.begin(); it != m.end(); ++it) #define DBG(x) cout << "# # # " << x << '\n'; #define fri(i, s, n) for (long long i = s; i < n; i++) #define mod 1000000007LL #define mod2 998244353 #define vct2 vector<vector<ll>> #define vct vector<ll> #define pll pair<ll, ll> #define rz(n) resize(n) #define all(v) v.begin(), v.end() #define mkp make_pair #define arrin(a, n) \ for (ll i = 0; i < n; i++) { \ cin >> a[i]; \ } #define arrout(a, n) \ for (ll i = 0; i < n; i++) { \ cout << a[i] << " "; \ } #define ex(s) cout << s << endl, exit(0); #define infy 2e18 #define five 100005; #define six 1000005; #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; //___________________________________________________________________________________________________________________________________________________________ const int N = five; ll seg[6 * N]; void update(int ind, int rl, int rr, int idx, ll val) { if (rl == rr) { seg[ind] = val; return; } int mid = (rl + rr) / 2; if (idx <= mid && idx >= rl) { update(2 * ind, rl, mid, idx, val); } else { update(2 * ind + 1, mid + 1, rr, idx, val); } seg[ind] = max(seg[2 * ind], seg[2 * ind + 1]); } ll q(int ind, int rl, int rr, int ql, int qr) { if (ql > rr || rl > qr) { return 0; } if (rl >= ql && rr <= qr) { return seg[ind]; } int mid = (rl + rr) / 2; return max(q(2 * ind, rl, mid, ql, qr), q(2 * ind + 1, mid + 1, rr, ql, qr)); } int main() { memset(seg, 0, sizeof seg); int n; cin >> n; ll h[n]; ll a[n]; arrin(h, n); arrin(a, n); fri(i, 0, n) { h[i]--; } ll ans[n]; ll maxi = 0; fri(i, 0, n) { ll qq = q(1, 0, n - 1, 0, h[i]); ans[i] = qq + a[i]; update(1, 0, n - 1, h[i], ans[i]); maxi = max(maxi, ans[i]); } cout << maxi << endl; }
replace
71
72
71
72
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define PB emplace_back #define mid ((be + en) / 2) #define cl c * 2 #define cr cl + 1 using namespace std; const int N = 1e5 + 100; long long int mx[N], dp[N], h[N], a[N], n; long long int que(int l, int r, int be = 0, int en = n, int c = 1) { if (r <= be || en <= l) return 0; if (l <= be && en <= r) return mx[c]; return max(que(l, r, be, mid, cl), que(l, r, mid, en, cr)); } long long int up(int l, long long int val, int be = 0, int en = n, int c = 1) { if (be + 1 == en) mx[c] = val; else if (l < mid) up(l, val, be, mid, cl); else up(l, val, mid, en, cr); if (be + 1 != en) mx[c] = max(mx[cl], mx[cr]); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { long long int xm = que(0, h[i]); up(h[i], xm + a[i]); } cout << que(0, *max_element(a, a + n) + 1); }
#include <bits/stdc++.h> #define PB emplace_back #define mid ((be + en) / 2) #define cl c * 2 #define cr cl + 1 using namespace std; const int N = (1e5 + 100) * 16; long long int mx[N], dp[N], h[N], a[N], n; long long int que(int l, int r, int be = 0, int en = n, int c = 1) { if (r <= be || en <= l) return 0; if (l <= be && en <= r) return mx[c]; return max(que(l, r, be, mid, cl), que(l, r, mid, en, cr)); } long long int up(int l, long long int val, int be = 0, int en = n, int c = 1) { if (be + 1 == en) mx[c] = val; else if (l < mid) up(l, val, be, mid, cl); else up(l, val, mid, en, cr); if (be + 1 != en) mx[c] = max(mx[cl], mx[cr]); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { long long int xm = que(0, h[i]); up(h[i], xm + a[i]); } cout << que(0, *max_element(a, a + n) + 1); }
replace
9
10
9
10
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define M 1000000007 #define mod 998244353 #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define pi pair<ll, ll> using namespace std; const ll N = 100010; ll h[N], a[N]; ll sgt[4 * N]; void build(ll st, ll en, ll pos) { if (st == en) { sgt[pos] = 0; return; } ll mid = (st + en) / 2; build(st, mid, 2 * pos + 1); build(mid + 1, en, 2 * pos + 2); sgt[pos] = max(sgt[2 * pos + 1], sgt[2 * pos + 2]); } void update(ll st, ll en, ll pos, ll idx, ll val) { if (st == en) { sgt[pos] = val; return; } ll mid = (st + en) / 2; if (idx >= st && idx <= mid) { update(st, mid, 2 * pos + 1, idx, val); } else { update(mid + 1, en, 2 * pos + 2, idx, val); } sgt[pos] = max(sgt[2 * pos + 1], sgt[2 * pos + 2]); } ll query(ll st, ll en, ll pos, ll l, ll r) { if (st > r || en < l) { return 0; } if (st >= l && en <= r) { return sgt[pos]; } ll mid = (st + en) / 2; return max(query(st, mid, 2 * pos + 1, l, r), query(mid + 1, en, 2 * pos + 2, l, r)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; for (ll i = 0; i < n; ++i) { cin >> h[i]; --h[i]; } for (ll i = 0; i < n; ++i) { cin >> a[i]; } build(0, n - 1, 0); ll dp[n]; dp[0] = a[0]; update(0, n - 1, 0, h[0], a[0]); for (ll i = 1; i < n; ++i) { ll lol = 0; if (h[i] != 0) { lol = query(0, n - 1, 0, 0, h[i] - 1); } dp[i] = lol + a[i]; update(0, n - 1, 0, h[i], dp[i]); } ll ans = *max_element(dp, dp + n); cout << ans << endl; return (0); }
#include <bits/stdc++.h> #define ll long long int #define M 1000000007 #define mod 998244353 #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define pi pair<ll, ll> using namespace std; const ll N = 200010; ll h[N], a[N]; ll sgt[4 * N]; void build(ll st, ll en, ll pos) { if (st == en) { sgt[pos] = 0; return; } ll mid = (st + en) / 2; build(st, mid, 2 * pos + 1); build(mid + 1, en, 2 * pos + 2); sgt[pos] = max(sgt[2 * pos + 1], sgt[2 * pos + 2]); } void update(ll st, ll en, ll pos, ll idx, ll val) { if (st == en) { sgt[pos] = val; return; } ll mid = (st + en) / 2; if (idx >= st && idx <= mid) { update(st, mid, 2 * pos + 1, idx, val); } else { update(mid + 1, en, 2 * pos + 2, idx, val); } sgt[pos] = max(sgt[2 * pos + 1], sgt[2 * pos + 2]); } ll query(ll st, ll en, ll pos, ll l, ll r) { if (st > r || en < l) { return 0; } if (st >= l && en <= r) { return sgt[pos]; } ll mid = (st + en) / 2; return max(query(st, mid, 2 * pos + 1, l, r), query(mid + 1, en, 2 * pos + 2, l, r)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; for (ll i = 0; i < n; ++i) { cin >> h[i]; --h[i]; } for (ll i = 0; i < n; ++i) { cin >> a[i]; } build(0, n - 1, 0); ll dp[n]; dp[0] = a[0]; update(0, n - 1, 0, h[0], a[0]); for (ll i = 1; i < n; ++i) { ll lol = 0; if (h[i] != 0) { lol = query(0, n - 1, 0, 0, h[i] - 1); } dp[i] = lol + a[i]; update(0, n - 1, 0, h[i], dp[i]); } ll ans = *max_element(dp, dp + n); cout << ans << endl; return (0); }
replace
8
9
8
9
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<ll, ll> #define sorted(a_1) sort(a_1.begin(), a_1.end()) #define rsorted(a_1) sort(a_1.rbegin(), a_1.rend()) #define t1(a_1) cout << a_1 << endl; #define t2(a_1) \ for (auto it_test : a_1) \ cout << it_test << " "; ll bittree[6]; void update(ll index, ll n, ll val) { for (ll i = index; i <= n;) { bittree[i] = max(bittree[i], val); i += i & (-i); } } ll get(ll u, ll n) { ll index = u; ll sum = 0; for (ll i = index; i > 0;) { sum = max(bittree[i], sum); i -= i & (-i); } return sum; } void solve() { ll n; cin >> n; vector<ll> height(n), val(n); vector<pair<ll, ll>> pair; for (ll i = 0; i < n; i++) { cin >> height[i]; pair.pb({height[i], i}); } for (auto &i : val) cin >> i; sorted(pair); memset(bittree, 0, sizeof(bittree)); ll ans = 0; for (ll i = 0; i < n; i++) { ll res = val[pair[i].second] + get(pair[i].second + 1, n); ans = max(ans, res); update(pair[i].second + 1, n, res); } ans = max(ans, get(n, n)); // t2(bittree) // t1(endl) t1(ans); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<ll, ll> #define sorted(a_1) sort(a_1.begin(), a_1.end()) #define rsorted(a_1) sort(a_1.rbegin(), a_1.rend()) #define t1(a_1) cout << a_1 << endl; #define t2(a_1) \ for (auto it_test : a_1) \ cout << it_test << " "; ll bittree[1000001]; void update(ll index, ll n, ll val) { for (ll i = index; i <= n;) { bittree[i] = max(bittree[i], val); i += i & (-i); } } ll get(ll u, ll n) { ll index = u; ll sum = 0; for (ll i = index; i > 0;) { sum = max(bittree[i], sum); i -= i & (-i); } return sum; } void solve() { ll n; cin >> n; vector<ll> height(n), val(n); vector<pair<ll, ll>> pair; for (ll i = 0; i < n; i++) { cin >> height[i]; pair.pb({height[i], i}); } for (auto &i : val) cin >> i; sorted(pair); memset(bittree, 0, sizeof(bittree)); ll ans = 0; for (ll i = 0; i < n; i++) { ll res = val[pair[i].second] + get(pair[i].second + 1, n); ans = max(ans, res); update(pair[i].second + 1, n, res); } ans = max(ans, get(n, n)); // t2(bittree) // t1(endl) t1(ans); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
12
13
12
13
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 100001; int d[N], n; struct BIT { long long f[N]; void update(int pos, long long x) { for (; pos <= n; pos += pos & -pos) f[pos] = max(f[pos], x); } long long get(int pos) { if (!pos) return 0; long long res = -1; for (; pos; pos -= pos & -pos) res = max(res, f[pos]); return res; } } bit; int h[N], a[N], s[N]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; } for (int i = 1; i <= n; i++) cin >> a[i]; long long res = -1, cur; for (int i = 1; i <= n; i++) { cur = bit.get(h[i] - 1); cur += a[i]; res = max(res, cur); bit.update(h[i], cur); } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 400001; int d[N], n; struct BIT { long long f[N]; void update(int pos, long long x) { for (; pos <= n; pos += pos & -pos) f[pos] = max(f[pos], x); } long long get(int pos) { if (!pos) return 0; long long res = -1; for (; pos; pos -= pos & -pos) res = max(res, f[pos]); return res; } } bit; int h[N], a[N], s[N]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; } for (int i = 1; i <= n; i++) cin >> a[i]; long long res = -1, cur; for (int i = 1; i <= n; i++) { cur = bit.get(h[i] - 1); cur += a[i]; res = max(res, cur); bit.update(h[i], cur); } cout << res; return 0; }
replace
4
5
4
5
0
p03176
C++
Runtime Error
// // ROIGold.cpp // Main calisma // // Created by Rakhman on 05/02/2019. // Copyright © 2019 Rakhman. All rights reserved. // #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer return cout << "NO", 0; #define FOR(i, start, finish, k) for (int i = start; i <= finish; i += k) const int MXN = 1e5 + 200; const long long MNN = 3e3 + 200; const long long MOD = 1e9 + 7; const long long INF = 1e13; const int OO = 1e9 + 500; typedef long long llong; typedef unsigned long long ullong; using namespace std; llong n, k, h[MXN], a[MXN], dp[MXN], ans; llong t[MXN * 4]; llong get(int v, int tl, int tr, int L, int R) { if (L <= tl && tr <= R) { return t[v]; } if (L > tr || tl > R) { return 0; } int tm = (tl + tr) / 2; return max(get(v * 2, tl, tm, L, R), get(v * 2 + 1, tm + 1, tr, L, R)); } void upd(llong v, llong tl, llong tr, llong ind, llong x) { if (tl == tr) { t[v] = x; return; } int tm = (tl + tr) / 2; if (ind <= tm) { upd(v * 2, tl, tm, ind, x); } else { upd(v * 2 + 1, tm + 1, tr, ind, x); } t[v] = max(t[v * 2], t[v * 2 + 1]); } int main() { ios; cin >> 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++) { dp[i] = get(1, 1, n, 1, h[i] - 1) + a[i]; ans = max(dp[i], ans); upd(1, 1, n, h[i], dp[i]); } cout << ans; }
// // ROIGold.cpp // Main calisma // // Created by Rakhman on 05/02/2019. // Copyright © 2019 Rakhman. All rights reserved. // #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer return cout << "NO", 0; #define FOR(i, start, finish, k) for (int i = start; i <= finish; i += k) const int MXN = 2e5 + 200; const long long MNN = 3e3 + 200; const long long MOD = 1e9 + 7; const long long INF = 1e13; const int OO = 1e9 + 500; typedef long long llong; typedef unsigned long long ullong; using namespace std; llong n, k, h[MXN], a[MXN], dp[MXN], ans; llong t[MXN * 4]; llong get(int v, int tl, int tr, int L, int R) { if (L <= tl && tr <= R) { return t[v]; } if (L > tr || tl > R) { return 0; } int tm = (tl + tr) / 2; return max(get(v * 2, tl, tm, L, R), get(v * 2 + 1, tm + 1, tr, L, R)); } void upd(llong v, llong tl, llong tr, llong ind, llong x) { if (tl == tr) { t[v] = x; return; } int tm = (tl + tr) / 2; if (ind <= tm) { upd(v * 2, tl, tm, ind, x); } else { upd(v * 2 + 1, tm + 1, tr, ind, x); } t[v] = max(t[v * 2], t[v * 2 + 1]); } int main() { ios; cin >> 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++) { dp[i] = get(1, 1, n, 1, h[i] - 1) + a[i]; ans = max(dp[i], ans); upd(1, 1, n, h[i], dp[i]); } cout << ans; }
replace
42
43
42
43
0
p03176
C++
Time Limit Exceeded
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> #define ll long long #define MAX 25 * 1e13 #define N 200010 using namespace std; int MOD = 1000000007; vector<ll> bitree(N); int n; int lowbit(int t) { return t & (-t); } ll query(int h) { ll ret = 0; for (int i = h; i; i -= lowbit(i)) { ret = max(ret, bitree[i]); } return ret; } void update(int h, ll v) { for (int i = h; i <= n; i++) { bitree[i] = max(bitree[i], v); } } int main() { cin >> n; ll ret = 0; vector<int> h(n + 1); vector<int> val(n + 1); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { cin >> val[i]; } for (int i = 0; i < n; i++) { ll m = query(h[i]); ret = max(m + val[i], ret); update(h[i], m + val[i]); } cout << ret << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> #define ll long long #define MAX 25 * 1e13 #define N 200010 using namespace std; int MOD = 1000000007; vector<ll> bitree(N); int n; int lowbit(int t) { return t & (-t); } ll query(int h) { ll ret = 0; for (int i = h; i; i -= lowbit(i)) { ret = max(ret, bitree[i]); } return ret; } void update(int h, ll v) { for (int i = h; i <= n; i += lowbit(i)) { bitree[i] = max(bitree[i], v); } } int main() { cin >> n; ll ret = 0; vector<int> h(n + 1); vector<int> val(n + 1); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { cin >> val[i]; } for (int i = 0; i < n; i++) { ll m = query(h[i]); ret = max(m + val[i], ret); update(h[i], m + val[i]); } cout << ret << endl; return 0; }
replace
27
28
27
28
TLE
p03176
C++
Runtime Error
// In the name of Allah #include <bits/stdc++.h> using namespace std; #define MAX 200011 #define mod 1000000007 #define inf 1000000000000000 #define ll long long #define endl '\n' ll dp[2 * MAX]; int h[MAX], w[MAX]; void update(int node, int l, int r, int i, ll v) { if (l == r) { dp[node] = v; } else { int mid = (l + r) >> 1; if (i <= mid) update(2 * node + 1, l, mid, i, v); else update(2 * node + 2, mid + 1, r, i, v); dp[node] = max(dp[2 * node + 1], dp[2 * node + 2]); } } ll get(int node, int l, int r, int x, int y) { if (x <= l && r <= y) { return dp[node]; } int mid = (l + r) >> 1; ll ans = 0; if (x <= mid) ans = max(ans, get(2 * node + 1, l, mid, x, y)); if (y >= mid + 1) ans = max(ans, get(2 * node + 2, mid + 1, r, x, y)); return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> w[i]; update(0, 1, n, h[0], w[0]); for (int i = 1; i < n; i++) update(0, 1, n, h[i], get(0, 1, n, 1, h[i]) + w[i]); cout << dp[0]; return 0; }
// In the name of Allah #include <bits/stdc++.h> using namespace std; #define MAX 200011 #define mod 1000000007 #define inf 1000000000000000 #define ll long long #define endl '\n' ll dp[4 * MAX]; int h[MAX], w[MAX]; void update(int node, int l, int r, int i, ll v) { if (l == r) { dp[node] = v; } else { int mid = (l + r) >> 1; if (i <= mid) update(2 * node + 1, l, mid, i, v); else update(2 * node + 2, mid + 1, r, i, v); dp[node] = max(dp[2 * node + 1], dp[2 * node + 2]); } } ll get(int node, int l, int r, int x, int y) { if (x <= l && r <= y) { return dp[node]; } int mid = (l + r) >> 1; ll ans = 0; if (x <= mid) ans = max(ans, get(2 * node + 1, l, mid, x, y)); if (y >= mid + 1) ans = max(ans, get(2 * node + 2, mid + 1, r, x, y)); return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> w[i]; update(0, 1, n, h[0], w[0]); for (int i = 1; i < n; i++) update(0, 1, n, h[i], get(0, 1, n, 1, h[i]) + w[i]); cout << dp[0]; return 0; }
replace
8
9
8
9
0
p03176
C++
Runtime Error
#include <stdio.h> #include <vector> using namespace std; const int Cv = 1 << 17, C = 100001; typedef long long ll; int n, a[C]; ll val[2 * Cv], x, v, am; void insert(int a, ll w) { for (a += Cv; a > 0; a /= 2) val[a] = max(val[a], w); } ll query(int l) { ll ww = 0; for (l += Cv; l > 1; l /= 2) if (l % 2 == 1) ww = max(ww, val[l - 1]); return ww; } int main() { int i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) { scanf("%lld", &v); x = query(a[i]); if (x + v > am) am = x + v; insert(a[i], x + v); } printf("%lld\n", am); return 0; }
#include <stdio.h> #include <vector> using namespace std; const int Cv = 1 << 18, C = 210001; typedef long long ll; int n, a[C]; ll val[2 * Cv], x, v, am; void insert(int a, ll w) { for (a += Cv; a > 0; a /= 2) val[a] = max(val[a], w); } ll query(int l) { ll ww = 0; for (l += Cv; l > 1; l /= 2) if (l % 2 == 1) ww = max(ww, val[l - 1]); return ww; } int main() { int i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) { scanf("%lld", &v); x = query(a[i]); if (x + v > am) am = x + v; insert(a[i], x + v); } printf("%lld\n", am); return 0; }
replace
3
4
3
4
0
p03176
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n; int h[200055], a[200055]; typedef pair<int, long long> P; #define ft first #define sd second int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d", &h[i]); } for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } set<P> dp; dp.insert(P(0, 0)); for (int i = 0; i < n; i++) { auto ite = --dp.lower_bound(P(h[i], 0)); P p = P(h[i], ite->sd + a[i]); ++ite; while (ite != dp.end()) { if (ite->sd <= p.sd) { ite = dp.erase(ite); } else { ++ite; } } dp.insert(p); } cout << dp.rbegin()->sd; }
#include <bits/stdc++.h> using namespace std; int n; int h[200055], a[200055]; typedef pair<int, long long> P; #define ft first #define sd second int main() { cin >> n; for (int i = 0; i < n; i++) { scanf("%d", &h[i]); } for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } set<P> dp; dp.insert(P(0, 0)); for (int i = 0; i < n; i++) { auto ite = --dp.lower_bound(P(h[i], 0)); P p = P(h[i], ite->sd + a[i]); ++ite; while (ite != dp.end()) { if (ite->sd <= p.sd) { ite = dp.erase(ite); } else { break; } } dp.insert(p); } cout << dp.rbegin()->sd; }
replace
35
36
35
36
TLE
p03176
C++
Runtime Error
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define MP make_pair #define F first #define S second #define MEM(a, b) memset(a, b, sizeof a) #define Tie ios::sync_with_stdio(0), cin.tie(0); using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll n, w[100001], v[100001], ans, tmp; map<ll, ll> m; int main() { Tie m[0] = 0; cin >> n; for (int i = 0; i < n; i++) cin >> w[i]; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { auto p = m.upper_bound(w[i]); p--; ans = max(ans, m[w[i]] = p->S + v[i]); tmp = p->S + v[i], p++, p++; while (p != m.end() && p->S <= tmp) { auto tmp = p++; m.erase(tmp); } } cout << ans << '\n'; }
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define MP make_pair #define F first #define S second #define MEM(a, b) memset(a, b, sizeof a) #define Tie ios::sync_with_stdio(0), cin.tie(0); using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll n, w[200001], v[200001], ans, tmp; map<ll, ll> m; int main() { Tie m[0] = 0; cin >> n; for (int i = 0; i < n; i++) cin >> w[i]; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n; i++) { auto p = m.upper_bound(w[i]); p--; ans = max(ans, m[w[i]] = p->S + v[i]); tmp = p->S + v[i], p++, p++; while (p != m.end() && p->S <= tmp) { auto tmp = p++; m.erase(tmp); } } cout << ans << '\n'; }
replace
14
15
14
15
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 1009 #define INF 1000000009 #define MOD 1000000007 typedef long long int ll; #define sd(x) scanf("%d", &x) #define sd2(x, y) scanf("%lld%lld", &x, &y) #define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define pf(x) prllf("%d", x); #define pf2(x, y) prllf("%d %d\n", x, y); #define pf3(x, y, z) prllf("%d %d %d\n", x, y, z); #define fi first #define se second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define _ \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define tr(x) cout << x << endl; #define tr2(x, y) cout << x << " " << y << " " << endl; #define tr3(x, y, z) cout << x << " " << y << " " << z << endl; #define tr4(x, y, z, a) \ cout << x << " " << y << " " << z << " " << a << " " << endl; ll input[N]; ll tree[4 * N + 9]; ll a[N], b[N]; void update(ll low, ll high, ll pos, ll up, ll index) { if (low == high) { tree[pos] = up; return; } ll mid = (low + high) / 2; if (index <= mid) { update(low, mid, 2 * pos + 1, up, index); } else { update(mid + 1, high, 2 * pos + 2, up, index); } tree[pos] = max(tree[2 * pos + 1], tree[2 * pos + 2]); } ll query(ll low, ll high, ll pos, ll l, ll r) { if (low > r || high < l) { return 0; } if (low >= l && high <= r) { return tree[pos]; } ll mid = (low + high) / 2; ll p1 = query(low, mid, 2 * pos + 1, l, r); ll p2 = query(mid + 1, high, 2 * pos + 2, l, r); return max(p1, p2); } int main() { ll i, j, n, m, t, k, x, y; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { cin >> b[i]; } ll ans = b[0], temp; update(0, n, 0, b[0], a[0]); for (i = 1; i < n; i++) { temp = query(0, n, 0, 0, a[i] - 1); temp += b[i]; // tr3(i,a[i],temp); ans = max(ans, temp); update(0, n, 0, temp, a[i]); // temp=query(0,n,0,0,a[i]-1); // tr3(i,a[i],temp); // cout << endl; } tr(ans); }
#include <bits/stdc++.h> using namespace std; #define N 200009 #define INF 1000000009 #define MOD 1000000007 typedef long long int ll; #define sd(x) scanf("%d", &x) #define sd2(x, y) scanf("%lld%lld", &x, &y) #define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z) #define pf(x) prllf("%d", x); #define pf2(x, y) prllf("%d %d\n", x, y); #define pf3(x, y, z) prllf("%d %d %d\n", x, y, z); #define fi first #define se second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define _ \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define tr(x) cout << x << endl; #define tr2(x, y) cout << x << " " << y << " " << endl; #define tr3(x, y, z) cout << x << " " << y << " " << z << endl; #define tr4(x, y, z, a) \ cout << x << " " << y << " " << z << " " << a << " " << endl; ll input[N]; ll tree[4 * N + 9]; ll a[N], b[N]; void update(ll low, ll high, ll pos, ll up, ll index) { if (low == high) { tree[pos] = up; return; } ll mid = (low + high) / 2; if (index <= mid) { update(low, mid, 2 * pos + 1, up, index); } else { update(mid + 1, high, 2 * pos + 2, up, index); } tree[pos] = max(tree[2 * pos + 1], tree[2 * pos + 2]); } ll query(ll low, ll high, ll pos, ll l, ll r) { if (low > r || high < l) { return 0; } if (low >= l && high <= r) { return tree[pos]; } ll mid = (low + high) / 2; ll p1 = query(low, mid, 2 * pos + 1, l, r); ll p2 = query(mid + 1, high, 2 * pos + 2, l, r); return max(p1, p2); } int main() { ll i, j, n, m, t, k, x, y; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n; i++) { cin >> b[i]; } ll ans = b[0], temp; update(0, n, 0, b[0], a[0]); for (i = 1; i < n; i++) { temp = query(0, n, 0, 0, a[i] - 1); temp += b[i]; // tr3(i,a[i],temp); ans = max(ans, temp); update(0, n, 0, temp, a[i]); // temp=query(0,n,0,0,a[i]-1); // tr3(i,a[i],temp); // cout << endl; } tr(ans); }
replace
2
3
2
3
0
p03176
C++
Runtime Error
#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; }
replace
20
21
20
21
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll n, h[200005], b[200005], dp[200005]; int main() { cin >> n; int base = 1; while (base <= n) base *= 2; vector<ll> tree(n * 2, 0); for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) { ll query = base + h[i]; ll yet_best = 0; while (query > 1) { if (query % 2) yet_best = max(yet_best, tree[query - 1]); query /= 2; } dp[h[i]] = yet_best + b[i]; for (int j = base + h[i]; j > 0; j /= 2) tree[j] = max(tree[j], dp[h[i]]); } ll ans = 0; for (int i = 0; i <= n; i++) ans = max(ans, dp[i]); cout << ans << endl; return (0); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll n, h[200005], b[200005], dp[200005]; int main() { cin >> n; int base = 1; while (base <= n) base *= 2; vector<ll> tree(base * 2, 0); for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < n; i++) { ll query = base + h[i]; ll yet_best = 0; while (query > 1) { if (query % 2) yet_best = max(yet_best, tree[query - 1]); query /= 2; } dp[h[i]] = yet_best + b[i]; for (int j = base + h[i]; j > 0; j /= 2) tree[j] = max(tree[j], dp[h[i]]); } ll ans = 0; for (int i = 0; i <= n; i++) ans = max(ans, dp[i]); cout << ans << endl; return (0); }
replace
10
11
10
11
0
p03176
C++
Runtime Error
#define taskname "" #include <algorithm> #include <iostream> using namespace std; #define long long long const int N = 1e5 + 10; int n, h[N], a[N]; long f[N]; #define mid ((l + r) >> 1) #define lc (id << 1) #define rc (lc + 1) struct segmentTree { long tree[N << 2]; void update(int id, int l, int r, int x, long w) { if (x < l || r < x) return; if (l == r) { tree[id] = w; return; } update(lc, l, mid, x, w), update(rc, mid + 1, r, x, w); tree[id] = max(tree[lc], tree[rc]); } long get(int id, int l, int r, int x, int y) { if (y < l || r < x) return 0; if (x <= l && r <= y) return tree[id]; return max(get(lc, l, mid, x, y), get(rc, mid + 1, r, x, y)); } } seg; int main() { // freopen(taskname".INP", "r", stdin); // freopen(taskname".OUT", "w", stdout); cin.tie(nullptr); ios_base::sync_with_stdio(false); cin >> 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) { long maxVal = seg.get(1, 1, n, 0, h[i] - 1); f[i] = maxVal + a[i]; seg.update(1, 1, n, h[i], f[i]); } cout << seg.tree[1]; return 0; }
#define taskname "" #include <algorithm> #include <iostream> using namespace std; #define long long long const int N = 2e5 + 10; int n, h[N], a[N]; long f[N]; #define mid ((l + r) >> 1) #define lc (id << 1) #define rc (lc + 1) struct segmentTree { long tree[N << 2]; void update(int id, int l, int r, int x, long w) { if (x < l || r < x) return; if (l == r) { tree[id] = w; return; } update(lc, l, mid, x, w), update(rc, mid + 1, r, x, w); tree[id] = max(tree[lc], tree[rc]); } long get(int id, int l, int r, int x, int y) { if (y < l || r < x) return 0; if (x <= l && r <= y) return tree[id]; return max(get(lc, l, mid, x, y), get(rc, mid + 1, r, x, y)); } } seg; int main() { // freopen(taskname".INP", "r", stdin); // freopen(taskname".OUT", "w", stdout); cin.tie(nullptr); ios_base::sync_with_stdio(false); cin >> 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) { long maxVal = seg.get(1, 1, n, 0, h[i] - 1); f[i] = maxVal + a[i]; seg.update(1, 1, n, h[i], f[i]); } cout << seg.tree[1]; return 0; }
replace
8
9
8
9
0
p03176
C++
Runtime Error
/* 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); const int MAX_N = 100025; ll Max(ll a, ll b) { if (a > b) return a; return b; } struct node { int id, h; ll s; } arr[MAX_N]; ll dp[MAX_N], maxx[MAX_N << 2]; void up(int rt) { maxx[rt] = Max(maxx[rt << 1], maxx[rt << 1 | 1]); } void update(int rt, int l, int r, int x, ll v) { if (l == r) { maxx[rt] = Max(maxx[rt], v); return; } if (x <= mid) update(rt << 1, l, mid, x, v); else update(rt << 1 | 1, mid + 1, r, x, v); up(rt); } ll query(int rt, int l, int r, int x, int y) { if (x > r || y < l) return 0; if (x <= l && r <= y) { return maxx[rt]; } if (x > mid) return query(rt << 1 | 1, mid + 1, r, x, y); else if (y <= mid) return query(rt << 1, l, mid, x, y); else return Max(query(rt << 1, l, mid, x, y), query(rt << 1 | 1, mid + 1, r, x, y)); } int main() { // ios::sync_with_stdio(false); // freopen("a.txt","r",stdin); // freopen("b.txt","w",stdout); int n; ll ans = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &arr[i].h); for (int i = 1; i <= n; ++i) scanf("%lld", &arr[i].s), arr[i].id = i; for (int i = 1; i <= n; ++i) { ll tmp = 0; if (arr[i].h > 1) tmp = query(1, 1, n, 1, arr[i].h - 1); update(1, 1, n, arr[i].h, tmp + arr[i].s); } printf("%lld\n", maxx[1]); // 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); const int MAX_N = 200025; ll Max(ll a, ll b) { if (a > b) return a; return b; } struct node { int id, h; ll s; } arr[MAX_N]; ll dp[MAX_N], maxx[MAX_N << 2]; void up(int rt) { maxx[rt] = Max(maxx[rt << 1], maxx[rt << 1 | 1]); } void update(int rt, int l, int r, int x, ll v) { if (l == r) { maxx[rt] = Max(maxx[rt], v); return; } if (x <= mid) update(rt << 1, l, mid, x, v); else update(rt << 1 | 1, mid + 1, r, x, v); up(rt); } ll query(int rt, int l, int r, int x, int y) { if (x > r || y < l) return 0; if (x <= l && r <= y) { return maxx[rt]; } if (x > mid) return query(rt << 1 | 1, mid + 1, r, x, y); else if (y <= mid) return query(rt << 1, l, mid, x, y); else return Max(query(rt << 1, l, mid, x, y), query(rt << 1 | 1, mid + 1, r, x, y)); } int main() { // ios::sync_with_stdio(false); // freopen("a.txt","r",stdin); // freopen("b.txt","w",stdout); int n; ll ans = 0; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &arr[i].h); for (int i = 1; i <= n; ++i) scanf("%lld", &arr[i].s), arr[i].id = i; for (int i = 1; i <= n; ++i) { ll tmp = 0; if (arr[i].h > 1) tmp = query(1, 1, n, 1, arr[i].h - 1); update(1, 1, n, arr[i].h, tmp + arr[i].s); } printf("%lld\n", maxx[1]); // fclose(stdin); // fclose(stdout); // cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << // endl; return 0; }
replace
62
63
62
63
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 100050; typedef long long ll; ll H[N]; ll B[N]; ll tree[4 * N]; int n; void update(int nd, int s, int e, int i, ll v) { if (s > i || e < i) return; if (s >= i && e <= i) { tree[nd] = max(tree[nd], v); return; } int mid = (s + e) / 2, l = 2 * nd, r = l + 1; update(l, s, mid, i, v); update(r, mid + 1, e, i, v); tree[nd] = max(tree[l], tree[r]); } ll query(int nd, int s, int e, int i, int j) { if (s > j || e < i) return 0; if (s >= i && e <= j) return tree[nd]; int mid = (s + e) / 2, l = 2 * nd, r = l + 1; return max(query(l, s, mid, i, j), query(r, mid + 1, e, i, j)); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &H[i]); for (int i = 1; i <= n; i++) scanf("%lld", &B[i]); ll ans = 0; for (int i = 1; i <= n; i++) { ll ret = query(1, 1, n, 1, H[i]); ans = max(ans, ret + B[i]); update(1, 1, n, H[i], ret + B[i]); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const int N = 200050; typedef long long ll; ll H[N]; ll B[N]; ll tree[4 * N]; int n; void update(int nd, int s, int e, int i, ll v) { if (s > i || e < i) return; if (s >= i && e <= i) { tree[nd] = max(tree[nd], v); return; } int mid = (s + e) / 2, l = 2 * nd, r = l + 1; update(l, s, mid, i, v); update(r, mid + 1, e, i, v); tree[nd] = max(tree[l], tree[r]); } ll query(int nd, int s, int e, int i, int j) { if (s > j || e < i) return 0; if (s >= i && e <= j) return tree[nd]; int mid = (s + e) / 2, l = 2 * nd, r = l + 1; return max(query(l, s, mid, i, j), query(r, mid + 1, e, i, j)); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &H[i]); for (int i = 1; i <= n; i++) scanf("%lld", &B[i]); ll ans = 0; for (int i = 1; i <= n; i++) { ll ret = query(1, 1, n, 1, H[i]); ans = max(ans, ret + B[i]); update(1, 1, n, H[i], ret + B[i]); } printf("%lld\n", ans); }
replace
3
4
3
4
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define nt _int128 #define mod 1000000007 ll n, arr[200005], brr[200005]; ll dp[200005]; void update(ll i, ll val) { while (i <= n) { dp[i] = max(dp[i], val); i += (i & -i); } } ll query(ll i) { ll max1 = 0; while (i > 0) { max1 = max(max1, dp[i]); i = i - (i & -i); } return max1; } ll func(ll i) { ll max1 = 0LL; for (ll i = 1; i <= n; i++) { ll x = query(arr[i] - 1); update(arr[i], brr[i] + x); max1 = max(max1, x + brr[i]); } return max1; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; // cin >> t; t = 1; while (t--) { cin >> n; for (ll i = 1; i <= n; i++) cin >> arr[i]; for (ll i = 1; i <= n; i++) cin >> brr[i]; memset(dp, 0, sizeof(dp)); ll x = func(1); cout << x; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define nt _int128 #define mod 1000000007 ll n, arr[200005], brr[200005]; ll dp[200005]; void update(ll i, ll val) { while (i <= n) { dp[i] = max(dp[i], val); i += (i & -i); } } ll query(ll i) { ll max1 = 0; while (i > 0) { max1 = max(max1, dp[i]); i = i - (i & -i); } return max1; } ll func(ll i) { ll max1 = 0LL; for (ll i = 1; i <= n; i++) { ll x = query(arr[i] - 1); update(arr[i], brr[i] + x); max1 = max(max1, x + brr[i]); } return max1; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; // cin >> t; t = 1; while (t--) { cin >> n; for (ll i = 1; i <= n; i++) cin >> arr[i]; for (ll i = 1; i <= n; i++) cin >> brr[i]; memset(dp, 0, sizeof(dp)); ll x = func(1); cout << x; } return 0; }
replace
33
37
33
37
0
p03176
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <iostream> #include <limits> #include <map> #include <queue> #include <tuple> #include <vector> using namespace std; #define INF 1LL << 62 #define MAX 1100000 #define MOD 1000000007 typedef long long ll; typedef pair<ll, ll> P; typedef pair<pair<int, int>, int> p; typedef pair<pair<int, int>, int> p; #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) //__builtin_popcount(S) // https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035 const int MAX_N = 210000; // セグメント木を持つグローバル配列 ll n; ll dat[2 * MAX_N - 1]; // 初期化 void init(ll n_) { // 簡単のために要素数を2のべき乗に n = 1; while (n < n_) n *= 2; // 全ての値をINT_MAXに for (int i = 0; i < 2 * n - 1; i++) dat[i] = -1; } // k番目の値(0-indexed)をaに変更 void update(int k, ll 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]); } } //[a,b)の最小値を求める // 後ろの方の引数は、計算の簡単のための引数 // kは接点の番号、l,rはその接点が[l,r)に対応づいていることを表す // したがって、外からはquery(a,b,0,0,n)として呼ぶ ll query(int a, int b, int k, int l, int r) { //[a,b)と[l,r)が交差しなければ,INT_MAX if (r <= a || b <= l) return -1; //[a,b)が[l,r)を完全に含んでいれば、この節点の値 if (a <= l && r <= b) return dat[k]; else { // そうでなければ、2つの子の最小値 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); } } int main() { int N; cin >> N; int h[210000]; ll a[210000]; init(N); for (int i = 0; i < N; i++) { cin >> h[i]; h[i]--; } for (int i = 0; i < N; i++) cin >> a[i]; for (int i = 0; i < N; i++) { ll x = query(0, h[i], 0, 0, n); // cout<<i<<" "<<x<<endl; if (x < 0) x = 0; update(h[i], x + a[i]); } cout << query(0, N + 1, 0, 0, n) << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <iostream> #include <limits> #include <map> #include <queue> #include <tuple> #include <vector> using namespace std; #define INF 1LL << 62 #define MAX 1100000 #define MOD 1000000007 typedef long long ll; typedef pair<ll, ll> P; typedef pair<pair<int, int>, int> p; typedef pair<pair<int, int>, int> p; #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) //__builtin_popcount(S) // https://kyopro-friends.hatenablog.com/entry/2019/01/12/231035 const int MAX_N = 420000; // セグメント木を持つグローバル配列 ll n; ll dat[2 * MAX_N - 1]; // 初期化 void init(ll n_) { // 簡単のために要素数を2のべき乗に n = 1; while (n < n_) n *= 2; // 全ての値をINT_MAXに for (int i = 0; i < 2 * n - 1; i++) dat[i] = -1; } // k番目の値(0-indexed)をaに変更 void update(int k, ll 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]); } } //[a,b)の最小値を求める // 後ろの方の引数は、計算の簡単のための引数 // kは接点の番号、l,rはその接点が[l,r)に対応づいていることを表す // したがって、外からはquery(a,b,0,0,n)として呼ぶ ll query(int a, int b, int k, int l, int r) { //[a,b)と[l,r)が交差しなければ,INT_MAX if (r <= a || b <= l) return -1; //[a,b)が[l,r)を完全に含んでいれば、この節点の値 if (a <= l && r <= b) return dat[k]; else { // そうでなければ、2つの子の最小値 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); } } int main() { int N; cin >> N; int h[210000]; ll a[210000]; init(N); for (int i = 0; i < N; i++) { cin >> h[i]; h[i]--; } for (int i = 0; i < N; i++) cin >> a[i]; for (int i = 0; i < N; i++) { ll x = query(0, h[i], 0, 0, n); // cout<<i<<" "<<x<<endl; if (x < 0) x = 0; update(h[i], x + a[i]); } cout << query(0, N + 1, 0, 0, n) << endl; }
replace
26
27
26
27
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 5; struct SegmentTree { ll t[N << 2]; void init(int u, int b, int e) { if (b == e) { t[u] = 0; return; } int mid = (b + e) >> 1; init(u << 1, b, mid); init(u << 1 | 1, mid + 1, e); t[u] = max(t[u << 1], t[u << 1 | 1]); } void upd(int u, int b, int e, int i, ll x) { if (i < b or e < i) return; if (i <= b and e <= i) { t[u] = x; return; } int mid = (b + e) >> 1; upd(u << 1, b, mid, i, x); upd(u << 1 | 1, mid + 1, e, i, x); t[u] = max(t[u << 1], t[u << 1 | 1]); } ll query(int u, int b, int e, int i, int j) { if (j < b or e < i) return 0LL; if (i <= b and e <= j) return t[u]; int mid = (b + e) >> 1; ll p1 = query(u << 1, b, mid, i, j); ll p2 = query(u << 1 | 1, mid + 1, e, i, j); return max(p1, p2); } } t; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> h(n + 1); for (int i = 1; i <= n; i++) { cin >> h[i]; } vector<ll> dp(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> dp[i]; } for (int i = 1; i <= n; i++) { if (h[i] == 1) { t.upd(1, 1, n, h[i], dp[i]); continue; } dp[i] += 1LL * t.query(1, 1, n, 1, h[i] - 1); t.upd(1, 1, n, h[i], dp[i]); } cout << *max_element(dp.begin(), dp.end()) << '\n'; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 5; struct SegmentTree { ll t[N << 2]; void init(int u, int b, int e) { if (b == e) { t[u] = 0; return; } int mid = (b + e) >> 1; init(u << 1, b, mid); init(u << 1 | 1, mid + 1, e); t[u] = max(t[u << 1], t[u << 1 | 1]); } void upd(int u, int b, int e, int i, ll x) { if (i < b or e < i) return; if (i <= b and e <= i) { t[u] = x; return; } int mid = (b + e) >> 1; upd(u << 1, b, mid, i, x); upd(u << 1 | 1, mid + 1, e, i, x); t[u] = max(t[u << 1], t[u << 1 | 1]); } ll query(int u, int b, int e, int i, int j) { if (j < b or e < i) return 0LL; if (i <= b and e <= j) return t[u]; int mid = (b + e) >> 1; ll p1 = query(u << 1, b, mid, i, j); ll p2 = query(u << 1 | 1, mid + 1, e, i, j); return max(p1, p2); } } t; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> h(n + 1); for (int i = 1; i <= n; i++) { cin >> h[i]; } vector<ll> dp(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> dp[i]; } for (int i = 1; i <= n; i++) { if (h[i] == 1) { t.upd(1, 1, n, h[i], dp[i]); continue; } dp[i] += 1LL * t.query(1, 1, n, 1, h[i] - 1); t.upd(1, 1, n, h[i], dp[i]); } cout << *max_element(dp.begin(), dp.end()) << '\n'; }
replace
5
6
5
6
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int max_n = 100500; int d = 1; ll t[max_n << 2]; void update(int i, ll x, int tl = 0, int tr = d - 1, int v = 1) { if (tl == tr) { t[v] = x; return; } int tm = (tl + tr) >> 1; if (i <= tm) update(i, x, tl, tm, v << 1); else update(i, x, tm + 1, tr, v << 1 | 1); t[v] = max(t[v << 1], t[v << 1 | 1]); } ll get(int l, int r, int tl = 0, int tr = d - 1, int v = 1) { if (l == tl && r == tr) { return t[v]; } int tm = (tl + tr) >> 1; ll ans = 0; if (l <= tm) { ans = max(ans, get(l, min(r, tm), tl, tm, v << 1)); } if (r > tm) { ans = max(ans, get(max(l, tm + 1), r, tm + 1, tr, v << 1 | 1)); } return ans; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cout.precision(20); cout << fixed; int n; cin >> n; while (d <= n) d <<= 1; vector<ll> h(n), a(n); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { update(h[i], get(0, h[i] - 1) + a[i]); } cout << get(0, n); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int max_n = 200500; int d = 1; ll t[max_n << 2]; void update(int i, ll x, int tl = 0, int tr = d - 1, int v = 1) { if (tl == tr) { t[v] = x; return; } int tm = (tl + tr) >> 1; if (i <= tm) update(i, x, tl, tm, v << 1); else update(i, x, tm + 1, tr, v << 1 | 1); t[v] = max(t[v << 1], t[v << 1 | 1]); } ll get(int l, int r, int tl = 0, int tr = d - 1, int v = 1) { if (l == tl && r == tr) { return t[v]; } int tm = (tl + tr) >> 1; ll ans = 0; if (l <= tm) { ans = max(ans, get(l, min(r, tm), tl, tm, v << 1)); } if (r > tm) { ans = max(ans, get(max(l, tm + 1), r, tm + 1, tr, v << 1 | 1)); } return ans; } int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cout.precision(20); cout << fixed; int n; cin >> n; while (d <= n) d <<= 1; vector<ll> h(n), a(n); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { update(h[i], get(0, h[i] - 1) + a[i]); } cout << get(0, n); }
replace
6
7
6
7
0
p03176
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> #define ls(x) x << 1 #define rs(x) x << 1 | 1 #define ll long long #define tree ans #define rep(i, a, b) for (int i = a; i <= b; i++) void read(int &x) { x = 0; int flag = 1; char ch = ' '; while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag; } void read(ll &x) { x = 0; int flag = 1; char ch = ' '; while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag; } using namespace std; const int maxn = 100010; int n, h[maxn], a[maxn]; ll ans[maxn << 2], dp[maxn], tag[maxn << 2]; void push_up(int p) { ans[p] = max(ans[ls(p)], ans[rs(p)]); } void change(int p, ll x) { ans[p] = max(ans[p], x); tag[p] = max(tag[p], x); } void push_down(int p, int l, int r) { change(ls(p), tag[p]), change(rs(p), tag[p]); tag[p] = 0; } ll query(int p, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) return ans[p]; if (tag[p]) push_down(p, l, r); int mid = (l + r) >> 1; ll ret = 0; if (ql <= mid) ret = max(ret, query(ls(p), l, mid, ql, qr)); if (qr > mid) ret = max(ret, query(rs(p), mid + 1, r, ql, qr)); return ret; } void update(int p, int l, int r, int ql, int qr, ll x) { if (ql <= l && r <= qr) { change(p, x); return; } if (tag[p]) push_down(p, l, r); int mid = (l + r) >> 1; if (ql <= mid) update(ls(p), l, mid, ql, qr, x); if (qr > mid) update(rs(p), mid + 1, r, ql, qr, x); push_up(p); } int main() { read(n); rep(i, 1, n) read(h[i]); rep(i, 1, n) read(a[i]); ll ans = 0; rep(i, 1, n) { ll tmp = h[i] == 1 ? 0 : query(1, 1, n, 1, h[i] - 1); dp[i] = tmp + a[i]; ans = max(ans, dp[i]); update(1, 1, n, h[i], n, dp[i]); } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> #define ls(x) x << 1 #define rs(x) x << 1 | 1 #define ll long long #define tree ans #define rep(i, a, b) for (int i = a; i <= b; i++) void read(int &x) { x = 0; int flag = 1; char ch = ' '; while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag; } void read(ll &x) { x = 0; int flag = 1; char ch = ' '; while (ch < '0' || ch > '9') { if (ch == '-') flag = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag; } using namespace std; const int maxn = 200010; int n, h[maxn], a[maxn]; ll ans[maxn << 2], dp[maxn], tag[maxn << 2]; void push_up(int p) { ans[p] = max(ans[ls(p)], ans[rs(p)]); } void change(int p, ll x) { ans[p] = max(ans[p], x); tag[p] = max(tag[p], x); } void push_down(int p, int l, int r) { change(ls(p), tag[p]), change(rs(p), tag[p]); tag[p] = 0; } ll query(int p, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) return ans[p]; if (tag[p]) push_down(p, l, r); int mid = (l + r) >> 1; ll ret = 0; if (ql <= mid) ret = max(ret, query(ls(p), l, mid, ql, qr)); if (qr > mid) ret = max(ret, query(rs(p), mid + 1, r, ql, qr)); return ret; } void update(int p, int l, int r, int ql, int qr, ll x) { if (ql <= l && r <= qr) { change(p, x); return; } if (tag[p]) push_down(p, l, r); int mid = (l + r) >> 1; if (ql <= mid) update(ls(p), l, mid, ql, qr, x); if (qr > mid) update(rs(p), mid + 1, r, ql, qr, x); push_up(p); } int main() { read(n); rep(i, 1, n) read(h[i]); rep(i, 1, n) read(a[i]); ll ans = 0; rep(i, 1, n) { ll tmp = h[i] == 1 ? 0 : query(1, 1, n, 1, h[i] - 1); dp[i] = tmp + a[i]; ans = max(ans, dp[i]); update(1, 1, n, h[i], n, dp[i]); } printf("%lld\n", ans); return 0; }
replace
37
38
37
38
0
p03176
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL << 60) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") #define ALL(v) (v).begin(), (v).end() int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #if 1 //------------- // DUMPマクロ // https://www.creativ.xyz/dump-cpp-652/ // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #endif struct SegmentTree { public: int n; vector<int> node; public: SegmentTree(vector<int> v) { int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, -INF); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = max(node[2 * i + 1], node[2 * i + 2]); } void update(int x, int val) { x += (n - 1); node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = max(node[2 * x + 1], node[2 * x + 2]); } } int getmax(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return -INF; if (a <= l && r <= b) return node[k]; int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2); int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r); return max(vl, vr); } }; int dp[223456]; // 最後がh_iになるときのmax void solve() { int N; cin >> N; vector<int> h(N), a(N); int maxh = 0; rep(i, N) { cin >> h[i]; maxh = max(maxh, h[i]); } rep(i, N) cin >> a[i]; SegmentTree seg(vector<int>(maxh + 1, 0)); rep(i, N) { rep(j, h[i]) { int r = seg.getmax(0, h[i]); seg.update(h[i], max(seg.getmax(h[i], h[i] + 1), r + a[i])); } // dump(seg.node); } int ans = 0; rep(i, N + 1) { ans = max(ans, seg.node[i + N - 1]); } cout << ans << endl; } signed main() { cout << fixed << setprecision(18) << endl; cerr << fixed << setprecision(18) << endl; solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL << 60) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") #define ALL(v) (v).begin(), (v).end() int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #if 1 //------------- // DUMPマクロ // https://www.creativ.xyz/dump-cpp-652/ // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #endif struct SegmentTree { public: int n; vector<int> node; public: SegmentTree(vector<int> v) { int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, -INF); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = max(node[2 * i + 1], node[2 * i + 2]); } void update(int x, int val) { x += (n - 1); node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = max(node[2 * x + 1], node[2 * x + 2]); } } int getmax(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return -INF; if (a <= l && r <= b) return node[k]; int vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2); int vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r); return max(vl, vr); } }; int dp[223456]; // 最後がh_iになるときのmax void solve() { int N; cin >> N; vector<int> h(N), a(N); int maxh = 0; rep(i, N) { cin >> h[i]; maxh = max(maxh, h[i]); } rep(i, N) cin >> a[i]; SegmentTree seg(vector<int>(maxh + 1, 0)); rep(i, N) { int r = seg.getmax(0, h[i]); seg.update(h[i], max(seg.getmax(h[i], h[i] + 1), r + a[i])); // dump(seg.node); } int ans = 0; rep(i, N + 1) { ans = max(ans, seg.node[i + N - 1]); } cout << ans << endl; } signed main() { cout << fixed << setprecision(18) << endl; cerr << fixed << setprecision(18) << endl; solve(); }
replace
152
156
152
154
TLE
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define ld long double #define dd double #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pll> vplll; ll mod = 1e9 + 7; const ld PI = 2 * acos(0.0); const vector<ll> dx = {1, -1, 0, 0}; const vector<ll> dy = {0, 0, 1, -1}; #define round(x, y) ((x + y - 1) / y) #define ce(x, y) ((x + y - 1) / y) #define amax(x, y) \ if (y > x) \ x = y; #define amin(x, y) \ if (y < x) \ x = y; #define lcm(x, y) ((x) * (y) / __gcd(x, y)) #define len(x) (ll) x.length() #define sq(x) ((x) * (x)) #define cb(x) ((x) * (x) * (x)) const int N = 1e5; // limit for array size int n; // array size ll seg[2 * N]; void build(int ar[]) { // build the tree for (int i = n - 1; i > 0; --i) seg[i] = max(seg[i << 1], seg[i << 1 | 1]); } void modify(int p, ll value) { // set value at position p for (seg[p += n] = value; p > 1; p >>= 1) seg[p >> 1] = max(seg[p], seg[p ^ 1]); } ll query(int l, int r) { // sum on interval [l, r) ll res = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) res = max(res, seg[l++]); if (r & 1) res = max(res, seg[--r]); } return res; } vector<pair<ll, pll>> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll a, b, c, t, m, k, q; t = 1; // cin>>t; while (t--) { cin >> n; ll ar[n], br[n]; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = 0; i < n; i++) { cin >> br[i]; v.pb(mp(ar[i], mp(br[i], i + 1))); } sort(all(v)); reverse(all(v)); for (auto j : v) { pll y = j.ss; // cout<<j.ff<<" "<<y.ff<<" "<<y.ss<<endl; ll ans = query(y.ss, n); // cout<<ans<<" "; ans += br[y.ss - 1]; // cout<<ans<<"c"<<j.ff-1<<endl;; modify(y.ss - 1, ans); } cout << query(0, n) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define ld long double #define dd double #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pll> vplll; ll mod = 1e9 + 7; const ld PI = 2 * acos(0.0); const vector<ll> dx = {1, -1, 0, 0}; const vector<ll> dy = {0, 0, 1, -1}; #define round(x, y) ((x + y - 1) / y) #define ce(x, y) ((x + y - 1) / y) #define amax(x, y) \ if (y > x) \ x = y; #define amin(x, y) \ if (y < x) \ x = y; #define lcm(x, y) ((x) * (y) / __gcd(x, y)) #define len(x) (ll) x.length() #define sq(x) ((x) * (x)) #define cb(x) ((x) * (x) * (x)) const int N = 1e5; // limit for array size int n; // array size ll seg[4 * N]; void build(int ar[]) { // build the tree for (int i = n - 1; i > 0; --i) seg[i] = max(seg[i << 1], seg[i << 1 | 1]); } void modify(int p, ll value) { // set value at position p for (seg[p += n] = value; p > 1; p >>= 1) seg[p >> 1] = max(seg[p], seg[p ^ 1]); } ll query(int l, int r) { // sum on interval [l, r) ll res = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) res = max(res, seg[l++]); if (r & 1) res = max(res, seg[--r]); } return res; } vector<pair<ll, pll>> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll a, b, c, t, m, k, q; t = 1; // cin>>t; while (t--) { cin >> n; ll ar[n], br[n]; for (int i = 0; i < n; i++) cin >> ar[i]; for (int i = 0; i < n; i++) { cin >> br[i]; v.pb(mp(ar[i], mp(br[i], i + 1))); } sort(all(v)); reverse(all(v)); for (auto j : v) { pll y = j.ss; // cout<<j.ff<<" "<<y.ff<<" "<<y.ss<<endl; ll ans = query(y.ss, n); // cout<<ans<<" "; ans += br[y.ss - 1]; // cout<<ans<<"c"<<j.ff-1<<endl;; modify(y.ss - 1, ans); } cout << query(0, n) << endl; } return 0; }
replace
39
40
39
40
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const static ll MOD = 1e9 + 7; const static ll INF = 1e14; #include <bits/stdc++.h> using namespace std; // このSegmentTreeは最小値を扱う仕様になっている struct SegmentTree { private: ll n; vector<ll> node; ll INF = 1e18; public: // 元配列 v をセグメント木で表現する SegmentTree(vector<ll> v) { // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく // セグメント木全体で必要なノード数は 2n-1 個である ll sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, INF); // 最下段に値を入れたあとに、下の段から順番に値を入れる // 値を入れるには、自分の子の 2 値を参照すれば良い for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]); } void update(ll x, ll val) { // x番目をvalに変える // 最下段のノードにアクセスする x += (n - 1); // 最下段のノードを更新したら、あとは親に上って更新していく node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } ll get_X(ll x) { return node[x]; } // 要求区間 [a, b) 中の要素の最小値を答える // k := 自分がいるノードのインデックス // 対象区間は [l, r) にあたる ll get_min(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) { // 最初に呼び出されたときの対象区間は [0, n) if (r < 0) r = n; // 要求区間と対象区間が交わらない -> 適当に返す if (r <= a || b <= l) return INF; // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う if (a <= l && r <= b) return node[k]; // 要求区間が対象区間の一部を被覆 -> 子について探索を行う // 左側の子を vl ・ 右側の子を vr としている // 新しい対象区間は、現在の対象区間を半分に割ったもの ll vl = get_min(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = get_min(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } }; // DP : Nこめまで読んだ時のMax // tail : DPの時の部分列の最大値 // Max : 部分列の末尾がNの時のAの合計のMax int main() { ll N; cin >> N; vector<ll> A(N), H(N), DP(N + 1), tail(N + 1), Max(N + 2); for (int i = 0; i < N; i++) cin >> H[i]; for (int i = 0; i < N; i++) cin >> A[i]; DP[1] = A[0]; tail[1] = H[0]; Max[H[0]] = -A[0]; SegmentTree tree(Max); for (int i = 2; i <= N; i++) { if (tail[i - 1] < H[i - 1]) { // 即決で使う DP[i] = DP[i - 1] + A[i - 1]; tail[i] = H[i - 1]; tree.update(tail[i], -DP[i]); } else { // 使うか使わないかわからない // 今までのDPの値と、A[N]を使った場合の値を比べて決めたい ll comp1 = DP[i - 1]; // 使わなかった場合 ll temp = tree.get_min(0, H[i - 1]) * (-1); ll comp2 = A[i - 1] + temp; // 使った場合 if (comp1 < comp2) { // 使った場合 DP[i] = comp2; tail[i] = H[i - 1]; Max[tail[i]] = DP[i]; tree.update(tail[i], -DP[i]); } else { DP[i] = DP[i - 1]; tail[i] = tail[i - 1]; Max[H[i - 1]] = Max[H[i - 1] - 1] + A[i - 1]; // tree.update(Max[H[i-1]], -temp-A[i-1]); tree.update(tree.get_X(H[i - 1]), -temp - A[i - 1]); } } } cout << DP[N] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const static ll MOD = 1e9 + 7; const static ll INF = 1e14; #include <bits/stdc++.h> using namespace std; // このSegmentTreeは最小値を扱う仕様になっている struct SegmentTree { private: ll n; vector<ll> node; ll INF = 1e18; public: // 元配列 v をセグメント木で表現する SegmentTree(vector<ll> v) { // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく // セグメント木全体で必要なノード数は 2n-1 個である ll sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, INF); // 最下段に値を入れたあとに、下の段から順番に値を入れる // 値を入れるには、自分の子の 2 値を参照すれば良い for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]); } void update(ll x, ll val) { // x番目をvalに変える // 最下段のノードにアクセスする x += (n - 1); // 最下段のノードを更新したら、あとは親に上って更新していく node[x] = val; while (x > 0) { x = (x - 1) / 2; node[x] = min(node[2 * x + 1], node[2 * x + 2]); } } ll get_X(ll x) { return node[x]; } // 要求区間 [a, b) 中の要素の最小値を答える // k := 自分がいるノードのインデックス // 対象区間は [l, r) にあたる ll get_min(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) { // 最初に呼び出されたときの対象区間は [0, n) if (r < 0) r = n; // 要求区間と対象区間が交わらない -> 適当に返す if (r <= a || b <= l) return INF; // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う if (a <= l && r <= b) return node[k]; // 要求区間が対象区間の一部を被覆 -> 子について探索を行う // 左側の子を vl ・ 右側の子を vr としている // 新しい対象区間は、現在の対象区間を半分に割ったもの ll vl = get_min(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = get_min(a, b, 2 * k + 2, (l + r) / 2, r); return min(vl, vr); } }; // DP : Nこめまで読んだ時のMax // tail : DPの時の部分列の最大値 // Max : 部分列の末尾がNの時のAの合計のMax int main() { ll N; cin >> N; vector<ll> A(N), H(N), DP(N + 1), tail(N + 1), Max(N + 2); for (int i = 0; i < N; i++) cin >> H[i]; for (int i = 0; i < N; i++) cin >> A[i]; DP[1] = A[0]; tail[1] = H[0]; Max[H[0]] = -A[0]; SegmentTree tree(Max); for (int i = 2; i <= N; i++) { if (tail[i - 1] < H[i - 1]) { // 即決で使う DP[i] = DP[i - 1] + A[i - 1]; tail[i] = H[i - 1]; tree.update(tail[i], -DP[i]); } else { // 使うか使わないかわからない // 今までのDPの値と、A[N]を使った場合の値を比べて決めたい ll comp1 = DP[i - 1]; // 使わなかった場合 ll temp = tree.get_min(0, H[i - 1]) * (-1); ll comp2 = A[i - 1] + temp; // 使った場合 if (comp1 < comp2) { // 使った場合 DP[i] = comp2; tail[i] = H[i - 1]; Max[tail[i]] = DP[i]; tree.update(tail[i], -DP[i]); } else { DP[i] = DP[i - 1]; tail[i] = tail[i - 1]; Max[H[i - 1]] = Max[H[i - 1] - 1] + A[i - 1]; // tree.update(Max[H[i-1]], -temp-A[i-1]); // cout << H[i-1] << endl; // cout << tree.get_X(H[i-1]) << endl; tree.update(H[i - 1], -temp - A[i - 1]); } } } cout << DP[N] << endl; }
replace
114
115
114
117
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define fi first #define se second const int N = 100100; const long long mod = 1e9 + 7; using namespace std; int n; int a[N]; int b[N]; long long d[N]; void upd(int x, long long y) { while (x < N) { d[x] = max(d[x], y); x += x & -x; } } long long get(int x) { long long res = 0; while (x > 0) { res = max(res, d[x]); x -= x & -x; } return res; } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } long long res = 0; for (int i = 1; i <= n; i++) { long long now = get(a[i]) + b[i]; res = max(res, now); upd(a[i], now); } cout << res << "\n"; }
#include <bits/stdc++.h> #define fi first #define se second const int N = 200200; const long long mod = 1e9 + 7; using namespace std; int n; int a[N]; int b[N]; long long d[N]; void upd(int x, long long y) { while (x < N) { d[x] = max(d[x], y); x += x & -x; } } long long get(int x) { long long res = 0; while (x > 0) { res = max(res, d[x]); x -= x & -x; } return res; } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } long long res = 0; for (int i = 1; i <= n; i++) { long long now = get(a[i]) + b[i]; res = max(res, now); upd(a[i], now); } cout << res << "\n"; }
replace
5
6
5
6
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<ll, ll> pii; typedef pair<ld, ld> pld; ll n; ll h[100009]; ll a[100009]; ll bit[100009]; void upd(ll idx, ll val) { ++idx; while (idx <= n + 1) { bit[idx] = max(bit[idx], val); idx += idx & (-idx); } } ll get(ll idx) { ++idx; ll ret = 0; while (idx > 0) { ret = max(bit[idx], ret); idx -= idx & (-idx); } return ret; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); cin >> n; for (ll i = 0; i < n; ++i) cin >> h[i]; for (ll i = 0; i < n; ++i) cin >> a[i]; for (ll i = 0; i < n; ++i) { upd(h[i], a[i] + get(h[i] - 1)); } cout << get(n) << "\n"; }
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<ll, ll> pii; typedef pair<ld, ld> pld; ll n; ll h[200009]; ll a[200009]; ll bit[200009]; void upd(ll idx, ll val) { ++idx; while (idx <= n + 1) { bit[idx] = max(bit[idx], val); idx += idx & (-idx); } } ll get(ll idx) { ++idx; ll ret = 0; while (idx > 0) { ret = max(bit[idx], ret); idx -= idx & (-idx); } return ret; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); cin >> n; for (ll i = 0; i < n; ++i) cin >> h[i]; for (ll i = 0; i < n; ++i) cin >> a[i]; for (ll i = 0; i < n; ++i) { upd(h[i], a[i] + get(h[i] - 1)); } cout << get(n) << "\n"; }
replace
14
17
14
17
0
p03176
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> h(n); for (int i = 0; i < n; ++i) cin >> h[i]; vector<ll> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; ll res = 0; set<pair<ll, ll>> st; st.insert({0ll, 0ll}); for (int i = 0; i < n; ++i) { auto it = prev(st.lower_bound({h[i], 0})); ll cost = a[i] + (*it).second; it++; while (it != st.end()) { auto nxt = next(it); if ((*it).second <= cost) { st.erase(it); } it = nxt; } st.insert({h[i], cost}); res = max(res, cost); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; vector<ll> h(n); for (int i = 0; i < n; ++i) cin >> h[i]; vector<ll> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; ll res = 0; set<pair<ll, ll>> st; st.insert({0ll, 0ll}); for (int i = 0; i < n; ++i) { auto it = prev(st.lower_bound({h[i], 0})); ll cost = a[i] + (*it).second; it++; while (it != st.end()) { auto nxt = next(it); if ((*it).second <= cost) { st.erase(it); } else { break; } it = nxt; } st.insert({h[i], cost}); res = max(res, cost); } cout << res << endl; return 0; }
insert
27
27
27
29
TLE
p03176
C++
Runtime Error
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define F first #define S second #define ld long double #define built __builtin_popcountll #define mst(a, i) memset(a, i, sizeof(a)) #define all(x) x.begin(), x.end() #define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define reprr(i, a, b) for (ll i = a; i >= b; i--) #define pi 3.14159265358979323846264338327950288419716939937510582097494459230 ll max3(ll x, ll y, ll z) { return max(max(x, y), z); } ll min3(ll x, ll y, ll z) { return min(min(x, y), z); } const ll N = 1e5 + 10, M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; const int INF = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } #define trace(...) \ cerr << "Line:" << __LINE__ << " "; \ __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } int X[] = {0, 1, 0, -1}; int Y[] = {-1, 0, 1, 0}; // assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) // is(65-90) and 32 for space ll power(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = ((x % mod) * (x % mod)) % mod; n = n / 2; } return result; } int n; int h[N], a[N]; int ans = 0; int fenwick[M]; int update(int p, int val) { for (int i = p; i <= M; i += ((i) & (-i))) fenwick[i] = max(fenwick[i], val); } int sum(int p) { int res = 0; for (int i = p; i; i -= ((i) & (-i))) res = max(res, fenwick[i]); return res; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; rep(i, 1, n + 1) cin >> h[i]; rep(i, 1, n + 1) cin >> a[i]; for (int i = 1; i <= n; i++) { int x = sum(h[i] - 1); trace(x); ans = max(ans, x + a[i]); update(h[i], x + a[i]); } cout << ans; return 0; }
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<ll, ll> #define vpii vector<pair<ll, ll>> #define F first #define S second #define ld long double #define built __builtin_popcountll #define mst(a, i) memset(a, i, sizeof(a)) #define all(x) x.begin(), x.end() #define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define reprr(i, a, b) for (ll i = a; i >= b; i--) #define pi 3.14159265358979323846264338327950288419716939937510582097494459230 ll max3(ll x, ll y, ll z) { return max(max(x, y), z); } ll min3(ll x, ll y, ll z) { return min(min(x, y), z); } const ll N = 1e5 + 10, M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7, inf = 1e17 + 10; const int INF = 1e9 + 7; void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } #define trace(...) \ cerr << "Line:" << __LINE__ << " "; \ __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } int X[] = {0, 1, 0, -1}; int Y[] = {-1, 0, 1, 0}; // assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) // is(65-90) and 32 for space ll power(ll x, ll n) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = ((x % mod) * (x % mod)) % mod; n = n / 2; } return result; } int n; int h[M], a[M]; int ans = 0; int fenwick[M]; int update(int p, int val) { for (int i = p; i <= M; i += ((i) & (-i))) fenwick[i] = max(fenwick[i], val); } int sum(int p) { int res = 0; for (int i = p; i; i -= ((i) & (-i))) res = max(res, fenwick[i]); return res; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; rep(i, 1, n + 1) cin >> h[i]; rep(i, 1, n + 1) cin >> a[i]; for (int i = 1; i <= n; i++) { int x = sum(h[i] - 1); trace(x); ans = max(ans, x + a[i]); update(h[i], x + a[i]); } cout << ans; return 0; }
replace
74
75
74
75
-11
Line:82 x : 0
p03176
C++
Runtime Error
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; const ll MOD = 1E+09 + 7; const ll INF = 1E18; const int MAX_N = 1E+05; int N; int H[MAX_N + 1]; ll dp[MAX_N + 1], A[MAX_N + 1]; ll getmax(int i); void setmax(int i, ll x); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> 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++) { setmax(H[i], getmax(H[i] - 1) + A[i]); } cout << getmax(N) << "\n"; return 0; } ll getmax(int i) { ll s = 0; while (i > 0) { s = max(s, dp[i]); i -= i & -i; } return s; } void setmax(int i, ll x) { while (i <= N) { dp[i] = max(dp[i], x); i += i & -i; } }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; const ll MOD = 1E+09 + 7; const ll INF = 1E18; const int MAX_N = 2E+05; int N; int H[MAX_N + 1]; ll dp[MAX_N + 1], A[MAX_N + 1]; ll getmax(int i); void setmax(int i, ll x); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> 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++) { setmax(H[i], getmax(H[i] - 1) + A[i]); } cout << getmax(N) << "\n"; return 0; } ll getmax(int i) { ll s = 0; while (i > 0) { s = max(s, dp[i]); i -= i & -i; } return s; } void setmax(int i, ll x) { while (i <= N) { dp[i] = max(dp[i], x); i += i & -i; } }
replace
28
29
28
29
0
p03176
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int N; scanf("%d", &N); vector<int> H(N), A(N); vector<long long> dp(N, 0); int base = 1; while (base <= N) { base <<= 1; } vector<long long> tree(2 * base, 0); for (int i = 0; i < N; ++i) { scanf("%d", &H[i]); } for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); dp[i] = A[i]; } for (int i = 0; i < N; ++i) { int x = base + H[i]; long long best = 0; while (x > 1) { if (x & 1) { best = max(best, tree[x - 1]); } x >>= 1; } dp[H[i]] = best + A[i]; for (int k = base + H[i]; k >= 1; k >>= 1) { tree[k] = max(tree[k], dp[H[i]]); } } cout << tree[1]; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int N; scanf("%d", &N); vector<int> H(N), A(N); vector<long long> dp(2 * N, 0); int base = 1; while (base <= N) { base <<= 1; } vector<long long> tree(2 * base, 0); for (int i = 0; i < N; ++i) { scanf("%d", &H[i]); } for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); dp[i] = A[i]; } for (int i = 0; i < N; ++i) { int x = base + H[i]; long long best = 0; while (x > 1) { if (x & 1) { best = max(best, tree[x - 1]); } x >>= 1; } dp[H[i]] = best + A[i]; for (int k = base + H[i]; k >= 1; k >>= 1) { tree[k] = max(tree[k], dp[H[i]]); } } cout << tree[1]; }
replace
11
12
11
12
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100001; ll dp[N]; ll getMid(ll s, ll e) { return s + (e - s) / 2; } ll MaxUtil(ll *st, ll ss, ll se, ll l, ll r, ll node) { if (l <= ss && r >= se) return st[node]; if (se < l || ss > r) return -1; ll mid = getMid(ss, se); return max(MaxUtil(st, ss, mid, l, r, 2 * node + 1), MaxUtil(st, mid + 1, se, l, r, 2 * node + 2)); } void updateValue(ll arr[], ll *st, ll ss, ll se, ll index, ll value, ll node) { if (index < ss || index > se) { cout << "Invalid Input" << endl; return; } if (ss == se) { arr[index] = value; st[node] = value; } else { ll mid = getMid(ss, se); if (index >= ss && index <= mid) updateValue(arr, st, ss, mid, index, value, 2 * node + 1); else updateValue(arr, st, mid + 1, se, index, value, 2 * node + 2); st[node] = max(st[2 * node + 1], st[2 * node + 2]); } return; } ll getMax(ll *st, ll n, ll l, ll r) { if (l < 0 || r > n - 1 || l > r) { printf("Invalid Input"); return -1; } return MaxUtil(st, 0, n - 1, l, r, 0); } ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } ll mid = getMid(ss, se); st[si] = max(constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2)); return st[si]; } ll *constructST(ll arr[], ll n) { ll x = (int)(ceil(log2(n))); ll max_size = 2 * (int)pow(2, x) - 1; ll *st = new ll[max_size]; constructSTUtil(arr, 0, n - 1, st, 0); return st; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // n = 10; // ll a[10] = {1,2,3,4,5,6,7,8,9,10}; // ll st = constructST(a,n); int n; cin >> n; ll h[n + 1], c[n + 1]; for (int i = 0; i < n; ++i) cin >> h[i]; for (int i = 0; i < n; ++i) cin >> c[i]; ll *tree = constructST(dp, n); for (int i = 0; i < n; ++i) { if (h[i] == 1) updateValue(dp, tree, 0, n - 1, 0, c[i], 0); else { ll z = getMax(tree, n, 0, h[i] - 2); updateValue(dp, tree, 0, n - 1, h[i] - 1, z + c[i], 0); } } // for(int i = 0; i < n; ++i) cout<<dp[i]<<" "; // cout<<"\n"; cout << *max_element(dp, dp + n) << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200001; ll dp[N]; ll getMid(ll s, ll e) { return s + (e - s) / 2; } ll MaxUtil(ll *st, ll ss, ll se, ll l, ll r, ll node) { if (l <= ss && r >= se) return st[node]; if (se < l || ss > r) return -1; ll mid = getMid(ss, se); return max(MaxUtil(st, ss, mid, l, r, 2 * node + 1), MaxUtil(st, mid + 1, se, l, r, 2 * node + 2)); } void updateValue(ll arr[], ll *st, ll ss, ll se, ll index, ll value, ll node) { if (index < ss || index > se) { cout << "Invalid Input" << endl; return; } if (ss == se) { arr[index] = value; st[node] = value; } else { ll mid = getMid(ss, se); if (index >= ss && index <= mid) updateValue(arr, st, ss, mid, index, value, 2 * node + 1); else updateValue(arr, st, mid + 1, se, index, value, 2 * node + 2); st[node] = max(st[2 * node + 1], st[2 * node + 2]); } return; } ll getMax(ll *st, ll n, ll l, ll r) { if (l < 0 || r > n - 1 || l > r) { printf("Invalid Input"); return -1; } return MaxUtil(st, 0, n - 1, l, r, 0); } ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } ll mid = getMid(ss, se); st[si] = max(constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2)); return st[si]; } ll *constructST(ll arr[], ll n) { ll x = (int)(ceil(log2(n))); ll max_size = 2 * (int)pow(2, x) - 1; ll *st = new ll[max_size]; constructSTUtil(arr, 0, n - 1, st, 0); return st; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // n = 10; // ll a[10] = {1,2,3,4,5,6,7,8,9,10}; // ll st = constructST(a,n); int n; cin >> n; ll h[n + 1], c[n + 1]; for (int i = 0; i < n; ++i) cin >> h[i]; for (int i = 0; i < n; ++i) cin >> c[i]; ll *tree = constructST(dp, n); for (int i = 0; i < n; ++i) { if (h[i] == 1) updateValue(dp, tree, 0, n - 1, 0, c[i], 0); else { ll z = getMax(tree, n, 0, h[i] - 2); updateValue(dp, tree, 0, n - 1, h[i] - 1, z + c[i], 0); } } // for(int i = 0; i < n; ++i) cout<<dp[i]<<" "; // cout<<"\n"; cout << *max_element(dp, dp + n) << "\n"; }
replace
3
4
3
4
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int N = 100005; const int MOD = 1000000007; int h[N], a[N], i, n, M; LL w[3 * N]; void insert(int v, LL b) { int s = M + v; while (s) { w[s] = max(w[s], b); s /= 2; } } LL query(int a, int b) { int va = M + a, vb = M + b; LL wyn = w[va]; if (va != vb) wyn = max(wyn, w[vb]); while (va / 2 != vb / 2) { if (va % 2 == 0) wyn = max(wyn, w[va + 1]); if (vb % 2 == 1) wyn = max(wyn, w[vb - 1]); va /= 2; vb /= 2; } return wyn; } void init(int a) { M = 1; while (M < a) M *= 2; for (int i = 1; i < 2 * M; i++) w[i] = 0; M--; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &h[i]); for (i = 1; i <= n; i++) scanf("%d", &a[i]); init(n); for (i = 1; i <= n; i++) { if (h[i] == 1) insert(h[i], a[i]); else insert(h[i], query(1, h[i] - 1) + a[i]); } printf("%lld\n", query(1, n)); return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int N = 200005; const int MOD = 1000000007; int h[N], a[N], i, n, M; LL w[3 * N]; void insert(int v, LL b) { int s = M + v; while (s) { w[s] = max(w[s], b); s /= 2; } } LL query(int a, int b) { int va = M + a, vb = M + b; LL wyn = w[va]; if (va != vb) wyn = max(wyn, w[vb]); while (va / 2 != vb / 2) { if (va % 2 == 0) wyn = max(wyn, w[va + 1]); if (vb % 2 == 1) wyn = max(wyn, w[vb - 1]); va /= 2; vb /= 2; } return wyn; } void init(int a) { M = 1; while (M < a) M *= 2; for (int i = 1; i < 2 * M; i++) w[i] = 0; M--; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &h[i]); for (i = 1; i <= n; i++) scanf("%d", &a[i]); init(n); for (i = 1; i <= n; i++) { if (h[i] == 1) insert(h[i], a[i]); else insert(h[i], query(1, h[i] - 1) + a[i]); } printf("%lld\n", query(1, n)); return 0; }
replace
7
8
7
8
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define pb emplace_back #define fi first #define se second #define int long long using namespace std; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); } const int MAXN = 3e5; int seg[MAXN]; int n; void update(int i, int val) { for (seg[i += n] = val; i > 1; i >>= 1) seg[i >> 1] = max(seg[i], seg[i ^ 1]); } int query(int l, int r) { r++; int a = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (r & 1) a = max(a, seg[--r]); if (l & 1) a = max(seg[l++], a); } return a; } int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cin >> n; vector<int> h(n); for (int o = 0; o < n; o++) { int y; cin >> y; h[y - 1] = o; } vector<int> a(n); for (int o = 0; o < n; o++) { cin >> a[o]; } for (int i = 0; i < n; ++i) update(h[i], query(0, h[i]) + a[h[i]]); cout << query(0, n - 1); }
#include <bits/stdc++.h> #define pb emplace_back #define fi first #define se second #define int long long using namespace std; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); } const int MAXN = 5e5; int seg[MAXN]; int n; void update(int i, int val) { for (seg[i += n] = val; i > 1; i >>= 1) seg[i >> 1] = max(seg[i], seg[i ^ 1]); } int query(int l, int r) { r++; int a = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (r & 1) a = max(a, seg[--r]); if (l & 1) a = max(seg[l++], a); } return a; } int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cin >> n; vector<int> h(n); for (int o = 0; o < n; o++) { int y; cin >> y; h[y - 1] = o; } vector<int> a(n); for (int o = 0; o < n; o++) { cin >> a[o]; } for (int i = 0; i < n; ++i) update(h[i], query(0, h[i]) + a[h[i]]); cout << query(0, n - 1); }
replace
12
13
12
13
0
p03176
Python
Runtime Error
def get(i): mx = 0 while i > 0: if bit[i] > mx: mx = bit[i] i -= i & -i return mx def update(i, x): while i < n + 1: if x > bit[i]: bit[i] = x i += i & -i def f(hs, a_s): for h, a in zip(hs, a_s): update(h, get(h - 1) + a) print(max(bit)) n = int(input()) hs = list(map(int, input().split())) a_s = list(map(int, input().split())) bit = [0] * (n + 1) f(n, hs, a_s)
def get(i): mx = 0 while i > 0: if bit[i] > mx: mx = bit[i] i -= i & -i return mx def update(i, x): while i < n + 1: if x > bit[i]: bit[i] = x i += i & -i def f(hs, a_s): for h, a in zip(hs, a_s): update(h, get(h - 1) + a) print(max(bit)) n = int(input()) hs = list(map(int, input().split())) a_s = list(map(int, input().split())) bit = [0] * (n + 1) f(hs, a_s)
replace
26
27
26
27
TypeError: f() takes 2 positional arguments but 3 were given
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03176/Python/s612498010.py", line 27, in <module> f(n, hs, a_s) TypeError: f() takes 2 positional arguments but 3 were given
p03176
C++
Runtime Error
#pragma GCC optimize "03" #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int t[4 * N], h[N], b[N]; void upd(int nd, int s, int e, int id, int v) { if (s == e) { t[nd] = v; return; } int md = (s + e) >> 1; if (id <= md) upd(2 * nd, s, md, id, v); else upd(2 * nd + 1, md + 1, e, id, v); t[nd] = max(t[2 * nd], t[2 * nd + 1]); } int query(int nd, int s, int e, int l, int r) { if (s > e || s > r || e < l) return 0; if (s >= l && e <= r) return t[nd]; int md = (s + e) >> 1; return max(query(2 * nd, s, md, l, r), query(2 * nd + 1, md + 1, e, l, r)); } signed main() { IOS; #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) { int p = query(1, 1, n, 1, h[i]); ans = max(ans, p + b[i]); upd(1, 1, n, h[i], p + b[i]); } cout << ans; return 0; }
#pragma GCC optimize "03" #include "bits/stdc++.h" using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; int t[4 * N], h[N], b[N]; void upd(int nd, int s, int e, int id, int v) { if (s == e) { t[nd] = v; return; } int md = (s + e) >> 1; if (id <= md) upd(2 * nd, s, md, id, v); else upd(2 * nd + 1, md + 1, e, id, v); t[nd] = max(t[2 * nd], t[2 * nd + 1]); } int query(int nd, int s, int e, int l, int r) { if (s > e || s > r || e < l) return 0; if (s >= l && e <= r) return t[nd]; int md = (s + e) >> 1; return max(query(2 * nd, s, md, l, r), query(2 * nd + 1, md + 1, e, l, r)); } signed main() { IOS; #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, ans = 0; cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) { int p = query(1, 1, n, 1, h[i]); ans = max(ans, p + b[i]); upd(1, 1, n, h[i], p + b[i]); } cout << ans; return 0; }
replace
18
19
18
19
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; vector<long long> st(MAXN); long long update(int l, int r, int v, int i, long long val) { if (l > i || r < i) return st[v]; if (l == r) return st[v] = max(val, st[v]); int m = l + r >> 1; return st[v] = max(update(l, m, v << 1, i, val), update(m + 1, r, v << 1 | 1, i, val)); } long long query(int l, int r, int v, int li, int ri) { if (l > ri || r < li) return 0; if (l >= li && r <= ri) return st[v]; int m = l + r >> 1; return max(query(l, m, v << 1, li, ri), query(m + 1, r, v << 1 | 1, li, ri)); } int main() { int n; scanf("%i", &n); vector<int> h(n + 1), a(n + 1); for (int x = 1; x <= n; x++) scanf("%i", &h[x]); for (int x = 1; x <= n; x++) scanf("%i", &a[x]); for (int x = 1; x <= n; x++) update(1, n, 1, h[x], query(1, n, 1, 1, h[x] - 1) + a[x]); printf("%lli\n", st[1]); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; vector<long long> st(MAXN << 2); long long update(int l, int r, int v, int i, long long val) { if (l > i || r < i) return st[v]; if (l == r) return st[v] = max(val, st[v]); int m = l + r >> 1; return st[v] = max(update(l, m, v << 1, i, val), update(m + 1, r, v << 1 | 1, i, val)); } long long query(int l, int r, int v, int li, int ri) { if (l > ri || r < li) return 0; if (l >= li && r <= ri) return st[v]; int m = l + r >> 1; return max(query(l, m, v << 1, li, ri), query(m + 1, r, v << 1 | 1, li, ri)); } int main() { int n; scanf("%i", &n); vector<int> h(n + 1), a(n + 1); for (int x = 1; x <= n; x++) scanf("%i", &h[x]); for (int x = 1; x <= n; x++) scanf("%i", &a[x]); for (int x = 1; x <= n; x++) update(1, n, 1, h[x], query(1, n, 1, 1, h[x] - 1) + a[x]); printf("%lli\n", st[1]); }
replace
6
7
6
7
0
p03176
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; using ld = long double; #define st first #define nd second const int MAXN = 1e5 + 5, inf = 1e9; const ll INF = 1e18, mod = 1e9 + 7; const ld PI = 3.1415926535897932384626433832795; int cnt[MAXN]; ll dp[MAXN], h[MAXN], a[MAXN]; bool vis[MAXN], used[MAXN]; vector<int> G[MAXN]; vector<ll> V; set<ll> S; map<ll, int> M; stack<ll> St; queue<ll> Q; ll Tree[2 * 1024 * 1024], Base = 1; void chTree(int node, ll v) { node += Base; Tree[node] = v; while (node /= 2) { Tree[node] = max(Tree[2 * node], Tree[2 * node + 1]); } } ll read(int node, int lo, int hi, int l, int r) { if (r < lo or hi < l) { return 0; } if (l <= lo and hi <= r) { return Tree[node]; } int mid = (lo + hi) / 2; return max(read(2 * node, lo, mid, l, r), read(2 * node + 1, mid + 1, hi, l, r)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << setprecision(13) << fixed; ////////////////////////////////////////// ////////////////////////////////////////// int n; cin >> n; while (Base <= n) { Base *= 2; } 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++) { dp[h[i]] = read(1, 0, Base - 1, 1, h[i]) + a[i]; chTree(h[i], dp[h[i]]); } ll res = 0; for (int i = 1; i <= n; i++) { // cout << dp[i] << " "; res = max(res, dp[i]); } // cout << "\n"; cout << res << "\n"; }
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; using ll = long long; using ld = long double; #define st first #define nd second const int MAXN = 2e5 + 5, inf = 1e9; const ll INF = 1e18, mod = 1e9 + 7; const ld PI = 3.1415926535897932384626433832795; int cnt[MAXN]; ll dp[MAXN], h[MAXN], a[MAXN]; bool vis[MAXN], used[MAXN]; vector<int> G[MAXN]; vector<ll> V; set<ll> S; map<ll, int> M; stack<ll> St; queue<ll> Q; ll Tree[2 * 1024 * 1024], Base = 1; void chTree(int node, ll v) { node += Base; Tree[node] = v; while (node /= 2) { Tree[node] = max(Tree[2 * node], Tree[2 * node + 1]); } } ll read(int node, int lo, int hi, int l, int r) { if (r < lo or hi < l) { return 0; } if (l <= lo and hi <= r) { return Tree[node]; } int mid = (lo + hi) / 2; return max(read(2 * node, lo, mid, l, r), read(2 * node + 1, mid + 1, hi, l, r)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << setprecision(13) << fixed; ////////////////////////////////////////// ////////////////////////////////////////// int n; cin >> n; while (Base <= n) { Base *= 2; } 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++) { dp[h[i]] = read(1, 0, Base - 1, 1, h[i]) + a[i]; chTree(h[i], dp[h[i]]); } ll res = 0; for (int i = 1; i <= n; i++) { // cout << dp[i] << " "; res = max(res, dp[i]); } // cout << "\n"; cout << res << "\n"; }
replace
20
21
20
21
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007; #define inf (1LL << 60) using namespace std; struct flower { ll hi; ll bty; }; ll solve(vector<flower> &v, int n) { vector<ll> dp(n + 1); map<ll, ll> m; dp[1] = v[1].bty; m[v[1].hi] = dp[1]; ll ans = dp[1]; for (int i = 2; i <= n; i++) { dp[i] = v[i].bty; auto it = m.lower_bound(v[i].hi + 1); if (it != m.begin()) { it--; dp[i] += it->second; } m[v[i].hi] = dp[i]; it = m.upper_bound(v[i].hi); while (it->second <= dp[i]) { auto temp = it; temp++; m.erase(it); it = temp; } ans = max(ans, dp[i]); } return ans; } int main() { int n; cin >> n; vector<flower> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i].hi; for (int i = 1; i <= n; i++) cin >> v[i].bty; cout << solve(v, n); return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007; #define inf (1LL << 60) using namespace std; struct flower { ll hi; ll bty; }; ll solve(vector<flower> &v, int n) { vector<ll> dp(n + 1); map<ll, ll> m; dp[1] = v[1].bty; m[v[1].hi] = dp[1]; ll ans = dp[1]; for (int i = 2; i <= n; i++) { dp[i] = v[i].bty; auto it = m.lower_bound(v[i].hi + 1); if (it != m.begin()) { it--; dp[i] += it->second; } m[v[i].hi] = dp[i]; it = m.upper_bound(v[i].hi); while (it != m.end() && it->second <= dp[i]) { auto temp = it; temp++; m.erase(it); it = temp; } ans = max(ans, dp[i]); } return ans; } int main() { int n; cin >> n; vector<flower> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i].hi; for (int i = 1; i <= n; i++) cin >> v[i].bty; cout << solve(v, n); return 0; }
replace
27
28
27
28
0
p03176
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 #define int long long const int MAX_N = 1 << 17; int n, dat[2 * MAX_N - 1]; void init(int n_) { n = 1; while (n < n_) n *= 2; rep(i, 2 * n - 1) dat[i] = 0; } // k番目の値(0-indexed)をaに変更 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]); } } // [a, b)の最大値を探す. int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } int h[200010]; int a[200010]; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; init(N); rep(i, N) cin >> h[i]; rep(i, N) cin >> a[i]; rep(i, N) { int tmp = query(0, h[i], 0, 0, n); update(h[i] - 1, tmp + a[i]); // rep(i, N) cout << dat[n - 1 + i] << " "; // cout << endl; } cout << query(0, N, 0, 0, n) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n; i >= 0; i--) #define REP(i, s, t) for (int i = s; i <= t; i++) #define RREP(i, s, t) for (int i = s; i >= t; i--) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 #define int long long const int MAX_N = 1 << 18; int n, dat[2 * MAX_N - 1]; void init(int n_) { n = 1; while (n < n_) n *= 2; rep(i, 2 * n - 1) dat[i] = 0; } // k番目の値(0-indexed)をaに変更 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]); } } // [a, b)の最大値を探す. int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) return dat[k]; else { int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } int h[200010]; int a[200010]; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; init(N); rep(i, N) cin >> h[i]; rep(i, N) cin >> a[i]; rep(i, N) { int tmp = query(0, h[i], 0, 0, n); update(h[i] - 1, tmp + a[i]); // rep(i, N) cout << dat[n - 1 + i] << " "; // cout << endl; } cout << query(0, N, 0, 0, n) << endl; return 0; }
replace
12
13
12
13
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N = 100006; struct flower { ll hi; ll bt; }; ll n; vector<flower> v(N); ll lis() { vector<ll> dp(n + 1); dp[0] = 0; dp[1] = v[1].bt; map<ll, ll> m; m[v[1].hi] = dp[1]; ll ans = dp[1]; for (ll i = 2; i <= n; i++) { dp[i] = v[i].bt; auto it = m.lower_bound(v[i].hi + 1); if (it != m.begin()) { it--; dp[i] += it->second; } m[v[i].hi] = dp[i]; it = m.upper_bound(v[i].hi); while (it != m.end() && it->second <= dp[i]) { auto temp = it; temp++; m.erase(it); it = temp; } ans = max(ans, dp[i]); } return ans; } int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> v[i].hi; } for (ll i = 1; i <= n; i++) { cin >> v[i].bt; } cout << lis() << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; const ll N = 200006; struct flower { ll hi; ll bt; }; ll n; vector<flower> v(N); ll lis() { vector<ll> dp(n + 1); dp[0] = 0; dp[1] = v[1].bt; map<ll, ll> m; m[v[1].hi] = dp[1]; ll ans = dp[1]; for (ll i = 2; i <= n; i++) { dp[i] = v[i].bt; auto it = m.lower_bound(v[i].hi + 1); if (it != m.begin()) { it--; dp[i] += it->second; } m[v[i].hi] = dp[i]; it = m.upper_bound(v[i].hi); while (it != m.end() && it->second <= dp[i]) { auto temp = it; temp++; m.erase(it); it = temp; } ans = max(ans, dp[i]); } return ans; } int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> v[i].hi; } for (ll i = 1; i <= n; i++) { cin >> v[i].bt; } cout << lis() << endl; }
replace
3
4
3
4
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long st[400005] = {}; int h[100005], w[100005]; void update(int x, int l, int r, int z, long long int zz) { if (l > z || r < z) return; if (l == r) { st[x] = zz; return; } int mid = (l + r) / 2; update(x * 2, l, mid, z, zz); update(x * 2 + 1, mid + 1, r, z, zz); st[x] = max(st[x * 2], st[x * 2 + 1]); } long long query(int x, int l, int r, int ll, int rr) { if (l > rr || r < ll) return 0; if (l >= ll && r <= rr) return st[x]; int mid = (l + r) / 2; return max(query(x * 2, l, mid, ll, rr), query(x * 2 + 1, mid + 1, r, ll, rr)); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) { cin >> w[i]; } long long ans = 0; for (int i = 0; i < n; i++) { long long asd = query(1, 1, n, 1, h[i]); update(1, 1, n, h[i], asd + w[i]); ans = max(ans, asd + w[i]); } cout << ans; }
#include <bits/stdc++.h> using namespace std; long long st[800005] = {}; long long h[200005], w[200005]; void update(int x, int l, int r, int z, long long int zz) { if (l > z || r < z) return; if (l == r) { st[x] = zz; return; } int mid = (l + r) / 2; update(x * 2, l, mid, z, zz); update(x * 2 + 1, mid + 1, r, z, zz); st[x] = max(st[x * 2], st[x * 2 + 1]); } long long query(int x, int l, int r, int ll, int rr) { if (l > rr || r < ll) return 0; if (l >= ll && r <= rr) return st[x]; int mid = (l + r) / 2; return max(query(x * 2, l, mid, ll, rr), query(x * 2 + 1, mid + 1, r, ll, rr)); } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < n; i++) { cin >> w[i]; } long long ans = 0; for (int i = 0; i < n; i++) { long long asd = query(1, 1, n, 1, h[i]); update(1, 1, n, h[i], asd + w[i]); ans = max(ans, asd + w[i]); } cout << ans; }
replace
2
4
2
4
0
p03176
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++) #define NFOR(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); --i) #define rep(i, a) for (ll i = 0; i < a; i++) #define endl "\n" #define fi first #define se second #define MOD 1000000007 #define inf 1e18 #define pb push_back #define Case cout << "Case #" << ++cas << ": "; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(v) v.begin(), v.end() typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const map<S, T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> void prc(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } const int maxn = 20005; inline ll L(ll a) { return (a << 1) + 1; } inline ll R(ll a) { return (a << 1) + 2; } class SegTree { ll T[maxn << 2]; public: void build() { memset(T, 0, sizeof(T)); } void update(ll node, ll st, ll en, ll pos, ll val) { if (st > en) return; if (st == en) T[node] = val; else { ll mid = (st + en) >> 1; if (pos > mid) update(R(node), mid + 1, en, pos, val); else update(L(node), st, mid, pos, val); T[node] = max(T[L(node)], T[R(node)]); } } ll query(ll node, ll st, ll en, ll pos) { if (st > en) return -1; if (st == en) return T[node]; else { ll mid = (st + en) >> 1; if (pos > mid) return max(T[L(node)], query(R(node), mid + 1, en, pos)); else return query(L(node), st, mid, pos); } } }; void solve() { SegTree st; st.build(); ll n; cin >> n; vl h(n); rep(i, n) cin >> h[i]; vl a(n); rep(i, n) cin >> a[i]; ll ans = 0; ll N = *max_element(all(h)) + 1; // pr(N); rep(i, n) { ll temp = st.query(0, 0, N, h[i]) + a[i]; ans = max(temp, ans); st.update(0, 0, N, h[i], temp); } cout << ans << endl; } int main() { fastio; ll t = 1; // cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++) #define NFOR(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); --i) #define rep(i, a) for (ll i = 0; i < a; i++) #define endl "\n" #define fi first #define se second #define MOD 1000000007 #define inf 1e18 #define pb push_back #define Case cout << "Case #" << ++cas << ": "; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(v) v.begin(), v.end() typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const map<S, T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> void prc(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } const int maxn = 200005; inline ll L(ll a) { return (a << 1) + 1; } inline ll R(ll a) { return (a << 1) + 2; } class SegTree { ll T[maxn << 2]; public: void build() { memset(T, 0, sizeof(T)); } void update(ll node, ll st, ll en, ll pos, ll val) { if (st > en) return; if (st == en) T[node] = val; else { ll mid = (st + en) >> 1; if (pos > mid) update(R(node), mid + 1, en, pos, val); else update(L(node), st, mid, pos, val); T[node] = max(T[L(node)], T[R(node)]); } } ll query(ll node, ll st, ll en, ll pos) { if (st > en) return -1; if (st == en) return T[node]; else { ll mid = (st + en) >> 1; if (pos > mid) return max(T[L(node)], query(R(node), mid + 1, en, pos)); else return query(L(node), st, mid, pos); } } }; void solve() { SegTree st; st.build(); ll n; cin >> n; vl h(n); rep(i, n) cin >> h[i]; vl a(n); rep(i, n) cin >> a[i]; ll ans = 0; ll N = *max_element(all(h)) + 1; // pr(N); rep(i, n) { ll temp = st.query(0, 0, N, h[i]) + a[i]; ans = max(temp, ans); st.update(0, 0, N, h[i], temp); } cout << ans << endl; } int main() { fastio; ll t = 1; // cin >> t; while (t--) { solve(); } }
replace
65
66
65
66
0
p03176
C++
Runtime Error
/* $$$$$$$\ $$\ $$$$$$$\ $$ __$$\ \__| $$ __$$\ $$ | $$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ _____|$$$$$$$\ | \____$$\ $$ __$$\ $$ _____|\____$$\ $$ __$$\ $$ / $$ |$$ | \__|$$ |\$$$$$$\ $$ __$$\ $$$$$$$ |$$ | \__|$$ / $$$$$$$ | $$ | $$ |$$ | $$ |$$ | $$ | \____$$\ $$ | $$ |$$ __$$ |$$ | $$ | $$ __$$ | $$$$$$$ |\$$$$$$ |$$ | $$ |$$$$$$$ |$$$$$$$ |\$$$$$$$ |$$ | \$$$$$$$\\$$$$$$$ | \_______/ \______/ \__| \__|\_______/ \_______/ \_______|\__| \_______|\_______| */ #include <bits/stdc++.h> using namespace std; #define PB push_back #define MP make_pair #define INS insert #define LB lower_bound #define UB upper_bound #define pii pair<int, int> #define pll pair<long long, long long> #define si pair<string, int> #define is pair<int, string> #define X first #define Y second #define _ << " " << #define sz(x) (int)x.size() #define all(a) (a).begin(), (a).end() #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORD(i, a, b) for (int i = (a); i > (b); --i) #define FORR(i, l, r) for (int i = (l); i <= (r); ++i) #define FORP(i, a, b) for ((i) = (a); (i) < (b); ++i) #define FORA(i, x) for (auto &i : x) #define REP(i, n) FOR(i, 0, n) #define BITS(x) __builtin_popcount(x) #define MSET memset #define MCPY memcpy #define SQ(a) (a) * (a) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<ll> vll; typedef vector<pll> vpl; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<si> vsi; typedef vector<is> vis; typedef vector<string> vs; //((float) t)/CLOCKS_PER_SEC const int MOD = 1e9 + 7; const int PI = acos(-1); const int LOG = 20; const int INF = 1e9 + 10; const ll INFL = 1e18 + 10; const int ABC = 30; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const int dox[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int doy[] = {0, 0, -1, 1, -1, 1, -1, 1}; inline int sum(int a, int b) { if (a + b >= MOD) return a + b - MOD; if (a + b < 0) return a + b + MOD; return a + b; } inline void add(int &a, int b) { a = sum(a, b); } inline int mul(int a, int b) { return (ll)a * (ll)b % MOD; } inline int sub(int a, int b) { return (a - b + MOD) % MOD; } inline int pot(ll pot, int n) { ll ret = 1; while (n) { if (n & 1) ret = (ret * pot) % MOD; pot = (pot * pot) % MOD; n >>= 1; } return ret; } inline int divide(int a, int b) { return mul(a, pot(b, MOD - 2)); } ll lcm(ll a, ll b) { return abs(a * b) / __gcd(a, b); } inline double ccw(pii A, pii B, pii C) { return (A.X * B.Y) - (A.Y * B.X) + (B.X * C.Y) - (B.Y * C.X) + (C.X * A.Y) - (C.Y * A.X); } inline int CCW(pii A, pii B, pii C) { double val = ccw(A, B, C); double eps = max(max(abs(A.X), abs(A.Y)), max(max(abs(B.X), abs(B.Y)), max(abs(C.X), abs(C.Y)))) / 1e9; if (val <= -eps) return -1; if (val >= eps) return 1; return 0; } void to_upper(string &x) { REP(i, sz(x)) x[i] = toupper(x[i]); } void to_lower(string &x) { REP(i, sz(x)) x[i] = tolower(x[i]); } string its(ll x) { if (x == 0) return "0"; string ret = ""; while (x > 0) { ret += (x % 10) + '0'; x /= 10; } reverse(all(ret)); return ret; } ll sti(string s) { ll ret = 0; REP(i, sz(s)) { ret *= 10; ret += (s[i] - '0'); } return ret; } const int N = 1e5 + 10; int n, sor[N]; vll h, b; vpl v; struct Loga { vll f; int n; Loga(int _n) { n = _n; f.resize(n + 100, 0); } void update(int x, ll val) { for (x++; x < n; x += (x & -x)) f[x] = max(f[x], val); } ll query(int x) { ll ret = 0; for (; x > 0; x -= (x & -x)) ret = max(ret, f[x]); return ret; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; REP(i, n) { ll x; cin >> x; h.PB(x); v.PB({x, i}); } REP(i, n) { ll x; cin >> x; b.PB(x); } sort(all(v)); REP(i, sz(v)) sor[v[i].Y] = i + 1; Loga dp(n + 10); REP(i, n) { // cout << dp.query(sor[i]) << '\n'; dp.update(sor[i], dp.query(sor[i]) + b[i]); } cout << dp.query(n + 1) << '\n'; return 0; }
/* $$$$$$$\ $$\ $$$$$$$\ $$ __$$\ \__| $$ __$$\ $$ | $$ | $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$ | $$ | $$$$$$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$$\ |$$ __$$\ $$ __$$\ $$ |$$ _____|$$$$$$$\ | \____$$\ $$ __$$\ $$ _____|\____$$\ $$ __$$\ $$ / $$ |$$ | \__|$$ |\$$$$$$\ $$ __$$\ $$$$$$$ |$$ | \__|$$ / $$$$$$$ | $$ | $$ |$$ | $$ |$$ | $$ | \____$$\ $$ | $$ |$$ __$$ |$$ | $$ | $$ __$$ | $$$$$$$ |\$$$$$$ |$$ | $$ |$$$$$$$ |$$$$$$$ |\$$$$$$$ |$$ | \$$$$$$$\\$$$$$$$ | \_______/ \______/ \__| \__|\_______/ \_______/ \_______|\__| \_______|\_______| */ #include <bits/stdc++.h> using namespace std; #define PB push_back #define MP make_pair #define INS insert #define LB lower_bound #define UB upper_bound #define pii pair<int, int> #define pll pair<long long, long long> #define si pair<string, int> #define is pair<int, string> #define X first #define Y second #define _ << " " << #define sz(x) (int)x.size() #define all(a) (a).begin(), (a).end() #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORD(i, a, b) for (int i = (a); i > (b); --i) #define FORR(i, l, r) for (int i = (l); i <= (r); ++i) #define FORP(i, a, b) for ((i) = (a); (i) < (b); ++i) #define FORA(i, x) for (auto &i : x) #define REP(i, n) FOR(i, 0, n) #define BITS(x) __builtin_popcount(x) #define MSET memset #define MCPY memcpy #define SQ(a) (a) * (a) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<ll> vll; typedef vector<pll> vpl; typedef vector<double> vd; typedef vector<ld> vld; typedef vector<si> vsi; typedef vector<is> vis; typedef vector<string> vs; //((float) t)/CLOCKS_PER_SEC const int MOD = 1e9 + 7; const int PI = acos(-1); const int LOG = 20; const int INF = 1e9 + 10; const ll INFL = 1e18 + 10; const int ABC = 30; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const int dox[] = {-1, 1, 0, 0, -1, -1, 1, 1}; const int doy[] = {0, 0, -1, 1, -1, 1, -1, 1}; inline int sum(int a, int b) { if (a + b >= MOD) return a + b - MOD; if (a + b < 0) return a + b + MOD; return a + b; } inline void add(int &a, int b) { a = sum(a, b); } inline int mul(int a, int b) { return (ll)a * (ll)b % MOD; } inline int sub(int a, int b) { return (a - b + MOD) % MOD; } inline int pot(ll pot, int n) { ll ret = 1; while (n) { if (n & 1) ret = (ret * pot) % MOD; pot = (pot * pot) % MOD; n >>= 1; } return ret; } inline int divide(int a, int b) { return mul(a, pot(b, MOD - 2)); } ll lcm(ll a, ll b) { return abs(a * b) / __gcd(a, b); } inline double ccw(pii A, pii B, pii C) { return (A.X * B.Y) - (A.Y * B.X) + (B.X * C.Y) - (B.Y * C.X) + (C.X * A.Y) - (C.Y * A.X); } inline int CCW(pii A, pii B, pii C) { double val = ccw(A, B, C); double eps = max(max(abs(A.X), abs(A.Y)), max(max(abs(B.X), abs(B.Y)), max(abs(C.X), abs(C.Y)))) / 1e9; if (val <= -eps) return -1; if (val >= eps) return 1; return 0; } void to_upper(string &x) { REP(i, sz(x)) x[i] = toupper(x[i]); } void to_lower(string &x) { REP(i, sz(x)) x[i] = tolower(x[i]); } string its(ll x) { if (x == 0) return "0"; string ret = ""; while (x > 0) { ret += (x % 10) + '0'; x /= 10; } reverse(all(ret)); return ret; } ll sti(string s) { ll ret = 0; REP(i, sz(s)) { ret *= 10; ret += (s[i] - '0'); } return ret; } const int N = 2e5 + 10; int n, sor[N]; vll h, b; vpl v; struct Loga { vll f; int n; Loga(int _n) { n = _n; f.resize(n + 100, 0); } void update(int x, ll val) { for (x++; x < n; x += (x & -x)) f[x] = max(f[x], val); } ll query(int x) { ll ret = 0; for (; x > 0; x -= (x & -x)) ret = max(ret, f[x]); return ret; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; REP(i, n) { ll x; cin >> x; h.PB(x); v.PB({x, i}); } REP(i, n) { ll x; cin >> x; b.PB(x); } sort(all(v)); REP(i, sz(v)) sor[v[i].Y] = i + 1; Loga dp(n + 10); REP(i, n) { // cout << dp.query(sor[i]) << '\n'; dp.update(sor[i], dp.query(sor[i]) + b[i]); } cout << dp.query(n + 1) << '\n'; return 0; }
replace
146
147
146
147
0
p03177
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define SPEED \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define RFOR(i, b, a) for (ll i = b; i >= a; --i) #define ALL(x) x.begin(), x.end() #define DEBUG(args...) \ { \ string _s = #args; \ replace(ALL(_s), ' ', '\0'); \ replace(ALL(_s), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ _debug(_it, args); \ } #define endl "\n" #define F first #define S second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void _debug(istream_iterator<string>) {} template <typename T, typename... Args> void _debug(istream_iterator<string> it, T first, Args... args) { cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const pair<T1, T2> &p) { return out << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { if (v.empty()) return out << "[]"; else { out << '['; for (auto &e : v) { out << e << ", "; } return out << "\b\b]"; } } template <typename T> inline ostream &operator<<(ostream &out, const set<T> &s) { if (s.empty()) return out << "{}"; else { out << '{'; for (auto &e : s) { out << e << ", "; } return out << "\b\b}"; } } template <typename T> inline ostream &operator<<(ostream &out, const unordered_set<T> &s) { return out << set<T>(ALL(s)); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const map<T1, T2> &m) { if (m.empty()) return out << "{}"; out << '{'; for (auto &p : m) { out << p << ", "; } return out << "\b\b}"; } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const unordered_map<T1, T2> &m) { return out << map<T1, T2>(ALL(m)); } template <typename T> inline ostream &operator<<(ostream &out, const ordered_set<T> &s) { return out << set<T>(ALL(s)); } typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef unordered_map<ll, ll> STll; /************************************** MAIN PROGRAM * ********************************************/ const int MAX = 51; bool a[MAX][MAX]; const int MOD = 1e9 + 7; ll n, k; map<ll, ll> cache[MAX][MAX]; ll mul(ll a, ll b) { return (a % MOD) * (b % MOD) % MOD; } ll ans(int i, int j, ll k) { if (cache[i][j].count(k)) { return cache[i][j][k]; } if (k == 1) { return a[i][j]; } ll val = 0; FOR(r, 0, n) { val += mul(ans(i, r, k / 2), ans(r, j, (k + 1) / 2)); if (val >= MOD) { val -= MOD; } } return cache[i][j][k] = val; } int main() { // freopen("input.txt", "r", stdin); SPEED cin >> n >> k; FOR(i, 0, n) { FOR(j, 0, n) { cin >> a[i][j]; } } ll result = 0; FOR(i, 0, n) { FOR(j, 0, n) { result += ans(i, j, k); if (result >= MOD) { result -= MOD; } } } cout << result; } /************************************** END OF PROGRAM * ******************************************/
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define SPEED \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define RFOR(i, b, a) for (ll i = b; i >= a; --i) #define ALL(x) x.begin(), x.end() #define DEBUG(args...) \ { \ string _s = #args; \ replace(ALL(_s), ' ', '\0'); \ replace(ALL(_s), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ _debug(_it, args); \ } #define endl "\n" #define F first #define S second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void _debug(istream_iterator<string>) {} template <typename T, typename... Args> void _debug(istream_iterator<string> it, T first, Args... args) { cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const pair<T1, T2> &p) { return out << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { if (v.empty()) return out << "[]"; else { out << '['; for (auto &e : v) { out << e << ", "; } return out << "\b\b]"; } } template <typename T> inline ostream &operator<<(ostream &out, const set<T> &s) { if (s.empty()) return out << "{}"; else { out << '{'; for (auto &e : s) { out << e << ", "; } return out << "\b\b}"; } } template <typename T> inline ostream &operator<<(ostream &out, const unordered_set<T> &s) { return out << set<T>(ALL(s)); } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const map<T1, T2> &m) { if (m.empty()) return out << "{}"; out << '{'; for (auto &p : m) { out << p << ", "; } return out << "\b\b}"; } template <typename T1, typename T2> inline ostream &operator<<(ostream &out, const unordered_map<T1, T2> &m) { return out << map<T1, T2>(ALL(m)); } template <typename T> inline ostream &operator<<(ostream &out, const ordered_set<T> &s) { return out << set<T>(ALL(s)); } typedef long long ll; typedef long double ld; typedef vector<long long> vll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef unordered_map<ll, ll> STll; /************************************** MAIN PROGRAM * ********************************************/ const int MAX = 51; bool a[MAX][MAX]; const int MOD = 1e9 + 7; ll n, k; map<ll, ll> cache[MAX][MAX]; ll mul(ll a, ll b) { return (a % MOD) * (b % MOD) % MOD; } ll ans(int i, int j, ll k) { if (cache[i][j].count(k)) { return cache[i][j][k]; } if (k == 0) { return 0; } if (k == 1) { return a[i][j]; } ll val = 0; FOR(r, 0, n) { val += mul(ans(i, r, k / 2), ans(r, j, (k + 1) / 2)); if (val >= MOD) { val -= MOD; } } return cache[i][j][k] = val; } int main() { // freopen("input.txt", "r", stdin); SPEED cin >> n >> k; FOR(i, 0, n) { FOR(j, 0, n) { cin >> a[i][j]; } } ll result = 0; FOR(i, 0, n) { FOR(j, 0, n) { result += ans(i, j, k); if (result >= MOD) { result -= MOD; } } } cout << result; } /************************************** END OF PROGRAM * ******************************************/
insert
108
108
108
111
TLE
p03177
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/numeric> using namespace std; using namespace __gnu_cxx; #define ll long long const long double EPS = 1e-8; const long double PI = acos(-1); const int N = 1e5 + 9; const ll inf = (ll)-1e18; const int mod = 1e9 + 7; typedef vector<vector<ll>> Mat; vector<pair<int, int>> dir = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; struct Mul { int sz = 1; Mat operator()(const Mat &a, const Mat &b) const { Mat ret(a.size(), vector<ll>(b[0].size())); for (int i = 0; i < ret.size(); i++) { // row in first matrix for (int j = 0; j < ret[0].size(); j++) { // col in second matrix for (int k = 0; k < b.size(); k++) { ret[i][j] = (ret[i][j] + (a[i][k] * b[k][j]) % mod) % mod; } } } return ret; } }; Mat identity_element(const Mul &mul) { Mat ret(mul.sz, vector<ll>(mul.sz)); for (int i = 0; i < mul.sz; i++) ret[i][i] = 1; return ret; } int main() { freopen("input.txt", "r", stdin); int t; // scanf("%d", &t); // while (t--) { int n; ll k; scanf("%d%lld", &n, &k); Mat v(n, vector<ll>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%lld", &v[i][j]); } } Mul multiplyOperator; multiplyOperator.sz = n * n; Mat ans = power(v, k, multiplyOperator); ll a = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a = (a + ans[i][j]) % mod; } } printf("%lld\n", a); // } }
#include <bits/stdc++.h> #include <ext/numeric> using namespace std; using namespace __gnu_cxx; #define ll long long const long double EPS = 1e-8; const long double PI = acos(-1); const int N = 1e5 + 9; const ll inf = (ll)-1e18; const int mod = 1e9 + 7; typedef vector<vector<ll>> Mat; vector<pair<int, int>> dir = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; struct Mul { int sz = 1; Mat operator()(const Mat &a, const Mat &b) const { Mat ret(a.size(), vector<ll>(b[0].size())); for (int i = 0; i < ret.size(); i++) { // row in first matrix for (int j = 0; j < ret[0].size(); j++) { // col in second matrix for (int k = 0; k < b.size(); k++) { ret[i][j] = (ret[i][j] + (a[i][k] * b[k][j]) % mod) % mod; } } } return ret; } }; Mat identity_element(const Mul &mul) { Mat ret(mul.sz, vector<ll>(mul.sz)); for (int i = 0; i < mul.sz; i++) ret[i][i] = 1; return ret; } int main() { // freopen("input.txt", "r", stdin); int t; // scanf("%d", &t); // while (t--) { int n; ll k; scanf("%d%lld", &n, &k); Mat v(n, vector<ll>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%lld", &v[i][j]); } } Mul multiplyOperator; multiplyOperator.sz = n * n; Mat ans = power(v, k, multiplyOperator); ll a = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a = (a + ans[i][j]) % mod; } } printf("%lld\n", a); // } }
replace
41
42
41
42
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p03177
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) #define pb push_back #define all(a) a.begin(), a.end() #define rall(c) (c).rbegin(), (c).rend() #define mp make_pair #define double long double typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll inf = 1e9 + 7; const ll mod = 1e9 + 7; int main() { ll n, K; cin >> n >> K; vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(65))); rep(i, n) rep(j, n) { ll a; cin >> a; if (a) dp[i][j][0] = 1; } REP(l, 1, 65) { rep(i, n) { rep(j, n) { rep(k, n) { dp[i][j][l] += dp[i][k][l - 1] % inf * dp[k][j][l - 1] % inf; dp[i][j][l] %= inf; } } } } vector<vector<ll>> path(n, vector<ll>(65)); rep(i, n) path[i][0] = 1; rep(k, 65) { if ((1LL << k) & K) { rep(i, n) { rep(j, n) { path[i][k + 1] += path[j][k] % inf * dp[j][i][k] % inf; path[i][k + 1] %= inf; } } } else { rep(i, n) { path[i][k + 1] = path[i][k]; } } } ll ans = 0; rep(i, n) { ans += path[i][64]; ans %= inf; } rep(i, 3) { rep(j, n) { rep(k, n) { // cout<<i<<' '<<j<<' '<<k<<' '<<dp[j][k][i]<<endl; } } } cout << ans << endl; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) #define pb push_back #define all(a) a.begin(), a.end() #define rall(c) (c).rbegin(), (c).rend() #define mp make_pair #define double long double typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll inf = 1e9 + 7; const ll mod = 1e9 + 7; int main() { ll n, K; cin >> n >> K; vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n, vector<ll>(65))); rep(i, n) rep(j, n) { ll a; cin >> a; if (a) dp[i][j][0] = 1; } REP(l, 1, 65) { rep(i, n) { rep(j, n) { rep(k, n) { dp[i][j][l] += dp[i][k][l - 1] % inf * dp[k][j][l - 1] % inf; dp[i][j][l] %= inf; } } } } vector<vector<ll>> path(n, vector<ll>(65)); rep(i, n) path[i][0] = 1; rep(k, 64) { if ((1LL << k) & K) { rep(i, n) { rep(j, n) { path[i][k + 1] += path[j][k] % inf * dp[j][i][k] % inf; path[i][k + 1] %= inf; } } } else { rep(i, n) { path[i][k + 1] = path[i][k]; } } } ll ans = 0; rep(i, n) { ans += path[i][64]; ans %= inf; } rep(i, 3) { rep(j, n) { rep(k, n) { // cout<<i<<' '<<j<<' '<<k<<' '<<dp[j][k][i]<<endl; } } } cout << ans << endl; }
replace
38
39
38
39
-6
free(): invalid pointer
p03177
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef struct matrix { long long int m[55][55]; } M; const int MOD = 1000000007; long long int N, K; M g; M mul(M a, M b) { M c; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { c.m[i][j] = 0; for (int k = 0; k < N; k++) { c.m[i][j] += (a.m[i][k] * b.m[k][j]) % MOD; c.m[i][j] %= MOD; } } } return c; } M exp(M a, int p) { if (p == 1) { return a; } M c = exp(a, p / 2); c = mul(c, c); if (p % 2 == 1) c = mul(a, c); return c; } int main() { // freopen("test.in", "r+", stdin); cin >> N >> K; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> g.m[i][j]; g = exp(g, K); long long int result = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { result += g.m[i][j]; result %= MOD; } } cout << result << endl; }
#include <bits/stdc++.h> using namespace std; typedef struct matrix { long long int m[55][55]; } M; const int MOD = 1000000007; long long int N, K; M g; M mul(M a, M b) { M c; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { c.m[i][j] = 0; for (int k = 0; k < N; k++) { c.m[i][j] += (a.m[i][k] * b.m[k][j]) % MOD; c.m[i][j] %= MOD; } } } return c; } M exp(M a, long long int p) { if (p == 1) { return a; } M c = exp(a, p / 2); c = mul(c, c); if (p % 2 == 1) c = mul(a, c); return c; } int main() { // freopen("test.in", "r+", stdin); cin >> N >> K; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> g.m[i][j]; g = exp(g, K); long long int result = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { result += g.m[i][j]; result %= MOD; } } cout << result << endl; }
replace
24
25
24
25
0
p03177
C++
Runtime Error
#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; }
replace
44
45
44
45
0
p03177
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; using namespace std; const ll MOD = 1e9 + 7; class Matrix { public: int m, n; vector<vector<ll>> a; Matrix(int s, int t) { m = s; n = t; a = vector<vector<ll>>(m, vector<ll>(n, 0)); } void print() { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << a[i][j] << " "; } cout << endl; } } }; Matrix mulMatrix(Matrix m1, Matrix m2) { int m = m1.m; int n = m2.n; int len = m1.n; Matrix ans = Matrix(m, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < len; k++) { ans.a[i][j] += m1.a[i][k] * m2.a[k][j]; ans.a[i][j] %= MOD; } } } return ans; } Matrix mulMatrix_pow(Matrix M, int N) { if (N == 1) return M; else { if (N % 2 == 0) { Matrix tmp = mulMatrix_pow(M, N / 2); return mulMatrix(tmp, tmp); } else { Matrix tmp = mulMatrix_pow(M, (N - 1) / 2); return mulMatrix(M, mulMatrix(tmp, tmp)); } } } //================================================== int main() { int N; ll K; cin >> N >> K; Matrix A = Matrix(N, N); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> A.a[j][i]; } } // ANS = A^k * B Matrix B = Matrix(N, 1); for (int i = 0; i < N; i++) B.a[i][0] = 1; Matrix ANS = mulMatrix(mulMatrix_pow(A, K), B); ll ans = 0; for (int i = 0; i < N; i++) ans += ANS.a[i][0]; cout << ans % MOD << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; using namespace std; const ll MOD = 1e9 + 7; class Matrix { public: int m, n; vector<vector<ll>> a; Matrix(int s, int t) { m = s; n = t; a = vector<vector<ll>>(m, vector<ll>(n, 0)); } void print() { for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cout << a[i][j] << " "; } cout << endl; } } }; Matrix mulMatrix(Matrix m1, Matrix m2) { int m = m1.m; int n = m2.n; int len = m1.n; Matrix ans = Matrix(m, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < len; k++) { ans.a[i][j] += m1.a[i][k] * m2.a[k][j]; ans.a[i][j] %= MOD; } } } return ans; } Matrix mulMatrix_pow(Matrix M, ll N) { if (N == 1) return M; else { if (N % 2 == 0) { Matrix tmp = mulMatrix_pow(M, N / 2); return mulMatrix(tmp, tmp); } else { Matrix tmp = mulMatrix_pow(M, (N - 1) / 2); return mulMatrix(M, mulMatrix(tmp, tmp)); } } } //================================================== int main() { int N; ll K; cin >> N >> K; Matrix A = Matrix(N, N); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> A.a[j][i]; } } // ANS = A^k * B Matrix B = Matrix(N, 1); for (int i = 0; i < N; i++) B.a[i][0] = 1; Matrix ANS = mulMatrix(mulMatrix_pow(A, K), B); ll ans = 0; for (int i = 0; i < N; i++) ans += ANS.a[i][0]; cout << ans % MOD << endl; return 0; }
replace
55
56
55
56
0
p03177
C++
Runtime Error
#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; ll mat[51][51], extr[51][51], n; void mul(ll b[51][51]) { ll m[n][n]; forn(i, n) { forn(j, n) { m[i][j] = 0; forn(k, n) { ll temp = ((mat[i][k] % mod) * (b[k][j] % mod)) % mod; m[i][j] = ((m[i][j] % mod) + (temp % mod)) % mod; } } } forn(i, n) forn(j, n) mat[i][j] = m[i][j] % mod; } void rec(ll k) { if (k <= 1) return; rec(k / 2); mul(mat); if (k % 2) mul(extr); } int main() { sync file(); ll k; cin >> n >> k; forn(i, n) forn(j, n) cin >> mat[i][j], extr[i][j] = mat[i][j]; rec(k); ll ans = 0; forn(i, n) forn(j, n) ans = (ans + mat[i][j]) % mod; cout << ans; 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; ll mat[51][51], extr[51][51], n; void mul(ll b[51][51]) { ll m[n][n]; forn(i, n) { forn(j, n) { m[i][j] = 0; forn(k, n) { ll temp = ((mat[i][k] % mod) * (b[k][j] % mod)) % mod; m[i][j] = ((m[i][j] % mod) + (temp % mod)) % mod; } } } forn(i, n) forn(j, n) mat[i][j] = m[i][j] % mod; } void rec(ll k) { if (k <= 1) return; rec(k / 2); mul(mat); if (k % 2) mul(extr); } int main() { sync // file(); ll k; cin >> n >> k; forn(i, n) forn(j, n) cin >> mat[i][j], extr[i][j] = mat[i][j]; rec(k); ll ans = 0; forn(i, n) forn(j, n) ans = (ans + mat[i][j]) % mod; cout << ans; return 0; }
replace
60
62
60
63
0
p03177
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define M 1000000007 ll walk(vector<vector<ll>> &adj, ll n, ll K) { ll dp[K + 1][n][n]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[1][i][j] = adj[i][j]; for (int k = 2; k <= K; k++) { for (int z = 0; z < n; z++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { // No. of paths from i to j in 'k' steps += // No. of paths from i to z in (k-1) steps * // No. of paths from z to j in (k-1) steps dp[k][i][j] = (dp[k][i][j] + (dp[k - 1][i][z] * dp[k - 1][z][j]) % M) % M; } } ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans = (ans + dp[K][i][j]) % M; return ans; } void multiply(vector<vector<ll>> &A, vector<vector<ll>> &B, ll n) { // Multiply the matrices 'A' and 'B' and store the result in 'A' itself vector<vector<ll>> C(n, vector<ll>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { C[i][j] = 0; for (int k = 0; k < n; k++) C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % M) % M; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) A[i][j] = C[i][j]; } void matrixExponentiation(vector<vector<ll>> &A, ll n, ll k) { if (k <= 1) return; if (k % 2 == 0) { matrixExponentiation(A, n, k / 2); multiply(A, A, n); } else { vector<vector<ll>> tempMatrix(A); matrixExponentiation(A, n, k - 1); multiply(A, tempMatrix, n); } } ll walkOptimized(vector<vector<ll>> &adj, ll n, ll K) { // 'adj' contains for each cell (i, j) the no. of ways to // reach from 'i' to 'j' in 1 step // Suppose If we have a matrix 'A', in which each cell // (i, j) denotes the number of paths from i to j in exactly 4 steps // Then if we multiply it with 'adj', then after multiplying we will get // a matrix in which for each cell (i, j) it stores the no. of ways // to reach from 'i' to 'j' in exactly 5 steps // Hence we just need to multiply 'adj' K times, i.e. // we need to find adj^K, then in the end take the sum of all values // in that matrix because the paths can start or end at any vertex // To quickly find this exponentiation, we can use matrix exponentiation matrixExponentiation(adj, n, K); ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans = (ans + adj[i][j]) % M; return ans; } int main() { ll n, k; cin >> n >> k; vector<vector<ll>> adj(n, vector<ll>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> adj[i][j]; ll ans = walk(adj, n, k); // ll ans = walkOptimized(adj, n, k); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define M 1000000007 ll walk(vector<vector<ll>> &adj, ll n, ll K) { ll dp[K + 1][n][n]; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[1][i][j] = adj[i][j]; for (int k = 2; k <= K; k++) { for (int z = 0; z < n; z++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { // No. of paths from i to j in 'k' steps += // No. of paths from i to z in (k-1) steps * // No. of paths from z to j in (k-1) steps dp[k][i][j] = (dp[k][i][j] + (dp[k - 1][i][z] * dp[k - 1][z][j]) % M) % M; } } ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans = (ans + dp[K][i][j]) % M; return ans; } void multiply(vector<vector<ll>> &A, vector<vector<ll>> &B, ll n) { // Multiply the matrices 'A' and 'B' and store the result in 'A' itself vector<vector<ll>> C(n, vector<ll>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { C[i][j] = 0; for (int k = 0; k < n; k++) C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % M) % M; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) A[i][j] = C[i][j]; } void matrixExponentiation(vector<vector<ll>> &A, ll n, ll k) { if (k <= 1) return; if (k % 2 == 0) { matrixExponentiation(A, n, k / 2); multiply(A, A, n); } else { vector<vector<ll>> tempMatrix(A); matrixExponentiation(A, n, k - 1); multiply(A, tempMatrix, n); } } ll walkOptimized(vector<vector<ll>> &adj, ll n, ll K) { // 'adj' contains for each cell (i, j) the no. of ways to // reach from 'i' to 'j' in 1 step // Suppose If we have a matrix 'A', in which each cell // (i, j) denotes the number of paths from i to j in exactly 4 steps // Then if we multiply it with 'adj', then after multiplying we will get // a matrix in which for each cell (i, j) it stores the no. of ways // to reach from 'i' to 'j' in exactly 5 steps // Hence we just need to multiply 'adj' K times, i.e. // we need to find adj^K, then in the end take the sum of all values // in that matrix because the paths can start or end at any vertex // To quickly find this exponentiation, we can use matrix exponentiation matrixExponentiation(adj, n, K); ll ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans = (ans + adj[i][j]) % M; return ans; } int main() { ll n, k; cin >> n >> k; vector<vector<ll>> adj(n, vector<ll>(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> adj[i][j]; // ll ans = walk(adj, n, k); ll ans = walkOptimized(adj, n, k); cout << ans; return 0; }
replace
94
96
94
96
0
p03177
C++
Runtime Error
// #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second #define pb push_back #define REP(i, a, b) for (long long int i = a; i < b; i++) #define mp make_pair #define INF 1000000000000000000 #define mod 1000000007 #define pi pair<ll, ll> #define pd pair<ld, ld> #define vi vector<ll> #define vd vector<ld> #define vvi vector<vi> #define vvd vector<vd> #define vpi vector<pi> #define vpd vector<pd> #define us unordered_set<ll> #define um unordered_map<ll, ll> #define sortA(a) sort(a.begin(), a.end()) #define sortD(a) sort(a.begin(), a.end(), greater<ll>()) #define all(a) a.begin(), a.end() #define N 100005 #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define in insert #define fbo find_by_order #define ook order_of_key void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif ll powmod(ll x, ll y) { if (x == 0) return 0; if (y == 0 || x == 1) return 1; if (y % 2 == 0) return powmod((x * x) % mod, y / 2) % mod; return (x * powmod(x, y - 1) % mod) % mod; } vvi mul(vvi A, vvi B, ll m) { ll n = A.size(); vvi C(n, vi(n)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { for (ll k = 0; k < n; ++k) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; } } } return C; } // when n is integer vvi matexp(vvi M, ll n, ll m) { if (n == 0) { for (ll i = 0; i < (ll)M.size(); ++i) { fill(M[i].begin(), M[i].end(), 0); M[i][i] = 1; } return M; } if (n == 1) return M; if (n % 2 == 0) { return matexp(mul(M, M, m), n / 2, m); } else { return mul(M, matexp(M, n - 1, m), m); } } void solve() { ll n, k; cin >> n >> k; vvi a(n, vi(n)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { cin >> a[i][j]; } } vvi M = matexp(a, k, mod); ll ans = 0; for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { ans = (ans + M[i][j]) % mod; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1; // cin>>t; while (t--) { solve(); } }
// #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second #define pb push_back #define REP(i, a, b) for (long long int i = a; i < b; i++) #define mp make_pair #define INF 1000000000000000000 #define mod 1000000007 #define pi pair<ll, ll> #define pd pair<ld, ld> #define vi vector<ll> #define vd vector<ld> #define vvi vector<vi> #define vvd vector<vd> #define vpi vector<pi> #define vpd vector<pd> #define us unordered_set<ll> #define um unordered_map<ll, ll> #define sortA(a) sort(a.begin(), a.end()) #define sortD(a) sort(a.begin(), a.end(), greater<ll>()) #define all(a) a.begin(), a.end() #define N 100005 #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define in insert #define fbo find_by_order #define ook order_of_key void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif ll powmod(ll x, ll y) { if (x == 0) return 0; if (y == 0 || x == 1) return 1; if (y % 2 == 0) return powmod((x * x) % mod, y / 2) % mod; return (x * powmod(x, y - 1) % mod) % mod; } vvi mul(vvi A, vvi B, ll m) { ll n = A.size(); vvi C(n, vi(n)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { for (ll k = 0; k < n; ++k) { C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m; } } } return C; } // when n is integer vvi matexp(vvi M, ll n, ll m) { if (n == 0) { for (ll i = 0; i < (ll)M.size(); ++i) { fill(M[i].begin(), M[i].end(), 0); M[i][i] = 1; } return M; } if (n == 1) return M; if (n % 2 == 0) { return matexp(mul(M, M, m), n / 2, m); } else { return mul(M, matexp(M, n - 1, m), m); } } void solve() { ll n, k; cin >> n >> k; vvi a(n, vi(n)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { cin >> a[i][j]; } } vvi M = matexp(a, k, mod); ll ans = 0; for (ll i = 0; i < n; ++i) { for (ll j = 0; j < n; ++j) { ans = (ans + M[i][j]) % mod; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); ll t = 1; // cin>>t; while (t--) { solve(); } }
delete
140
144
140
140
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p03177
C++
Runtime Error
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // typedef typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // conversion inline LL toLong(string s) { LL v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) LL((a).size()) #define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define UNTIL(p) while (!(p)) // constant const double EPS = 1e-5; const double PI = acos(-1.0); // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; #define PUTS(x) cout << (x) << endl; const LL MOD = 1e9 + 7; const LL M = 100; LL n; vector<vector<LL>> link; LL dp[50][50][M] = {0}; map<LL, LL> memo[50][50]; LL f(LL i, LL j, LL k) { if (k < M) { return dp[i][j][k]; } if (EXIST(memo[i][j], k)) { return memo[i][j][k]; } LL x = k / 2; LL y = k - x; LL sum = 0; REP(t, n) { sum += (f(i, t, x) * f(t, j, y)) % MOD; sum %= MOD; } memo[i][j].insert(MP(k, sum)); return sum; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); LL k; cin >> n >> k; link.resize(n); REP(i, n) { REP(j, n) { LL a; cin >> a; if (a == 1) link[i].PB(j); } } REP(i, n) dp[i][i][0] = 1; REP(len, M) { REP(i, n) { for (LL to : link[i]) { REP(st, n) { dp[st][to][len + 1] += dp[st][i][len]; dp[st][to][len + 1] %= MOD; } } } } LL ans = 0; REP(i, n) REP(j, n) { ans += f(i, j, k); ans %= MOD; } PUTS(ans); }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // typedef typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // conversion inline LL toLong(string s) { LL v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) LL((a).size()) #define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define UNTIL(p) while (!(p)) // constant const double EPS = 1e-5; const double PI = acos(-1.0); // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; #define PUTS(x) cout << (x) << endl; const LL MOD = 1e9 + 7; const LL M = 100; LL n; vector<vector<LL>> link; LL dp[50][50][M + 1] = {0}; map<LL, LL> memo[50][50]; LL f(LL i, LL j, LL k) { if (k < M) { return dp[i][j][k]; } if (EXIST(memo[i][j], k)) { return memo[i][j][k]; } LL x = k / 2; LL y = k - x; LL sum = 0; REP(t, n) { sum += (f(i, t, x) * f(t, j, y)) % MOD; sum %= MOD; } memo[i][j].insert(MP(k, sum)); return sum; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); LL k; cin >> n >> k; link.resize(n); REP(i, n) { REP(j, n) { LL a; cin >> a; if (a == 1) link[i].PB(j); } } REP(i, n) dp[i][i][0] = 1; REP(len, M) { REP(i, n) { for (LL to : link[i]) { REP(st, n) { dp[st][to][len + 1] += dp[st][i][len]; dp[st][to][len + 1] %= MOD; } } } } LL ans = 0; REP(i, n) REP(j, n) { ans += f(i, j, k); ans %= MOD; } PUTS(ans); }
replace
80
81
80
81
0
p03177
C++
Runtime Error
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,sse2,sse3,sse4,mmx,tune=native") #include <cstring> #include <iostream> const int MAX_N = 50; using ull = unsigned long long; const int MOD = 1e9 + 7; int n; struct Matrix { int a[MAX_N][MAX_N]; Matrix() : a() {} inline Matrix &operator*=(const Matrix b) { register int i, j, k, l; register const int *p2; static ull tmp[MAX_N]; ull cur; for (i = 0; i < MAX_N; ++i) { memset(tmp, 0, sizeof(ull) * MAX_N); for (k = 0, l = (MAX_N & ~15); k < l;) { #define opt \ do { \ if (a[i][k]) { \ for (cur = a[i][k], p2 = b.a[k], j = 0; j < MAX_N; j++, p2++) \ tmp[j] += cur * (*p2); \ } \ k++; \ } while (0) opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; for (j = 0; j < MAX_N; j++) tmp[j] %= MOD; } for (; k < MAX_N;) { opt; } #undef opt for (j = 0; j < MAX_N; j++) a[i][j] = tmp[j] % MOD; } return *this; } }; inline int add(int x, int v) { return x + v >= MOD ? x + v - MOD : x + v; } inline Matrix power(Matrix &a, long long b) { Matrix ret; for (int i = 0; i < n; ++i) ret.a[i][i] = 1; for (; b; b >>= 1, a *= a) if (b & 1) ret *= a; return ret; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); Matrix a; long long k; std::cin >> n >> k; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) std::cin >> a.a[i][j]; auto ret = power(a, k); int ans = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) ans = add(ans, ret.a[i][j]); std::cout << ans; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,sse2,sse3,sse4,mmx,tune=native") #include <cstring> #include <iostream> const int MAX_N = 50; using ull = unsigned long long; const int MOD = 1e9 + 7; int n; struct Matrix { int a[MAX_N][MAX_N]; Matrix() : a() {} inline Matrix &operator*=(const Matrix b) { register int i, j, k, l; register const int *p2; static ull tmp[MAX_N]; ull cur; for (i = 0; i < MAX_N; ++i) { memset(tmp, 0, sizeof(ull) * MAX_N); for (k = 0, l = (MAX_N & ~15); k < l;) { #define opt \ do { \ if (a[i][k]) { \ for (cur = a[i][k], p2 = b.a[k], j = 0; j < MAX_N; j++, p2++) \ tmp[j] += cur * (*p2); \ } \ k++; \ } while (0) opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; opt; for (j = 0; j < MAX_N; j++) tmp[j] %= MOD; } for (; k < MAX_N;) { opt; } #undef opt for (j = 0; j < MAX_N; j++) a[i][j] = tmp[j] % MOD; } return *this; } }; inline int add(int x, int v) { return x + v >= MOD ? x + v - MOD : x + v; } inline Matrix power(Matrix &a, long long b) { Matrix ret; for (int i = 0; i < n; ++i) ret.a[i][i] = 1; for (; b; b >>= 1, a *= a) if (b & 1) ret *= a; return ret; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); Matrix a; long long k; std::cin >> n >> k; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) std::cin >> a.a[i][j]; auto ret = power(a, k); int ans = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) ans = add(ans, ret.a[i][j]); std::cout << ans; return 0; }
replace
1
2
1
2
0
p03177
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> // using namespace __gnu_pbds; using namespace std; // template <typename T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, // tree_order_statistics_node_update>; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") typedef long long int ll; const ll N = 1e6; // const ll m = 1e9 + 7; // const ll inf= 1e14; const ll mod = 1e9 + 7; const ll INF = 1e14; #define x first #define y second #define pb push_back #define mp make_pair #define pld pair<ld, ld> #define pll pair<ll, ll> #define pii pair<int, int> #define ld long double void mul(std::vector<vector<ll>> &a, std::vector<vector<ll>> b) { ll n = a.size(); std::vector<std::vector<ll>> c; c = a; // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // cout<<b[i][j]<<" "; // } // cout<<'\n'; // } // cout<<'\n'; // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // cout<<a[i][j]<<" "; // } // cout<<'\n'; // } // cout<<'\n'; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = 0; for (int k = 0; k < n; k++) { a[i][j] += c[i][k] * b[k][j]; a[i][j] %= mod; } } } // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // cout<<a[i][j]<<" "; // } // cout<<'\n'; // } // cout<<'\n'; } void matrix_exp(std::vector<vector<ll>> &mat, ll k) { std::vector<std::vector<ll>> te = mat; while (k) { // cout<<k<<'\n'; if (k % 2) { mul(mat, te); } k /= 2; mul(te, te); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; std::vector<vector<ll>> adj(n, vector<ll>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> adj[i][j]; } } matrix_exp(adj, k - 1); ll ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans += adj[i][j]; ans %= mod; } } cout << ans << '\n'; } }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> // using namespace __gnu_pbds; using namespace std; // template <typename T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, // tree_order_statistics_node_update>; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") typedef long long int ll; const ll N = 1e6; // const ll m = 1e9 + 7; // const ll inf= 1e14; const ll mod = 1e9 + 7; const ll INF = 1e14; #define x first #define y second #define pb push_back #define mp make_pair #define pld pair<ld, ld> #define pll pair<ll, ll> #define pii pair<int, int> #define ld long double void mul(std::vector<vector<ll>> &a, std::vector<vector<ll>> b) { ll n = a.size(); std::vector<std::vector<ll>> c; c = a; // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // cout<<b[i][j]<<" "; // } // cout<<'\n'; // } // cout<<'\n'; // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // cout<<a[i][j]<<" "; // } // cout<<'\n'; // } // cout<<'\n'; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = 0; for (int k = 0; k < n; k++) { a[i][j] += c[i][k] * b[k][j]; a[i][j] %= mod; } } } // for(int i = 0;i<n;i++){ // for(int j = 0;j<n;j++){ // cout<<a[i][j]<<" "; // } // cout<<'\n'; // } // cout<<'\n'; } void matrix_exp(std::vector<vector<ll>> &mat, ll k) { std::vector<std::vector<ll>> te = mat; while (k) { // cout<<k<<'\n'; if (k % 2) { mul(mat, te); } k /= 2; mul(te, te); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; std::vector<vector<ll>> adj(n, vector<ll>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> adj[i][j]; } } matrix_exp(adj, k - 1); ll ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans += adj[i][j]; ans %= mod; } } cout << ans << '\n'; } }
delete
79
84
79
79
-6
p03178
C++
Runtime Error
#include <iostream> using namespace std; #define in(v) \ v; \ cin >> v; #define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i) #define rrep(i, n) for (long long i = (n); i >= 0; --i) template <int MOD> struct MInt { long long val; constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; } MInt operator-() const { return MInt(-val); } MInt operator+(const MInt &n) const { return MInt(val) += n; } MInt operator-(const MInt &n) const { return MInt(val) -= n; } MInt &operator+=(const MInt &n) { val = (val + n.val) % MOD; return *this; } MInt &operator-=(const MInt &n) { val = (MOD + val - n.val) % MOD; return *this; } friend ostream &operator<<(ostream &os, const MInt &n) { os << n.val; return os; } friend istream &operator>>(istream &os, MInt &n) { os >> n.val; return os; } }; constexpr int MOD = 1e9 + 7; using mint = MInt<MOD>; string K; int D; constexpr int MAX_N = 10000, MAX_D = 100; mint dp[MAX_N][MAX_D][2]; int main() { cin >> K >> D; dp[K.size()][0][0] = dp[K.size()][0][1] = 1; rrep(i, K.size() - 1) rep(r, D) rep(lower, 2) { int n = K[i] - '0'; rep(j, (lower ? 9 : n) + 1) dp[i][r][lower] += dp[i + 1][(r + j) % D][lower || (j < n)]; } cout << dp[0][0][false] - 1 << endl; return 0; }
#include <iostream> using namespace std; #define in(v) \ v; \ cin >> v; #define rep(i, n) for (int i = 0, _i = (n); i < _i; ++i) #define rrep(i, n) for (long long i = (n); i >= 0; --i) template <int MOD> struct MInt { long long val; constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; } MInt operator-() const { return MInt(-val); } MInt operator+(const MInt &n) const { return MInt(val) += n; } MInt operator-(const MInt &n) const { return MInt(val) -= n; } MInt &operator+=(const MInt &n) { val = (val + n.val) % MOD; return *this; } MInt &operator-=(const MInt &n) { val = (MOD + val - n.val) % MOD; return *this; } friend ostream &operator<<(ostream &os, const MInt &n) { os << n.val; return os; } friend istream &operator>>(istream &os, MInt &n) { os >> n.val; return os; } }; constexpr int MOD = 1e9 + 7; using mint = MInt<MOD>; string K; int D; constexpr int MAX_N = 10000, MAX_D = 100; mint dp[MAX_N + 1][MAX_D][2]; int main() { cin >> K >> D; dp[K.size()][0][0] = dp[K.size()][0][1] = 1; rrep(i, K.size() - 1) rep(r, D) rep(lower, 2) { int n = K[i] - '0'; rep(j, (lower ? 9 : n) + 1) dp[i][r][lower] += dp[i + 1][(r + j) % D][lower || (j < n)]; } cout << dp[0][0][false] - 1 << endl; return 0; }
replace
40
41
40
41
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> #define endl '\n' #define left aba #define right abc #define oo if (LOG) #define pb push_back #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0) #ifdef LOCAL #define LOG 1 #else #define LOG 0 #endif using namespace std; const int DIG = 10005, MAXD = 105, MOD = (int)(1e9) + 7; string k; int d, n; inline void add(long long &aa, long long bb) { aa += bb; aa %= MOD; } long long dp[DIG][2][MAXD]; long long go(int pos, bool fl, int sum) { if (pos >= n) return sum % d == 0 ? 1 : 0; if (dp[pos][fl][sum % d] != -1) return dp[pos][fl][sum % d]; long long ret = 0; for (int i = 0; i <= 9; ++i) { if (fl || (!fl && i <= k[pos] - '0')) { long long nxt = go(pos + 1, fl | (i < k[pos] - '0'), sum + i); add(ret, nxt); } } return dp[pos][fl][sum % d] = ret; } int main() { FIO; cin >> k >> d; n = (int)k.size(); for (int i = 0; i < DIG; ++i) for (int j = 0; j < 2; ++j) for (int l = 0; l < MAXD; ++l) dp[i][j][l] = -1; long long ans = go(0, 0, 0) - 1; assert(ans >= 0); cout << ans << endl; oo cout << "Time: " << (double)clock() / CLOCKS_PER_SEC << "s" << endl; return 0; }
#include <bits/stdc++.h> #define endl '\n' #define left aba #define right abc #define oo if (LOG) #define pb push_back #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0) #ifdef LOCAL #define LOG 1 #else #define LOG 0 #endif using namespace std; const int DIG = 10005, MAXD = 105, MOD = (int)(1e9) + 7; string k; int d, n; inline void add(long long &aa, long long bb) { aa += bb; aa %= MOD; } long long dp[DIG][2][MAXD]; long long go(int pos, bool fl, int sum) { if (pos >= n) return sum % d == 0 ? 1 : 0; if (dp[pos][fl][sum % d] != -1) return dp[pos][fl][sum % d]; long long ret = 0; for (int i = 0; i <= 9; ++i) { if (fl || (!fl && i <= k[pos] - '0')) { long long nxt = go(pos + 1, fl | (i < k[pos] - '0'), sum + i); add(ret, nxt); } } return dp[pos][fl][sum % d] = ret; } int main() { FIO; cin >> k >> d; n = (int)k.size(); for (int i = 0; i < DIG; ++i) for (int j = 0; j < 2; ++j) for (int l = 0; l < MAXD; ++l) dp[i][j][l] = -1; long long ans = go(0, 0, 0) - 1; if (ans < 0) ans += MOD; cout << ans << endl; oo cout << "Time: " << (double)clock() / CLOCKS_PER_SEC << "s" << endl; return 0; }
replace
57
58
57
59
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long string k; ll n, d; const ll mod = 1e9 + 7; ll memo[100001][2][101]; ll go(ll pos, ll par, ll val) { if (pos == n) { if (val % d == 0) return 1; return 0; } if (memo[pos][par][val] != -1) return memo[pos][par][val]; ll ans = 0; if (par == 0) { for (ll i = 0; i < 10; i++) { ans += go(pos + 1, par, (val + i) % d); ans %= mod; } } else { ans += go(pos + 1, par, (val + k[pos] - '0' + d) % d); ans %= mod; for (ll i = 0; i < k[pos] - '0'; i++) { ans += go(pos + 1, 0, (val + i) % d); ans %= mod; } } return memo[pos][par][val] = ans; } int main() { #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 cin >> k >> d; memset(memo, -1, sizeof(memo)); n = k.size(); ll ans = (go(0, 1, 0) - 1 + mod) % mod; cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long string k; ll n, d; const ll mod = 1e9 + 7; ll memo[100001][2][101]; ll go(ll pos, ll par, ll val) { if (pos == n) { if (val % d == 0) return 1; return 0; } if (memo[pos][par][val] != -1) return memo[pos][par][val]; ll ans = 0; if (par == 0) { for (ll i = 0; i < 10; i++) { ans += go(pos + 1, par, (val + i) % d); ans %= mod; } } else { ans += go(pos + 1, par, (val + k[pos] - '0' + d) % d); ans %= mod; for (ll i = 0; i < k[pos] - '0'; i++) { ans += go(pos + 1, 0, (val + i) % d); ans %= mod; } } return memo[pos][par][val] = ans; } int main() { cin >> k >> d; memset(memo, -1, sizeof(memo)); n = k.size(); ll ans = (go(0, 1, 0) - 1 + mod) % mod; cout << ans; }
replace
33
39
33
34
-11
p03178
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define FOR(i, x, y) for (ll i = x; i < y; i++) #define MOD 1000000007 typedef long long ll; using namespace std; ll dp[1001][101]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; ll d; cin >> s >> d; dp[0][0] = 1; FOR(i, 1, s.size()) { FOR(j, 0, d) { dp[i][j] = 0; FOR(k, 0, 10) { dp[i][j] = (dp[i][j] + dp[i - 1][(j - k + 100 * d) % d]) % MOD; } } } ll ans = dp[s.size() - 1][0] - 1; ll pref = 0; FOR(j, 1, s[0] - '0') { ans = (ans + dp[s.size() - 1][(100000 * d - (pref + j)) % d]) % MOD; } pref += (s[0] - '0'); FOR(i, 1, s.size()) { FOR(j, 0, s[i] - '0') { ans = (ans + dp[s.size() - i - 1][(100000 * d - (pref + j)) % d]) % MOD; } pref += (s[i] - '0'); } ans += (pref % d == 0); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define FOR(i, x, y) for (ll i = x; i < y; i++) #define MOD 1000000007 typedef long long ll; using namespace std; ll dp[10001][101]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; ll d; cin >> s >> d; dp[0][0] = 1; FOR(i, 1, s.size()) { FOR(j, 0, d) { dp[i][j] = 0; FOR(k, 0, 10) { dp[i][j] = (dp[i][j] + dp[i - 1][(j - k + 100 * d) % d]) % MOD; } } } ll ans = dp[s.size() - 1][0] - 1; ll pref = 0; FOR(j, 1, s[0] - '0') { ans = (ans + dp[s.size() - 1][(100000 * d - (pref + j)) % d]) % MOD; } pref += (s[0] - '0'); FOR(i, 1, s.size()) { FOR(j, 0, s[i] - '0') { ans = (ans + dp[s.size() - i - 1][(100000 * d - (pref + j)) % d]) % MOD; } pref += (s[i] - '0'); } ans += (pref % d == 0); cout << ans << '\n'; return 0; }
replace
7
8
7
8
0
p03178
C++
Runtime Error
#pragma GCC optimize("O3") #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define M 1000000007 #define M2 998244353 #define ll long long #define pll pair<long, long> #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPI(i, a, b) for (ll i = b - 1; i >= a; i--) #define ff first #define ss second #define pb push_back #define db pop_back #define mp make_pair #define mt make_tuple #define g(a, b) get<a>(b) #define INF (ll)1e18 + 100 #define o_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define o_setll \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // member functions : // 1. order_of_key(k) : number of elements strictly lesser than k // 2. find_by_order(k) : k-th element in the set /*ll modI(ll a, ll m); ll gcd(ll a, ll b); ll powM(ll x, unsigned ll y, unsigned ll m); void pairsort(int a[], int b[], int n); void pairsortll(ll a[],ll b[],ll n); ll logint(ll x,ll y); ll gcd(ll x,ll y) { if(x==0) return y; return gcd(y%x,x); } ll powM(ll x,ll y,ll m) { if(y==0) return 1; ll p=powM(x,y/2,m)%m; p=(p*p)%m; return (y%2==0)?p:(x*p)%m; } ll modI(ll a, ll m) { return powM(a, m-2, m); } void pairsort(int a[],int b[],int n) { pair<int,int> v[n]; REP(i,0,n) { v[i].ff=a[i]; v[i].ss=b[i]; } sort(v,v+n); REP(i,0,n) { a[i]=v[i].ff; b[i]=v[i].ss; } } void pairsortll(ll a[],ll b[],ll n) { pair<ll,ll> v[n]; REP(i,0,n) { v[i].ff=a[i]; v[i].ss=b[i]; } sort(v,v+n); REP(i,0,n) { a[i]=v[i].ff; b[i]=v[i].ss; } } ll logint(ll x,ll y) { ll ans=0; ll a=1; for(ll i=0;i<=x;i++) { if(x<a) { return ans; } ans++; a*=y; } return -1; }*/ const int N = 1e4 + 5; ll dp[101][N][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // Hey, You // Don't practise these // easy questions. string s; int d; cin >> s >> d; int n = s.size(); memset(dp, 0, sizeof(dp)); REP(i, 0, 10) { if (i < s[0] - '0') { dp[i][0][0] = 1; // dp[i][0][0] %= M; } else if (i == s[0] - '0') { dp[i % d][0][1] = 1; // dp[i][0][1] %= M; } else { break; } } REP(i, 0, n - 1) { int z = s[i + 1] - '0'; REP(j, 0, d + 10) { REP(k, 0, 2) { if (k == 0) { REP(h, 0, 10) { dp[(j + h) % d][i + 1][0] += dp[j][i][0]; dp[(j + h) % d][i + 1][0] %= M; } } else { REP(h, 0, z) { dp[(j + h) % d][i + 1][0] += dp[j][i][k]; dp[(j + h) % d][i + 1][0] %= M; } dp[(j + z) % d][i + 1][1] += dp[j][i][k]; dp[(j + z) % d][i + 1][1] %= M; } } } } ll ans = 0; ans = (dp[0][n - 1][0] + dp[0][n - 1][1] - 1 + M) % M; cout << ans % M; }
#pragma GCC optimize("O3") #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define M 1000000007 #define M2 998244353 #define ll long long #define pll pair<long, long> #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPI(i, a, b) for (ll i = b - 1; i >= a; i--) #define ff first #define ss second #define pb push_back #define db pop_back #define mp make_pair #define mt make_tuple #define g(a, b) get<a>(b) #define INF (ll)1e18 + 100 #define o_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define o_setll \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // member functions : // 1. order_of_key(k) : number of elements strictly lesser than k // 2. find_by_order(k) : k-th element in the set /*ll modI(ll a, ll m); ll gcd(ll a, ll b); ll powM(ll x, unsigned ll y, unsigned ll m); void pairsort(int a[], int b[], int n); void pairsortll(ll a[],ll b[],ll n); ll logint(ll x,ll y); ll gcd(ll x,ll y) { if(x==0) return y; return gcd(y%x,x); } ll powM(ll x,ll y,ll m) { if(y==0) return 1; ll p=powM(x,y/2,m)%m; p=(p*p)%m; return (y%2==0)?p:(x*p)%m; } ll modI(ll a, ll m) { return powM(a, m-2, m); } void pairsort(int a[],int b[],int n) { pair<int,int> v[n]; REP(i,0,n) { v[i].ff=a[i]; v[i].ss=b[i]; } sort(v,v+n); REP(i,0,n) { a[i]=v[i].ff; b[i]=v[i].ss; } } void pairsortll(ll a[],ll b[],ll n) { pair<ll,ll> v[n]; REP(i,0,n) { v[i].ff=a[i]; v[i].ss=b[i]; } sort(v,v+n); REP(i,0,n) { a[i]=v[i].ff; b[i]=v[i].ss; } } ll logint(ll x,ll y) { ll ans=0; ll a=1; for(ll i=0;i<=x;i++) { if(x<a) { return ans; } ans++; a*=y; } return -1; }*/ const int N = 1e4 + 5; ll dp[101][N][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // Hey, You // Don't practise these // easy questions. string s; int d; cin >> s >> d; int n = s.size(); memset(dp, 0, sizeof(dp)); REP(i, 0, 10) { if (i < s[0] - '0') { dp[i][0][0] = 1; // dp[i][0][0] %= M; } else if (i == s[0] - '0') { dp[i % d][0][1] = 1; // dp[i][0][1] %= M; } else { break; } } REP(i, 0, n - 1) { int z = s[i + 1] - '0'; REP(j, 0, min(101, d + 10)) { REP(k, 0, 2) { if (k == 0) { REP(h, 0, 10) { dp[(j + h) % d][i + 1][0] += dp[j][i][0]; dp[(j + h) % d][i + 1][0] %= M; } } else { REP(h, 0, z) { dp[(j + h) % d][i + 1][0] += dp[j][i][k]; dp[(j + h) % d][i + 1][0] %= M; } dp[(j + z) % d][i + 1][1] += dp[j][i][k]; dp[(j + z) % d][i + 1][1] %= M; } } } } ll ans = 0; ans = (dp[0][n - 1][0] + dp[0][n - 1][1] - 1 + M) % M; cout << ans % M; }
replace
134
135
134
135
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") typedef long long ll; typedef pair<ll, ll> pr; typedef vector<ll> vc; typedef unordered_map<ll, ll> umap; #define pb emplace_back #define rep(i, a, b) for (ll i = a; i <= b; i++) #define repr(i, a, b) for (ll i = a; i >= b; i--) #define reps(i, v) for (ll i = 0; i < v.size(); i++) template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } const ll mod = 1e9 + 7; int main() { // your code goes here string k; ll n, d, pb, dp[105][1005] = {0}, sum[1005] = {0}; cin >> k >> d; n = k.size(); dp[0][0] = 1; rep(i, 1, n) { pb = k[i - 1] - '0'; sum[i] = (sum[i - 1] + pb) % d; rep(j, 0, d - 1) rep(k, 0, 9) dp[(j + k) % d][i] = (dp[(j + k) % d][i] + dp[j][i - 1]) % mod; rep(k, pb + 1, 9) dp[(sum[i - 1] + k) % d][i] = (dp[(sum[i - 1] + k) % d][i] - 1 + mod) % mod; } cout << (dp[0][n] - 1 + mod) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") typedef long long ll; typedef pair<ll, ll> pr; typedef vector<ll> vc; typedef unordered_map<ll, ll> umap; #define pb emplace_back #define rep(i, a, b) for (ll i = a; i <= b; i++) #define repr(i, a, b) for (ll i = a; i >= b; i--) #define reps(i, v) for (ll i = 0; i < v.size(); i++) template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } const ll mod = 1e9 + 7; int main() { // your code goes here string k; ll n, d, pb, dp[105][10005] = {0}, sum[1005] = {0}; cin >> k >> d; n = k.size(); dp[0][0] = 1; rep(i, 1, n) { pb = k[i - 1] - '0'; sum[i] = (sum[i - 1] + pb) % d; rep(j, 0, d - 1) rep(k, 0, 9) dp[(j + k) % d][i] = (dp[(j + k) % d][i] + dp[j][i - 1]) % mod; rep(k, pb + 1, 9) dp[(sum[i - 1] + k) % d][i] = (dp[(sum[i - 1] + k) % d][i] - 1 + mod) % mod; } cout << (dp[0][n] - 1 + mod) % mod << endl; return 0; }
replace
20
21
20
21
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define lsb(x) (x & -x) using namespace std; const int MOD = 1000000007; inline void mod(int &x) { if (x >= MOD) x -= MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); freopen("a.in", "r", stdin); string s; int d; cin >> s >> d; int ndigits = s.size(); vector<vector<int>> dp(d, vector<int>(ndigits + 1, 0)); dp[0][0] = 1; for (int i = 0; i < ndigits; i++) for (int r = 0; r < d; r++) for (int digit = 0; digit < 10; digit++) dp[(r + digit) % d][i + 1] = (dp[(r + digit) % d][i + 1] + dp[r][i]) % MOD; int ans = dp[0][ndigits - 1]; ans--; // il scot pe 0 if (ans < 0) ans += MOD; int sumofdigits = (d * 10 - (s[0] - '0')) % d; for (int digit = 1; digit < s[0] - '0'; digit++) { ans += dp[(d * 10 - digit) % d][ndigits - 1]; mod(ans); } for (int i = 1; i < s.size(); i++) { for (int digit = 0; digit < s[i] - '0'; digit++) { ans += dp[(sumofdigits + d * 10 - digit) % d][ndigits - i - 1]; mod(ans); } sumofdigits = (sumofdigits + d * 10 - (s[i] - '0')) % d; } if (sumofdigits == 0) { ans++; mod(ans); } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define lsb(x) (x & -x) using namespace std; const int MOD = 1000000007; inline void mod(int &x) { if (x >= MOD) x -= MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("a.in", "r", stdin); string s; int d; cin >> s >> d; int ndigits = s.size(); vector<vector<int>> dp(d, vector<int>(ndigits + 1, 0)); dp[0][0] = 1; for (int i = 0; i < ndigits; i++) for (int r = 0; r < d; r++) for (int digit = 0; digit < 10; digit++) dp[(r + digit) % d][i + 1] = (dp[(r + digit) % d][i + 1] + dp[r][i]) % MOD; int ans = dp[0][ndigits - 1]; ans--; // il scot pe 0 if (ans < 0) ans += MOD; int sumofdigits = (d * 10 - (s[0] - '0')) % d; for (int digit = 1; digit < s[0] - '0'; digit++) { ans += dp[(d * 10 - digit) % d][ndigits - 1]; mod(ans); } for (int i = 1; i < s.size(); i++) { for (int digit = 0; digit < s[i] - '0'; digit++) { ans += dp[(sumofdigits + d * 10 - digit) % d][ndigits - i - 1]; mod(ans); } sumofdigits = (sumofdigits + d * 10 - (s[i] - '0')) % d; } if (sumofdigits == 0) { ans++; mod(ans); } cout << ans; return 0; }
replace
18
19
18
19
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03178
C++
Runtime Error
#include <iostream> #include <string> using namespace std; typedef long long ll; const ll MOD = 1000000007; string K; int D; ll dp[10001][2][101]; // dp[i][j][k] := i - 1桁目(1-idx)まで決定済みで、これからi番目を決定する // jが1ならばKとスレスレの状態、0ならばそうでない // kはその時の各桁の和のmod D int main() { cin >> K >> D; dp[0][1][0] = 1; for (int i = 0; i <= K.size(); i++) { for (int j = 0; j < 2; j++) { for (int amari = 0; amari <= D; amari++) { dp[i][j][amari] %= MOD; int limit = j ? K[i] - '0' : 9; for (int keta_val = 0; keta_val <= limit; keta_val++) { dp[i + 1][(!j) ? 0 : ((keta_val == limit) ? 1 : 0)] [(amari + keta_val) % D] += dp[i][j][amari]; } } } } // 000...000はレグレーション違反なので、その分を引く cout << (dp[K.size()][0][0] + dp[K.size()][1][0] - 1 + MOD) % MOD << endl; return 0; }
#include <iostream> #include <string> using namespace std; typedef long long ll; const ll MOD = 1000000007; string K; int D; ll dp[10002][2][101]; // dp[i][j][k] := i - 1桁目(1-idx)まで決定済みで、これからi番目を決定する // jが1ならばKとスレスレの状態、0ならばそうでない // kはその時の各桁の和のmod D int main() { cin >> K >> D; dp[0][1][0] = 1; for (int i = 0; i <= K.size(); i++) { for (int j = 0; j < 2; j++) { for (int amari = 0; amari <= D; amari++) { dp[i][j][amari] %= MOD; int limit = j ? K[i] - '0' : 9; for (int keta_val = 0; keta_val <= limit; keta_val++) { dp[i + 1][(!j) ? 0 : ((keta_val == limit) ? 1 : 0)] [(amari + keta_val) % D] += dp[i][j][amari]; } } } } // 000...000はレグレーション違反なので、その分を引く cout << (dp[K.size()][0][0] + dp[K.size()][1][0] - 1 + MOD) % MOD << endl; return 0; }
replace
11
12
11
12
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define double /*long*/ double #define endl '\n' #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define vppll vector<pair<pll, pll>> #define mp make_pair #define pb push_back #define mapll map<ll, ll> #define fir first #define sec second #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define fo(i, b) for (i = 0; i < b; i++) #define repa(i, a, b) for (i = a; i < b; i++) #define repb(i, a, b) for (i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define s(v) v.size() const long long int MAX = (ll)(1e18 + 1); const long long int MIN = (ll)(-1e18 - 1); const long long int mod = (ll)(1e9 + 7); using namespace std; ll max(ll a, ll b, ll c) { return max(max(a, b), c); } ll min(ll a, ll b, ll c) { return min(min(a, b), c); } ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power_mod(ll a, ll n, ll mod_) { ll p = 1; while (n) { if (n % 2) { p = (p * a) % mod_; } n /= 2; a = (a * a) % mod_; } return p % mod_; } /*Code Begins*/ string s; ll d; ll dp[10000][100][2]; ll count(ll ind, ll sum, ll fl) { if (ind == s(s) and sum) return 0; if (ind == s(s) and sum == 0) return 1; if (dp[ind][sum][fl] >= 0) return dp[ind][sum][fl]; dp[ind][sum][fl] = 0; if (fl) { int x = s[ind] - '0', i; fo(i, x) { dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind + 1, (sum + i) % d, 0)) % mod; } dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind + 1, (sum + x) % d, 1)) % mod; } else { int i; fo(i, 10) { dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind + 1, (sum + i) % d, 0)) % mod; } } return dp[ind][sum][fl]; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif _cin; // cout << setprecision(15); ll mn = MAX, mx = MIN; ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0; ll x = 0, y = 0, fx, diff, tot = 0, l, r; int TC = 1; // cin >> TC; while (TC--) { cin >> s; cin >> d; fo(i, 10000) fo(j, 100) fo(k, 2) dp[i][j][k] = -1; cnt = (count(0, 0, 1) + mod - 1) % mod; cout << cnt; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define double /*long*/ double #define endl '\n' #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define vppll vector<pair<pll, pll>> #define mp make_pair #define pb push_back #define mapll map<ll, ll> #define fir first #define sec second #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define fo(i, b) for (i = 0; i < b; i++) #define repa(i, a, b) for (i = a; i < b; i++) #define repb(i, a, b) for (i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define s(v) v.size() const long long int MAX = (ll)(1e18 + 1); const long long int MIN = (ll)(-1e18 - 1); const long long int mod = (ll)(1e9 + 7); using namespace std; ll max(ll a, ll b, ll c) { return max(max(a, b), c); } ll min(ll a, ll b, ll c) { return min(min(a, b), c); } ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power_mod(ll a, ll n, ll mod_) { ll p = 1; while (n) { if (n % 2) { p = (p * a) % mod_; } n /= 2; a = (a * a) % mod_; } return p % mod_; } /*Code Begins*/ string s; ll d; ll dp[10000][100][2]; ll count(ll ind, ll sum, ll fl) { if (ind == s(s) and sum) return 0; if (ind == s(s) and sum == 0) return 1; if (dp[ind][sum][fl] >= 0) return dp[ind][sum][fl]; dp[ind][sum][fl] = 0; if (fl) { int x = s[ind] - '0', i; fo(i, x) { dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind + 1, (sum + i) % d, 0)) % mod; } dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind + 1, (sum + x) % d, 1)) % mod; } else { int i; fo(i, 10) { dp[ind][sum][fl] = (dp[ind][sum][fl] + count(ind + 1, (sum + i) % d, 0)) % mod; } } return dp[ind][sum][fl]; } int main() { _cin; // cout << setprecision(15); ll mn = MAX, mx = MIN; ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0; ll x = 0, y = 0, fx, diff, tot = 0, l, r; int TC = 1; // cin >> TC; while (TC--) { cin >> s; cin >> d; fo(i, 10000) fo(j, 100) fo(k, 2) dp[i][j][k] = -1; cnt = (count(0, 0, 1) + mod - 1) % mod; cout << cnt; } return 0; }
replace
85
90
85
86
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int ll d, dp[2002][2002][2][2], mod = 1e9 + 7; string a, b; ll rec(ll pos, ll rem, bool flag1, bool flag2) { if (dp[pos][rem][flag1][flag2] != -1) return dp[pos][rem][flag1][flag2]; if (pos == a.length()) return !rem; ll ans = 0, start1 = 0, end1 = 9; if (!flag1) start1 = a[pos] - '0'; if (!flag2) end1 = b[pos] - '0'; for (int i = start1; i <= end1; i++) { ans = (ans + rec(pos + 1, (rem + i) % d, (flag1 | i > start1), (flag2 | i < end1))) % mod; } return dp[pos][rem][flag1][flag2] = ans; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> b >> d; a = ""; for (int i = 0; i < b.length() - 1; i++) a += '0'; a += '1'; memset(dp, -1, sizeof(dp)); cout << rec(0, 0, 0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int const int MAXK = 10005; const int MAXD = 105; ll d, dp[MAXK][MAXD][2][2], mod = 1e9 + 7; string a, b; ll rec(ll pos, ll rem, bool flag1, bool flag2) { if (dp[pos][rem][flag1][flag2] != -1) return dp[pos][rem][flag1][flag2]; if (pos == a.length()) return !rem; ll ans = 0, start1 = 0, end1 = 9; if (!flag1) start1 = a[pos] - '0'; if (!flag2) end1 = b[pos] - '0'; for (int i = start1; i <= end1; i++) { ans = (ans + rec(pos + 1, (rem + i) % d, (flag1 | i > start1), (flag2 | i < end1))) % mod; } return dp[pos][rem][flag1][flag2] = ans; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> b >> d; a = ""; for (int i = 0; i < b.length() - 1; i++) a += '0'; a += '1'; memset(dp, -1, sizeof(dp)); cout << rec(0, 0, 0, 0) << endl; return 0; }
replace
5
6
5
9
-11
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void input() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll mod = 1000000007; string k; ll d; ll dp[10005][105][3]; ll recur(ll ind, ll rem, ll check) { if (ind == k.size() && rem == 0) { return 1; } if (ind == k.size()) return 0; if (dp[ind][rem][check] != -1) return dp[ind][rem][check]; ll ans = 0; if (check) { for (ll i = 0; i <= 9; i++) { ans = (ans + recur(ind + 1, (rem + i) % d, 1)) % mod; } } else { for (ll i = 0; i <= k[ind] - '0'; i++) { if (i < k[ind] - '0') ans = (ans + recur(ind + 1, (rem + i) % d, 1)) % mod; else ans = (ans + recur(ind + 1, (rem + i) % d, 0)) % mod; } } dp[ind][rem][check] = ans; return ans; } int main() { fastio(); input(); cin >> k >> d; memset(dp, -1, sizeof(dp)); ll ans = recur(0, 0, 0) - 1; if (ans < 0) ans += mod; cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long int void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void input() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll mod = 1000000007; string k; ll d; ll dp[10005][105][3]; ll recur(ll ind, ll rem, ll check) { if (ind == k.size() && rem == 0) { return 1; } if (ind == k.size()) return 0; if (dp[ind][rem][check] != -1) return dp[ind][rem][check]; ll ans = 0; if (check) { for (ll i = 0; i <= 9; i++) { ans = (ans + recur(ind + 1, (rem + i) % d, 1)) % mod; } } else { for (ll i = 0; i <= k[ind] - '0'; i++) { if (i < k[ind] - '0') ans = (ans + recur(ind + 1, (rem + i) % d, 1)) % mod; else ans = (ans + recur(ind + 1, (rem + i) % d, 0)) % mod; } } dp[ind][rem][check] = ans; return ans; } int main() { fastio(); cin >> k >> d; memset(dp, -1, sizeof(dp)); ll ans = recur(0, 0, 0) - 1; if (ans < 0) ans += mod; cout << ans; }
delete
51
52
51
51
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) const int N = 1e4, M = 7 + 1e9; int n, d, a[N], dp[N][101][2]; string s; vector<vector<int>> moves; int cal(int i, int sum, bool clicked) { if (i == n) return sum % d == 0; int &ret = dp[i][sum][clicked]; if (~ret) return ret; ret = 0; if (!clicked) { f(j, 0, s[i] - '0') ret = (ret + cal(i + 1, (sum + j) % d, 1)) % M; ret = (ret + cal(i + 1, (sum + s[i] - '0') % d, 0)) % M; } else f(j, 0, 10) ret = (ret + cal(i + 1, (sum + j) % d, 1)) % M; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif memset(dp, -1, sizeof dp); cin >> s >> d; n = (int)s.size(); cout << (cal(0, 0, 0) - 1 + M) % M; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) const int N = 1e4, M = 7 + 1e9; int n, d, a[N], dp[N][101][2]; string s; vector<vector<int>> moves; int cal(int i, int sum, bool clicked) { if (i == n) return sum % d == 0; int &ret = dp[i][sum][clicked]; if (~ret) return ret; ret = 0; if (!clicked) { f(j, 0, s[i] - '0') ret = (ret + cal(i + 1, (sum + j) % d, 1)) % M; ret = (ret + cal(i + 1, (sum + s[i] - '0') % d, 0)) % M; } else f(j, 0, 10) ret = (ret + cal(i + 1, (sum + j) % d, 1)) % M; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); memset(dp, -1, sizeof dp); cin >> s >> d; n = (int)s.size(); cout << (cal(0, 0, 0) - 1 + M) % M; }
delete
25
28
25
25
-8
p03178
C++
Runtime Error
//============================================================================ // Name : s // Date : Tue Mar 5 16:14:07 CST 2019 // Author : landcold7 // Description : Actions speak louder more than words //============================================================================ #include "bits/stdc++.h" using namespace std; #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define mst(x, y) memset(x, y, sizeof(x)) #define pvar(x) cout << #x << ": " #define fora(e, c) for (auto &e : c) #define fori(i, a, b) for (int i = a; i < b; ++i) #define ford(i, a, b) for (int i = a; i > b; --i) #define output(v) cout << (v) << '\n' #define jam(x, n) cout << "Case #" << x << ": " << n << "\n" #define prt(x, a, n) \ { \ cout << x[a]; \ if (a < n - 1) \ cout << " "; \ } #define par(x, s, n, v) \ if (v) \ pvar(x); \ fori(y, s, n) prt(x, y, n) cout << "\n" #ifndef __has_trace #define trace(...) #endif typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef vector<pii> vpii; const int mod = (int)1e9 + 7; // Digit dp problem void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } void solve() { string k; int d; cin >> k >> d; int n = sz(k); vvi dp(d, vi(2)); dp[0][0] = 1; fori(i, 0, n) { vvi new_dp(d, vi(2)); fori(sum, 0, d) { for (bool sm_already : {false, true}) { for (int digit = 0; digit < 10; ++digit) { if (digit > k[i] - '0' && !sm_already) { break; } bool small = sm_already || (digit < k[i] - '0'); // trace(sum, i, digit, sm_already, small); add(new_dp[(sum + digit) % d][small], dp[sum][sm_already]); } } } dp = new_dp; } int ret = (dp[0][0] + dp[0][1] - 1) % mod; if (!dp[0][0] && !dp[0][1]) { assert(ret == mod - 1); } output(ret); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
//============================================================================ // Name : s // Date : Tue Mar 5 16:14:07 CST 2019 // Author : landcold7 // Description : Actions speak louder more than words //============================================================================ #include "bits/stdc++.h" using namespace std; #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define mst(x, y) memset(x, y, sizeof(x)) #define pvar(x) cout << #x << ": " #define fora(e, c) for (auto &e : c) #define fori(i, a, b) for (int i = a; i < b; ++i) #define ford(i, a, b) for (int i = a; i > b; --i) #define output(v) cout << (v) << '\n' #define jam(x, n) cout << "Case #" << x << ": " << n << "\n" #define prt(x, a, n) \ { \ cout << x[a]; \ if (a < n - 1) \ cout << " "; \ } #define par(x, s, n, v) \ if (v) \ pvar(x); \ fori(y, s, n) prt(x, y, n) cout << "\n" #ifndef __has_trace #define trace(...) #endif typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef vector<pii> vpii; const int mod = (int)1e9 + 7; // Digit dp problem void add(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } void solve() { string k; int d; cin >> k >> d; int n = sz(k); vvi dp(d, vi(2)); dp[0][0] = 1; fori(i, 0, n) { vvi new_dp(d, vi(2)); fori(sum, 0, d) { for (bool sm_already : {false, true}) { for (int digit = 0; digit < 10; ++digit) { if (digit > k[i] - '0' && !sm_already) { break; } bool small = sm_already || (digit < k[i] - '0'); // trace(sum, i, digit, sm_already, small); add(new_dp[(sum + digit) % d][small], dp[sum][sm_already]); } } } dp = new_dp; } int ret = (dp[0][0] + dp[0][1] - 1 + mod) % mod; output(ret); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
replace
76
80
76
77
0
p03178
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define IOS \ cin.sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, a, b) for (int i = a; i <= b; i++) #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define mem(x) memset(x, 0, sizeof(x)) #define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define pai pair<int, int> #define pal pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vpai vector<pii> const int mod = 1e9 + 7; const int INF = INT_MAX; const int sze = 10001; ll dp[sze][101][2]; ll calc(string str, int pos, int d, int tight, int sum) { if (pos == (int)str.length()) { if (sum == 0) return 1; else return 0; } if (dp[pos][sum][tight] != -1) return dp[pos][sum][tight]; ll res = 0; if (tight == 1) { for (int i = 0; i <= str[pos] - '0'; i++) { if (i == str[pos] - '0') { res = (res + calc(str, pos + 1, d, 1, (sum + i) % d)) % mod; } else res = (res + calc(str, pos + 1, d, 0, (sum + i) % d)) % mod; } } else { for (int i = 0; i < 10; i++) res = (res + calc(str, pos + 1, d, 0, (sum + i) % d)) % mod; } return dp[pos][sum][tight] = res; } void solve() { string str; cin >> str; int d; cin >> d; memset(dp, -1, sizeof(dp)); cout << (calc(str, 0, d, 1, 0) - 1 + mod) % mod; } int main() { IOS; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ cin.sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, a, b) for (int i = a; i <= b; i++) #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define mem(x) memset(x, 0, sizeof(x)) #define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define pai pair<int, int> #define pal pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vpai vector<pii> const int mod = 1e9 + 7; const int INF = INT_MAX; const int sze = 10001; ll dp[sze][101][2]; ll calc(string str, int pos, int d, int tight, int sum) { if (pos == (int)str.length()) { if (sum == 0) return 1; else return 0; } if (dp[pos][sum][tight] != -1) return dp[pos][sum][tight]; ll res = 0; if (tight & 1) { for (int i = 0; i <= str[pos] - '0'; i++) { if (i == str[pos] - '0') { res = (res + calc(str, pos + 1, d, 1, (sum + i) % d)) % mod; } else res = (res + calc(str, pos + 1, d, 0, (sum + i) % d)) % mod; } } else { for (int i = 0; i < 10; i++) res = (res + calc(str, pos + 1, d, 0, (sum + i) % d)) % mod; } return dp[pos][sum][tight] = res; } void solve() { string str; cin >> str; int d; cin >> d; memset(dp, -1, sizeof(dp)); cout << (calc(str, 0, d, 1, 0) - 1 + mod) % mod; } int main() { IOS; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
41
42
41
42
TLE
p03178
C++
Runtime Error
#include <bits/stdc++.h> #define F first #define S second using namespace std; typedef long long LL; typedef pair<int, int> pii; const LL INF = 0x3f3f3f3f3f3f3f3fLL; const LL MOD = 1e9 + 7; LL dp[1005][105][2], D; vector<int> arr; LL solve(int i, int d, int op) { if (i == -1) return d == 0; if (~dp[i][d][op]) return dp[i][d][op]; dp[i][d][op] = 0; int up = op ? arr[i] : 9; for (int k = 0; k <= up; k++) (dp[i][d][op] += solve(i - 1, (d + k) % D, op && (k == arr[i]))) %= MOD; return dp[i][d][op]; } void marmot0814() { string s; cin >> s >> D; for (auto &c : s) arr.push_back(c - '0'); reverse(arr.begin(), arr.end()); memset(dp, -1, sizeof(dp)); cout << (solve(arr.size() - 1, 0, 1) + MOD - 1) % MOD << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1, kase = 0; // cin >> t; while (t--) { // cout << "Case #" << ++kase << ":"; marmot0814(); } }
#include <bits/stdc++.h> #define F first #define S second using namespace std; typedef long long LL; typedef pair<int, int> pii; const LL INF = 0x3f3f3f3f3f3f3f3fLL; const LL MOD = 1e9 + 7; LL dp[10005][105][2], D; vector<int> arr; LL solve(int i, int d, int op) { if (i == -1) return d == 0; if (~dp[i][d][op]) return dp[i][d][op]; dp[i][d][op] = 0; int up = op ? arr[i] : 9; for (int k = 0; k <= up; k++) (dp[i][d][op] += solve(i - 1, (d + k) % D, op && (k == arr[i]))) %= MOD; return dp[i][d][op]; } void marmot0814() { string s; cin >> s >> D; for (auto &c : s) arr.push_back(c - '0'); reverse(arr.begin(), arr.end()); memset(dp, -1, sizeof(dp)); cout << (solve(arr.size() - 1, 0, 1) + MOD - 1) % MOD << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1, kase = 0; // cin >> t; while (t--) { // cout << "Case #" << ++kase << ":"; marmot0814(); } }
replace
8
9
8
9
0
p03178
C++
Runtime Error
#include "bits/stdc++.h" #define all(x) (x).begin(), (x).end() using namespace std; const int MSIZE = 101; const long long mod = 1e9 + 7; long long dp[MSIZE][101]; void Precalc(int d) { memset(dp, 0, sizeof dp); dp[0][0] = 1; for (int i = 1; i < MSIZE; i++) { for (int c = 0; c < 10; c++) { for (int p = 0; p < d; p++) { int n = (c + p) % d; dp[i][n] += dp[i - 1][p]; dp[i][n] %= mod; } } } } long long Get(int len, int cur, int d) { return dp[len][(d - (cur % d)) % d]; } long long Get(string &arr, int d, int i, int n, int cur) { if (i == n) return (cur % d == 0); long long ans = 0; for (int dig = 0; dig < arr[i]; dig++) { ans += Get(n - 1 - i, cur + dig, d); ans %= mod; } ans += Get(arr, d, i + 1, n, cur + arr[i]); ans %= mod; return ans; } int main() { ios_base::sync_with_stdio(false); string k; cin >> k; int d; cin >> d; Precalc(d); for (char &ch : k) ch -= '0'; cout << (mod - 1 + Get(k, d, 0, k.size(), 0)) % mod << endl; }
#include "bits/stdc++.h" #define all(x) (x).begin(), (x).end() using namespace std; const int MSIZE = 10101; const long long mod = 1e9 + 7; long long dp[MSIZE][101]; void Precalc(int d) { memset(dp, 0, sizeof dp); dp[0][0] = 1; for (int i = 1; i < MSIZE; i++) { for (int c = 0; c < 10; c++) { for (int p = 0; p < d; p++) { int n = (c + p) % d; dp[i][n] += dp[i - 1][p]; dp[i][n] %= mod; } } } } long long Get(int len, int cur, int d) { return dp[len][(d - (cur % d)) % d]; } long long Get(string &arr, int d, int i, int n, int cur) { if (i == n) return (cur % d == 0); long long ans = 0; for (int dig = 0; dig < arr[i]; dig++) { ans += Get(n - 1 - i, cur + dig, d); ans %= mod; } ans += Get(arr, d, i + 1, n, cur + arr[i]); ans %= mod; return ans; } int main() { ios_base::sync_with_stdio(false); string k; cin >> k; int d; cin >> d; Precalc(d); for (char &ch : k) ch -= '0'; cout << (mod - 1 + Get(k, d, 0, k.size(), 0)) % mod << endl; }
replace
5
6
5
6
0
p03178
C++
Runtime Error
#include <iostream> #include <string.h> using namespace std; const int mod = 1000000007; int dp[12345][123]; string k; int a[123]; int l, d; long long ans; long long dfs(int pos, int site, bool flag) { // cout<<"POS:"<<pos<<" SITE:"<<site<<" FLAG:"<<flag<<endl; if (pos == l + 1) return dp[pos][site] = (site == 0); // site等于0,dp等于1 if (!flag && dp[pos][site] != -1) return dp[pos][site]; int len; if (flag) len = a[pos]; else len = 9; long long sum = 0; for (int i = 0; i <= len; ++i) { sum += dfs(pos + 1, (site + i) % d, flag && i == len); sum %= mod; } if (!flag) dp[pos][site] = sum; return sum; } int main() { memset(dp, -1, sizeof(dp)); cin >> k >> d; l = k.size(); for (int i = 1; i <= l; i++) { a[i] = k[i - 1] - '0'; } ans = (dfs(1, 0, true) - 1 + mod) % mod; cout << ans << endl; return 0; }
#include <iostream> #include <string.h> using namespace std; const int mod = 1000000007; int dp[12345][123]; string k; int a[12345]; int l, d; long long ans; long long dfs(int pos, int site, bool flag) { // cout<<"POS:"<<pos<<" SITE:"<<site<<" FLAG:"<<flag<<endl; if (pos == l + 1) return dp[pos][site] = (site == 0); // site等于0,dp等于1 if (!flag && dp[pos][site] != -1) return dp[pos][site]; int len; if (flag) len = a[pos]; else len = 9; long long sum = 0; for (int i = 0; i <= len; ++i) { sum += dfs(pos + 1, (site + i) % d, flag && i == len); sum %= mod; } if (!flag) dp[pos][site] = sum; return sum; } int main() { memset(dp, -1, sizeof(dp)); cin >> k >> d; l = k.size(); for (int i = 1; i <= l; i++) { a[i] = k[i - 1] - '0'; } ans = (dfs(1, 0, true) - 1 + mod) % mod; cout << ans << endl; return 0; }
replace
7
8
7
8
0
p03178
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 #define inf 1e18 #define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc) #define cin(t) \ int t; \ cin >> t #define w(t) while (t--) #define nl cout << endl; #define pii pair<int, int> #define mp make_pair #define pb push_back #define ft(i) (i & (-1 * i)) #define arrIn(arr, size) \ for (int i = 0; i < size; i++) { \ cin >> arr[i]; \ } #define arrOut(arr, size, seperater) \ for (int i = 0; i < size; i++) { \ cout << arr[i] << seperater; \ } using namespace std; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } int powmd(int a, int b) { if (b == 1) return a; if (b == 0) return 1; int half = powmd(a, b / 2); int ans = half * half; ans %= mod; if (b & 1) { ans *= a; } ans %= mod; return ans; } void fastIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int dp[10004][105][2]; int solve(string k, int d, int pos, int rem, int tight) { if (dp[pos][rem][tight] != -1) return dp[pos][rem][tight]; int up = (tight) ? (k[pos] - '0') : 9; int ans = 0; if (pos == k.length() - 1) { for (int i = 0; i <= up; i++) { if (rem == i % d) ans++; } return dp[pos][rem][tight] = ans; } for (int i = 0; i <= up; i++) { ans += solve(k, d, pos + 1, (d + rem - (i % d)) % d, (tight and (i == (k[pos] - '0')))); ans %= mod; } return dp[pos][rem][tight] = ans; } int32_t main() { fastIO(); string k; cin >> k; int d; cin >> d; memset(dp, -1, sizeof(dp)); cout << (solve(k, d, 0, 0, 1) - 1 + mod) % mod << endl; return 0; } // cout << "Case #" << i << ": " << answer << endl;
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 #define inf 1e18 #define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc) #define cin(t) \ int t; \ cin >> t #define w(t) while (t--) #define nl cout << endl; #define pii pair<int, int> #define mp make_pair #define pb push_back #define ft(i) (i & (-1 * i)) #define arrIn(arr, size) \ for (int i = 0; i < size; i++) { \ cin >> arr[i]; \ } #define arrOut(arr, size, seperater) \ for (int i = 0; i < size; i++) { \ cout << arr[i] << seperater; \ } using namespace std; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } int powmd(int a, int b) { if (b == 1) return a; if (b == 0) return 1; int half = powmd(a, b / 2); int ans = half * half; ans %= mod; if (b & 1) { ans *= a; } ans %= mod; return ans; } void fastIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int dp[10004][105][2]; int solve(string &k, int &d, int pos, int rem, int tight) { if (dp[pos][rem][tight] != -1) return dp[pos][rem][tight]; int up = (tight) ? (k[pos] - '0') : 9; int ans = 0; if (pos == k.length() - 1) { for (int i = 0; i <= up; i++) { if (rem == i % d) ans++; } return dp[pos][rem][tight] = ans; } for (int i = 0; i <= up; i++) { ans += solve(k, d, pos + 1, (d + rem - (i % d)) % d, (tight and (i == (k[pos] - '0')))); ans %= mod; } return dp[pos][rem][tight] = ans; } int32_t main() { fastIO(); string k; cin >> k; int d; cin >> d; memset(dp, -1, sizeof(dp)); cout << (solve(k, d, 0, 0, 1) - 1 + mod) % mod << endl; return 0; } // cout << "Case #" << i << ": " << answer << endl;
replace
60
61
60
61
TLE
p03178
C++
Time Limit Exceeded
// // // Codeforces: ganariya // AtCoder: ganariya2525 // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMHBYYYWMMMM#BYYTTTYWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB9O1==?????zzCC111>>;;;;;;;;;;;<?TMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM9Olll=l======??????????>>>>>>;;;;;;;;;:;?TMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMM9ttlllllllll=l=======?????????>>>>>>;;;;;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMBOttOtttttltlllllllll=======??????????>>>>>>>;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMBttwOtttttttttttttlllllllll========?????????>>>>>>;;;;;<TMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMBrwZrttttttttttttttttttlllllllllll======???????????>>>>>>;;?HMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMSw0trtrrtrtrttrtttttttttttttlllOllllll========????<<zz??>>>>>>ZMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMX0ttrtrOOttrttrttOOttttttttttttltwllllllllll========??wy?????>>>vZMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMM0ttrI+wV1rtttttttwZtttttttltttOwylOXOllllllllllll=l====1dkz???????vZdMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMSrrwrtwZCjttttttttwSttOlllltllllwtXOlZkOlllllllllllllll==z+dk===?????X2JMMMMMMMMMMMMM // MMMMMMMMMMMMMBrtwwtrw0<jttttttttOXllOttltllttllOZwHOtXkyltlllllllllllllll<+XZ======?dk?JMMMMMMMMMMMM // MMMMMMMMMMMMStwdZtwXC<+ttttttOOOd6ltZlltllllttllStWWOOHWytttttltltOllltllz:zHllll===zX=?dMMMMMMMMMMM // MMMMMMMMMMBrwdKOtwW3;;zrttttwZwXRlldOllltltlltttwlXvktdXWytltttttttOttlttl<<dklllllllZ===dMMMMMMMMMM // MMMMMMMMM8tQM#ttwW3;;;1trttwSwfUOlORltllltlllllldtX>dktDOWOtlttltttOOttltO<;+WOllllllXlllzMMMMMMMMMM // MMMMMMMM9OdM#Ottd$;;;;;<?1z0OKjRltd0llltOllllllldZX>?WOw_WWOtttttttttOttI<;;<dkttttllllllldMMMMMMMMM // MMMMMMM9wMMMSttwS<;;;;>;;;J<j>(I<?U111zltllllllld0X>~dkwl(WkttlttlOOwWk<;;:;;zHttttttwOllllMMMMMMMMM // MMMMMMBdMMM8tttdI+zttttttdSXt~dlzXwlllzzOzzzzzlldkW<~?kOk~?sx++++jdHmH6+++<;;jdZtttttdkOtlldMMMMMMMM // MMMMM#dMMM#tttw0+tttttttdKdf((RsdfRllllldZllltlldWK~~_W0w_~OWOlOdgg9ZtOWOtttz+wktttttdpktttwMMMMMMMM // MMMMMWMMMMSlttdIttttttOdWHH>~(IzWDRll=llzRlllzlldk$>++dkd<~_XkdgH9tttttdktttt+OkrttrtdfpkttOMMMMMMMM // MMMMNWMMM#Zttlk=tttttOXWWd$_.(IdW1R=llll=SlllzOldK<_._(kd6+-(MM9lltttttrWktttztWZttrwXppWttrMMMMMMMM // MMMMNMMMM#lltwDzttllOXyW0X:..(OXk<Rl=ll=lwOlllOld3<``.(Rd>~?CdklllltttttXdXttzOWktrwwWpfpkrtMMMMMMMM // MMMMMMMMM@ltldIzlttOXyW$w$```(OyD(Rl==llldZ=llIlw;~```-Xd:~~~~UkylltttAyHdgSrzObRtOXwpfppWrrMMMMMMMM // MMMMMMMMM@llldtlllldVyW+d>```.wZ$ wl==lI=wRl=ll=w<```` // dd_..~~(RZXOQdggHH9ZwrzwHWrdXXppfppkrMMMMMMMM // MMMMMMMMM#llldlltlwyyyD(S-...,Wk] zI=l=llzWzl=l=P~```` // jZ``...~zQkH@MBUtrZtrtldHRdSdpfpffpkwMMMMMMMM // MMMMNMMMMNZllXtllldVyW3(Mf=<ONMHP~(k===l=zdk=lld3```...(C````..(M96lttttrrtrrtdHWHXpfpppfpRwMMMMMMMM // MMMMMMMMMMNzzWZllzyyyy(W@` =~MWK6 jz=lzlzvRz=lZ`.I+JgkWm&-. // `..(ZltlttttrtttrWWHppfppfpppSdMMMMMMMM MMMMMMMMMMMkAWRllzVyyS_(b // .MNHU-(Uz=lI={XkzO>.dVT7<TMHMNHHx-.(kwZyltttrtrrdHHpfppfpffpp0dMMMMMMMM // MMMMMMMMMMMMKyWzOzyyyk.`<! hdWMH]``(S==t=l(kX2 ?_` // WMMHH#HH+.XwkwOttttrwrZ~(HfpfpppfpWwXMMMMMMMM MMMMMMMMMMMMMHWROOyyyW;` `. // (WVM#b```(0=zzz wX!``` a.dM#NM@N(4WhXkXkWtttttwd3O_(HpffpfpfWwSMMMMMMMM // MMMMMMMMMMMMNZvWzXXyyXP```-_ ?o+?!````.4=Z=`(:```` HpbNNMHHH // (C=XXyWZWttrdwf:(>.dfppffppSXSMMMMMMMM // MMMMMMMMMMMMMRzuHzXyZXH.``````````````` ?zz ``````` ZKvTHHbWt `` // XZyyHZWOdSZ<::~`(fpfpfffXp0WMMMMMMM // MMMMMMMMMMMMMKzyyHvyZZW____.`````````````.I_```````` // ?nJzX7^````.WXWyyHyWKZ<:::_`Jffpfpfpfp0WMMMMMMM // MMMMMMMMMMMMM@zZyZWwWyXo-_~(~ ```````````` `````````````` // _`````.WXkyyVWmWc::<~ .HffppfffffkXMMMMMMM // MMMMMMMMMMMMMKzZZZZXkUXr~....```````....```````````` ... // ````..JXWWyyW83vXx~..WfffVfWVffffkdMMMMMMM // MMMMMMMMMMMMMRzZZZZZZZZb````````````<````````````./<~._<_.____`(WfdyW3<:~~(XWkVVVVVVVHVVVVV0dMMMMMMM // MMMMMMMMMMMMMSzZZZZZZZWX-```````````````````````````.......~~._j9jX=_~~_(XZyVHHkyyyyWHyyykykOMMMMMMM // MMMMMMMMMMMMMSzuuuuuZXWZW,```````````````````````````````.``..(3<! // ...JWyyXWyyyWHkyyWHyyyHyklMMMMMMM MMMMMMMMMMMMNXzuuuXXuXSuuXh,```````` .... // ```````````````````_~ .JWyyyyZyy0HyyZyyZyZXWZZZWHZIdMMMMMM // MMMMMMMMMMMMNwtuuuXkuXXuuuuXh,``````(:::~<?71(,``````````````.(UMNUkZZZZZZZHZZ0ZZZZZWWZZZWNXIdMMMMMM // MMMMMMMMMMMMNKOzuzXkuXuuuuuXuXW, ```` // _~~~:~~(}```````````.(YC;::<kCfZZZZXO#ZZVZZZZZMZZuuMMNXzMMMMMM // MMMMMMMMMMMMHKOzzuXkzdzzzzuXXzuuU&.``````````````````` // .JY>::::;;J=:dZuZuZd#uuruuuud#uuuXMMMNXdMMMMM // MMMMMMMMMMMMMNOvzzXkvMRzzzzXKzuzzzXh, // `````````````..JC<;:;;:;;+7<:~(HHuXIdNuuzuuuXMSuuuWMMMMROMMMMM // MMMMMMMMMMMMMNvvvrdkvM#vzzzzHzzzzzuzzUG. ``` // ...JdY<:;:;:::;;+v<~~~:(HpHmzMNXZzuzzd#zzzdMMMMMMRdMMMM // MMMMMMMMMMMMMNwrrvdRrMNwvvvvdRvvvzwkzzzzXWWHY=~~O+::::::::<+<~~~~~~~dppppWMMkZzzzwM#zzdMMMMMMMMNMMMM // MMMMMMMMMMMMMM#rrrwRrMMbOrrOZNkrvvvXwvvvvvwX;.~._W_:::::(?!~~~~~~~~(HpppppppHWdvwM#XwdMMMMMMMMMMNMMM // MMMMMMMMMMMMMMNyrrrRrWMMmzOrzdNyrrrZNvrwQWWfb....(r~~_J>_.....~.~~-dpfpffpfpppWHHMNdMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMNrtrStdMMMNxzrzMNmrrrdNWfVfffP._-.(~_J!............JpfpffpfpfffpppWNppppHMMMMMMMMMMMM // MMMMMMMMMMMMMMMMNOtXtdMMMMMNxzZMMNmgHyVVVVVW%..?/(.,(x-..........(HfffpffpffpffWHHffpffppfVyyWMMMMMM // include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define SHOW_VECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOW_MAP(v) \ { \ std::cerr << #v << endl; \ for (const auto &xxx : v) { \ std::cerr << xxx.first << " " << xxx.second << "\n"; \ } \ } using LL = long long; //~~~~~~~~~~~~~~~~~~~~~_(^~^ 」 ∠)_~~~~~~~~~~~~~~~~~~~~~ constexpr LL mod = 1e9 + 7; LL dp[10100][2][110]; LL f(string S, LL D, LL k = 0, bool tight = true, LL sum = 0) { if (k == S.size()) { return dp[k][tight][sum] = (sum == 0); } int x = S[k] - '0'; int r = tight ? x : 9; LL &ret = dp[k][tight][sum]; if (~ret) return ret; ret = 0; for (int i = 0; i <= r; i++) { ret += f(S, D, k + 1, tight && i == r, (sum + i) % D); ret %= mod; } return ret; } int main() { string K; LL D; cin >> K >> D; memset(dp, -1, sizeof(dp)); f(K, D); cout << (dp[0][0][0] + dp[0][1][0] + mod) % mod; return 0; }
// // // Codeforces: ganariya // AtCoder: ganariya2525 // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMHBYYYWMMMM#BYYTTTYWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMB9O1==?????zzCC111>>;;;;;;;;;;;<?TMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM9Olll=l======??????????>>>>>>;;;;;;;;;:;?TMMMMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMMMM9ttlllllllll=l=======?????????>>>>>>;;;;;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMMMBOttOtttttltlllllllll=======??????????>>>>>>>;;;;;;?TMMMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMMMBttwOtttttttttttttlllllllll========?????????>>>>>>;;;;;<TMMMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMMBrwZrttttttttttttttttttlllllllllll======???????????>>>>>>;;?HMMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMMSw0trtrrtrtrttrtttttttttttttlllOllllll========????<<zz??>>>>>>ZMMMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMMMX0ttrtrOOttrttrttOOttttttttttttltwllllllllll========??wy?????>>>vZMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMMM0ttrI+wV1rtttttttwZtttttttltttOwylOXOllllllllllll=l====1dkz???????vZdMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMSrrwrtwZCjttttttttwSttOlllltllllwtXOlZkOlllllllllllllll==z+dk===?????X2JMMMMMMMMMMMMM // MMMMMMMMMMMMMBrtwwtrw0<jttttttttOXllOttltllttllOZwHOtXkyltlllllllllllllll<+XZ======?dk?JMMMMMMMMMMMM // MMMMMMMMMMMMStwdZtwXC<+ttttttOOOd6ltZlltllllttllStWWOOHWytttttltltOllltllz:zHllll===zX=?dMMMMMMMMMMM // MMMMMMMMMMBrwdKOtwW3;;zrttttwZwXRlldOllltltlltttwlXvktdXWytltttttttOttlttl<<dklllllllZ===dMMMMMMMMMM // MMMMMMMMM8tQM#ttwW3;;;1trttwSwfUOlORltllltlllllldtX>dktDOWOtlttltttOOttltO<;+WOllllllXlllzMMMMMMMMMM // MMMMMMMM9OdM#Ottd$;;;;;<?1z0OKjRltd0llltOllllllldZX>?WOw_WWOtttttttttOttI<;;<dkttttllllllldMMMMMMMMM // MMMMMMM9wMMMSttwS<;;;;>;;;J<j>(I<?U111zltllllllld0X>~dkwl(WkttlttlOOwWk<;;:;;zHttttttwOllllMMMMMMMMM // MMMMMMBdMMM8tttdI+zttttttdSXt~dlzXwlllzzOzzzzzlldkW<~?kOk~?sx++++jdHmH6+++<;;jdZtttttdkOtlldMMMMMMMM // MMMMM#dMMM#tttw0+tttttttdKdf((RsdfRllllldZllltlldWK~~_W0w_~OWOlOdgg9ZtOWOtttz+wktttttdpktttwMMMMMMMM // MMMMMWMMMMSlttdIttttttOdWHH>~(IzWDRll=llzRlllzlldk$>++dkd<~_XkdgH9tttttdktttt+OkrttrtdfpkttOMMMMMMMM // MMMMNWMMM#Zttlk=tttttOXWWd$_.(IdW1R=llll=SlllzOldK<_._(kd6+-(MM9lltttttrWktttztWZttrwXppWttrMMMMMMMM // MMMMNMMMM#lltwDzttllOXyW0X:..(OXk<Rl=ll=lwOlllOld3<``.(Rd>~?CdklllltttttXdXttzOWktrwwWpfpkrtMMMMMMMM // MMMMMMMMM@ltldIzlttOXyW$w$```(OyD(Rl==llldZ=llIlw;~```-Xd:~~~~UkylltttAyHdgSrzObRtOXwpfppWrrMMMMMMMM // MMMMMMMMM@llldtlllldVyW+d>```.wZ$ wl==lI=wRl=ll=w<```` // dd_..~~(RZXOQdggHH9ZwrzwHWrdXXppfppkrMMMMMMMM // MMMMMMMMM#llldlltlwyyyD(S-...,Wk] zI=l=llzWzl=l=P~```` // jZ``...~zQkH@MBUtrZtrtldHRdSdpfpffpkwMMMMMMMM // MMMMNMMMMNZllXtllldVyW3(Mf=<ONMHP~(k===l=zdk=lld3```...(C````..(M96lttttrrtrrtdHWHXpfpppfpRwMMMMMMMM // MMMMMMMMMMNzzWZllzyyyy(W@` =~MWK6 jz=lzlzvRz=lZ`.I+JgkWm&-. // `..(ZltlttttrtttrWWHppfppfpppSdMMMMMMMM MMMMMMMMMMMkAWRllzVyyS_(b // .MNHU-(Uz=lI={XkzO>.dVT7<TMHMNHHx-.(kwZyltttrtrrdHHpfppfpffpp0dMMMMMMMM // MMMMMMMMMMMMKyWzOzyyyk.`<! hdWMH]``(S==t=l(kX2 ?_` // WMMHH#HH+.XwkwOttttrwrZ~(HfpfpppfpWwXMMMMMMMM MMMMMMMMMMMMMHWROOyyyW;` `. // (WVM#b```(0=zzz wX!``` a.dM#NM@N(4WhXkXkWtttttwd3O_(HpffpfpfWwSMMMMMMMM // MMMMMMMMMMMMNZvWzXXyyXP```-_ ?o+?!````.4=Z=`(:```` HpbNNMHHH // (C=XXyWZWttrdwf:(>.dfppffppSXSMMMMMMMM // MMMMMMMMMMMMMRzuHzXyZXH.``````````````` ?zz ``````` ZKvTHHbWt `` // XZyyHZWOdSZ<::~`(fpfpfffXp0WMMMMMMM // MMMMMMMMMMMMMKzyyHvyZZW____.`````````````.I_```````` // ?nJzX7^````.WXWyyHyWKZ<:::_`Jffpfpfpfp0WMMMMMMM // MMMMMMMMMMMMM@zZyZWwWyXo-_~(~ ```````````` `````````````` // _`````.WXkyyVWmWc::<~ .HffppfffffkXMMMMMMM // MMMMMMMMMMMMMKzZZZZXkUXr~....```````....```````````` ... // ````..JXWWyyW83vXx~..WfffVfWVffffkdMMMMMMM // MMMMMMMMMMMMMRzZZZZZZZZb````````````<````````````./<~._<_.____`(WfdyW3<:~~(XWkVVVVVVVHVVVVV0dMMMMMMM // MMMMMMMMMMMMMSzZZZZZZZWX-```````````````````````````.......~~._j9jX=_~~_(XZyVHHkyyyyWHyyykykOMMMMMMM // MMMMMMMMMMMMMSzuuuuuZXWZW,```````````````````````````````.``..(3<! // ...JWyyXWyyyWHkyyWHyyyHyklMMMMMMM MMMMMMMMMMMMNXzuuuXXuXSuuXh,```````` .... // ```````````````````_~ .JWyyyyZyy0HyyZyyZyZXWZZZWHZIdMMMMMM // MMMMMMMMMMMMNwtuuuXkuXXuuuuXh,``````(:::~<?71(,``````````````.(UMNUkZZZZZZZHZZ0ZZZZZWWZZZWNXIdMMMMMM // MMMMMMMMMMMMNKOzuzXkuXuuuuuXuXW, ```` // _~~~:~~(}```````````.(YC;::<kCfZZZZXO#ZZVZZZZZMZZuuMMNXzMMMMMM // MMMMMMMMMMMMHKOzzuXkzdzzzzuXXzuuU&.``````````````````` // .JY>::::;;J=:dZuZuZd#uuruuuud#uuuXMMMNXdMMMMM // MMMMMMMMMMMMMNOvzzXkvMRzzzzXKzuzzzXh, // `````````````..JC<;:;;:;;+7<:~(HHuXIdNuuzuuuXMSuuuWMMMMROMMMMM // MMMMMMMMMMMMMNvvvrdkvM#vzzzzHzzzzzuzzUG. ``` // ...JdY<:;:;:::;;+v<~~~:(HpHmzMNXZzuzzd#zzzdMMMMMMRdMMMM // MMMMMMMMMMMMMNwrrvdRrMNwvvvvdRvvvzwkzzzzXWWHY=~~O+::::::::<+<~~~~~~~dppppWMMkZzzzwM#zzdMMMMMMMMNMMMM // MMMMMMMMMMMMMM#rrrwRrMMbOrrOZNkrvvvXwvvvvvwX;.~._W_:::::(?!~~~~~~~~(HpppppppHWdvwM#XwdMMMMMMMMMMNMMM // MMMMMMMMMMMMMMNyrrrRrWMMmzOrzdNyrrrZNvrwQWWfb....(r~~_J>_.....~.~~-dpfpffpfpppWHHMNdMMMMMMMMMMMMMMMM // MMMMMMMMMMMMMMMNrtrStdMMMNxzrzMNmrrrdNWfVfffP._-.(~_J!............JpfpffpfpfffpppWNppppHMMMMMMMMMMMM // MMMMMMMMMMMMMMMMNOtXtdMMMMMNxzZMMNmgHyVVVVVW%..?/(.,(x-..........(HfffpffpffpffWHHffpffppfVyyWMMMMMM // include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define SHOW_VECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOW_MAP(v) \ { \ std::cerr << #v << endl; \ for (const auto &xxx : v) { \ std::cerr << xxx.first << " " << xxx.second << "\n"; \ } \ } using LL = long long; //~~~~~~~~~~~~~~~~~~~~~_(^~^ 」 ∠)_~~~~~~~~~~~~~~~~~~~~~ constexpr LL mod = 1e9 + 7; LL dp[10100][2][110]; LL f(string &S, LL D, LL k = 0, bool tight = true, LL sum = 0) { if (k == S.size()) { return dp[k][tight][sum] = (sum == 0); } int x = S[k] - '0'; int r = tight ? x : 9; LL &ret = dp[k][tight][sum]; if (~ret) return ret; ret = 0; for (int i = 0; i <= r; i++) { ret += f(S, D, k + 1, tight && i == r, (sum + i) % D); ret %= mod; } return ret; } int main() { string K; LL D; cin >> K >> D; memset(dp, -1, sizeof(dp)); f(K, D); cout << (dp[0][0][0] + dp[0][1][0] + mod) % mod; return 0; }
replace
130
131
130
131
TLE
p03178
C++
Runtime Error
#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'; }
replace
41
42
41
42
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod = 1000000007; string k; ll d; ll dp[10000][100][2]; ll solve(ll n, ll md, ll s) { if ((n == k.length()) && (md == 0)) return 1; if (n == k.length()) return 0; if (dp[n][md][s] != -1) return dp[n][md][s]; dp[n][md][s] = 0; int mx = (s == 0 ? k[n] : '9') - '0'; for (ll i = 0; i <= mx; i++) { ll nmd = (md + i) % d; ll ns = (s || (i < mx)) ? 1 : 0; dp[n][md][s] = (dp[n][md][s] + solve(n + 1, nmd, ns)) % mod; } return dp[n][md][s]; } int main() { cin >> k >> d; for (ll i = 0; i <= k.length(); i++) for (ll j = 0; j < d; j++) dp[i][j][0] = dp[i][j][1] = -1; cout << ((solve(0, 0, 0) + mod - 1) % mod) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll mod = 1000000007; string k; ll d; ll dp[20000][500][2]; ll solve(ll n, ll md, ll s) { if ((n == k.length()) && (md == 0)) return 1; if (n == k.length()) return 0; if (dp[n][md][s] != -1) return dp[n][md][s]; dp[n][md][s] = 0; int mx = (s == 0 ? k[n] : '9') - '0'; for (ll i = 0; i <= mx; i++) { ll nmd = (md + i) % d; ll ns = (s || (i < mx)) ? 1 : 0; dp[n][md][s] = (dp[n][md][s] + solve(n + 1, nmd, ns)) % mod; } return dp[n][md][s]; } int main() { cin >> k >> d; for (ll i = 0; i <= k.length(); i++) for (ll j = 0; j < d; j++) dp[i][j][0] = dp[i][j][1] = -1; cout << ((solve(0, 0, 0) + mod - 1) % mod) << endl; }
replace
6
7
6
7
0
p03178
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long; const int nax = 10123; char k[nax]; const int mod = 1e9 + 7; void add_self(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } int modder(int x, int moddi) { if (x >= moddi) return x - moddi; return x; } int main() { scanf("%s", k); int D; scanf("%d", &D); int len = strlen(k); vector<array<int, 2>> dp(D, array<int, 2>{}); vector<array<int, 2>> new_dp(D, array<int, 2>{}); // dp[sum][smaller_already] - the number of ways to choose digits so far // such that the sum of digits modulo D is 'sum' and 'smaller_already' // says whether we already chosen some digit smaller than in K dp[0][0] = 1; for (int where = 0; where < len; ++where) { fill(new_dp.begin(), new_dp.end(), array<int, 2>{}); for (int sum = 0; sum < D; ++sum) { int sum2 = sum % D; for (bool sm_already : {false, true}) { for (int digit = 0; digit < 10; ++digit) { if (digit > k[where] - '0' && !sm_already) { break; } add_self(new_dp[modder(sum2 + digit, D)] [sm_already || (digit < k[where] - '0')], dp[sum][sm_already]); } } } swap(dp, new_dp); } int answer = (dp[0][false] + dp[0][true]) % mod; --answer; if (answer == -1) { answer = mod - 1; } printf("%d\n", answer); }
#include "bits/stdc++.h" using namespace std; #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long; const int nax = 10123; char k[nax]; const int mod = 1e9 + 7; void add_self(int &a, int b) { a += b; if (a >= mod) { a -= mod; } } int modder(int x, int moddi) { while (x >= moddi) x -= moddi; return x; } int main() { scanf("%s", k); int D; scanf("%d", &D); int len = strlen(k); vector<array<int, 2>> dp(D, array<int, 2>{}); vector<array<int, 2>> new_dp(D, array<int, 2>{}); // dp[sum][smaller_already] - the number of ways to choose digits so far // such that the sum of digits modulo D is 'sum' and 'smaller_already' // says whether we already chosen some digit smaller than in K dp[0][0] = 1; for (int where = 0; where < len; ++where) { fill(new_dp.begin(), new_dp.end(), array<int, 2>{}); for (int sum = 0; sum < D; ++sum) { int sum2 = sum % D; for (bool sm_already : {false, true}) { for (int digit = 0; digit < 10; ++digit) { if (digit > k[where] - '0' && !sm_already) { break; } add_self(new_dp[modder(sum2 + digit, D)] [sm_already || (digit < k[where] - '0')], dp[sum][sm_already]); } } } swap(dp, new_dp); } int answer = (dp[0][false] + dp[0][true]) % mod; --answer; if (answer == -1) { answer = mod - 1; } printf("%d\n", answer); }
replace
51
53
51
53
-6
double free or corruption (out)
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; int dp[10001][10][2]; int solve(string &K, int &D, int pos, int d, bool tight) { if (dp[pos][d][tight] != -1) return dp[pos][d][tight]; int ub = (tight) ? (K[pos] - '0') : 9; int len = K.length() - 1; if (pos == len) { int ans = 0; for (int x = 0; x <= ub; x++) if (x % D == d) ans++; return ans; } int ans = 0; for (int x = 0; x <= ub; x++) ans = (ans + solve(K, D, pos + 1, (D + d - x % D) % D, tight && (x == ub))) % mod; return dp[pos][d][tight] = ans; } int32_t main() { string K; int D; cin >> K >> D; memset(dp, -1, sizeof dp); cout << (mod + solve(K, D, 0, 0, 1) - 1) % mod; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; int dp[10001][101][2]; int solve(string &K, int &D, int pos, int d, bool tight) { if (dp[pos][d][tight] != -1) return dp[pos][d][tight]; int ub = (tight) ? (K[pos] - '0') : 9; int len = K.length() - 1; if (pos == len) { int ans = 0; for (int x = 0; x <= ub; x++) if (x % D == d) ans++; return ans; } int ans = 0; for (int x = 0; x <= ub; x++) ans = (ans + solve(K, D, pos + 1, (D + d - x % D) % D, tight && (x == ub))) % mod; return dp[pos][d][tight] = ans; } int32_t main() { string K; int D; cin >> K >> D; memset(dp, -1, sizeof dp); cout << (mod + solve(K, D, 0, 0, 1) - 1) % mod; return 0; }
replace
4
5
4
5
0
p03178
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using namespace placeholders; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<vector<int>>; using VS = vector<string>; using ISS = istringstream; using OSS = ostringstream; using PII = pair<int, int>; using VPII = vector<pair<int, int>>; template <typename T = int> using VT = vector<T>; template <typename T = int> using VVT = vector<vector<T>>; template <typename T = int> using LIM = numeric_limits<T>; template <typename T> inline istream &operator>>(istream &s, vector<T> &v) { for (T &t : v) { s >> t; } return s; } template <typename T> inline ostream &operator<<(ostream &s, const vector<T> &v) { for (int i = 0; i < int(v.size()); ++i) { s << (" " + !i) << v[i]; } return s; } void in_impl(){}; template <typename T, typename... TS> void in_impl(T &head, TS &...tail) { cin >> head; in_impl(tail...); } #define IN(T, ...) \ T __VA_ARGS__; \ in_impl(__VA_ARGS__); template <typename T> struct getv_fmt; template <> struct getv_fmt<int> { static constexpr const char *fmt = "%d"; }; template <> struct getv_fmt<long long> { static constexpr const char *fmt = "%lld"; }; template <typename T> void getv(std::vector<T> &v) { for_each(begin(v), end(v), [](T &a) { scanf(getv_fmt<T>::fmt, &a); }); }; template <typename T> inline T fromString(const string &s) { T res; istringstream iss(s); iss >> res; return res; } template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); } #define NUMBERED(name, number) NUMBERED2(name, number) #define NUMBERED2(name, number) name##_##number #define REP1(n) REP2(NUMBERED(REP_COUNTER, __LINE__), n) #define REP2(i, n) REP3(i, 0, n) #define REP3(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define GET_REP(a, b, c, F, ...) F #define REP(...) GET_REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__) #define FOR(e, c) for (auto &&e : c) #define ALL(c) begin(c), end(c) #define AALL(a) \ (remove_all_extents<decltype(a)>::type *)a, \ (remove_all_extents<decltype(a)>::type *)a + \ sizeof(a) / sizeof(remove_all_extents<decltype(a)>::type) #define DRANGE(c, p) begin(c), begin(c) + (p), end(c) #define SZ(v) ((int)(v).size()) #define EXIST(c, e) ((c).find(e) != (c).end()) template <typename T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } #define PB push_back #define EM emplace #define EB emplace_back #define BI back_inserter #define MP make_pair #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl constexpr int MOD = 1'000'000'007; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12) << fixed; IN(string, K); IN(int, M); const int L = SZ(K); static int dp[1 << 13][128][2]; dp[0][0][0] = 1; REP(i, L) { const int D = K[i] - '0'; REP(j, M) { REP(k, 2) { REP(d, k ? 10 : D + 1) { const int nj = (j + d) % M; const int nk = k || d < D; (dp[i + 1][nj][nk] += dp[i][j][k]) %= MOD; } } } } cout << (LL(dp[L][0][0]) + dp[L][0][1] + (MOD - 1)) % MOD << endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using namespace placeholders; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<vector<int>>; using VS = vector<string>; using ISS = istringstream; using OSS = ostringstream; using PII = pair<int, int>; using VPII = vector<pair<int, int>>; template <typename T = int> using VT = vector<T>; template <typename T = int> using VVT = vector<vector<T>>; template <typename T = int> using LIM = numeric_limits<T>; template <typename T> inline istream &operator>>(istream &s, vector<T> &v) { for (T &t : v) { s >> t; } return s; } template <typename T> inline ostream &operator<<(ostream &s, const vector<T> &v) { for (int i = 0; i < int(v.size()); ++i) { s << (" " + !i) << v[i]; } return s; } void in_impl(){}; template <typename T, typename... TS> void in_impl(T &head, TS &...tail) { cin >> head; in_impl(tail...); } #define IN(T, ...) \ T __VA_ARGS__; \ in_impl(__VA_ARGS__); template <typename T> struct getv_fmt; template <> struct getv_fmt<int> { static constexpr const char *fmt = "%d"; }; template <> struct getv_fmt<long long> { static constexpr const char *fmt = "%lld"; }; template <typename T> void getv(std::vector<T> &v) { for_each(begin(v), end(v), [](T &a) { scanf(getv_fmt<T>::fmt, &a); }); }; template <typename T> inline T fromString(const string &s) { T res; istringstream iss(s); iss >> res; return res; } template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); } #define NUMBERED(name, number) NUMBERED2(name, number) #define NUMBERED2(name, number) name##_##number #define REP1(n) REP2(NUMBERED(REP_COUNTER, __LINE__), n) #define REP2(i, n) REP3(i, 0, n) #define REP3(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define GET_REP(a, b, c, F, ...) F #define REP(...) GET_REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__) #define FOR(e, c) for (auto &&e : c) #define ALL(c) begin(c), end(c) #define AALL(a) \ (remove_all_extents<decltype(a)>::type *)a, \ (remove_all_extents<decltype(a)>::type *)a + \ sizeof(a) / sizeof(remove_all_extents<decltype(a)>::type) #define DRANGE(c, p) begin(c), begin(c) + (p), end(c) #define SZ(v) ((int)(v).size()) #define EXIST(c, e) ((c).find(e) != (c).end()) template <typename T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } #define PB push_back #define EM emplace #define EB emplace_back #define BI back_inserter #define MP make_pair #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl constexpr int MOD = 1'000'000'007; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12) << fixed; IN(string, K); IN(int, M); const int L = SZ(K); static int dp[1 << 17][128][2]; dp[0][0][0] = 1; REP(i, L) { const int D = K[i] - '0'; REP(j, M) { REP(k, 2) { REP(d, k ? 10 : D + 1) { const int nj = (j + d) % M; const int nk = k || d < D; (dp[i + 1][nj][nk] += dp[i][j][k]) %= MOD; } } } } cout << (LL(dp[L][0][0]) + dp[L][0][1] + (MOD - 1)) % MOD << endl; return 0; }
replace
141
142
141
142
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define TemplateVersion "3.7.1" // Useful Marcos //====================START===================== // Compile use C++11 and above #ifdef LOCAL #define debug(args...) \ do { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } while (0) void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define MSG cout << "Finished" << endl #else #define debug(args...) #define MSG #endif #if __cplusplus >= 201703L template <typename... Args> void readln(Args &...args) { ((cin >> args), ...); } template <typename... Args> void writeln(Args... args) { ((cout << args << " "), ...); cout << endl; } #elif __cplusplus >= 201103L void readln() {} template <typename T, typename... Args> void readln(T &a, Args &...args) { cin >> a; readln(args...); } void writeln() { cout << endl; } template <typename T, typename... Args> void writeln(T a, Args... args) { cout << a << " "; writeln(args...); } #endif #if __cplusplus >= 201103L #define FOR(_i, _begin, _end) for (auto _i = _begin; _i < _end; _i++) #define FORR(_i, _begin, _end) for (auto _i = _begin; _i > _end; _i--) #else #define FOR(_i, _begin, _end) for (int _i = (int)_begin; _i < (int)_end; _i++) #define FORR(_i, _begin, _end) for (int _i = (int)_begin; _i > (int)_end; _i--) #define nullptr NULL #endif #if __cplusplus >= 201103L #define VIS(_kind, _name, _size) \ vector<_kind> _name(_size); \ for (auto &i : _name) \ cin >> i; #else #define VIS(_kind, _name, _size) \ vector<_kind> _name; \ _name.resize(_size); \ for (int i = 0; i < _size; i++) \ cin >> _name[i]; #endif // alias #define mp make_pair #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define clr(x) memset((x), 0, sizeof(x)) #define infty(x) memset((x), 0x3f, sizeof(x)) #define tcase() \ int T; \ cin >> T; \ FOR(kase, 1, T + 1) // Swap max/min template <typename T> bool smax(T &a, const T &b) { if (a > b) return false; a = b; return true; } template <typename T> bool smin(T &a, const T &b) { if (a < b) return false; a = b; return true; } // ceil divide template <typename T> T cd(T a, T b) { return (a + b - 1) / b; } // min exchange template <typename T> bool se(T &a, T &b) { if (a < b) return false; swap(a, b); return true; } // A better MAX choice const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef set<int> si; typedef vector<string> cb; //====================END===================== // Constants here const int MAXK = 10010; const int MAXD = 110; const int MOD = 1e9 + 7; int num[MAXK]; ll memo[MAXK][MAXD]; int D; ll dfs(int pos, int rem, bool limit) { if (pos == -1) { return rem == 0; } if (!limit && memo[pos][rem] != -1) { return memo[pos][rem]; } ll ans = 0; int maxx = limit ? num[pos] : 9; for (int i = 0; i <= maxx; i++) { ans = (ans + dfs(pos - 1, (rem + i) % D, limit && i == num[pos])) % MOD; } if (!limit) { memo[pos][rem] = ans; } return ans; } // Pre-Build Function inline void build() { memset(memo, -1, sizeof memo); } // Actual Solver inline void solve() { string K; readln(K, D); D %= 100; int len = K.size(); for (int i = len - 1; i >= 0; i--) { num[i] = K[len - i - 1] - '0'; } writeln((dfs(len - 1, 0, true) + MOD - 1) % MOD); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef LOCAL clock_t _begin = clock(); #endif build(); solve(); #ifdef LOCAL cerr << "Time elapsed: " << (double)(clock() - _begin) * 1000 / CLOCKS_PER_SEC << "ms." << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define TemplateVersion "3.7.1" // Useful Marcos //====================START===================== // Compile use C++11 and above #ifdef LOCAL #define debug(args...) \ do { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } while (0) void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define MSG cout << "Finished" << endl #else #define debug(args...) #define MSG #endif #if __cplusplus >= 201703L template <typename... Args> void readln(Args &...args) { ((cin >> args), ...); } template <typename... Args> void writeln(Args... args) { ((cout << args << " "), ...); cout << endl; } #elif __cplusplus >= 201103L void readln() {} template <typename T, typename... Args> void readln(T &a, Args &...args) { cin >> a; readln(args...); } void writeln() { cout << endl; } template <typename T, typename... Args> void writeln(T a, Args... args) { cout << a << " "; writeln(args...); } #endif #if __cplusplus >= 201103L #define FOR(_i, _begin, _end) for (auto _i = _begin; _i < _end; _i++) #define FORR(_i, _begin, _end) for (auto _i = _begin; _i > _end; _i--) #else #define FOR(_i, _begin, _end) for (int _i = (int)_begin; _i < (int)_end; _i++) #define FORR(_i, _begin, _end) for (int _i = (int)_begin; _i > (int)_end; _i--) #define nullptr NULL #endif #if __cplusplus >= 201103L #define VIS(_kind, _name, _size) \ vector<_kind> _name(_size); \ for (auto &i : _name) \ cin >> i; #else #define VIS(_kind, _name, _size) \ vector<_kind> _name; \ _name.resize(_size); \ for (int i = 0; i < _size; i++) \ cin >> _name[i]; #endif // alias #define mp make_pair #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define clr(x) memset((x), 0, sizeof(x)) #define infty(x) memset((x), 0x3f, sizeof(x)) #define tcase() \ int T; \ cin >> T; \ FOR(kase, 1, T + 1) // Swap max/min template <typename T> bool smax(T &a, const T &b) { if (a > b) return false; a = b; return true; } template <typename T> bool smin(T &a, const T &b) { if (a < b) return false; a = b; return true; } // ceil divide template <typename T> T cd(T a, T b) { return (a + b - 1) / b; } // min exchange template <typename T> bool se(T &a, T &b) { if (a < b) return false; swap(a, b); return true; } // A better MAX choice const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef set<int> si; typedef vector<string> cb; //====================END===================== // Constants here const int MAXK = 10010; const int MAXD = 110; const int MOD = 1e9 + 7; int num[MAXK]; ll memo[MAXK][MAXD]; int D; ll dfs(int pos, int rem, bool limit) { if (pos == -1) { return rem == 0; } if (!limit && memo[pos][rem] != -1) { return memo[pos][rem]; } ll ans = 0; int maxx = limit ? num[pos] : 9; for (int i = 0; i <= maxx; i++) { ans = (ans + dfs(pos - 1, (rem + i) % D, limit && i == num[pos])) % MOD; } if (!limit) { memo[pos][rem] = ans; } return ans; } // Pre-Build Function inline void build() { memset(memo, -1, sizeof memo); } // Actual Solver inline void solve() { string K; readln(K, D); int len = K.size(); for (int i = len - 1; i >= 0; i--) { num[i] = K[len - i - 1] - '0'; } writeln((dfs(len - 1, 0, true) + MOD - 1) % MOD); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef LOCAL clock_t _begin = clock(); #endif build(); solve(); #ifdef LOCAL cerr << "Time elapsed: " << (double)(clock() - _begin) * 1000 / CLOCKS_PER_SEC << "ms." << endl; #endif return 0; }
delete
153
154
153
153
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define all(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<char> vchar; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef unsigned long long ull; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } static ModInt factorial(ll n) { ModInt<mod> tmp(n); for (int i = 1; i < n; i++) { tmp *= ModInt<mod>(n - i); } return tmp; } static ModInt Combination(ll n, ll k) { return factorial(n) / (factorial(n - k) * factorial(k)); } }; using mint = ModInt<(int)1e9 + 7>; int main() { string S; int D, keta; cin >> D >> S; keta = S.size(); auto dp = make_v<mint>(keta + 1, D, 2); // dp[i][res][flag] := // i桁目まで決定し、決めた部分の和%Dがresになるような数<=Nのパターン // flagはぴったりかより小さいか // dp[keta][0][0]+dp[keta][1][0]-1が答え dp[0][0][1] = 1; for (size_t i = 0; i < keta; i++) { for (size_t j = 0; j < D; j++) { for (size_t k = 0; k < 10; k++) { dp[i + 1][(j + k) % D][0] += dp[i][j][0]; // 未満のやつ } for (size_t k = 0; k < S[i] - '0'; k++) { dp[i + 1][(j + k) % D][0] += dp[i][j][1]; } dp[i + 1][(j + S[i] - '0') % D][1] += dp[i][j][1]; } } cout << dp[keta][0][0] + dp[keta][0][1] - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define all(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<char> vchar; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef unsigned long long ull; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } static ModInt factorial(ll n) { ModInt<mod> tmp(n); for (int i = 1; i < n; i++) { tmp *= ModInt<mod>(n - i); } return tmp; } static ModInt Combination(ll n, ll k) { return factorial(n) / (factorial(n - k) * factorial(k)); } }; using mint = ModInt<(int)1e9 + 7>; int main() { string S; int D, keta; cin >> S; cin >> D; keta = S.size(); auto dp = make_v<mint>(keta + 1, D, 2); // dp[i][res][flag] := // i桁目まで決定し、決めた部分の和%Dがresになるような数<=Nのパターン // flagはぴったりかより小さいか // dp[keta][0][0]+dp[keta][1][0]-1が答え dp[0][0][1] = 1; for (size_t i = 0; i < keta; i++) { for (size_t j = 0; j < D; j++) { for (size_t k = 0; k < 10; k++) { dp[i + 1][(j + k) % D][0] += dp[i][j][0]; // 未満のやつ } for (size_t k = 0; k < S[i] - '0'; k++) { dp[i + 1][(j + k) % D][0] += dp[i][j][1]; } dp[i + 1][(j + S[i] - '0') % D][1] += dp[i][j][1]; } } cout << dp[keta][0][0] + dp[keta][0][1] - 1 << endl; return 0; }
replace
138
139
138
140
0
p03178
C++
Runtime Error
/*alurquiza*/ // S:Digit Sum #include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, SIZE = 1e4 + 1, MAXR = 100, CANTD = 10; int DP[SIZE][CANTD][MAXR]; void sum(int &a, int b) { a += b; if (a >= MOD) a -= MOD; if (a < 0) a += MOD; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); freopen(".in", "r", stdin); // freopen(".out","w",stdout); string K; int D; cin >> K >> D; int N = K.size(); for (int i = 0; i < 10; i++) DP[0][i][0] = 1; for (int i = 1; i <= N; i++) { /// DP[i][d][r] -> poniendo el digito d en la posicion i en cuantos numeros /// la suma de sus digitos es = r; for (int d = 0; d < 10; d++) { for (int r = 0; r < D; r++) { int newr = (r - (d % D) + D) % D; sum(DP[i][d][r], DP[i - 1][9][newr]); } } /// acumular la dinamica para todos los digitos con distancia r for (int d = 1; d < 10; d++) { for (int r = 0; r < D; r++) { sum(DP[i][d][r], DP[i][d - 1][r]); } } } int sol = 0, r = 0; for (int i = 0; i < N; i++) { int pos = N - i; int digit = K[i] - '0'; if (digit) { sum(sol, DP[pos][digit - 1][r] % MOD); r = (r - (digit % D) + D) % D; } } /// A la solucion le quito el numero 0 y le sumo si el numero inicial cumple /// la condicion cout << (sol - 1 + !r + MOD) % MOD << '\n'; return 0; }
/*alurquiza*/ // S:Digit Sum #include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7, SIZE = 1e4 + 1, MAXR = 100, CANTD = 10; int DP[SIZE][CANTD][MAXR]; void sum(int &a, int b) { a += b; if (a >= MOD) a -= MOD; if (a < 0) a += MOD; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen(".in","r",stdin); // freopen(".out","w",stdout); string K; int D; cin >> K >> D; int N = K.size(); for (int i = 0; i < 10; i++) DP[0][i][0] = 1; for (int i = 1; i <= N; i++) { /// DP[i][d][r] -> poniendo el digito d en la posicion i en cuantos numeros /// la suma de sus digitos es = r; for (int d = 0; d < 10; d++) { for (int r = 0; r < D; r++) { int newr = (r - (d % D) + D) % D; sum(DP[i][d][r], DP[i - 1][9][newr]); } } /// acumular la dinamica para todos los digitos con distancia r for (int d = 1; d < 10; d++) { for (int r = 0; r < D; r++) { sum(DP[i][d][r], DP[i][d - 1][r]); } } } int sol = 0, r = 0; for (int i = 0; i < N; i++) { int pos = N - i; int digit = K[i] - '0'; if (digit) { sum(sol, DP[pos][digit - 1][r] % MOD); r = (r - (digit % D) + D) % D; } } /// A la solucion le quito el numero 0 y le sumo si el numero inicial cumple /// la condicion cout << (sol - 1 + !r + MOD) % MOD << '\n'; return 0; }
replace
21
22
21
22
0
p03178
C++
Runtime Error
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nCr(ll n, ll r) { if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- string k; int D; ll memo[10010][2][110]; ll dp(int i, int f, int d) { if (i == k.size()) return d == 0 ? 1 : 0; if (memo[i][f][d] != -1) return memo[i][f][d]; ll res = 0; int now = k[i] - '0'; for (int di = 0; di <= (f ? 9 : now); di++) { res += dp(i + 1, (f || (di < now)), (d + di) % D) % MOD; res %= MOD; } return memo[i][f][d] = res; } void init() { for (int i = 0; i <= k.size(); i++) { for (int j = 0; j < 2; j++) { for (int l = 0; l <= D; l++) { memo[i][j][l] = -1; } } } } int main(void) { cin >> D >> k; init(); ll ans = dp(0, 0, 0) + ((-1) % MOD); if (ans < 0) ans += MOD; cout << ans % MOD << endl; }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nCr(ll n, ll r) { if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- string k; int D; ll memo[10010][2][110]; ll dp(int i, int f, int d) { if (i == k.size()) return d == 0 ? 1 : 0; if (memo[i][f][d] != -1) return memo[i][f][d]; ll res = 0; int now = k[i] - '0'; for (int di = 0; di <= (f ? 9 : now); di++) { res += dp(i + 1, (f || (di < now)), (d + di) % D) % MOD; res %= MOD; } return memo[i][f][d] = res; } void init() { for (int i = 0; i <= k.size(); i++) { for (int j = 0; j < 2; j++) { for (int l = 0; l <= D; l++) { memo[i][j][l] = -1; } } } } int main(void) { cin >> k >> D; init(); ll ans = dp(0, 0, 0) + ((-1) % MOD); if (ans < 0) ans += MOD; cout << ans % MOD << endl; }
replace
97
98
97
98
0
p03178
C++
Runtime Error
// Author : Sarthak Kapoor #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define rep(i, n) for (int i = 0; i < n; ++i) #define repa(i, a, n) for (int i = a; i < n; ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define repba(i, b, a) for (int i = b; i >= a; --i) #define repab(i, a, b) for (int i = a; i < b; ++i) #define ll long long #define ull unsigned long long #define vi vector<int> #define viip vector<pair<int, pair<int, int>>> #define mp make_pair #define vip vector<pair<int, int>> #define pb push_back #define fi first #define sec second #define all(v) v.begin(), v.end() #define s(v) v.size() ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // use rng()%n for numbers in range [0,n-1] ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fastexp(ll x, ll a) { ll res = 1; while (a > 0) { if (a & 1) { res = (res * x) % mod; } a = a >> 1; x = (x * x) % mod; } return res; } ll inverse(ll n) { return fastexp(n, mod - 2); } template <typename T> void add(T &a, T b) { a += b; if (a >= mod) a -= mod; } template <typename T> void sub(T &a, T b) { a -= b; if (a < 0) a += mod; } template <typename T> void mul(T &a, T b) { a *= b; if (a > mod) a %= mod; } ll dp[101][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int d; string s; cin >> s; cin >> d; int n = s(s); dp[0][0] = 1; rep(i, n) { ll temp[d][2]; rep(j, d) { rep(k, 2) temp[j][k] = 0; } rep(j, d) { rep(k, 2) { rep(di, 10) { if (di > s[i] - '0') { if (k) { add(temp[j][k], dp[(j - di + 10 * d) % d][k]); } } else if (di == s[i] - '0') { add(temp[j][k], dp[(j - di + 10 * d) % d][k]); // add() } else { add(temp[j][1], dp[(j - di + 10 * d) % d][k]); } } } } rep(j, d) { rep(k, 2) { dp[j][k] = temp[j][k]; } } } ll ans = 0; rep(i, 2) { add(ans, dp[0][i]); } sub(ans, 1ll); cout << ans; return 0; }
// Author : Sarthak Kapoor #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define rep(i, n) for (int i = 0; i < n; ++i) #define repa(i, a, n) for (int i = a; i < n; ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define repba(i, b, a) for (int i = b; i >= a; --i) #define repab(i, a, b) for (int i = a; i < b; ++i) #define ll long long #define ull unsigned long long #define vi vector<int> #define viip vector<pair<int, pair<int, int>>> #define mp make_pair #define vip vector<pair<int, int>> #define pb push_back #define fi first #define sec second #define all(v) v.begin(), v.end() #define s(v) v.size() ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // use rng()%n for numbers in range [0,n-1] ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fastexp(ll x, ll a) { ll res = 1; while (a > 0) { if (a & 1) { res = (res * x) % mod; } a = a >> 1; x = (x * x) % mod; } return res; } ll inverse(ll n) { return fastexp(n, mod - 2); } template <typename T> void add(T &a, T b) { a += b; if (a >= mod) a -= mod; } template <typename T> void sub(T &a, T b) { a -= b; if (a < 0) a += mod; } template <typename T> void mul(T &a, T b) { a *= b; if (a > mod) a %= mod; } ll dp[101][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int d; string s; cin >> s; cin >> d; int n = s(s); dp[0][0] = 1; rep(i, n) { ll temp[d][2]; rep(j, d) { rep(k, 2) temp[j][k] = 0; } rep(j, d) { rep(k, 2) { rep(di, 10) { if (di > s[i] - '0') { if (k) { add(temp[j][k], dp[(j - di + 10 * d) % d][k]); } } else if (di == s[i] - '0') { add(temp[j][k], dp[(j - di + 10 * d) % d][k]); // add() } else { add(temp[j][1], dp[(j - di + 10 * d) % d][k]); } } } } rep(j, d) { rep(k, 2) { dp[j][k] = temp[j][k]; } } } ll ans = 0; rep(i, 2) { add(ans, dp[0][i]); } sub(ans, 1ll); cout << ans; return 0; }
replace
62
66
62
66
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define mod 1000000007 int dp[3001][102][2]; int countdigitsum(int pos, int d, bool tight, string k, int D) { int ub = tight ? k[pos] - '0' : 9; if (dp[pos][d][tight] != -1) { return dp[pos][d][tight]; } if (pos == k.length() - 1) { int ans = 0; for (int x = 0; x <= ub; x++) { if (x % D == d) { ans++; } } return ans; } int ans = 0; for (int x = 0; x <= ub; x++) { ans = (ans + countdigitsum(pos + 1, (D + d - x % D) % D, tight && (x == ub), k, D)) % mod; } return dp[pos][d][tight] = ans; } signed main() { string k; cin >> k; int D; cin >> D; memset(dp, -1, sizeof dp); cout << (mod + countdigitsum(0, 0, 1, k, D) - 1) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define mod 1000000007 int dp[30001][1002][2]; int countdigitsum(int pos, int d, bool tight, string k, int D) { int ub = tight ? k[pos] - '0' : 9; if (dp[pos][d][tight] != -1) { return dp[pos][d][tight]; } if (pos == k.length() - 1) { int ans = 0; for (int x = 0; x <= ub; x++) { if (x % D == d) { ans++; } } return ans; } int ans = 0; for (int x = 0; x <= ub; x++) { ans = (ans + countdigitsum(pos + 1, (D + d - x % D) % D, tight && (x == ub), k, D)) % mod; } return dp[pos][d][tight] = ans; } signed main() { string k; cin >> k; int D; cin >> D; memset(dp, -1, sizeof dp); cout << (mod + countdigitsum(0, 0, 1, k, D) - 1) % mod << endl; return 0; }
replace
4
5
4
5
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long #define dd double #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define vll vector<long long> #define vdd vector<double> #define vpii vector<pair<int, int>> #define vpll vector<pair<long long, long long>> #define vvi vector<vector<int>> #define vvl vector<vector<long long>> #define mii map<int, int> #define mll map<long long, long long> #define umii unordered_map<int, int> #define umll unordered_map<long long, long long> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, b) for (int i = a; i < b; i++) #define rev(i, n) for (int i = n; i >= 0; i--) #define rev2(i, a, b) for (int i = a; i >= b; i--) #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define inf 9e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl '\n' #define all(x) x.begin(), x.end() #define d0(x) cout << x << " " #define d1(x) cout << x << endl #define d2(x, y) cout << x << " " << y << endl #define d3(x, y, z) cout << x << " " << y << " " << z << endl #define d4(x, y, z, w) cout << x << " " << y << " " << z << " " << w << endl #define read2(x, y) cin >> x >> y #define read3(x, y, z) cin >> x >> y >> z #define read4(x, y, z, w) cin >> x >> y >> z >> w #define read5(x, y, z, w, a) cin >> x >> y >> z >> w >> a #define sz(a) (int)a.size() const ll mod = 1e9 + 7; const double PI = 3.14159265359; const ll MOD = 998244353; void i_o() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } string k; ll d, n; ll dp[10005][102][2]; ll mem(ll i, ll sum, int flag) { if (i == n) { if (sum == 0) return 1; else return 0; } ll &res = dp[i][sum][flag]; if (res != -1) return res; res = 0; ll lim; if (flag) lim = k[i] - '0'; else lim = 9; for (int j = 0; j <= lim; j++) { int flg; if (j == lim && flag) flg = 1; else flg = 0; ll sum1 = (sum + j) % d; res += mem(i + 1, sum1, flg); } res %= mod; return res; } int main() { fio i_o(); cin >> k; cin >> d; n = k.length(); memset(dp, -1, sizeof(dp)); ll ans = mem(0, 0, 1); ans--; ans += mod; d1(ans % mod); return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long #define dd double #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define vll vector<long long> #define vdd vector<double> #define vpii vector<pair<int, int>> #define vpll vector<pair<long long, long long>> #define vvi vector<vector<int>> #define vvl vector<vector<long long>> #define mii map<int, int> #define mll map<long long, long long> #define umii unordered_map<int, int> #define umll unordered_map<long long, long long> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, a, b) for (int i = a; i < b; i++) #define rev(i, n) for (int i = n; i >= 0; i--) #define rev2(i, a, b) for (int i = a; i >= b; i--) #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define inf 9e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl '\n' #define all(x) x.begin(), x.end() #define d0(x) cout << x << " " #define d1(x) cout << x << endl #define d2(x, y) cout << x << " " << y << endl #define d3(x, y, z) cout << x << " " << y << " " << z << endl #define d4(x, y, z, w) cout << x << " " << y << " " << z << " " << w << endl #define read2(x, y) cin >> x >> y #define read3(x, y, z) cin >> x >> y >> z #define read4(x, y, z, w) cin >> x >> y >> z >> w #define read5(x, y, z, w, a) cin >> x >> y >> z >> w >> a #define sz(a) (int)a.size() const ll mod = 1e9 + 7; const double PI = 3.14159265359; const ll MOD = 998244353; void i_o() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } string k; ll d, n; ll dp[10005][102][2]; ll mem(ll i, ll sum, int flag) { if (i == n) { if (sum == 0) return 1; else return 0; } ll &res = dp[i][sum][flag]; if (res != -1) return res; res = 0; ll lim; if (flag) lim = k[i] - '0'; else lim = 9; for (int j = 0; j <= lim; j++) { int flg; if (j == lim && flag) flg = 1; else flg = 0; ll sum1 = (sum + j) % d; res += mem(i + 1, sum1, flg); } res %= mod; return res; } int main() { fio // i_o(); cin >> k; cin >> d; n = k.length(); memset(dp, -1, sizeof(dp)); ll ans = mem(0, 0, 1); ans--; ans += mod; d1(ans % mod); return 0; }
replace
94
96
94
98
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long #define double long double #define endl '\n' const int mod = (int)1e9 + 7; int n, D; vector<int> a; int cache[10001][101][2]; int solve(int i, int d, int small) { if (i >= n) { return d == 0; } if (cache[i][d][small] != -1) { return cache[i][d][small]; } int res = 0; for (int dig = 0; dig <= (small ? 9 : a[i]); dig++) { res += solve(i + 1, (d + dig) % D, small | (dig < a[i])); if (res >= mod) { res -= mod; } } return cache[i][d][small] = res; } signed main() { fio; string s; cin >> s >> D; n = (int)s.length(); a.resize(n); for (int i = 0; i < n; i++) { a[i] = s[i] - '0'; } memset(cache, -1, sizeof(cache)); int answer = solve(0, 0, 0) - 1; assert(answer >= 0); cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long #define double long double #define endl '\n' const int mod = (int)1e9 + 7; int n, D; vector<int> a; int cache[10001][101][2]; int solve(int i, int d, int small) { if (i >= n) { return d == 0; } if (cache[i][d][small] != -1) { return cache[i][d][small]; } int res = 0; for (int dig = 0; dig <= (small ? 9 : a[i]); dig++) { res += solve(i + 1, (d + dig) % D, small | (dig < a[i])); if (res >= mod) { res -= mod; } } return cache[i][d][small] = res; } signed main() { fio; string s; cin >> s >> D; n = (int)s.length(); a.resize(n); for (int i = 0; i < n; i++) { a[i] = s[i] - '0'; } memset(cache, -1, sizeof(cache)); int answer = solve(0, 0, 0) - 1; if (answer < 0) { answer += mod; } cout << answer << endl; return 0; }
replace
46
47
46
49
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 2; const int mod = 1e9 + 7; int d, n, ans, dp[105][N], pref[N]; string s; int main() { cin >> s >> d; n = s.size(); s = ' ' + s; for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + s[i] - '0'; } dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= 9; j++) { if (i == 1 && !j) continue; for (int k = 0; k < d; k++) { int to = (k + j) % d; dp[i][to] = (dp[i - 1][k] + dp[i][to]) % mod; } } ans = (ans + dp[i][0]) % mod; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k < d; k++) { int to = (k + j) % d; dp[i][to] = (dp[i - 1][k] + dp[i][to]) % mod; } } } for (int i = 1; i <= n; i++) { for (int j = 0; j < s[i] - '0'; j++) { if (i == 1 && !j) continue; int sum = (pref[i - 1] + j) % d; ans = (ans + dp[n - i][(d - sum + d) % d]) % mod; } } if (pref[n] % d == 0) ans = (ans + 1) % mod; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 2; const int mod = 1e9 + 7; int d, n, ans, dp[N][105], pref[N]; string s; int main() { cin >> s >> d; n = s.size(); s = ' ' + s; for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + s[i] - '0'; } dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= 9; j++) { if (i == 1 && !j) continue; for (int k = 0; k < d; k++) { int to = (k + j) % d; dp[i][to] = (dp[i - 1][k] + dp[i][to]) % mod; } } ans = (ans + dp[i][0]) % mod; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k < d; k++) { int to = (k + j) % d; dp[i][to] = (dp[i - 1][k] + dp[i][to]) % mod; } } } for (int i = 1; i <= n; i++) { for (int j = 0; j < s[i] - '0'; j++) { if (i == 1 && !j) continue; int sum = (pref[i - 1] + j) % d; ans = (ans + dp[n - i][(d - sum + d) % d]) % mod; } } if (pref[n] % d == 0) ans = (ans + 1) % mod; cout << ans << endl; }
replace
7
8
7
8
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll> #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define vll vector<ll> #define M 100011 #define MOD 1000000007 ll md = MOD; string s1; ll a[1011]; ll dp[1011][110][2]; ll f(ll x, ll mod, ll k, ll m, ll sum) { if (x < 0) { if (mod == 0) { return 1; } return 0; } if (dp[x][mod][k] != -1 && k == 0) return dp[x][mod][k]; ll mx = 9; if (k == 1) mx = a[x]; ll ans = 0; for (ll i = 0; i <= mx; ++i) { ll nc = 0; if (i == a[x]) nc = k; ans += f(x - 1, (mod + i) % m, nc, m, 10 * sum + i) % md; ans %= md; } dp[x][mod][k] = ans % md; return ans % md; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t, i, j, m, x, y, n, z, p, k, T; string s2, s3; x = 1; cin >> s1 >> m; n = s1.size(); reverse(s1.begin(), s1.end()); memset(dp, -1, sizeof(dp)); for (i = 0; i < n; ++i) a[i] = s1[i] - '0'; cout << (f(n - 1, 0, 1, m, 0) % md - 1 + md) % md; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll> #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define vll vector<ll> #define M 100011 #define MOD 1000000007 ll md = MOD; string s1; ll a[10110]; ll dp[10110][110][2]; ll f(ll x, ll mod, ll k, ll m, ll sum) { if (x < 0) { if (mod == 0) { return 1; } return 0; } if (dp[x][mod][k] != -1 && k == 0) return dp[x][mod][k]; ll mx = 9; if (k == 1) mx = a[x]; ll ans = 0; for (ll i = 0; i <= mx; ++i) { ll nc = 0; if (i == a[x]) nc = k; ans += f(x - 1, (mod + i) % m, nc, m, 10 * sum + i) % md; ans %= md; } dp[x][mod][k] = ans % md; return ans % md; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t, i, j, m, x, y, n, z, p, k, T; string s2, s3; x = 1; cin >> s1 >> m; n = s1.size(); reverse(s1.begin(), s1.end()); memset(dp, -1, sizeof(dp)); for (i = 0; i < n; ++i) a[i] = s1[i] - '0'; cout << (f(n - 1, 0, 1, m, 0) % md - 1 + md) % md; return 0; }
replace
14
16
14
16
0
p03178
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll dp[105][101][2]; const ll mod = 1e9 + 7; int main() { string s; cin >> s; int n = s.size(); int D; cin >> D; dp[0][0][0] = 1; rep(i, n) rep(j, D) rep(k, 2) { ll nd = s[i] - '0'; rep(d, 10) { int ni = i + 1, nj = (j + d) % D, nk = k; if (k == 0) { if (d > nd) continue; if (d < nd) nk = 1; } dp[ni][nj][nk] += dp[i][j][k]; dp[ni][nj][nk] %= mod; } } int ans = dp[n][0][0] + dp[n][0][1]; ans -= 1; if (ans < 0) ans += mod; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll dp[10001][101][2]; const ll mod = 1e9 + 7; int main() { string s; cin >> s; int n = s.size(); int D; cin >> D; dp[0][0][0] = 1; rep(i, n) rep(j, D) rep(k, 2) { ll nd = s[i] - '0'; rep(d, 10) { int ni = i + 1, nj = (j + d) % D, nk = k; if (k == 0) { if (d > nd) continue; if (d < nd) nk = 1; } dp[ni][nj][nk] += dp[i][j][k]; dp[ni][nj][nk] %= mod; } } int ans = dp[n][0][0] + dp[n][0][1]; ans -= 1; if (ans < 0) ans += mod; cout << ans << endl; return 0; }
replace
10
11
10
11
0
p03178
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < (b); i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int, int>; const int inf = 1 << 20; const int mod = 1e9 + 7; ll dp[1005][2][105]; int ctoi(char c) { return c - '0'; } int main() { string K; int D; cin >> K >> D; dp[0][0][0] = 1; rep(i, 0, K.size()) rep(j, 0, D) { int k = ctoi(K[i]); rep(digit, 0, 10)(dp[i + 1][1][(j + digit) % D] += dp[i][1][j]) %= mod; rep(digit, 0, k)(dp[i + 1][1][(j + digit) % D] += dp[i][0][j]) %= mod; (dp[i + 1][0][(j + k) % D] += dp[i][0][j]) %= mod; } int ans = (dp[K.size()][0][0] + dp[K.size()][1][0] - 1 + mod) % mod; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < (b); i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair<int, int>; const int inf = 1 << 20; const int mod = 1e9 + 7; ll dp[100005][2][105]; int ctoi(char c) { return c - '0'; } int main() { string K; int D; cin >> K >> D; dp[0][0][0] = 1; rep(i, 0, K.size()) rep(j, 0, D) { int k = ctoi(K[i]); rep(digit, 0, 10)(dp[i + 1][1][(j + digit) % D] += dp[i][1][j]) %= mod; rep(digit, 0, k)(dp[i + 1][1][(j + digit) % D] += dp[i][0][j]) %= mod; (dp[i + 1][0][(j + k) % D] += dp[i][0][j]) %= mod; } int ans = (dp[K.size()][0][0] + dp[K.size()][1][0] - 1 + mod) % mod; cout << ans << endl; return 0; }
replace
10
11
10
11
0