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
p02787
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; #define int long long int #define mod 1000000007 #define string_mod 2549536629329_base_255 #define pb push_back #define F first #define S second #define ff first #define endl "\n" #define ss second #define all(v) v.begin(), v.end() template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int power(int x, unsigned int y, int p) { int res = 1; x = x % p; // cout << x << " "; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res % p; } int lcm(int a, int b) { return (a * b) / __gcd(a, b); } int h, n; vector<pair<int, int>> v(10001); int dp[10001][10001]; int solve(int in, int sum) { // cout << sum << " "; if (in >= n && sum > 0) { return 1e15; } if (sum <= 0) { return 0; } int ze = 0; if (dp[in][max(ze, sum)] != -1) { return dp[in][max(ze, sum)]; } int ans = 1e15; int s = sum - v[in].F; ans = min(ans, solve(in + 1, sum)); ans = min(ans, v[in].S + solve(0, s)); return dp[in][max(ze, sum)] = ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; tc = 1; memset(dp, -1, sizeof(dp)); while (tc--) { cin >> h >> n; for (int i = 0; i < n; i++) { cin >> v[i].F >> v[i].S; } int ans = solve(0, h); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long int #define mod 1000000007 #define string_mod 2549536629329_base_255 #define pb push_back #define F first #define S second #define ff first #define endl "\n" #define ss second #define all(v) v.begin(), v.end() template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int power(int x, unsigned int y, int p) { int res = 1; x = x % p; // cout << x << " "; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res % p; } int lcm(int a, int b) { return (a * b) / __gcd(a, b); } int h, n; vector<pair<int, int>> v(10001); int dp[10001][10001]; int solve(int in, int sum) { // cout << sum << " "; if (in >= n && sum > 0) { return 1e15; } if (sum <= 0) { return 0; } int ze = 0; if (dp[in][max(ze, sum)] != -1) { return dp[in][max(ze, sum)]; } int ans = 1e15; int s = sum - v[in].F; ans = min(ans, solve(in + 1, sum)); ans = min(ans, v[in].S + solve(in, s)); return dp[in][max(ze, sum)] = ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; tc = 1; memset(dp, -1, sizeof(dp)); while (tc--) { cin >> h >> n; for (int i = 0; i < n; i++) { cin >> v[i].F >> v[i].S; } int ans = solve(0, h); cout << ans << endl; } return 0; }
replace
51
52
51
52
-11
p02787
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long int dp[2000]; void upd(int &x, int y) { if (x > y) x = y; } int a[2000], b[2000]; signed main() { memset(dp, 0x3f, sizeof dp); dp[0] = 0; int n, h; cin >> h >> n; int ans = 2e9; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) { // cout<<i<<endl; for (int j = 0; j <= 2e4; j++) { if (j - a[i] >= 0) upd(dp[j], dp[j - a[i]] + b[i]); if (j >= h) upd(ans, dp[j]); // cout<<j<<" "<<dp[j]<<endl; } } cout << ans << endl; getchar(); getchar(); }
#include <bits/stdc++.h> using namespace std; // #define int long long int dp[25000]; void upd(int &x, int y) { if (x > y) x = y; } int a[2000], b[2000]; signed main() { memset(dp, 0x3f, sizeof dp); dp[0] = 0; int n, h; cin >> h >> n; int ans = 2e9; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) { // cout<<i<<endl; for (int j = 0; j <= 2e4; j++) { if (j - a[i] >= 0) upd(dp[j], dp[j - a[i]] + b[i]); if (j >= h) upd(ans, dp[j]); // cout<<j<<" "<<dp[j]<<endl; } } cout << ans << endl; getchar(); getchar(); }
replace
4
5
4
5
-11
p02787
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = a; i <= b; i++) #define FORD(i, a, b) for (ll i = a; i >= b; i--) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair #define MEMSET(v, h) memset((v), h, sizeof(v)) #define sqr(x) ((x) * (x)) #define cub(x) ((x) * (x) * (x)) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} // ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int dp[20500]; const int MAX = 1001001001; int main() { int h, n; cin >> h >> n; FOR(i, 1, 20499) { dp[i] = MAX; } FOR(i, 1, n) { int a, b; cin >> a >> b; FOR(j, 0, 20000 - a) { int ref = 1; while (j + a * ref <= 20000) { chmin(dp[j + a * ref], dp[j] + b * ref); ++ref; } } // FOR(j,0,10) cout << dp[i][j] << " "; // cout << endl; } int ans = MAX; FOR(i, h, 20000) { chmin(ans, dp[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = a; i <= b; i++) #define FORD(i, a, b) for (ll i = a; i >= b; i--) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair #define MEMSET(v, h) memset((v), h, sizeof(v)) #define sqr(x) ((x) * (x)) #define cub(x) ((x) * (x) * (x)) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} // ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int dp[20500]; const int MAX = 1001001001; int main() { int h, n; cin >> h >> n; FOR(i, 1, 20499) { dp[i] = MAX; } FOR(i, 1, n) { int a, b; cin >> a >> b; FOR(j, 0, 20000 - a - 1) { chmin(dp[j + a], dp[j] + b); } // FOR(j,0,10) cout << dp[i][j] << " "; // cout << endl; } int ans = MAX; FOR(i, h, 20000) { chmin(ans, dp[i]); } cout << ans << endl; }
replace
40
47
40
41
TLE
p02787
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup. using namespace std; typedef long long ll; using Graph = vector<vector<int>>; int main() { ll H, N; cin >> H >> N; vector<int> A(N), B(N); rep(i, N) { cin >> A[i] >> B[i]; } vector<vector<int>> dp( N, vector<int>( H + 1, 0)); // dp[i][j] : 最初に魔法i, ダメージj を与える最小の消費魔力 vector<ll> dp2(H, 0); // dp[i][0] = 0; for (int j = 1; j < H + 1; j++) { for (int i = 0; i < N; i++) { if (A[i] >= j) { dp[i][j] = B[i]; } else { // A[i] < j; // ll tmp = dp[0][j-A[i]]; // for(int k = 1; k<N; k++) { // if(tmp > dp[k][j-A[i]]) tmp = dp[k][j-A[i]]; // } dp[i][j] = B[i] + dp2[j - A[i]]; } } dp2[j] = dp[0][j]; for (int k = 1; k < N; k++) { if (dp2[j] > dp[k][j]) dp2[j] = dp[k][j]; } } // for(int i=0; i<N; i++) { // for(int j=0; j<H+1; j++) { // cout << dp[i][j] << ' '; // } // cout << endl; // } ll ans = dp[0][H]; rep(i, N) { if (ans > dp[i][H]) ans = dp[i][H]; } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup. using namespace std; typedef long long ll; using Graph = vector<vector<int>>; int main() { ll H, N; cin >> H >> N; vector<int> A(N), B(N); rep(i, N) { cin >> A[i] >> B[i]; } vector<vector<int>> dp( N, vector<int>( H + 1, 0)); // dp[i][j] : 最初に魔法i, ダメージj を与える最小の消費魔力 vector<int> dp2(H, 0); // dp[i][0] = 0; for (int j = 1; j < H + 1; j++) { for (int i = 0; i < N; i++) { if (A[i] >= j) { dp[i][j] = B[i]; } else { // A[i] < j; // ll tmp = dp[0][j-A[i]]; // for(int k = 1; k<N; k++) { // if(tmp > dp[k][j-A[i]]) tmp = dp[k][j-A[i]]; // } dp[i][j] = B[i] + dp2[j - A[i]]; } } dp2[j] = dp[0][j]; for (int k = 1; k < N; k++) { if (dp2[j] > dp[k][j]) dp2[j] = dp[k][j]; } } // for(int i=0; i<N; i++) { // for(int j=0; j<H+1; j++) { // cout << dp[i][j] << ' '; // } // cout << endl; // } ll ans = dp[0][H]; rep(i, N) { if (ans > dp[i][H]) ans = dp[i][H]; } cout << ans << endl; return 0; }
replace
27
28
27
28
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02787
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 100100100; int main() { int h, n; cin >> h >> n; int m = 2 * h + 100; vector<int> hs(m, INF); vector<P> ab(n); rep(i, n) { int a, b; cin >> a >> b; ab[i] = P(a, b); } hs[0] = 0; for (int i = 0; i <= h; i++) { rep(j, n) { int a = ab[j].first; int b = ab[j].second; hs[i + a] = min(hs[i + a], hs[i] + b); } } int ans = INF; for (int i = h; i < m; i++) { ans = min(hs[i], ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 100100100; int main() { int h, n; cin >> h >> n; int m = 1e8 + 10; vector<int> hs(m, INF); vector<P> ab(n); rep(i, n) { int a, b; cin >> a >> b; ab[i] = P(a, b); } hs[0] = 0; for (int i = 0; i <= h; i++) { rep(j, n) { int a = ab[j].first; int b = ab[j].second; hs[i + a] = min(hs[i + a], hs[i] + b); } } int ans = INF; for (int i = h; i < m; i++) { ans = min(hs[i], ans); } cout << ans << endl; return 0; }
replace
12
13
12
13
0
p02787
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FILL0(x) memset(x, 0, sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; 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; } ll dp[10010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int H, N; cin >> H >> N; vector<P> ab(N); rep(i, N) { cin >> ab[i].first >> ab[i].second; } rep(i, 10010) { dp[i] = ll(1e8); } dp[0] = 0; rep(i, N) { rep(j, H + 1) { if (j - ab[i].second >= 0) // ピッタリ { chmin(dp[j], ab[i].second + dp[j - ab[i].first]); } else // 以上 { chmin(dp[j], ab[i].second); } } } cout << dp[H] << endl; return 0; } // cout << setprecision(13); // next_permutation(); //__gcd(); // reverse(); // set ,tuple ,pair; // bitset // vector.find
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FILL0(x) memset(x, 0, sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; 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; } ll dp[10010]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int H, N; cin >> H >> N; vector<P> ab(N); rep(i, N) { cin >> ab[i].first >> ab[i].second; } rep(i, 10010) { dp[i] = ll(1e8); } dp[0] = 0; rep(i, N) { rep(j, H + 1) { if (j - ab[i].first >= 0) // ピッタリ { chmin(dp[j], ab[i].second + dp[j - ab[i].first]); } else // 以上 { chmin(dp[j], ab[i].second); } } } cout << dp[H] << endl; return 0; } // cout << setprecision(13); // next_permutation(); //__gcd(); // reverse(); // set ,tuple ,pair; // bitset // vector.find
replace
45
46
45
46
0
p02787
C++
Runtime Error
#include <iostream> using namespace std; const int INF = 1 << 29; int dp[10005]; // dp[j]:=体力jを消費するまでの魔力の最小値. int main() { int H, N; int a[1000], b[1000]; cin >> H >> N; for (int i = 0; i < N; i++) cin >> a[i] >> b[i]; for (int i = 0; i <= H; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= H; j++) { dp[j] = min(dp[j], dp[j - a[i]] + b[i]); } } cout << dp[H] << endl; }
#include <iostream> using namespace std; const int INF = 1 << 29; int dp[10005]; // dp[j]:=体力jを消費するまでの魔力の最小値. int main() { int H, N; int a[1000], b[1000]; cin >> H >> N; for (int i = 0; i < N; i++) cin >> a[i] >> b[i]; for (int i = 0; i <= H; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 1; j <= H; j++) { if (j <= a[i]) dp[j] = min(dp[j], b[i]); else dp[j] = min(dp[j], dp[j - a[i]] + b[i]); } } cout << dp[H] << endl; }
replace
19
21
19
24
0
p02787
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 int dp[52345]; // dp[damage] = min of maryoku void solve() { int H, N; cin >> H >> N; vector<int> A(N), B(N); rep(i, N) cin >> A[i] >> B[i]; rep(i, H + 12345) dp[i] = INF; dp[0] = 0; rep(i, N) { rep(j, H) { rep(d, 12345) { if (j + A[i] * d > H + 10000) break; dp[j + A[i] * d] = min(dp[j + A[i] * d], dp[j] + B[i] * d); } } } int ans = INF; for (int d = H; d <= H + 10000; d++) { ans = min(ans, dp[d]); } 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 int dp[52345]; // dp[damage] = min of maryoku void solve() { int H, N; cin >> H >> N; vector<int> A(N), B(N); rep(i, N) cin >> A[i] >> B[i]; rep(i, H + 12345) dp[i] = INF; dp[0] = 0; rep(i, N) { rep(j, H) { if (j + A[i] > H + 10000) break; dp[j + A[i]] = min(dp[j + A[i]], dp[j] + B[i]); } } int ans = INF; for (int d = H; d <= H + 10000; d++) { ans = min(ans, dp[d]); } cout << ans << endl; } signed main() { cout << fixed << setprecision(18) << endl; cerr << fixed << setprecision(18) << endl; solve(); }
replace
111
116
111
114
TLE
p02787
Python
Time Limit Exceeded
h, n = map(int, input().split()) x = [list(map(int, input().split())) for _ in range(n)] a, b = x[0] dp = [-(-i // a) * b for i in range(h + 1)] for j in range(1, n): a, b = x[j] for i in range(h + 1): if i >= a: dp[i] = min(dp[i], dp[i - a] + b) else: dp[i] = min(dp[i], b) print(dp[-1])
h, n = map(int, input().split()) x = [list(map(int, input().split())) for _ in range(n)] a, b = x[0] dp = [-(-i // a) * b for i in range(h + 1)] for j in range(1, n): a, b = x[j] for i in range(min(h + 1, a)): dp[i] = min(dp[i], b) for i in range(a, h + 1): dp[i] = min(dp[i], dp[i - a] + b) print(dp[-1])
replace
6
11
6
10
TLE
p02787
Python
Time Limit Exceeded
H, N = map(int, input().split()) M = [tuple(map(int, input().split())) for i in range(N)] dp = [(i + M[0][0] - 1) // M[0][0] * M[0][1] for i in range(H + 1)] for i in range(N): Ai, Bi = M[i] ndp = [0] * (H + 1) if Ai >= H: ndp[0 : H + 1] = [min(dp[j], Bi) for j in range(H + 1)] else: ndp[0 : Ai + 1] = [min(dp[j], Bi) for j in range(Ai + 1)] for j in range(Ai + 1, H + 1): ndp[j] = min(dp[j], ndp[j - Ai] + Bi) dp = ndp print(dp[H])
H, N = map(int, input().split()) M = [tuple(map(int, input().split())) for i in range(N)] dp = [(j + M[0][0] - 1) // M[0][0] * M[0][1] for j in range(H + 1)] for i in range(1, N): Ai, Bi = M[i] ndp = [0] * (H + 1) if Ai >= H: ndp[0 : H + 1] = [min(dp[j], Bi) for j in range(H + 1)] else: ndp[0 : Ai + 1] = [min(dp[j], Bi) for j in range(Ai + 1)] for j in range(Ai + 1, H + 1): ndp[j] = min(dp[j], ndp[j - Ai] + Bi) dp = ndp print(dp[H])
replace
3
5
3
5
TLE
p02787
Python
Time Limit Exceeded
import sys H, N = map(int, input().split()) A = [0] * N B = [0] * N for i in range(N): a, b = map(int, sys.stdin.readline().rstrip().split()) A[i] = a B[i] = b max_A = max(A) INF = 10**18 dp = [INF] * (H + max_A) dp[0] = 0 for i in range(0, H): for j in range(N): dp[i + A[j]] = min(dp[i] + B[j], dp[i + A[j]]) print(min(dp[H : H + max_A]))
import sys H, N = map(int, input().split()) A = [0] * N B = [0] * N for i in range(N): a, b = map(int, sys.stdin.readline().rstrip().split()) A[i] = a B[i] = b max_A = max(A) INF = 10**18 dp = [INF] * (H + max_A) dp[0] = 0 for i in range(H): for j in range(N): dp[i + A[j]] = min(dp[i] + B[j], dp[i + A[j]]) print(min(dp[H : H + max_A]))
replace
16
17
16
17
TLE
p02787
C++
Runtime Error
// #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define mod 1000000007 #define ll long long #define INF 0x3f3f3f3f using namespace std; char mp[110][110][110]; int vis[110][110][110]; int dir[6][3] = {-1, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1}; int arr[1000000]; int brr[1000000]; int f[1000000] = {0}; int main() { int h, n; cin >> h >> n; for (int i = 0; i <= h; i++) { f[i] = 2e9; } for (int i = 0; i < n; i++) { cin >> arr[i] >> brr[i]; } f[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= h; j++) { int nj = min(j + arr[i], h); f[nj] = min(f[nj], f[nj - arr[i]] + brr[i]); // cout<<f[j]<<endl; } } cout << f[h] << endl; }
// #include<bits/stdc++.h> #include <algorithm> #include <cmath> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define mod 1000000007 #define ll long long #define INF 0x3f3f3f3f using namespace std; char mp[110][110][110]; int vis[110][110][110]; int dir[6][3] = {-1, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1}; int arr[1000000]; int brr[1000000]; int f[1000000] = {0}; int main() { int h, n; cin >> h >> n; for (int i = 0; i <= h; i++) { f[i] = 2e9; } for (int i = 0; i < n; i++) { cin >> arr[i] >> brr[i]; } f[0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= h; j++) { int nj = min(j + arr[i], h); f[nj] = min(f[nj], f[j] + brr[i]); // cout<<f[nj]<<endl; } } cout << f[h] << endl; }
replace
42
44
42
44
0
p02787
C++
Runtime Error
// 5/6 // 個数制限なしナップサック問題 #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; ll dp[110][10010]; // const int INF = 1000000000; int main() { int H, N; cin >> H >> N; vector<ll> A(N), B(N); rep(i, N) cin >> A[i] >> B[i]; // dp初期化 rep(i, H + 1) dp[0][i] = 10000000000; for (ll i = 0; i < N; i++) { for (ll j = 0; j <= H; j++) { if (j <= A[i]) { dp[i + 1][j] = min(B[i], dp[i][j]); } else { dp[i + 1][j] = min(dp[i + 1][j - A[i]] + B[i], dp[i][j]); } } } cout << dp[N][H] << endl; return 0; }
// 5/6 // 個数制限なしナップサック問題 #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; ll dp[1010][10010]; // const int INF = 1000000000; int main() { int H, N; cin >> H >> N; vector<ll> A(N), B(N); rep(i, N) cin >> A[i] >> B[i]; // dp初期化 rep(i, H + 1) dp[0][i] = 10000000000; for (ll i = 0; i < N; i++) { for (ll j = 0; j <= H; j++) { if (j <= A[i]) { dp[i + 1][j] = min(B[i], dp[i][j]); } else { dp[i + 1][j] = min(dp[i + 1][j - A[i]] + B[i], dp[i][j]); } } } cout << dp[N][H] << endl; return 0; }
replace
10
11
10
11
0
p02787
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i) #define repds(i, n) for (int i = (int)(n); i > 0; --i) #define loop(i, x, n) for (int i = (int)(x); i < (n); ++i) #define loops(i, x, n) for (int i = (int)(x); i <= (n); ++i) #define loopd(i, x, n) for (int i = (int)(x); i > (n); --i) #define loopds(i, x, n) for (int i = (int)(x); i >= (n); --i) #define itrep(i, s) for (auto i = begin(s); i != end(s); ++i) #define itrepd(i, s) for (auto i = --end(s); i != begin(s); --i) #define all(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ }(x) #define rall(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \ }(x) using ll = long long; using ld = long double; constexpr ll inf = static_cast<ll>(1e17); constexpr int iinf = static_cast<int>(1e9); constexpr double dinf = 1e10; constexpr ld ldinf = 1e17; ll mod = static_cast<ll>(1e9 + 7); std::ostream &endn(std::ostream &os) { return os.put(os.widen('\n')); } template <class T> constexpr int sz(const T &a) { return (int)a.size(); } template <class T> constexpr T pow2(const T a) { return a * a; } template <class T, class... Args> constexpr T mins(T &a, Args... args) { return a = min<T>({a, args...}); } template <class T, class... Args> constexpr T maxs(T &a, Args... args) { return a = max<T>({a, args...}); } template <typename A, size_t N, typename T> void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll h; int n; ll a[105], b[105]; ll dp[10005]; void solve() { cin >> h >> n; rep(i, n) cin >> a[i] >> b[i]; fillArray(dp, inf); dp[0] = 0; rep(i, n) rep(j, 10002) { if (j >= a[i]) mins(dp[j], dp[j - a[i]] + b[i]); } ll ans = inf; loop(i, h, 10002) mins(ans, dp[i]); cout << ans << endn; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); cout << flush; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define repd(i, n) for (int i = (int)(n - 1); i >= 0; --i) #define repds(i, n) for (int i = (int)(n); i > 0; --i) #define loop(i, x, n) for (int i = (int)(x); i < (n); ++i) #define loops(i, x, n) for (int i = (int)(x); i <= (n); ++i) #define loopd(i, x, n) for (int i = (int)(x); i > (n); --i) #define loopds(i, x, n) for (int i = (int)(x); i >= (n); --i) #define itrep(i, s) for (auto i = begin(s); i != end(s); ++i) #define itrepd(i, s) for (auto i = --end(s); i != begin(s); --i) #define all(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ }(x) #define rall(f, x, ...) \ [&](decltype(x) &whole) { \ return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); \ }(x) using ll = long long; using ld = long double; constexpr ll inf = static_cast<ll>(1e17); constexpr int iinf = static_cast<int>(1e9); constexpr double dinf = 1e10; constexpr ld ldinf = 1e17; ll mod = static_cast<ll>(1e9 + 7); std::ostream &endn(std::ostream &os) { return os.put(os.widen('\n')); } template <class T> constexpr int sz(const T &a) { return (int)a.size(); } template <class T> constexpr T pow2(const T a) { return a * a; } template <class T, class... Args> constexpr T mins(T &a, Args... args) { return a = min<T>({a, args...}); } template <class T, class... Args> constexpr T maxs(T &a, Args... args) { return a = max<T>({a, args...}); } template <typename A, size_t N, typename T> void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll h; int n; ll a[1005], b[1005]; ll dp[10005]; void solve() { cin >> h >> n; rep(i, n) cin >> a[i] >> b[i]; fillArray(dp, inf); dp[0] = 0; rep(i, n) rep(j, 10002) { if (j >= a[i]) mins(dp[j], dp[j - a[i]] + b[i]); } ll ans = inf; loop(i, h, 10002) mins(ans, dp[i]); cout << ans << endn; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); cout << flush; return 0; }
replace
44
45
44
45
0
p02787
C++
Runtime Error
// #pragma GCC optimize("Og,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace boost::multiprecision; using namespace __gnu_pbds; template <typename T> using os = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef double ld; #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #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 pii pair<ll, ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll, ll> #define umi unordered_map<ll, ll, custom_hash> #define all(a) (a).begin(), (a).end() #define pb push_back #define make make_pair #define ff first #define ss second #define osl os<ll> #define ospii os<pair<ll, ll>> #define endl "\n" #define n_l '\n' #define dbg(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ cout << to_string(__VA_ARGS__) << endl template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template <size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() { ; } template <typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); } #define dbgm(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ dbgm(__VA_ARGS__); \ cout << endl clock_t time_p = clock(); void Auriel() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename R> void println(R r) { for (auto i : r) cout << i << " "; cout << endl; } template <typename R> void print(R r) { int e = 0; for (auto i : r) cout << i << endl; } template <typename R> void scnln(R &r) { for (auto &i : r) cin >> i; } ll st[200005] = {0}, ft[200005] = {0}, parent[200005], tt = 0, level[200005] = {0}, fans = 0; ll binexp(ll a, ll b, ll m) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } // ll dp[100001]; void dfs(vector<pair<ll, ll>> graph[], ll start, ll *visit, ll color) { visit[start] = 1; level[1] = 0; st[start] = tt; tt++; for (auto child : graph[start]) { if (!visit[child.ff]) { // level[child]=level[start]+1; // parent[child]=start; // tans+=b[child]; if (child.ss == color) dfs(graph, child.ff, visit, color); } } ft[start] = tt; } ll depth[20005]; void make_set(int v) { parent[v] = v; depth[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (depth[a] < depth[b]) swap(a, b); parent[b] = a; if (depth[a] == depth[b]) depth[a]++; } } void dijikstra(vector<pair<ll, ll>> graph[], ll start, ll *visit, ll *cost) { cost[start] = 0; // visit[start]=1; multiset<pair<ll, ll>> ms; ms.insert({0, start}); while (ms.size() != 0) { pair<ll, ll> p = *ms.begin(); ms.erase(ms.begin()); ll x = p.second; // ll w=p.second; if (visit[x] == 1) continue; visit[x] = 1; for (int i = 0; i < graph[x].size(); i++) { ll e = graph[x][i].first; ll w = graph[x][i].second; if (cost[x] + w < cost[e]) { cost[e] = w + cost[x]; ms.insert({cost[e], e}); } } } } int bfs1(vector<ll> graph[], ll *visit, ll *level, ll &ans, ll start) { queue<ll> q; // ll start=1; q.push(start); level[start] = 0; visit[start] = 1; while (q.size() != 0) { ll p = q.front(); q.pop(); for (auto it = graph[p].begin(); it != graph[p].end(); it++) { if (visit[*it] == 1) continue; level[(*it)] = level[p] + 1; ans = max(ans, level[*it]); if (ans == 5) { ll h = 90; } if (visit[(*it)] != 1) { q.push((*it)); visit[(*it)] = 1; } } } } ll dp[10000000]; int main() { ios ll md = ll(1e15 + 7); rep(i, 0, 10000000) dp[i] = 999999999999; dp[0] = 0; ll h, n; cin >> h >> n; vi a(n), b(n); rep(i, 0, n) cin >> a[i] >> b[i]; rep(i, 0, n) dp[a[i]] = b[i]; rep(i, 1, 100000) { rep(j, 0, n) { // if(i-a[j]>0) dp[i] = min(dp[min(0LL, i - a[j])] + b[j], dp[i]); if (dp[i] < 0) ll h = 89; } } ll ans = LLONG_MAX; rep(i, h, 100000) { ans = min(dp[i], ans); } cout << dp[h] << endl; Auriel(); }
// #pragma GCC optimize("Og,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; // using namespace boost::multiprecision; using namespace __gnu_pbds; template <typename T> using os = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef double ld; #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #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 pii pair<ll, ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll, ll> #define umi unordered_map<ll, ll, custom_hash> #define all(a) (a).begin(), (a).end() #define pb push_back #define make make_pair #define ff first #define ss second #define osl os<ll> #define ospii os<pair<ll, ll>> #define endl "\n" #define n_l '\n' #define dbg(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ cout << to_string(__VA_ARGS__) << endl template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template <size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() { ; } template <typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); } #define dbgm(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ dbgm(__VA_ARGS__); \ cout << endl clock_t time_p = clock(); void Auriel() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename R> void println(R r) { for (auto i : r) cout << i << " "; cout << endl; } template <typename R> void print(R r) { int e = 0; for (auto i : r) cout << i << endl; } template <typename R> void scnln(R &r) { for (auto &i : r) cin >> i; } ll st[200005] = {0}, ft[200005] = {0}, parent[200005], tt = 0, level[200005] = {0}, fans = 0; ll binexp(ll a, ll b, ll m) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } // ll dp[100001]; void dfs(vector<pair<ll, ll>> graph[], ll start, ll *visit, ll color) { visit[start] = 1; level[1] = 0; st[start] = tt; tt++; for (auto child : graph[start]) { if (!visit[child.ff]) { // level[child]=level[start]+1; // parent[child]=start; // tans+=b[child]; if (child.ss == color) dfs(graph, child.ff, visit, color); } } ft[start] = tt; } ll depth[20005]; void make_set(int v) { parent[v] = v; depth[v] = 0; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (depth[a] < depth[b]) swap(a, b); parent[b] = a; if (depth[a] == depth[b]) depth[a]++; } } void dijikstra(vector<pair<ll, ll>> graph[], ll start, ll *visit, ll *cost) { cost[start] = 0; // visit[start]=1; multiset<pair<ll, ll>> ms; ms.insert({0, start}); while (ms.size() != 0) { pair<ll, ll> p = *ms.begin(); ms.erase(ms.begin()); ll x = p.second; // ll w=p.second; if (visit[x] == 1) continue; visit[x] = 1; for (int i = 0; i < graph[x].size(); i++) { ll e = graph[x][i].first; ll w = graph[x][i].second; if (cost[x] + w < cost[e]) { cost[e] = w + cost[x]; ms.insert({cost[e], e}); } } } } int bfs1(vector<ll> graph[], ll *visit, ll *level, ll &ans, ll start) { queue<ll> q; // ll start=1; q.push(start); level[start] = 0; visit[start] = 1; while (q.size() != 0) { ll p = q.front(); q.pop(); for (auto it = graph[p].begin(); it != graph[p].end(); it++) { if (visit[*it] == 1) continue; level[(*it)] = level[p] + 1; ans = max(ans, level[*it]); if (ans == 5) { ll h = 90; } if (visit[(*it)] != 1) { q.push((*it)); visit[(*it)] = 1; } } } } ll dp[10000000]; int main() { ios ll md = ll(1e15 + 7); rep(i, 0, 10000000) dp[i] = 999999999999; dp[0] = 0; ll h, n; cin >> h >> n; vi a(n), b(n); rep(i, 0, n) cin >> a[i] >> b[i]; rep(i, 0, n) dp[a[i]] = b[i]; rep(i, 1, 100000) { rep(j, 0, n) { // if(i-a[j]>0) dp[i] = min(dp[max(0LL, i - a[j])] + b[j], dp[i]); if (dp[i] < 0) ll h = 89; } } ll ans = LLONG_MAX; rep(i, h, 100000) { ans = min(dp[i], ans); } cout << dp[h] << endl; Auriel(); }
replace
251
252
251
252
0
Time Taken : 0.104536
p02787
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long H, N, ans = 10000000000; cin >> H >> N; vector<long long> A(N), B(N), cost(30000, 10000000000); for (size_t i = 0; i < N; i++) { cin >> A.at(i) >> B.at(i); } cost.at(0) = 0; for (size_t i = 0; i < N; i++) { cost.at(A.at(i)) = B.at(i); } for (size_t i = 0; i < 30000; i++) { for (size_t j = 0; j < N; j++) { if (i - A.at(j) >= 0) { cost.at(i) = min(cost.at(i - A.at(j)) + B.at(j), cost.at(i)); } } } for (size_t i = H; i < 30000; i++) { ans = min(ans, cost.at(i)); } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { long long H, N, ans = 10000000000; cin >> H >> N; vector<long long> A(N), B(N), cost(30000, 10000000000); for (size_t i = 0; i < N; i++) { cin >> A.at(i) >> B.at(i); } cost.at(0) = 0; for (size_t i = 0; i < N; i++) { cost.at(A.at(i)) = B.at(i); } for (size_t i = 0; i < 30000; i++) { for (size_t j = 0; j < N; j++) { if (i >= A.at(j)) { cost.at(i) = min(cost.at(i - A.at(j)) + B.at(j), cost.at(i)); } } } for (size_t i = H; i < 30000; i++) { ans = min(ans, cost.at(i)); } cout << ans; }
replace
18
19
18
19
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551608) >= this->size() (which is 30000)
p02787
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // greater<T> for sorting // decreasingly #define ll long long #define pll pair<ll, ll> #define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin()) #define fill(v, p) memset(v, p, sizeof v) #define all(x) x.begin(), x.end() #define at_(x, i) x.find_by_order(i) #define koto_(x, i) x.order_of_key(i) #define PI acos(-1.0) #define EPS 0.000000001 #define INF 1LL << 62 #define MAX 300005 #define MOD 1000000007 map<ll, ll> vis[1005], dp[1005]; ll a[MAX], b[MAX], h, n; ll rec(ll pos, ll health) { if (pos >= n) { if (health <= 0) return 0; return INT_MAX; } if (health <= 0) return 0; if (vis[pos][health]) return dp[pos][health]; ll p = b[pos] + rec(pos, health - a[pos]); ll q = rec(pos + 1, health); if (health < 0) health = 0; vis[pos][health] = 1; return dp[pos][health] = min(p, q); } signed int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(0); cin >> h >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } cout << rec(0, h) << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // greater<T> for sorting // decreasingly #define ll long long #define pll pair<ll, ll> #define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin()) #define fill(v, p) memset(v, p, sizeof v) #define all(x) x.begin(), x.end() #define at_(x, i) x.find_by_order(i) #define koto_(x, i) x.order_of_key(i) #define PI acos(-1.0) #define EPS 0.000000001 #define INF 1LL << 62 #define MAX 300005 #define MOD 1000000007 ll vis[1005][10005], dp[1005][10005]; ll a[MAX], b[MAX], h, n; ll rec(ll pos, ll health) { if (pos >= n) { if (health <= 0) return 0; return INT_MAX; } if (health <= 0) return 0; if (vis[pos][health]) return dp[pos][health]; ll p = b[pos] + rec(pos, health - a[pos]); ll q = rec(pos + 1, health); if (health < 0) health = 0; vis[pos][health] = 1; return dp[pos][health] = min(p, q); } signed int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(0); cin >> h >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } cout << rec(0, h) << endl; return 0; }
replace
25
26
25
26
TLE
p02787
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007; 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; } //--------------------------------------------------------------------------------------------------- void _main() { ll H, N; cin >> H >> N; vector<vector<ll>> dp(N + 1, vector<ll>(10000 * 1000 + 1, infl)); dp[0][0] = 0; rep(i, 0, N) { ll a, b; cin >> a >> b; rep(j, 0, H + 1) { if (j > a) dp[i + 1][j] = min(dp[i][j], min(dp[i][j - a] + b, dp[i + 1][j - a] + b)); else dp[i + 1][j] = min(dp[i][j], dp[i][0] + b); } } cout << dp[N][H] << endl; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007; 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; } //--------------------------------------------------------------------------------------------------- void _main() { ll H, N; cin >> H >> N; vector<vector<ll>> dp(N + 1, vector<ll>(H + 1, infl)); dp[0][0] = 0; rep(i, 0, N) { ll a, b; cin >> a >> b; rep(j, 0, H + 1) { if (j > a) dp[i + 1][j] = min(dp[i][j], min(dp[i][j - a] + b, dp[i + 1][j - a] + b)); else dp[i + 1][j] = min(dp[i][j], dp[i][0] + b); } } cout << dp[N][H] << endl; }
replace
36
37
36
37
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02787
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int h, n; cin >> h >> n; vector<int> a, b; for (int i = 0; i < n; i++) { int ai, bi; cin >> ai >> bi; a.push_back(ai); b.push_back(bi); } vector<vector<int>> dp(1001, vector<int>(10001, INF)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= h; j++) { if (dp[i][j] > dp[i - 1][j]) dp[i][j] = dp[i - 1][j]; if (j + a[i - 1] > h && dp[i][h] > dp[i][j] + b[i - 1]) dp[i][h] = dp[i][j] + b[i - 1]; else if (dp[i][j + a[i - 1]] > dp[i][j] + b[i - 1]) dp[i][j + a[i - 1]] = dp[i][j] + b[i - 1]; } } cout << dp[n][h]; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { int h, n; cin >> h >> n; vector<int> a, b; for (int i = 0; i < n; i++) { int ai, bi; cin >> ai >> bi; a.push_back(ai); b.push_back(bi); } vector<vector<int>> dp(2000, vector<int>(20000, INF)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= h; j++) { if (dp[i][j] > dp[i - 1][j]) dp[i][j] = dp[i - 1][j]; if (j + a[i - 1] > h && dp[i][h] > dp[i][j] + b[i - 1]) dp[i][h] = dp[i][j] + b[i - 1]; else if (dp[i][j + a[i - 1]] > dp[i][j] + b[i - 1]) dp[i][j + a[i - 1]] = dp[i][j] + b[i - 1]; } } cout << dp[n][h]; return 0; }
replace
13
14
13
14
0
p02787
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int h, n; cin >> h >> n; vector<int> dp(h + 1, 1000000000); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; for (int j = 1; j <= a; ++j) { dp[j] = min(dp[j], b); } for (int j = a + 1; j <= h; ++j) { dp[j] = min(dp[j], dp[j - a] + b); } } cout << dp[h] << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int h, n; cin >> h >> n; vector<int> dp(h + 1, 1000000000); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; for (int j = 1; j <= a; ++j) { if (h < j) { break; } dp[j] = min(dp[j], b); } for (int j = a + 1; j <= h; ++j) { dp[j] = min(dp[j], dp[j - a] + b); } } cout << dp[h] << endl; return 0; }
insert
15
15
15
18
0
p02787
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define endl '\n' #define int long long int h, n; int a[2000], b[2000]; int dp[1001][10001]; int f(int i, int left) { if (left <= 0) return 0; if (i == n) { if (left == 0) return 0; return 1e18; } return dp[i][left] = min({f(i + 1, left), b[i] + f(i, left - a[i]), b[i] + f(i + 1, left - a[i])}); } int32_t main() { cin >> h >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; memset(dp, -1, sizeof(dp)); cout << f(0, h); }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define endl '\n' #define int long long int h, n; int a[2000], b[2000]; int dp[1001][10001]; int f(int i, int left) { if (left <= 0) return 0; if (i == n) { if (left == 0) return 0; return 1e18; } if (dp[i][left] != -1) return dp[i][left]; return dp[i][left] = min({f(i + 1, left), b[i] + f(i, left - a[i]), b[i] + f(i + 1, left - a[i])}); } int32_t main() { cin >> h >> n; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; memset(dp, -1, sizeof(dp)); cout << f(0, h); }
insert
34
34
34
36
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #include <bits/stdtr1c++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; /// Typedef typedef long long ll; typedef unsigned long ul; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb push_back #define ppb pop_back #define MP make_pair #define ff first #define ss second #define sf scanf #define pf printf #define loop(i, y) for (int i = 0; i < int(y); i++) #define FOR(i, x, y) for (int i = int(x); i < int(y); i++) #define ROF(i, x, y) for (int i = int(x); i >= int(y); i--) #define all(c) c.begin(), c.end() #define sz(c) int(c.size()) #define clr(x, y) memset(x, y, sizeof(x)) #define si(x) scanf("%d", &x) #define sii(x, y) scanf("%d %d", &x, &y) #define siii(x, y, z) scanf("%d %d %d", &x, &y, &z) #define sl(x) scanf("%lld", &x) #define sll(x, y) scanf("%lld %lld", &x, &y) #define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z) #define FastIO ios_base::sync_with_stdio(false) #define FixedPrecision(x) \ ios_base::sync_with_stdio(false); \ cout.setf(ios::fixed); \ cout.precision(x); \ cin.tie(0); #define bitCheck(N, in) ((bool)(N & (1LL << (in)))) #define bitOff(N, in) (N & (~(1LL << (in)))) #define bitOn(N, in) (N | (1LL << (in))) #define bitFlip(a, k) (a ^ (1LL << (k))) #define popCount(x) __builtin_popcount(x) #define popCountLL(x) __builtin_popcountll(x) #define int2Bin(x, y) \ bitset<y> z = x; \ cout << z.to_string() << endl; #define tr(it, container) \ for (auto it = container.begin(); it != container.end(); it++) #define unq(v) (v).erase(unique(all(v)), v.end()) #define common(a, b) \ sort(all(a)), sort(all(b)), \ a.erase(set_intersection(all(a), all(b), a.begin()), a.end()) #define uncommon(a, b) \ sort(all(a)), sort(all(b)), \ a.erase(set_symmetric_difference(all(a), all(b), a.begin()), a.end()) #define DB(x) cout << #x << " = " << x << endl #define DDB(x, y) cout << #x << " = " << x << " " << #y << " = " << y << endl #define DDDB(x, y, z) \ cout << #x << " = " << x << " " << #y << " = " << y << " " << #z \ << " = " << z << endl #define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a)) /// template <typename T> using orderset = tree <T, null_type, less<T>, /// rb_tree_tag,tree_order_statistics_node_update>; *X.find_by_order(k) /// //returns the kth largest element.(0-based) X.order_of_key(val) //returns /// the no. of values less than val template <class T> inline T bigMod(T p, T e, T M) { ll ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T modInverse(T a, T M) { return bigMod(a, M - 2, M); } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { a = abs(a); b = abs(b); return (a / gcd(a, b)) * b; } template <class T> inline string int2String(T a) { ostringstream str; str << a; return str.str(); } template <class T> inline T string2int(string a) { stringstream str(a); T b; str >> b; return b; } template <class T> inline void read(T &r) { r = 0; int f = 1; char ch = getchar(); while (ch < '0' or ch > '9') { f = (ch == '-' ? -1 : 1), ch = getchar(); } while (ch >= '0' and ch <= '9') { r = r * 10 + ch - '0', ch = getchar(); } r *= f; } const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1}; const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2}; #ifdef VAMP #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " = " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...); } #else #define dbg(...) #endif ///******************************************START****************************************** /// START /// Constants #define MAX 10005 #define MOD 1000000007 #define base 1000000007 #define eps 1e-9B #define INF 1 << 20 // 2,305,843,009,213,693,952 #define inf 1 << 20 // 536,870,912 #define PI acos(-1.0) // 3.1415926535897932 // #define INF 0x3f3f3f3f3f3f3f3f // #define inf 0x3f3f3f3f struct Point { ll x, y; } P[MAX]; bool cmp(Point p, Point q) { if (p.x == q.x) return p.y < q.y; return p.x < q.x; } ll d, n, a; int main() { #ifdef VAMP clock_t tStart = clock(); freopen("E:\\Raihanur\\input.txt", "r", stdin); freopen("E:\\Raihanur\\output.txt", "w", stdout); #endif cin >> n >> d >> a; for (int i = 0; i < n; i++) { cin >> P[i].x >> P[i].y; P[i].y = (P[i].y + a - 1) / a; } d *= 2; sort(P, P + n, cmp); queue<pii> q; ll ans = 0, total = 0; FOR(i, 0, n) { ll x = P[i].x; ll h = P[i].y; while (sz(q) && q.front().ff < x) { total -= q.front().ss; q.pop(); } h -= total; if (h > 0) { ans += h; total += h; q.emplace(x + d, h); } } cout << ans << endl; #ifdef VAMP printf("\n>>Runtime: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC); #endif return 0; }
#include <bits/stdc++.h> using namespace std; // #include <bits/stdtr1c++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; /// Typedef typedef long long ll; typedef unsigned long ul; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb push_back #define ppb pop_back #define MP make_pair #define ff first #define ss second #define sf scanf #define pf printf #define loop(i, y) for (int i = 0; i < int(y); i++) #define FOR(i, x, y) for (int i = int(x); i < int(y); i++) #define ROF(i, x, y) for (int i = int(x); i >= int(y); i--) #define all(c) c.begin(), c.end() #define sz(c) int(c.size()) #define clr(x, y) memset(x, y, sizeof(x)) #define si(x) scanf("%d", &x) #define sii(x, y) scanf("%d %d", &x, &y) #define siii(x, y, z) scanf("%d %d %d", &x, &y, &z) #define sl(x) scanf("%lld", &x) #define sll(x, y) scanf("%lld %lld", &x, &y) #define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z) #define FastIO ios_base::sync_with_stdio(false) #define FixedPrecision(x) \ ios_base::sync_with_stdio(false); \ cout.setf(ios::fixed); \ cout.precision(x); \ cin.tie(0); #define bitCheck(N, in) ((bool)(N & (1LL << (in)))) #define bitOff(N, in) (N & (~(1LL << (in)))) #define bitOn(N, in) (N | (1LL << (in))) #define bitFlip(a, k) (a ^ (1LL << (k))) #define popCount(x) __builtin_popcount(x) #define popCountLL(x) __builtin_popcountll(x) #define int2Bin(x, y) \ bitset<y> z = x; \ cout << z.to_string() << endl; #define tr(it, container) \ for (auto it = container.begin(); it != container.end(); it++) #define unq(v) (v).erase(unique(all(v)), v.end()) #define common(a, b) \ sort(all(a)), sort(all(b)), \ a.erase(set_intersection(all(a), all(b), a.begin()), a.end()) #define uncommon(a, b) \ sort(all(a)), sort(all(b)), \ a.erase(set_symmetric_difference(all(a), all(b), a.begin()), a.end()) #define DB(x) cout << #x << " = " << x << endl #define DDB(x, y) cout << #x << " = " << x << " " << #y << " = " << y << endl #define DDDB(x, y, z) \ cout << #x << " = " << x << " " << #y << " = " << y << " " << #z \ << " = " << z << endl #define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a)) /// template <typename T> using orderset = tree <T, null_type, less<T>, /// rb_tree_tag,tree_order_statistics_node_update>; *X.find_by_order(k) /// //returns the kth largest element.(0-based) X.order_of_key(val) //returns /// the no. of values less than val template <class T> inline T bigMod(T p, T e, T M) { ll ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T modInverse(T a, T M) { return bigMod(a, M - 2, M); } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { a = abs(a); b = abs(b); return (a / gcd(a, b)) * b; } template <class T> inline string int2String(T a) { ostringstream str; str << a; return str.str(); } template <class T> inline T string2int(string a) { stringstream str(a); T b; str >> b; return b; } template <class T> inline void read(T &r) { r = 0; int f = 1; char ch = getchar(); while (ch < '0' or ch > '9') { f = (ch == '-' ? -1 : 1), ch = getchar(); } while (ch >= '0' and ch <= '9') { r = r * 10 + ch - '0', ch = getchar(); } r *= f; } const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1}; const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2}; #ifdef VAMP #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " = " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...); } #else #define dbg(...) #endif ///******************************************START****************************************** /// START /// Constants #define MAX 200005 #define MOD 1000000007 #define base 1000000007 #define eps 1e-9B #define INF 1 << 20 // 2,305,843,009,213,693,952 #define inf 1 << 20 // 536,870,912 #define PI acos(-1.0) // 3.1415926535897932 // #define INF 0x3f3f3f3f3f3f3f3f // #define inf 0x3f3f3f3f struct Point { ll x, y; } P[MAX]; bool cmp(Point p, Point q) { if (p.x == q.x) return p.y < q.y; return p.x < q.x; } ll d, n, a; int main() { #ifdef VAMP clock_t tStart = clock(); freopen("E:\\Raihanur\\input.txt", "r", stdin); freopen("E:\\Raihanur\\output.txt", "w", stdout); #endif cin >> n >> d >> a; for (int i = 0; i < n; i++) { cin >> P[i].x >> P[i].y; P[i].y = (P[i].y + a - 1) / a; } d *= 2; sort(P, P + n, cmp); queue<pii> q; ll ans = 0, total = 0; FOR(i, 0, n) { ll x = P[i].x; ll h = P[i].y; while (sz(q) && q.front().ff < x) { total -= q.front().ss; q.pop(); } h -= total; if (h > 0) { ans += h; total += h; q.emplace(x + d, h); } } cout << ans << endl; #ifdef VAMP printf("\n>>Runtime: %.10fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC); #endif return 0; }
replace
134
135
134
135
0
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define REP(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; template <class Monoid, class OpMonoid> class LazySegmentTree { using FuncMM = std::function<Monoid(Monoid, Monoid)>; using FuncMO = std::function<Monoid(Monoid, OpMonoid, int)>; using FuncOO = std::function<OpMonoid(OpMonoid, OpMonoid)>; const FuncMM funcMM; const FuncMO funcMO; const FuncOO funcOO; const Monoid monoidIdentity; const OpMonoid opMonoidIdentity; int N; std::vector<Monoid> dat; std::vector<OpMonoid> lazy; void setLazy(int k, const OpMonoid &om) { lazy[k] = funcOO(lazy[k], om); } void push(int k, int len) { if (lazy[k] == opMonoidIdentity) return; if (k < N) { setLazy(2 * k + 0, lazy[k]); setLazy(2 * k + 1, lazy[k]); } dat[k] = funcMO(dat[k], lazy[k], len); lazy[k] = opMonoidIdentity; } public: LazySegmentTree(int n, const FuncMM funcMM, const FuncMO funcMO, const FuncOO funcOO, const Monoid monoidIdentity, const OpMonoid opMonoidIdentity) : funcMM(funcMM), funcMO(funcMO), funcOO(funcOO), monoidIdentity(monoidIdentity), opMonoidIdentity(opMonoidIdentity) { N = 1; while (N < n) N *= 2; dat.resize(2 * N, monoidIdentity); lazy.resize(2 * N, opMonoidIdentity); } void dump() { std::cout << "dat: "; for (int i = 1; i < dat.size(); i++) { if (i == N) std::cout << "| "; std::cout << dat[i].ai << "(" << lazy[i].p << "," << lazy[i].q << "," << lazy[i].r << ") "; } std::cout << std::endl; } void set(int i, const Monoid &v) { dat[N + i] = v; } void init() { for (int i = N - 1; i > 0; i--) { dat[i] = funcMM(dat[2 * i + 0], dat[2 * i + 1]); } } void update(int s, int t, const OpMonoid &om) { update(s, t, om, 1, 0, N); } void update(int s, int t, const OpMonoid &om, int k, int l, int r) { push(k, r - l); if (r <= s || t <= l) return; if (s <= l && r <= t) { setLazy(k, om); push(k, r - l); return; } update(s, t, om, 2 * k + 0, l, (l + r) / 2); update(s, t, om, 2 * k + 1, (l + r) / 2, r); dat[k] = funcMM(dat[2 * k + 0], dat[2 * k + 1]); } Monoid query(int s, int t) { return query(s, t, 1, 0, N); } Monoid query(int s, int t, int k, int l, int r) { push(k, r - l); if (r <= s || t <= l) return monoidIdentity; if (s <= l && r <= t) return dat[k]; Monoid vl = query(s, t, 2 * k + 0, l, (l + r) / 2); Monoid vr = query(s, t, 2 * k + 1, (l + r) / 2, r); return funcMM(vl, vr); } }; struct VAL { ll ai; }; struct OP { ll p; }; bool operator==(const OP &a, const OP &b) { return a.p == b.p; } int main() { int N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> v; rep(i, N) { ll x, h; cin >> x >> h; v.emplace_back(x, h); } sort(ALLOF(v)); vector<int> range; int idx = 0; rep(i, N) { idx = i; while (idx + 1 < N && v[idx + 1].first <= v[i].first + 2 * D) idx++; range.push_back(idx + 1); } auto funcMM = [](const VAL &a, const VAL &b) { VAL ret; ret.ai = a.ai + b.ai; return ret; }; auto funcMO = [](const VAL &a, const OP &b, int k) { VAL ret; ret.ai = (a.ai + b.p) * k; return ret; }; auto funcOO = [](const OP &a, const OP &b) { OP ret; ret.p = b.p + a.p; return ret; }; LazySegmentTree<VAL, OP> lst(N, funcMM, funcMO, funcOO, (VAL){0}, (OP){0}); rep(i, N) { VAL val; val.ai = v[i].second; lst.set(i, val); } ll ret = 0; rep(i, N) { ll val = lst.query(i, i + 1).ai; // cout << i << " " << val << endl; if (val <= 0) continue; ll damage = (val + A - 1) / A; OP op; op.p = -damage * A; lst.update(i, range[i], op); // cout << " " << i << " " << range[i] << " " << op.p << endl; ret += damage; } cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; template <class Monoid, class OpMonoid> class LazySegmentTree { using FuncMM = std::function<Monoid(Monoid, Monoid)>; using FuncMO = std::function<Monoid(Monoid, OpMonoid, int)>; using FuncOO = std::function<OpMonoid(OpMonoid, OpMonoid)>; const FuncMM funcMM; const FuncMO funcMO; const FuncOO funcOO; const Monoid monoidIdentity; const OpMonoid opMonoidIdentity; int N; std::vector<Monoid> dat; std::vector<OpMonoid> lazy; void setLazy(int k, const OpMonoid &om) { lazy[k] = funcOO(lazy[k], om); } void push(int k, int len) { if (lazy[k] == opMonoidIdentity) return; if (k < N) { setLazy(2 * k + 0, lazy[k]); setLazy(2 * k + 1, lazy[k]); } dat[k] = funcMO(dat[k], lazy[k], len); lazy[k] = opMonoidIdentity; } public: LazySegmentTree(int n, const FuncMM funcMM, const FuncMO funcMO, const FuncOO funcOO, const Monoid monoidIdentity, const OpMonoid opMonoidIdentity) : funcMM(funcMM), funcMO(funcMO), funcOO(funcOO), monoidIdentity(monoidIdentity), opMonoidIdentity(opMonoidIdentity) { N = 1; while (N < n) N *= 2; dat.resize(2 * N, monoidIdentity); lazy.resize(2 * N, opMonoidIdentity); } void dump() { std::cout << "dat: "; for (int i = 1; i < dat.size(); i++) { if (i == N) std::cout << "| "; std::cout << dat[i].ai << "(" << lazy[i].p << "," << lazy[i].q << "," << lazy[i].r << ") "; } std::cout << std::endl; } void set(int i, const Monoid &v) { dat[N + i] = v; } void init() { for (int i = N - 1; i > 0; i--) { dat[i] = funcMM(dat[2 * i + 0], dat[2 * i + 1]); } } void update(int s, int t, const OpMonoid &om) { update(s, t, om, 1, 0, N); } void update(int s, int t, const OpMonoid &om, int k, int l, int r) { push(k, r - l); if (r <= s || t <= l) return; if (s <= l && r <= t) { setLazy(k, om); push(k, r - l); return; } update(s, t, om, 2 * k + 0, l, (l + r) / 2); update(s, t, om, 2 * k + 1, (l + r) / 2, r); dat[k] = funcMM(dat[2 * k + 0], dat[2 * k + 1]); } Monoid query(int s, int t) { return query(s, t, 1, 0, N); } Monoid query(int s, int t, int k, int l, int r) { push(k, r - l); if (r <= s || t <= l) return monoidIdentity; if (s <= l && r <= t) return dat[k]; Monoid vl = query(s, t, 2 * k + 0, l, (l + r) / 2); Monoid vr = query(s, t, 2 * k + 1, (l + r) / 2, r); return funcMM(vl, vr); } }; struct VAL { ll ai; }; struct OP { ll p; }; bool operator==(const OP &a, const OP &b) { return a.p == b.p; } int main() { int N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> v; rep(i, N) { ll x, h; cin >> x >> h; v.emplace_back(x, h); } sort(ALLOF(v)); vector<int> range; int idx = 0; rep(i, N) { while (idx + 1 < N && v[idx + 1].first <= v[i].first + 2 * D) idx++; range.push_back(idx + 1); } auto funcMM = [](const VAL &a, const VAL &b) { VAL ret; ret.ai = a.ai + b.ai; return ret; }; auto funcMO = [](const VAL &a, const OP &b, int k) { VAL ret; ret.ai = (a.ai + b.p) * k; return ret; }; auto funcOO = [](const OP &a, const OP &b) { OP ret; ret.p = b.p + a.p; return ret; }; LazySegmentTree<VAL, OP> lst(N, funcMM, funcMO, funcOO, (VAL){0}, (OP){0}); rep(i, N) { VAL val; val.ai = v[i].second; lst.set(i, val); } ll ret = 0; rep(i, N) { ll val = lst.query(i, i + 1).ai; // cout << i << " " << val << endl; if (val <= 0) continue; ll damage = (val + A - 1) / A; OP op; op.p = -damage * A; lst.update(i, range[i], op); // cout << " " << i << " " << range[i] << " " << op.p << endl; ret += damage; } cout << ret << endl; return 0; }
delete
121
122
121
121
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> #define LL long long using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e5 + 10, M = N * 400, mod = 1e9 + 7; int n; struct node { LL x, h; bool operator<(const node t) const { return x < t.x; } } s[N]; LL a, d; LL p[N]; // 前缀 int main() { cin >> n >> d >> a; for (int i = 1; i <= n; i++) { scanf("%lld%lld", &s[i].x, &s[i].h); } sort(s + 1, s + 1 + n); int r = 0; LL ans = 0; for (int l = 1; l <= n; l++) { p[l] += p[l - 1]; s[l].h += p[l]; // cout<<s[l].x<<' '<<p[l]<<' '<<s[l].h<<' '; while (r < n && s[r + 1].x <= s[l].x + 2 * d) r++; if (s[l].h < 0) s[l].h = 0; LL k = s[l].h / a + (s[l].h % a > 0); ans += k; p[l] -= k * a; p[r + 1] += k * a; // cout<<l<<' '<<r<<' '<<ans<<' '<<p[l]<<endl; } cout << ans; return 0; }
#include <bits/stdc++.h> #define LL long long using namespace std; const int INF = 0x3f3f3f3f; const int N = 2e5 + 10, M = N * 400, mod = 1e9 + 7; int n; struct node { LL x, h; bool operator<(const node t) const { return x < t.x; } } s[N]; LL a, d; LL p[N]; // 前缀 int main() { cin >> n >> d >> a; for (int i = 1; i <= n; i++) { scanf("%lld%lld", &s[i].x, &s[i].h); } sort(s + 1, s + 1 + n); int r = 0; LL ans = 0; for (int l = 1; l <= n; l++) { p[l] += p[l - 1]; s[l].h += p[l]; // cout<<s[l].x<<' '<<p[l]<<' '<<s[l].h<<' '; while (r < n && s[r + 1].x <= s[l].x + 2 * d) r++; if (s[l].h < 0) s[l].h = 0; LL k = s[l].h / a + (s[l].h % a > 0); ans += k; p[l] -= k * a; p[r + 1] += k * a; // cout<<l<<' '<<r<<' '<<ans<<' '<<p[l]<<endl; } cout << ans; return 0; }
replace
4
5
4
5
0
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define inf (ll)1e9 #define mod (ll)(1e9 + 7) #define d(x) cerr << #x << "=" << x << endl; #define p(x) cout << (x) << endl #define ps(x) cout << (x); #define pk(x) cout << (x) << " "; #define pfix(d, x) cout << fixed << setprecision(d) << x << endl; #define pb push_back #define all(v) (v).begin(), (v).end() #define minel(v) *min_element(all(v)) #define minind(v) distance((v).begin(), min_element(all(v))) #define maxel(v) *max_element(all(v)) #define maxind(v) distance((v).begin(), max_element(all(v))) #define p2d(v, n, m) \ rep(i, n) { \ rep(j, m) { pk(v[i][j]); } \ p(""); \ } #define fi first #define se second template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll a[100001], b[100001], c[100001], d, n, m, x, y, z, h, w, k, sum, mi = inf, ma = -inf, ans, s, t, l, r, res, tmp, itr, p, q; bool flag; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; char cha; string st; typedef map<ll, ll> imap; typedef pair<ll, ll> P; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<pair<ll, ll>> VP; P pa; ll damages[200002]; int main() { cin >> n >> d >> m; VP vp; rep(i, n) { cin >> x >> h; vp.pb({x, h}); } sort(all(vp)); // 尺取り法でx_iが左端の場合の攻撃範囲を求める ll bombnum, nowhp, damage; rep(i, n) { rep(j, r + 1, n) { if (vp[j].fi - vp[i].fi <= 2 * d) r++; } // iからはrまで届く。 nowhp = vp[i].se - damages[i]; if (nowhp > 0) { bombnum = ((nowhp % m) ? nowhp / m + 1 : nowhp / m); sum += bombnum; damage = bombnum * m; damages[i] += damage; damages[r + 1] -= damage; } damages[i + 1] += damages[i]; // rep(i,n+1)d(damages[i]); } p(sum); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define inf (ll)1e9 #define mod (ll)(1e9 + 7) #define d(x) cerr << #x << "=" << x << endl; #define p(x) cout << (x) << endl #define ps(x) cout << (x); #define pk(x) cout << (x) << " "; #define pfix(d, x) cout << fixed << setprecision(d) << x << endl; #define pb push_back #define all(v) (v).begin(), (v).end() #define minel(v) *min_element(all(v)) #define minind(v) distance((v).begin(), min_element(all(v))) #define maxel(v) *max_element(all(v)) #define maxind(v) distance((v).begin(), max_element(all(v))) #define p2d(v, n, m) \ rep(i, n) { \ rep(j, m) { pk(v[i][j]); } \ p(""); \ } #define fi first #define se second template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll a[100001], b[100001], c[100001], d, n, m, x, y, z, h, w, k, sum, mi = inf, ma = -inf, ans, s, t, l, r, res, tmp, itr, p, q; bool flag; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; char cha; string st; typedef map<ll, ll> imap; typedef pair<ll, ll> P; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<pair<ll, ll>> VP; P pa; ll damages[200002]; int main() { cin >> n >> d >> m; VP vp; rep(i, n) { cin >> x >> h; vp.pb({x, h}); } sort(all(vp)); // 尺取り法でx_iが左端の場合の攻撃範囲を求める ll bombnum, nowhp, damage; rep(i, n) { rep(j, r + 1, n) { if (vp[j].fi - vp[i].fi <= 2 * d) r++; else break; } // iからはrまで届く。 nowhp = vp[i].se - damages[i]; if (nowhp > 0) { bombnum = ((nowhp % m) ? nowhp / m + 1 : nowhp / m); sum += bombnum; damage = bombnum * m; damages[i] += damage; damages[r + 1] -= damage; } damages[i + 1] += damages[i]; // rep(i,n+1)d(damages[i]); } p(sum); return 0; }
insert
61
61
61
63
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; // 入力 ll n, Q; // BIT ll bit0[100001], bit1[100001]; ll sum(ll *b, int i) { ll s = 0; while (i > 0) { s += b[i]; i -= i & -i; } return s; } void add(ll *b, int i, ll v) { while (i <= n) { b[i] += v; i += i & -i; } } int main() { ll d, a; cin >> n >> d >> a; vector<P> A(n + 1); vector<ll> B(n + 1); for (int i = 1; i <= n; i++) { ll x, y; cin >> x >> y; A[i] = mp(x, y); B[i] = x; } sort(A.begin() + 1, A.end()); sort(B.begin() + 1, B.end()); // for(int i = 1; i <= n; i++) { // cout << A[i].sc << endl; // } for (int i = 1; i <= n; i++) { add(bit0, i, A[i].sc); } ll count = 0LL; for (int i = 1; i <= n; i++) { ll res = 0; res += sum(bit0, i) + sum(bit1, i) * i; res -= sum(bit0, i - 1) + sum(bit1, i - 1) * (i - 1); // cout << res << endl; if (res > 0) { // 爆撃(i ~ i + 2D) ll bomb = (res + a - 1) / a; count += bomb; auto index = upper_bound(B.begin() + 1, B.end(), B[i] + 2 * d); ll r = index - B.begin() - 1; // cout << "r" << r << endl; add(bit0, i, bomb * a * (i - 1)); add(bit1, i, -1 * bomb * a); add(bit0, r + 1, -1 * bomb * a * r); add(bit1, r + 1, bomb * a); } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; // 入力 ll n, Q; // BIT ll bit0[200001], bit1[200001]; ll sum(ll *b, int i) { ll s = 0; while (i > 0) { s += b[i]; i -= i & -i; } return s; } void add(ll *b, int i, ll v) { while (i <= n) { b[i] += v; i += i & -i; } } int main() { ll d, a; cin >> n >> d >> a; vector<P> A(n + 1); vector<ll> B(n + 1); for (int i = 1; i <= n; i++) { ll x, y; cin >> x >> y; A[i] = mp(x, y); B[i] = x; } sort(A.begin() + 1, A.end()); sort(B.begin() + 1, B.end()); // for(int i = 1; i <= n; i++) { // cout << A[i].sc << endl; // } for (int i = 1; i <= n; i++) { add(bit0, i, A[i].sc); } ll count = 0LL; for (int i = 1; i <= n; i++) { ll res = 0; res += sum(bit0, i) + sum(bit1, i) * i; res -= sum(bit0, i - 1) + sum(bit1, i - 1) * (i - 1); // cout << res << endl; if (res > 0) { // 爆撃(i ~ i + 2D) ll bomb = (res + a - 1) / a; count += bomb; auto index = upper_bound(B.begin() + 1, B.end(), B[i] + 2 * d); ll r = index - B.begin() - 1; // cout << "r" << r << endl; add(bit0, i, bomb * a * (i - 1)); add(bit1, i, -1 * bomb * a); add(bit0, r + 1, -1 * bomb * a * r); add(bit1, r + 1, bomb * a); } } cout << count << endl; return 0; }
replace
18
19
18
19
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(c) (c).begin(), (c).end() #define pb push_back #define dbg(...) \ do { \ cerr << __LINE__ << ": "; \ dbgprint(#__VA_ARGS__, __VA_ARGS__); \ } while (0); using namespace std; namespace std { template <class S, class T> struct hash<pair<S, T>> { size_t operator()(const pair<S, T> &p) const { return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second); } }; template <class T> struct hash<vector<T>> { size_t operator()(const vector<T> &v) const { size_t h = 0; for (auto i : v) h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1; return h; } }; } // namespace std template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", "); return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &v) { os << "{ "; for (const auto &i : v) os << i << ", "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &v) { os << "{"; for (const auto &i : v) os << " " << i.first << ": " << i.second << ","; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << ", " << p.second << ")"; } void dbgprint(const string &fmt) { cerr << endl; } template <class H, class... T> void dbgprint(const string &fmt, const H &h, const T &...r) { cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " "; dbgprint(fmt.substr(fmt.find(",") + 1), r...); } typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int main() { cin.tie(0); cin.sync_with_stdio(0); int n; ll d, a; cin >> n >> d >> a; d *= 2; vector<ll> ps; vector<pair<ll, ll>> in; rep(i, n) { ll x, h; cin >> x >> h; x *= 2; in.emplace_back(x, h); ps.pb(x - d); ps.pb(x); ps.pb(x + d + 1); } sort(all(ps)); ps.erase(unique(all(ps)), ps.end()); vector<vector<ll>> ev(ps.size()); rep(i, n) { ll x = in[i].first; x = lower_bound(all(ps), x - d) - ps.begin(); ev[x].pb(i); } ll bomb = 0, ans = 0; rep(i, ev.size()) for (ll j : ev[i]) { if (j < 0) bomb += j; else { ll x = in[j].first, h = in[j].second; x = lower_bound(all(ps), x + 2 * d + 1) - ps.begin(); if (h > bomb * a) { ll k = (h - bomb * a + a - 1) / a; ans += k; bomb += k; ev[x].pb(-k); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(c) (c).begin(), (c).end() #define pb push_back #define dbg(...) \ do { \ cerr << __LINE__ << ": "; \ dbgprint(#__VA_ARGS__, __VA_ARGS__); \ } while (0); using namespace std; namespace std { template <class S, class T> struct hash<pair<S, T>> { size_t operator()(const pair<S, T> &p) const { return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second); } }; template <class T> struct hash<vector<T>> { size_t operator()(const vector<T> &v) const { size_t h = 0; for (auto i : v) h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1; return h; } }; } // namespace std template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", "); return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &v) { os << "{ "; for (const auto &i : v) os << i << ", "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &v) { os << "{"; for (const auto &i : v) os << " " << i.first << ": " << i.second << ","; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << ", " << p.second << ")"; } void dbgprint(const string &fmt) { cerr << endl; } template <class H, class... T> void dbgprint(const string &fmt, const H &h, const T &...r) { cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " "; dbgprint(fmt.substr(fmt.find(",") + 1), r...); } typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int main() { cin.tie(0); cin.sync_with_stdio(0); int n; ll d, a; cin >> n >> d >> a; d *= 2; vector<ll> ps; vector<pair<ll, ll>> in; rep(i, n) { ll x, h; cin >> x >> h; x *= 2; in.emplace_back(x, h); ps.pb(x - d); ps.pb(x); ps.pb(x + d + 1); } sort(all(ps)); ps.erase(unique(all(ps)), ps.end()); vector<vector<ll>> ev(ps.size()); rep(i, n) { ll x = in[i].first; x = lower_bound(all(ps), x - d) - ps.begin(); ev[x].pb(i); } ll bomb = 0, ans = 0; rep(i, ev.size()) for (ll j : ev[i]) { if (j < 0) bomb += j; else { ll x = in[j].first, h = in[j].second; x = lower_bound(all(ps), x + d + 1) - ps.begin(); if (h > bomb * a) { ll k = (h - bomb * a + a - 1) / a; ans += k; bomb += k; ev[x].pb(-k); } } } cout << ans << endl; return 0; }
replace
96
97
96
97
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define fi first #define se second #define endl '\n' #define fcin \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define inf 0x3f3f3f3f #define all(x) x.begin(), x.end() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef pair<int, int> pii; /* * * stuff you should look for * * int overflow, array bounds * * special cases (n=1?), set tle * */ int n, d, a; vector<pii> mon; struct SegTree { vector<ll> st, lazy; SegTree() { st.resize(4 * n + 4, 0); lazy.resize(4 * n + 4, 0); } void build(int p, int l, int r) { if (l == r) st[p] = mon[l - 1].se; else { int mid = (l + r) / 2; build(p + p, l, mid); build(p + p + 1, mid + 1, r); st[p] = st[p + p] + st[p + p + 1]; } } void prop(int p, int l, int r) { if (lazy[p]) { st[p] += lazy[p] * (r - l + 1); if (l != r) { lazy[p + p] += lazy[p]; lazy[p + p + 1] += lazy[p]; } lazy[p] = 0; } } void upd(int p, int l, int r, int a, int b, ll x) { prop(p, l, r); if (l > b or r < a) return; if (l >= a and r <= b) { lazy[p] += x; prop(p, l, r); } else { int mid = (l + r) / 2; upd(p + p, l, mid, a, b, x); upd(p + p + 1, mid + 1, r, a, b, x); st[p] = st[p + p] + st[p + p + 1]; } } ll query(int p, int l, int r, int a, int b) { prop(p, l, r); if (l > b or r < a) return 0; if (l >= a and r <= b) return st[p]; else { int mid = (l + r) / 2; ll x = query(p + p, l, mid, a, b); ll y = query(p + p + 1, mid + 1, r, a, b); return x + y; } } }; int main() { fcin; cin >> n >> d >> a; for (int i = 0; i < n; i++) { int x, h; cin >> x >> h; h = (h + a - 1) / a; mon.eb(x, h); } sort(all(mon)); SegTree s; s.build(1, 1, n); ll ans = 0; for (int i = 0; i < n; i++) { ll hp = s.query(1, 1, n, i + 1, i + 1); if (hp <= 0) continue; int x = mon[i].fi; int lo = i, hi = n - 1; int last = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (x + 2 * d >= mon[mid].fi) { last = mid; lo = mid + 1; } else hi = mid - 1; } assert(last != -1); ans += hp; s.upd(1, 1, n, i + 1, last + 1, -hp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define fi first #define se second #define endl '\n' #define fcin \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define inf 0x3f3f3f3f #define all(x) x.begin(), x.end() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef pair<int, int> pii; /* * * stuff you should look for * * int overflow, array bounds * * special cases (n=1?), set tle * */ int n, d, a; vector<pii> mon; struct SegTree { vector<ll> st, lazy; SegTree() { st.resize(4 * n + 4, 0); lazy.resize(4 * n + 4, 0); } void build(int p, int l, int r) { if (l == r) st[p] = mon[l - 1].se; else { int mid = (l + r) / 2; build(p + p, l, mid); build(p + p + 1, mid + 1, r); st[p] = st[p + p] + st[p + p + 1]; } } void prop(int p, int l, int r) { if (lazy[p]) { st[p] += lazy[p] * (r - l + 1); if (l != r) { lazy[p + p] += lazy[p]; lazy[p + p + 1] += lazy[p]; } lazy[p] = 0; } } void upd(int p, int l, int r, int a, int b, ll x) { prop(p, l, r); if (l > b or r < a) return; if (l >= a and r <= b) { lazy[p] += x; prop(p, l, r); } else { int mid = (l + r) / 2; upd(p + p, l, mid, a, b, x); upd(p + p + 1, mid + 1, r, a, b, x); st[p] = st[p + p] + st[p + p + 1]; } } ll query(int p, int l, int r, int a, int b) { prop(p, l, r); if (l > b or r < a) return 0; if (l >= a and r <= b) return st[p]; else { int mid = (l + r) / 2; ll x = query(p + p, l, mid, a, b); ll y = query(p + p + 1, mid + 1, r, a, b); return x + y; } } }; int main() { fcin; cin >> n >> d >> a; for (int i = 0; i < n; i++) { int x, h; cin >> x >> h; h = (h + a - 1) / a; mon.eb(x, h); } sort(all(mon)); SegTree s; s.build(1, 1, n); ll ans = 0; for (int i = 0; i < n; i++) { ll hp = s.query(1, 1, n, i + 1, i + 1); if (hp <= 0) continue; int x = mon[i].fi; int lo = i, hi = n - 1; int last = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (x + (ll)2 * d >= mon[mid].fi) { last = mid; lo = mid + 1; } else hi = mid - 1; } assert(last != -1); ans += hp; s.upd(1, 1, n, i + 1, last + 1, -hp); } cout << ans << endl; return 0; }
replace
119
120
119
120
0
p02788
C++
Time Limit Exceeded
// https://atcoder.jp/contests/abc153/tasks/abc153_f #include <bits/stdc++.h> #if LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) 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; } int main() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // std::ifstream in("./input.txt"); std::cin.rdbuf(in.rdbuf()); #else cin.tie(0); ios::sync_with_stdio(false); #endif ll N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> xhn(N); for (auto &&xh : xhn) { cin >> xh.first >> xh.second; } sort(xhn.begin(), xhn.end()); vector<ll> xtbl; xtbl.reserve(N); for (const auto &xh : xhn) { xtbl.push_back(xh.first); } ll ans = 0; FOR(i, 0, N) { const auto &d = xhn.at(i); if (d.second <= 0) continue; ll times = (d.second + A - 1) / A; ans += times; ll del_val = times * A; ll pos = d.first + 2 * D; auto it = upper_bound(xtbl.begin() + i + 1, xtbl.end(), pos); //--it; ll lim = distance(xtbl.begin(), it); FOR(j, i, lim) { xhn.at(j).second -= del_val; } } cout << ans << endl; return 0; }
// https://atcoder.jp/contests/abc153/tasks/abc153_f #include <bits/stdc++.h> #if LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) 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; } int main() { #if LOCAL & 01 std::ifstream in("./test/sample-3.in"); // std::ifstream in("./input.txt"); std::cin.rdbuf(in.rdbuf()); #else cin.tie(0); ios::sync_with_stdio(false); #endif ll N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> xhn(N); for (auto &&xh : xhn) { cin >> xh.first >> xh.second; } sort(xhn.begin(), xhn.end()); vector<ll> xtbl; xtbl.reserve(N); for (const auto &xh : xhn) { xtbl.push_back(xh.first); } vector<ll> sub_tbl(N + 10, 0); ll ans = 0; ll add_val = 0; ll sub_val = 0; FOR(i, 0, N) { add_val -= sub_tbl.at(i); const auto &d = xhn.at(i); ll hp = d.second - add_val; if (hp <= 0) continue; ll times = (hp + A - 1) / A; ans += times; ll del_val = times * A; ll pos = d.first + 2 * D; auto it = upper_bound(xtbl.begin() + i + 1, xtbl.end(), pos); //--it; ll lim = distance(xtbl.begin(), it); // FOR(j,i,lim){ // xhn.at(j).second -= del_val; // } sub_tbl.at(lim) += del_val; add_val += del_val; } cout << ans << endl; return 0; } int main_() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // std::ifstream in("./input.txt"); std::cin.rdbuf(in.rdbuf()); #else cin.tie(0); ios::sync_with_stdio(false); #endif ll N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> xhn(N); for (auto &&xh : xhn) { cin >> xh.first >> xh.second; } sort(xhn.begin(), xhn.end()); vector<ll> xtbl; xtbl.reserve(N); for (const auto &xh : xhn) { xtbl.push_back(xh.first); } ll ans = 0; FOR(i, 0, N) { const auto &d = xhn.at(i); if (d.second <= 0) continue; ll times = (d.second + A - 1) / A; ans += times; ll del_val = times * A; ll pos = d.first + 2 * D; auto it = upper_bound(xtbl.begin() + i + 1, xtbl.end(), pos); //--it; ll lim = distance(xtbl.begin(), it); FOR(j, i, lim) { xhn.at(j).second -= del_val; } } cout << ans << endl; return 0; }
insert
26
26
26
76
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define repi(i, x) \ for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define pb push_back #define solve(a) ((a) ? "Yes" : "No") typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int, int> Pi; typedef vector<Pi> VPi; typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INFLL = 1LL << 60; const int INF = 1 << 30; const double PI = acos(-1); int main() { int n, a; ll d; ll ans = 0; cin >> n >> d >> a; VP q(n + 1); // x,h VP dis(n, mp(0LL, 0LL)); rep(i, n) { cin >> q[i].F >> q[i].S; dis[i].F = q[i].F; } q[n] = mp(INFLL, 0LL); sort(all(q)); sort(all(dis)); auto ter = dis.begin(); ll cnt = 0LL; for (int i = 0; i < n; i++) { if (i != 0) { dis[i].S += dis[i - 1].S; } cnt = max(0LL, (q[i].S - dis[i].S + a - 1) / (a)); // clog<<dis[i].F<<" "<<cnt<<endl; dis[i].S += cnt * a; ans += cnt; ter = upper_bound(all(dis), mp(dis[i].F + d * 2, INFLL)); ter->S -= a * cnt; } cout << ans << endl; }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define repi(i, x) \ for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define pb push_back #define solve(a) ((a) ? "Yes" : "No") typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int, int> Pi; typedef vector<Pi> VPi; typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INFLL = 1LL << 60; const int INF = 1 << 30; const double PI = acos(-1); int main() { int n, a; ll d; ll ans = 0; cin >> n >> d >> a; VP q(n + 1); // x,h VP dis(n, mp(0LL, 0LL)); rep(i, n) { cin >> q[i].F >> q[i].S; dis[i].F = q[i].F; } q[n] = mp(INFLL, 0LL); sort(all(q)); sort(all(dis)); auto ter = dis.begin(); ll cnt = 0LL; for (int i = 0; i < n; i++) { if (i != 0) { dis[i].S += dis[i - 1].S; } cnt = max(0LL, (q[i].S - dis[i].S + a - 1) / (a)); // clog<<dis[i].F<<" "<<cnt<<endl; dis[i].S += cnt * a; ans += cnt; ter = upper_bound(all(dis), mp(dis[i].F + d * 2, INFLL)); if (ter != dis.end()) { ter->S -= a * cnt; } } cout << ans << endl; }
replace
65
66
65
68
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define LL long long typedef pair<int, int> pii; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = getchar(); } while ('0' <= _c && _c <= '9') { x = (x << 1) + (x << 3) + (_c & 15); _c = getchar(); } if (_f) x = -x; } template <typename T> inline void Min(T &x, T y) { if (y < x) x = y; } template <typename T> inline void Max(T &x, T y) { if (x < y) x = y; } #define lowbit(x) ((x) & -(x)) #define lson l, mid, id << 1 #define rson mid + 1, r, id << 1 | 1 #define ls id << 1 #define rs id << 1 | 1 #define MID(l, r) ((l) + (((r) - (l)) >> 1)) #define fi first #define se second #define mk make_pair #define pb push_back const int INF = 0x3f3f3f3f; const int MOD = (int)1e9 + 7; // const int MOD = (int) 998244353; const int maxn = (int)1e4 + 20; const int maxm = (int)1e6 + 20; const double pi = (double)acos(-1.0); const double eps = (double)1e-8; inline int sig(double x) { return x < -eps ? -1 : eps < x; } LL fp(LL a, LL n, LL m = MOD) { LL res = 1; for (; n; n >>= 1, a = a * a % m) if (n & 1) res = res * a % m; return res; } int n; pair<LL, LL> p[maxn]; queue<pair<LL, LL>> Q; LL d, a; void work() { cin >> n; cin >> d >> a; for (int i = 0; i < n; i++) cin >> p[i].fi >> p[i].se; sort(p, p + n); LL now = 0; LL ans = 0; for (int i = 0; i < n; i++) { LL x = p[i].fi, h = p[i].se; while (Q.size() && Q.front().fi < x) { now -= Q.front().se; Q.pop(); } if (now >= h) continue; LL tmp = h - now; LL t = (tmp + a - 1) / a; now += a * t; ans += t; Q.push(mk(x + d * 2, a * t)); } cout << ans << endl; } int main() { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 // get_prime(); int tc = 1; // read(tc); for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); work(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define LL long long typedef pair<int, int> pii; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = getchar(); } while ('0' <= _c && _c <= '9') { x = (x << 1) + (x << 3) + (_c & 15); _c = getchar(); } if (_f) x = -x; } template <typename T> inline void Min(T &x, T y) { if (y < x) x = y; } template <typename T> inline void Max(T &x, T y) { if (x < y) x = y; } #define lowbit(x) ((x) & -(x)) #define lson l, mid, id << 1 #define rson mid + 1, r, id << 1 | 1 #define ls id << 1 #define rs id << 1 | 1 #define MID(l, r) ((l) + (((r) - (l)) >> 1)) #define fi first #define se second #define mk make_pair #define pb push_back const int INF = 0x3f3f3f3f; const int MOD = (int)1e9 + 7; // const int MOD = (int) 998244353; const int maxn = (int)2e5 + 20; const int maxm = (int)1e6 + 20; const double pi = (double)acos(-1.0); const double eps = (double)1e-8; inline int sig(double x) { return x < -eps ? -1 : eps < x; } LL fp(LL a, LL n, LL m = MOD) { LL res = 1; for (; n; n >>= 1, a = a * a % m) if (n & 1) res = res * a % m; return res; } int n; pair<LL, LL> p[maxn]; queue<pair<LL, LL>> Q; LL d, a; void work() { cin >> n; cin >> d >> a; for (int i = 0; i < n; i++) cin >> p[i].fi >> p[i].se; sort(p, p + n); LL now = 0; LL ans = 0; for (int i = 0; i < n; i++) { LL x = p[i].fi, h = p[i].se; while (Q.size() && Q.front().fi < x) { now -= Q.front().se; Q.pop(); } if (now >= h) continue; LL tmp = h - now; LL t = (tmp + a - 1) / a; now += a * t; ans += t; Q.push(mk(x + d * 2, a * t)); } cout << ans << endl; } int main() { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 // get_prime(); int tc = 1; // read(tc); for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); work(); } return 0; }
replace
50
51
50
51
0
p02788
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> #define int long long #define mod 1000000007 #define for0(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= (n); i++) #define mp make_pair using namespace std; int get() { int r; cin >> r; return r; } int n, d, a; pair<int, int> xh[123456]; int x[123456], k[123456]; signed main() { cin >> n >> d >> a; for1(i, n) cin >> xh[i].first >> xh[i].second; sort(xh + 1, xh + n + 1); x[0] = -1; for1(i, n) { if (i > 1) { int r = 0, l = i - 1; if (x[l] < xh[i].first) ; else { while (l - r > 1) { int mid = (r + l) / 2; if (x[mid] < xh[i].first) r = mid; else l = mid; } xh[i].second -= a * (k[i - 1] - k[r]); } } xh[i].second = max(xh[i].second, (int)0); int p = (xh[i].second + a - 1) / a; x[i] = xh[i].first + 2 * d; k[i] = k[i - 1] + p; } cout << k[n] << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> #define int long long #define mod 1000000007 #define for0(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= (n); i++) #define mp make_pair using namespace std; int get() { int r; cin >> r; return r; } int n, d, a; pair<int, int> xh[234567]; int x[234567], k[234567]; signed main() { cin >> n >> d >> a; for1(i, n) cin >> xh[i].first >> xh[i].second; sort(xh + 1, xh + n + 1); x[0] = -1; for1(i, n) { if (i > 1) { int r = 0, l = i - 1; if (x[l] < xh[i].first) ; else { while (l - r > 1) { int mid = (r + l) / 2; if (x[mid] < xh[i].first) r = mid; else l = mid; } xh[i].second -= a * (k[i - 1] - k[r]); } } xh[i].second = max(xh[i].second, (int)0); int p = (xh[i].second + a - 1) / a; x[i] = xh[i].first + 2 * d; k[i] = k[i - 1] + p; } cout << k[n] << endl; }
replace
18
20
18
20
0
p02788
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> //memset(dp,0,sizeof(dp)) #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define repp(i, n) for (int i = n - 1; i >= 0; i--) #define fi first #define se second #define pb push_back #define ALL(a) (a).begin(), (a).end() using namespace std; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef pair<ll, ll> P; typedef pair<ll, ll> Pll; // 小数点以下 cout << fixed << setprecision(10) << num << endl; // 桁数はlog10(mid)でやれ log(mid)/log(10)はWA // long*long<0で判定するな // 開区間と閉区間 // アルファベットが何番目かは x=s[i]-'a' // bfsはmain()内で rep(i,h)rep(j,w)rep(i,4)でバグ // 切り上げ:(a+(b-1))/b // 32bit以上は 1ull<<j] // map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se // で全探索 for(auto u:mp) u.fi u.se も可能 // n個のgcd,lcmは一つずつみて更新していく // 大きな数を扱うときは素因数分解した形で持っておく // (l/a[i]) = l*powmod(a[i],MOD-2)%MOD; // auto itr=lower_bound(a.begin(),a.end(), int main() { ll n, d, a; cin >> n >> d >> a; vector<Pll> m(n); rep(i, n) { cin >> m[i].fi >> m[i].se; if (m[i].se % a == 0) m[i].se /= a; else { m[i].se /= a; m[i].se++; } } // 座標と回数をpairで持つ sort(ALL(m)); int fin[n]; // fin[l]=r; d[r]-d[l]<=2*dなるmaxr int k = 0; rep(i, n) { while (m[i].fi + 2 * d >= m[k].se) { k++; } k--; fin[i] = k; } ll ans = 0; int dam[n]; rep(i, n) { if (i == 0) { dam[0] = m[0].se; continue; } auto itr = lower_bound(ALL(m), P(m[i].fi - 2 * d, 0)); ll d; if (itr == m.begin()) d = dam[i - 1]; else { itr--; d = dam[i - 1] - dam[itr - m.begin()]; } dam[i] = dam[i - 1] + max(0LL, m[i].se - d); } cout << dam[n - 1] << endl; }
#include <algorithm> #include <cmath> #include <cstring> //memset(dp,0,sizeof(dp)) #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define repp(i, n) for (int i = n - 1; i >= 0; i--) #define fi first #define se second #define pb push_back #define ALL(a) (a).begin(), (a).end() using namespace std; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef pair<ll, ll> P; typedef pair<ll, ll> Pll; // 小数点以下 cout << fixed << setprecision(10) << num << endl; // 桁数はlog10(mid)でやれ log(mid)/log(10)はWA // long*long<0で判定するな // 開区間と閉区間 // アルファベットが何番目かは x=s[i]-'a' // bfsはmain()内で rep(i,h)rep(j,w)rep(i,4)でバグ // 切り上げ:(a+(b-1))/b // 32bit以上は 1ull<<j] // map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se // で全探索 for(auto u:mp) u.fi u.se も可能 // n個のgcd,lcmは一つずつみて更新していく // 大きな数を扱うときは素因数分解した形で持っておく // (l/a[i]) = l*powmod(a[i],MOD-2)%MOD; // auto itr=lower_bound(a.begin(),a.end(), int main() { ll n, d, a; cin >> n >> d >> a; vector<Pll> m(n); rep(i, n) { cin >> m[i].fi >> m[i].se; if (m[i].se % a == 0) m[i].se /= a; else { m[i].se /= a; m[i].se++; } } // 座標と回数をpairで持つ sort(ALL(m)); ll dam[n]; rep(i, n) { if (i == 0) { dam[0] = m[0].se; continue; } auto itr = lower_bound(ALL(m), P(m[i].fi - 2 * d, 0)); ll d; if (itr == m.begin()) d = dam[i - 1]; else { itr--; d = dam[i - 1] - dam[itr - m.begin()]; } dam[i] = dam[i - 1] + max(0LL, m[i].se - d); } cout << dam[n - 1] << endl; }
replace
60
71
60
61
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // types typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<pll> vpll; // macros #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #define REP(i, n) for (int i = 0; i < ((int)n); i++) #define REP1(i, n) for (int i = 1; i < ((int)n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define PB push_back #define EB emplace_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL // constants const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, d, a; cin >> n >> d >> a; vll x(n), h(n); REP(i, n) cin >> x[i] >> h[i]; vector<pll> p(n); REP(i, n) { p[i].FI = x[i]; p[i].SE = h[i]; } map<ll, ll> m; sort(x.begin(), x.end()); sort(p.begin(), p.end()); REP(i, n) m[p[i].FI] = i; ll ans = 0; vll imos(n, 0); REP(i, n) { ll health = p[i].SE; if (i != 0) imos[i] += imos[i - 1]; health -= imos[i] * a; if (health <= 0) continue; auto it = upper_bound(x.begin(), x.end(), x[i] + 2 * d); ll t = it - x.begin(); ll k = health / a; if (health % a != 0) k++; imos[i] += k; imos[t] -= k; ans += k; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // types typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<pll> vpll; // macros #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define FI first #define SE second #define REP(i, n) for (int i = 0; i < ((int)n); i++) #define REP1(i, n) for (int i = 1; i < ((int)n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define PB push_back #define EB emplace_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL // constants const int inf = 1e9; const ll linf = 1LL << 50; const double eps = 1e-10; const int MOD = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, d, a; cin >> n >> d >> a; vll x(n), h(n); REP(i, n) cin >> x[i] >> h[i]; vector<pll> p(n); REP(i, n) { p[i].FI = x[i]; p[i].SE = h[i]; } map<ll, ll> m; sort(x.begin(), x.end()); sort(p.begin(), p.end()); REP(i, n) m[p[i].FI] = i; ll ans = 0; vll imos(n + 2, 0); REP(i, n) { ll health = p[i].SE; if (i != 0) imos[i] += imos[i - 1]; health -= imos[i] * a; if (health <= 0) continue; auto it = upper_bound(x.begin(), x.end(), x[i] + 2 * d); ll t = it - x.begin(); ll k = health / a; if (health % a != 0) k++; imos[i] += k; imos[t] -= k; ans += k; } cout << ans << endl; }
replace
62
63
62
63
0
p02788
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; int main() { int N, D, A; cin >> N >> D >> A; vector<pair<int, int>> v(N + 1); v[N] = make_pair(1000000010, 0); for (int i = 0; i < N; i++) { cin >> v[i].first >> v[i].second; v[i].second = (v[i].second + A - 1) / A; } sort(v.begin(), v.end()); vector<int> d(N, 0); int cur = 0; ll ans = 0; for (int i = 0; i < N; i++) { cur -= d[i]; // cout << v[i].first << " " << cur; if (cur < v[i].second) { ans += v[i].second - cur; int n = distance(v.begin(), upper_bound(v.begin(), v.end(), make_pair(v[i].first + 2 * D + 1, 0))); d[n] += v[i].second - cur; cur += v[i].second - cur; } // cout << " " << ans << endl; } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; int main() { int N, D, A; cin >> N >> D >> A; vector<pair<int, int>> v(N + 1); v[N] = make_pair(1000000010, 0); for (int i = 0; i < N; i++) { cin >> v[i].first >> v[i].second; v[i].second = (v[i].second + A - 1) / A; } sort(v.begin(), v.end()); vector<int> d(N + 1, 0); int cur = 0; ll ans = 0; for (int i = 0; i < N; i++) { cur -= d[i]; // cout << v[i].first << " " << cur; if (cur < v[i].second) { ans += v[i].second - cur; int n = distance(v.begin(), upper_bound(v.begin(), v.end(), make_pair(v[i].first + 2 * D + 1, 0))); d[n] += v[i].second - cur; cur += v[i].second - cur; } // cout << " " << ans << endl; } cout << ans << endl; return 0; }
replace
27
28
27
28
0
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long N, D, A; cin >> N >> D >> A; vector<pair<long, long>> monster; vector<long> damage(N + 1, 0); for (int i = 0; i < N; i++) { long x, h; cin >> x >> h; monster.push_back(make_pair(x, h)); } long count = 0; sort(monster.begin(), monster.end()); for (int i = 0; i < monster.size(); i++) { if (damage[i] < monster[i].second) { long pos; for (int j = i; j < monster.size(); j++) { if (monster[j].first > monster[i].first + 2 * D) { pos = j; break; } else if (j == monster.size() - 1) { pos = j + 1; } } long d = ((monster[i].second - damage[i]) + A - 1) / A; damage[i] += d * A; damage[pos] -= d * A; count += d; } damage[i + 1] += damage[i]; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long N, D, A; cin >> N >> D >> A; vector<pair<long, long>> monster; vector<long> damage(N + 1, 0); for (int i = 0; i < N; i++) { long x, h; cin >> x >> h; monster.push_back(make_pair(x, h)); } long count = 0; sort(monster.begin(), monster.end()); for (int i = 0; i < monster.size(); i++) { if (damage[i] < monster[i].second) { long pos = upper_bound(monster.begin(), monster.end(), make_pair(monster[i].first + 2 * D + 1, numeric_limits<long>::min())) - monster.begin(); long d = ((monster[i].second - damage[i]) + A - 1) / A; damage[i] += d * A; damage[pos] -= d * A; count += d; } damage[i + 1] += damage[i]; } cout << count << endl; }
replace
17
26
17
21
TLE
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } #define printpair(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << "{" << _.first << "," << _.second << "}" \ << ", "; \ cerr << "]" << endl; \ } #define bit(k) (1LL << (k)) typedef long long ll; 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 INF = 1e9; const ll INFLL = 1e18; const ll MOD = 1e9 + 7; const double PI = acos(-1.0); const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; /*------------------------------------/ for library*/ /*------------------------------------*/ void debug(queue<pair<int, ll>> q) { while (!q.empty()) { auto x = q.front(); q.pop(); cerr << "{" << x.first << ", " << x.second << "}, "; } cerr << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> XH(N); vector<ll> X(N), H(N); rep(i, N) { cin >> XH[i].first >> XH[i].second; } sort(all(XH)); rep(i, N) { X[i] = XH[i].first; H[i] = (XH[i].second + A - 1) / A; } // print(X);print(H); /*queueの中に必要なもの {index, そこでの爆発回数} */ ll sumq = 0; queue<pair<int, ll>> q; ll ans = 0; rep(i, N) { // 左端の設定 while (!q.empty()) { auto l = q.front().first; auto h = q.front().second; if (X[l] < X[i] - 2 * D) { sumq -= h; q.pop(); } else break; } debug(q); // cerr<<sumq<<endl; // すでに起こった爆発 H[i] -= sumq; if (H[i] <= 0) continue; // 今起こった爆発を記録 ans += H[i]; sumq += H[i]; q.push({i, H[i]}); } cout << ans << endl; } /*あるiを見たとき すでにある爆発でいくら減ってるかを計算したい 左端がどこまで効いてくるのかを考えたい qの中には,過去の履歴が残っている */
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < int(N); ++i) #define rep1(i, N) for (int i = 1; i < int(N); ++i) #define all(a) (a).begin(), (a).end() #define print(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << _ << ", "; \ cerr << "]" << endl; \ } #define printpair(v) \ { \ cerr << #v << ": [ "; \ for (auto _ : v) \ cerr << "{" << _.first << "," << _.second << "}" \ << ", "; \ cerr << "]" << endl; \ } #define bit(k) (1LL << (k)) typedef long long ll; 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 INF = 1e9; const ll INFLL = 1e18; const ll MOD = 1e9 + 7; const double PI = acos(-1.0); const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; /*------------------------------------/ for library*/ /*------------------------------------*/ void debug(queue<pair<int, ll>> q) { while (!q.empty()) { auto x = q.front(); q.pop(); cerr << "{" << x.first << ", " << x.second << "}, "; } cerr << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll N, D, A; cin >> N >> D >> A; vector<pair<ll, ll>> XH(N); vector<ll> X(N), H(N); rep(i, N) { cin >> XH[i].first >> XH[i].second; } sort(all(XH)); rep(i, N) { X[i] = XH[i].first; H[i] = (XH[i].second + A - 1) / A; } // print(X);print(H); /*queueの中に必要なもの {index, そこでの爆発回数} */ ll sumq = 0; queue<pair<int, ll>> q; ll ans = 0; rep(i, N) { // 左端の設定 while (!q.empty()) { auto l = q.front().first; auto h = q.front().second; if (X[l] < X[i] - 2 * D) { sumq -= h; q.pop(); } else break; } // debug(q); // cerr<<sumq<<endl; // すでに起こった爆発 H[i] -= sumq; if (H[i] <= 0) continue; // 今起こった爆発を記録 ans += H[i]; sumq += H[i]; q.push({i, H[i]}); } cout << ans << endl; } /*あるiを見たとき すでにある爆発でいくら減ってるかを計算したい 左端がどこまで効いてくるのかを考えたい qの中には,過去の履歴が残っている */
replace
93
94
93
94
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; long long int n, m, j, k, l, t, arr[100009], brr[100009], tree[600009], i, ans, d; vector<pair<ll, ll>> v; vector<ll> v1, v2; void update(ll node, ll start, ll end, ll idx, ll val) { if (start == end) { // Leaf node tree[node] += val; } else { int mid = (start + end) / 2; if (start <= idx and idx <= mid) { // If idx is in the left child, recurse on the left child update(2 * node + 1, start, mid, idx, val); } else { // if idx is in the right child, recurse on the right child update(2 * node + 2, mid + 1, end, idx, val); } // Internal node will have the sum of both of its children tree[node] = tree[2 * node + 1] + tree[2 * node + 2]; } } ll query(ll node, ll start, ll end, ll l, ll r) { if (r < start or end < l) { // range represented by a node is completely outside the given range return 0; } if (l <= start and end <= r) { // range represented by a node is completely inside the given range return tree[node]; } // range represented by a node is partially inside and partially outside the // given range ll mid = (start + end) / 2; ll p1 = query(2 * node + 1, start, mid, l, r); ll p2 = query(2 * node + 2, mid + 1, end, l, r); return (p1 + p2); } int main() { scanf("%lld %lld %lld", &n, &m, &d); for (i = 0; i < n; i++) { scanf("%lld %lld", &arr[i], &brr[i]); v.push_back({arr[i], brr[i]}); } sort(v.begin(), v.end()); for (i = 0; i < n; i++) { v1.push_back(v[i].first); v2.push_back(v[i].second); } for (i = 0; i < n; i++) { j = v1[i] - (2 * m); t = lower_bound(v1.begin(), v1.end(), j) - v1.begin(); while (t < 0) t = 0; while (v1[t] < j) t++; l = query(0, 0, n - 1, t, i); v2[i] -= l; if (v2[i] < 0) v2[i] = 0; j = v2[i] / d; if (v2[i] % d) j++; j *= d; update(0, 0, n - 1, i, j); j /= d; ans += j; } printf("%lld\n", ans); }
#include <bits/stdc++.h> typedef long long ll; using namespace std; long long int n, m, j, k, l, t, arr[200009], brr[200009], tree[600009], i, ans, d; vector<pair<ll, ll>> v; vector<ll> v1, v2; void update(ll node, ll start, ll end, ll idx, ll val) { if (start == end) { // Leaf node tree[node] += val; } else { int mid = (start + end) / 2; if (start <= idx and idx <= mid) { // If idx is in the left child, recurse on the left child update(2 * node + 1, start, mid, idx, val); } else { // if idx is in the right child, recurse on the right child update(2 * node + 2, mid + 1, end, idx, val); } // Internal node will have the sum of both of its children tree[node] = tree[2 * node + 1] + tree[2 * node + 2]; } } ll query(ll node, ll start, ll end, ll l, ll r) { if (r < start or end < l) { // range represented by a node is completely outside the given range return 0; } if (l <= start and end <= r) { // range represented by a node is completely inside the given range return tree[node]; } // range represented by a node is partially inside and partially outside the // given range ll mid = (start + end) / 2; ll p1 = query(2 * node + 1, start, mid, l, r); ll p2 = query(2 * node + 2, mid + 1, end, l, r); return (p1 + p2); } int main() { scanf("%lld %lld %lld", &n, &m, &d); for (i = 0; i < n; i++) { scanf("%lld %lld", &arr[i], &brr[i]); v.push_back({arr[i], brr[i]}); } sort(v.begin(), v.end()); for (i = 0; i < n; i++) { v1.push_back(v[i].first); v2.push_back(v[i].second); } for (i = 0; i < n; i++) { j = v1[i] - (2 * m); t = lower_bound(v1.begin(), v1.end(), j) - v1.begin(); while (t < 0) t = 0; while (v1[t] < j) t++; l = query(0, 0, n - 1, t, i); v2[i] -= l; if (v2[i] < 0) v2[i] = 0; j = v2[i] / d; if (v2[i] % d) j++; j *= d; update(0, 0, n - 1, i, j); j /= d; ans += j; } printf("%lld\n", ans); }
replace
3
4
3
4
0
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; #define all(x) (x).begin(), (x).end() #define fsp(x) cout << fixed << setprecision(x) const ll inf = LLONG_MAX; const long double pi = acos(-1); void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } // 二分探索 // main関数で呼び出す前に,l, // rの一方が条件を満たし他方が満たさないことを確認すること long long bs(long long l, long long r, ll d, vector<vll> v, ll i) { if (l + 1 == r) { if (v[l][0] - v[i][0] > 2 * d) return l; else return r; } long long mid = (l + r) / 2; if (v[mid][0] - v[i][0] > 2 * d) return bs(l, mid, d, v, i); else return bs(mid, r, d, v, i); } int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); ll n, d, a; cin >> n >> d >> a; vector<vll> v(n, vll(2)); for (ll i = 0; i < n; i++) cin >> v[i][0] >> v[i][1]; sort(all(v)); ll ans = 0; vll imos(n, 0); for (ll i = 0; i < n; i++) { if (i > 0) imos[i] += imos[i - 1]; if (v[i][1] <= imos[i]) continue; ll x = ceil((double)(v[i][1] - imos[i]) / a); ans += x; imos[i] += a * x; if (v[n - 1][0] - v[i][0] <= 2 * d) continue; ll y = bs(i, n - 1, d, v, i); imos[y] -= a * x; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; #define all(x) (x).begin(), (x).end() #define fsp(x) cout << fixed << setprecision(x) const ll inf = LLONG_MAX; const long double pi = acos(-1); void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } // 二分探索 // main関数で呼び出す前に,l, // rの一方が条件を満たし他方が満たさないことを確認すること // 配列を引数にするときは原則として参照渡しすること long long bs(long long l, long long r, ll d, vector<vll> &v, ll i) { if (l + 1 == r) { if (v[l][0] - v[i][0] > 2 * d) return l; else return r; } long long mid = (l + r) / 2; if (v[mid][0] - v[i][0] > 2 * d) return bs(l, mid, d, v, i); else return bs(mid, r, d, v, i); } int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); ll n, d, a; cin >> n >> d >> a; vector<vll> v(n, vll(2)); for (ll i = 0; i < n; i++) cin >> v[i][0] >> v[i][1]; sort(all(v)); ll ans = 0; vll imos(n, 0); for (ll i = 0; i < n; i++) { if (i > 0) imos[i] += imos[i - 1]; if (v[i][1] <= imos[i]) continue; ll x = ceil((double)(v[i][1] - imos[i]) / a); ans += x; imos[i] += a * x; if (v[n - 1][0] - v[i][0] <= 2 * d) continue; ll y = bs(i, n - 1, d, v, i); imos[y] -= a * x; } cout << ans << endl; }
replace
16
17
16
18
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int N; ll D, A; cin >> N >> D >> A; vector<ll> cum(N, 0); using Mon = pair<ll, ll>; vector<Mon> M(N); for (int i = 0; i < (int)N; ++i) cin >> M[i].first >> M[i].second; sort((M).begin(), (M).end()); ll ans = 0; for (int i = 0; i < (int)N; ++i) { if (i > 0) cum[i] += cum[i - 1]; if (M[i].second + cum[i] <= 0) continue; ll k = (M[i].second + cum[i] + A - 1) / A; ans += k; cum[i] -= A * k; int j = distance(M.begin(), upper_bound((M).begin(), (M).end(), make_pair(M[i].first + 2 * D, (ll)1e18))); cum[j] += A * k; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { int N; ll D, A; cin >> N >> D >> A; vector<ll> cum(N + 1, 0); using Mon = pair<ll, ll>; vector<Mon> M(N); for (int i = 0; i < (int)N; ++i) cin >> M[i].first >> M[i].second; sort((M).begin(), (M).end()); ll ans = 0; for (int i = 0; i < (int)N; ++i) { if (i > 0) cum[i] += cum[i - 1]; if (M[i].second + cum[i] <= 0) continue; ll k = (M[i].second + cum[i] + A - 1) / A; ans += k; cum[i] -= A * k; int j = distance(M.begin(), upper_bound((M).begin(), (M).end(), make_pair(M[i].first + 2 * D, (ll)1e18))); cum[j] += A * k; } cout << ans << endl; return 0; }
replace
22
23
22
23
-6
munmap_chunk(): invalid pointer
p02788
C++
Runtime Error
#include <bits/stdc++.h> typedef long long lint; using namespace std; lint n, d, a; vector<pair<lint, lint>> xh; int main() { cin >> n >> d >> a; xh.resize(n); for (int i = 0; i < n; i++) { cin >> xh[i].first >> xh[i].second; } sort(xh.begin(), xh.end()); vector<lint> x(n), h(n); for (int i = 0; i < n; i++) { x[i] = xh[i].first, h[i] = xh[i].second; } // right[i]:[i,right[i])を攻撃できる vector<lint> right(n); for (int i = 0; i < n; i++) { right[i] = upper_bound(x.begin(), x.end(), x[i] + 2 * d) - x.begin(); } vector<lint> damage(n, 0); lint dmg_now = 0; lint ans = 0; for (int i = 0; i < n; i++) { dmg_now -= damage[i]; if (h[i] - dmg_now <= 0) { continue; } else { lint rem = h[i] - dmg_now; lint num = (rem + a - 1) / a; dmg_now += num * a; damage[right[i]] += num * a; ans += num; } } cout << ans << endl; }
#include <bits/stdc++.h> typedef long long lint; using namespace std; lint n, d, a; vector<pair<lint, lint>> xh; int main() { cin >> n >> d >> a; xh.resize(n); for (int i = 0; i < n; i++) { cin >> xh[i].first >> xh[i].second; } sort(xh.begin(), xh.end()); vector<lint> x(n), h(n); for (int i = 0; i < n; i++) { x[i] = xh[i].first, h[i] = xh[i].second; } // right[i]:[i,right[i])を攻撃できる vector<lint> right(n); for (int i = 0; i < n; i++) { right[i] = upper_bound(x.begin(), x.end(), x[i] + 2 * d) - x.begin(); } vector<lint> damage(n, 0); lint dmg_now = 0; lint ans = 0; for (int i = 0; i < n; i++) { dmg_now -= damage[i]; if (h[i] - dmg_now <= 0) { continue; } else { lint rem = h[i] - dmg_now; lint num = (rem + a - 1) / a; dmg_now += num * a; if (right[i] < n) { damage[right[i]] += num * a; } ans += num; } } cout << ans << endl; }
replace
34
35
34
37
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define ll long long #define ld long double #define all(arr) arr.begin(), arr.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fo(i, l, r) for (int i = l; i <= r; i++) #define INF 1000000001 #define inf1 1000000000000000001 #define MOD 1000000007 #define pie 3.14159265358979323846264338327950L #define N 100005 #define M 1e6 + 9 #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define vecl vector<ll> #define umap unordered_map<ll, ll> #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define endl "\n" #define int long long using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; ll gcd(ll a, ll b) { if (!a) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } // ll n,k,a,b,c,d,x,y,z,m,l; // ll ans; // vecl arr(N); // ll dp[509][509]; // ll pre[N]; int sum[N]; void test_case() { int n, d, a; cin >> n >> d >> a; vector<pii> arr(n); rep(i, n) { cin >> arr[i].first >> arr[i].second; } sort(all(arr)); int dp[N]; for (int i = 0; i < n; i++) { int re = 2 * d + arr[i].first; pii temp = mpr(re, LONG_MAX); auto it = upper_bound(all(arr), temp); dp[i] = it - arr.begin(); } int ans = 0; int num = 0; for (int i = 0; i < n; i++) { num += sum[i]; if (arr[i].second - num >= 0) { int co = ((arr[i].second - num) + a - 1) / a; ans += co; num += co * a; sum[dp[i]] -= co * a; } } cout << ans << endl; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while (t--) { test_case(); } }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define ll long long #define ld long double #define all(arr) arr.begin(), arr.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fo(i, l, r) for (int i = l; i <= r; i++) #define INF 1000000001 #define inf1 1000000000000000001 #define MOD 1000000007 #define pie 3.14159265358979323846264338327950L #define N 200009 #define M 1e6 + 9 #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define vecl vector<ll> #define umap unordered_map<ll, ll> #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define endl "\n" #define int long long using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; ll gcd(ll a, ll b) { if (!a) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } // ll n,k,a,b,c,d,x,y,z,m,l; // ll ans; // vecl arr(N); // ll dp[509][509]; // ll pre[N]; int sum[N]; void test_case() { int n, d, a; cin >> n >> d >> a; vector<pii> arr(n); rep(i, n) { cin >> arr[i].first >> arr[i].second; } sort(all(arr)); int dp[N]; for (int i = 0; i < n; i++) { int re = 2 * d + arr[i].first; pii temp = mpr(re, LONG_MAX); auto it = upper_bound(all(arr), temp); dp[i] = it - arr.begin(); } int ans = 0; int num = 0; for (int i = 0; i < n; i++) { num += sum[i]; if (arr[i].second - num >= 0) { int co = ((arr[i].second - num) + a - 1) / a; ans += co; num += co * a; sum[dp[i]] -= co * a; } } cout << ans << endl; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while (t--) { test_case(); } }
replace
16
17
16
17
0
p02788
C++
Runtime Error
#pragma comment(linker, "/STACK:526000000") #define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; typedef string::const_iterator State; #define eps 1e-11L #define MAX_MOD 1000000007LL #define GYAKU 500000004LL #define MOD 998244353LL #define seg_size 262144 #define pb push_back #define mp make_pair typedef long long ll; #define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a)) #define ALL(x) (x).begin(), (x).end() unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } void init() { iostream::sync_with_stdio(false); cout << fixed << setprecision(100); } #define int ll int go[300000]; int imos[300000]; void solve() { int n, d, a; cin >> n >> d >> a; vector<pair<int, int>> inputs; REP(i, n) { int a, b; cin >> a >> b; inputs.push_back(mp(a, b)); } sort(ALL(inputs)); inputs.push_back(mp(3e9, 0)); int ans = 0; int next_go = 0; REP(i, n) { while (inputs[next_go + 1].first - inputs[i].first <= 2 * d) { next_go++; } go[i] = next_go; } int now_bomb = 0; for (int i = 0; i < n; ++i) { now_bomb += imos[i]; if (now_bomb * a < inputs[i].second) { int hoge = inputs[i].second - now_bomb * a; int cnt = (hoge + a - 1LL) / a; now_bomb += cnt; ans += cnt; imos[go[i] + 1] -= cnt; } } cout << ans << endl; } #undef int int main() { init(); solve(); }
#pragma comment(linker, "/STACK:526000000") #define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; typedef string::const_iterator State; #define eps 1e-11L #define MAX_MOD 1000000007LL #define GYAKU 500000004LL #define MOD 998244353LL #define seg_size 262144 #define pb push_back #define mp make_pair typedef long long ll; #define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a)) #define ALL(x) (x).begin(), (x).end() unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } void init() { iostream::sync_with_stdio(false); cout << fixed << setprecision(100); } #define int ll int go[300000]; int imos[300000]; void solve() { int n, d, a; cin >> n >> d >> a; vector<pair<int, int>> inputs; REP(i, n) { int a, b; cin >> a >> b; inputs.push_back(mp(a, b)); } sort(ALL(inputs)); inputs.push_back(mp(1e12, 0)); int ans = 0; int next_go = 0; REP(i, n) { while (inputs[next_go + 1].first - inputs[i].first <= 2 * d) { next_go++; } go[i] = next_go; } int now_bomb = 0; for (int i = 0; i < n; ++i) { now_bomb += imos[i]; if (now_bomb * a < inputs[i].second) { int hoge = inputs[i].second - now_bomb * a; int cnt = (hoge + a - 1LL) / a; now_bomb += cnt; ans += cnt; imos[go[i] + 1] -= cnt; } } cout << ans << endl; } #undef int int main() { init(); solve(); }
replace
43
44
43
44
0
p02788
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #pragma warning(disable : 4996) typedef long long ll; typedef long double ld; const ll MAXN = 2 * 1e5 + 10; ll tAdd[4 * MAXN]; ll a[4 * MAXN]; ll t[4 * MAXN]; void push(ll v, ll tl, ll tr) { if (tAdd[v] != 0) { t[v] += (tr - tl + 1) * tAdd[v]; tAdd[2 * v + 1] += tAdd[v]; tAdd[2 * v + 2] += tAdd[v]; } tAdd[v] = 0; } void build(ll v, ll tl, ll tr, ll a[]) { if (tl > tr) { return; } if (tl == tr) { t[v] = a[tl]; return; } ll tm = (tl + tr) / 2; build(2 * v + 1, tl, tm, a); build(2 * v + 2, tm + 1, tr, a); t[v] = t[2 * v + 1] + t[2 * v + 2]; return; } ll get(ll v, ll tl, ll tr, ll l, ll r) { push(v, tl, tr); if (l > tr || r < tl) { return 0; } if (l <= tl && r >= tr) { return t[v]; } ll tm = (tl + tr) / 2; return get(2 * v + 1, tl, tm, l, r) + get(2 * v + 2, tm + 1, tr, l, r); } void update(ll v, ll tl, ll tr, ll l, ll r, ll add) { push(v, tl, tr); if (l > tr || r < tl) { return; } if (l <= tl && r >= tr) { tAdd[v] += add; push(v, tl, tr); return; } ll tm = (tl + tr) / 2; update(2 * v + 1, tl, tm, l, r, add); update(2 * v + 2, tm + 1, tr, l, r, add); } int main() { #ifdef _DEBUG freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); ll n, d, at; cin >> n >> d >> at; vector<ll> coord(n); vector<pair<ll, ll>> kek(n); for (int i = 0; i < n; i++) { cin >> kek[i].first >> kek[i].second; } sort(kek.begin(), kek.end()); for (ll i = 0; i < n; i++) { coord[i] = kek[i].first; a[i] = kek[i].second; } build(0, 0, n - 1, a); ll ans = 0; for (ll i = 0; i < n; i++) { ll cur = get(0, 0, n - 1, i, i); // cout << cur << "\n"; if (cur <= 0) continue; ll cor = coord[i] + 2 * d; auto it = upper_bound(coord.begin(), coord.end(), cor); it--; ll r_bord = (it - coord.begin()); ll now_at = (cur - 1) / at + 1; ans += now_at; update(0, 0, n - 1, i, r_bord, -now_at * at); } cout << ans; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #pragma warning(disable : 4996) typedef long long ll; typedef long double ld; const ll MAXN = 1e6; ll tAdd[4 * MAXN]; ll a[4 * MAXN]; ll t[4 * MAXN]; void push(ll v, ll tl, ll tr) { if (tAdd[v] != 0) { t[v] += (tr - tl + 1) * tAdd[v]; tAdd[2 * v + 1] += tAdd[v]; tAdd[2 * v + 2] += tAdd[v]; } tAdd[v] = 0; } void build(ll v, ll tl, ll tr, ll a[]) { if (tl > tr) { return; } if (tl == tr) { t[v] = a[tl]; return; } ll tm = (tl + tr) / 2; build(2 * v + 1, tl, tm, a); build(2 * v + 2, tm + 1, tr, a); t[v] = t[2 * v + 1] + t[2 * v + 2]; return; } ll get(ll v, ll tl, ll tr, ll l, ll r) { push(v, tl, tr); if (l > tr || r < tl) { return 0; } if (l <= tl && r >= tr) { return t[v]; } ll tm = (tl + tr) / 2; return get(2 * v + 1, tl, tm, l, r) + get(2 * v + 2, tm + 1, tr, l, r); } void update(ll v, ll tl, ll tr, ll l, ll r, ll add) { push(v, tl, tr); if (l > tr || r < tl) { return; } if (l <= tl && r >= tr) { tAdd[v] += add; push(v, tl, tr); return; } ll tm = (tl + tr) / 2; update(2 * v + 1, tl, tm, l, r, add); update(2 * v + 2, tm + 1, tr, l, r, add); } int main() { #ifdef _DEBUG freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); ll n, d, at; cin >> n >> d >> at; vector<ll> coord(n); vector<pair<ll, ll>> kek(n); for (int i = 0; i < n; i++) { cin >> kek[i].first >> kek[i].second; } sort(kek.begin(), kek.end()); for (ll i = 0; i < n; i++) { coord[i] = kek[i].first; a[i] = kek[i].second; } build(0, 0, n - 1, a); ll ans = 0; for (ll i = 0; i < n; i++) { ll cur = get(0, 0, n - 1, i, i); // cout << cur << "\n"; if (cur <= 0) continue; ll cor = coord[i] + 2 * d; auto it = upper_bound(coord.begin(), coord.end(), cor); it--; ll r_bord = (it - coord.begin()); ll now_at = (cur - 1) / at + 1; ans += now_at; update(0, 0, n - 1, i, r_bord, -now_at * at); } cout << ans; }
replace
19
20
19
20
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define loop(i, a, b) for (lli i = a; i < b; i++) #define loopb(i, a, b) for (lli i = a; i >= b; i--) #define pb push_back #define umap unordered_map typedef long long int lli; typedef pair<lli, lli> pii; typedef vector<lli> vll; // use to avoid collision struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // for pair in unordered_map struct hash_pair { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); uint64_t x = hash1 ^ hash2; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; lli M = 1e9 + 7; lli power(lli x, lli y) { lli res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } lli n, d, a; vector<vll> S; lli solve() { cin >> n >> d >> a; S.clear(); loop(i, 0, n) { lli t1, t2; cin >> t1 >> t2; S.pb({t1, t2}); } sort(S.begin(), S.end(), [](const vll &v1, const vll &v2) { return v1[0] < v2[0]; }); lli ans = 0; lli temp = ceil((double)S[0][1] / (double)a); vector<lli> dq(n, 0); ans += temp; vll A(n + 1); loop(i, 0, n) A[i] = S[i][0]; A[n] = 1e15; dq[0] += temp; lli pos = lower_bound(A.begin(), A.end(), S[0][0] + 2 * d) - A.begin(); if (pos != n) { if (A[pos] == S[0][0] + 2 * d) pos++; dq[pos] -= temp; } // cout<<pos<<"\n"; loop(i, 1, n) { lli h = ceil((double)S[i][1] / (double)a); dq[i] += dq[i - 1]; // cout<<h<<"\n"; if (h > dq[i]) { lli tmp2 = (h - dq[i]); lli pos = lower_bound(A.begin(), A.end(), S[i][0] + 2 * d) - A.begin(); if (pos != n) { if (A[pos] == S[i][0] + 2 * d) pos++; dq[pos] -= (h - dq[i]); } ans += h - dq[i]; dq[i] += tmp2; } } cout << ans << "\n"; return 0; } int main() { // fastio; lli t; // cin>>t; t = 1; while (t > 0) { t--; solve(); } }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define loop(i, a, b) for (lli i = a; i < b; i++) #define loopb(i, a, b) for (lli i = a; i >= b; i--) #define pb push_back #define umap unordered_map typedef long long int lli; typedef pair<lli, lli> pii; typedef vector<lli> vll; // use to avoid collision struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; // for pair in unordered_map struct hash_pair { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); uint64_t x = hash1 ^ hash2; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; lli M = 1e9 + 7; lli power(lli x, lli y) { lli res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } lli n, d, a; vector<vll> S; lli solve() { cin >> n >> d >> a; S.clear(); loop(i, 0, n) { lli t1, t2; cin >> t1 >> t2; S.pb({t1, t2}); } sort(S.begin(), S.end(), [](const vll &v1, const vll &v2) { return v1[0] < v2[0]; }); lli ans = 0; lli temp = ceil((double)S[0][1] / (double)a); vector<lli> dq(n + 2, 0); ans += temp; vll A(n + 1); loop(i, 0, n) A[i] = S[i][0]; A[n] = 1e15; dq[0] += temp; lli pos = lower_bound(A.begin(), A.end(), S[0][0] + 2 * d) - A.begin(); if (pos != n) { if (A[pos] == S[0][0] + 2 * d) pos++; dq[pos] -= temp; } // cout<<pos<<"\n"; loop(i, 1, n) { lli h = ceil((double)S[i][1] / (double)a); dq[i] += dq[i - 1]; // cout<<h<<"\n"; if (h > dq[i]) { lli tmp2 = (h - dq[i]); lli pos = lower_bound(A.begin(), A.end(), S[i][0] + 2 * d) - A.begin(); if (pos != n) { if (A[pos] == S[i][0] + 2 * d) pos++; dq[pos] -= (h - dq[i]); } ans += h - dq[i]; dq[i] += tmp2; } } cout << ans << "\n"; return 0; } int main() { // fastio; lli t; // cin>>t; t = 1; while (t > 0) { t--; solve(); } }
replace
74
75
74
75
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; using ll = long long int; const long long int INF = 1001001001001001LL; const int inf = 1000000007; long long int MOD = 1000000007LL; double PI = 3.1415926535897932; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> p(n); rep(i, n) cin >> p[i].first >> p[i].second; sort(p.begin(), p.end()); vector<ll> imos(n, 0); ll cnt = 0; rep(i, n) { if (i > 0) imos[i] += imos[i - 1]; ll h = p[i].second - imos[i]; if (h > 0) { ll c = (h + a - 1) / a; ll damage = c * a; ll out = upper_bound(p.begin(), p.end(), make_pair(p[i].first + 2 * d, INF)) - p.begin(); imos[i] += damage; imos[out] -= damage; cnt += c; } } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; using ll = long long int; const long long int INF = 1001001001001001LL; const int inf = 1000000007; long long int MOD = 1000000007LL; double PI = 3.1415926535897932; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> p(n); rep(i, n) cin >> p[i].first >> p[i].second; sort(p.begin(), p.end()); vector<ll> imos(n + 1, 0); ll cnt = 0; rep(i, n) { if (i > 0) imos[i] += imos[i - 1]; ll h = p[i].second - imos[i]; if (h > 0) { ll c = (h + a - 1) / a; ll damage = c * a; ll out = upper_bound(p.begin(), p.end(), make_pair(p[i].first + 2 * d, INF)) - p.begin(); imos[i] += damage; imos[out] -= damage; cnt += c; } } cout << cnt << endl; return 0; }
replace
19
20
19
20
0
p02788
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> /*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags #pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX #pragma GCC target("avx2") //Enable AVX*/ using namespace __gnu_pbds; using namespace std; #define vi vector<int> using ll = long long; #define ld long double #define mp make_pair #define what_is(x) cerr << #x << " is " << x << endl; typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int p = 1e9 + 7; int mul(int a, int b) { return (1LL * a * b) % p; } int add(int a, int b) { int s = (a + b); if (s >= p) s -= p; return s; } int sub(int a, int b) { int s = (a + p - b); if (s >= p) s -= p; return s; } int po(int a, int deg) { if (deg == 0) return 1; if (deg % 2 == 1) return mul(a, po(a, deg - 1)); int t = po(a, deg / 2); return mul(t, t); } int inv(int n) { return po(n, p - 2); } vector<int> Z(vector<int> s) { int n = s.size(); vector<int> z(n); int L = 0, R = 0; for (int i = 1; i < n; i++) { if (i > R) { L = R = i; while (R < n && s[R - L] == s[R]) R++; z[i] = R - L; R--; } else { int k = i - L; if (z[k] < R - i + 1) z[i] = z[k]; else { L = i; while (R < n && s[R - L] == s[R]) R++; z[i] = R - L; R--; } } } return z; } mt19937 rnd(time(0)); //******CONVEX HULL TRICK******// /* struct Line { mutable ll k, m, p; bool operator<(const Line& o) const { return k < o.k; } bool operator<(ll x) const { return p < x; } }; struct CHT : multiset<Line, less<>> { // (for doubles, use inf = 1/.0, div(a,b) = a/b) const ll inf = LLONG_MAX; ll div(ll a, ll b) { // floored division return a /b - ((a ^ b) < 0 && a % b); } bool isect(iterator x, iterator y) { if (y == end()) { x->p = inf; return false; } if (x->k == y->k) x->p = x->m > y->m ? inf : -inf; else x->p = div(y->m - x->m, x->k - y->k); return x->p >= y->p; } void add(ll k, ll m) { auto z = insert({k, m, 0}), y = z++, x = y; while (isect(y, z)) z = erase(z); if (x != begin() && isect(--x, y)) isect(x, y = erase(y)); while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y)); } ll query(ll x) { assert(!empty()); auto l = *lower_bound(x); return l.k * x + l.m; } }; */ //******MAXFLOW******// /* typedef vector<int> VI; typedef vector<VI> VVI; const int INF = 1000000000; struct MaxFlow { int N; VVI cap, flow; VI dad, Q; MaxFlow(int N) : N(N), cap(N, VI(N)), flow(N, VI(N)), dad(N), Q(N) {} void AddEdge(int from, int to, int cap) { this->cap[from][to] += cap; } int BlockingFlow(int s, int t) { fill(dad.begin(), dad.end(), -1); dad[s] = -2; int head = 0, tail = 0; Q[tail++] = s; while (head < tail) { int x = Q[head++]; for (int i = 0; i < N; i++) { if (dad[i] == -1 && cap[x][i] - flow[x][i] > 0) { dad[i] = x; Q[tail++] = i; } } } if (dad[t] == -1) return 0; int totflow = 0; for (int i = 0; i < N; i++) { if (dad[i] == -1) continue; int amt = cap[i][t] - flow[i][t]; for (int j = i; amt && j != s; j = dad[j]) amt = min(amt, cap[dad[j]][j] - flow[dad[j]][j]); if (amt == 0) continue; flow[i][t] += amt; flow[t][i] -= amt; for (int j = i; j != s; j = dad[j]) { flow[dad[j]][j] += amt; flow[j][dad[j]] -= amt; } totflow += amt; } return totflow; } int GetMaxFlow(int source, int sink) { int totflow = 0; while (int flow = BlockingFlow(source, sink)) totflow += flow; return totflow; } };*/ //******DSU******// /* struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } DSU (int n) { sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ //******MODULAR FFT******// /* const int root = 646; const int root_1 = 208611436; const int root_pw = 1<<20; void fft (vector<int> & a, bool invert) { int n = (int) a.size(); for (int i=1, j=0; i<n; ++i) { int bit = n >> 1; for (; j>=bit; bit>>=1) j -= bit; j += bit; if (i < j) swap (a[i], a[j]); } for (int len=2; len<=n; len<<=1) { int wlen = invert ? root_1 : root; for (int i=len; i<root_pw; i<<=1) wlen = int (wlen * 1ll * wlen % p); for (int i=0; i<n; i+=len) { int w = 1; for (int j=0; j<len/2; ++j) { int u = a[i+j], v = int (a[i+j+len/2] * 1ll * w % p); a[i+j] = u+v < p ? u+v : u+v-p; a[i+j+len/2] = u-v >= 0 ? u-v : u-v+p; w = int (w * 1ll * wlen % p); } } } if (invert) { int nrev = po(n, p - 2); for (int i=0; i<n; ++i) a[i] = int (a[i] * 1ll * nrev % p); } } void poly_mult(vector < int >& a, vector < int > b) { int s = a.size() + b.size(); int r = 1; while (r < s) r *= 2; int solve1(vector<int> a) { int n = a.size(); int cnt = 0; vector<int> b; vector<int> c; while (true) { int maxx = 0; for (int i = 0; i<n; i++) { if (a[i]>maxx) b.push_back(a[i]); else c.push_back(a[i]); maxx = max(maxx, a[i]); } if (b.size()==n) break; cnt++; a.clear(); for (auto it: c) a.push_back(it); for (auto it: b) a.push_back(it); b.clear(); c.clear(); } return cnt; } int lds(vector<int> a) { int n = a.size(); vector<int> dp(n); int ans = 1; dp[n-1] = 1; for (int i = n-2; i>=0; i--) { for (int j = i+1; j<n; j++) if (a[i]>a[j]) dp[i] = max(dp[i], dp[j]+1); ans = max(ans, dp[i]); } return ans-1; } int solve2(vector<int> a) { return lds(a); } bool check(int n) { vector<int> a; for (int i = 1; i<=n; i++) a.push_back(i); do { if (solve1(a)!=solve2(a)) {for (auto it: a) cout<<it<<' '; cout<<endl; cout<<"Expected "<<solve1(a)<<endl; cout<<"Got "<<solve2(a)<<endl; return 0;} }while (next_permutation(a.begin(), a.end())); cout<<"OK"<<endl; }a.resize(r); b.resize(r); fft(a, false); fft(b, false); for (int j = 0; j < r; j++) { a[j] = mul(a[j], b[j]); } fft(a, true); while (!a.empty() && (a.back() == 0)) a.pop_back(); } */ const int N = 1e6; vector<ll> t(N); void build(vector<ll> a, int v, int tl, int tr) { if (tl == tr) { t[v] = a[tl]; } else { int tm = (tl + tr) / 2; build(a, v * 2, tl, tm); build(a, v * 2 + 1, tm + 1, tr); t[v] = 0; } } void update(int v, int tl, int tr, int l, int r, ll add) { if (l > r) return; if (l == tl && r == tr) { t[v] += add; } else { int tm = (tl + tr) / 2; update(v * 2, tl, tm, l, min(r, tm), add); update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, add); } } ll get(int v, int tl, int tr, int pos) { if (tl == tr) return t[v]; int tm = (tl + tr) / 2; if (pos <= tm) return t[v] + get(v * 2, tl, tm, pos); else return t[v] + get(v * 2 + 1, tm + 1, tr, pos); } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> m(n); for (int i = 0; i < n; i++) cin >> m[i].first >> m[i].second; sort(m.begin(), m.end()); vector<ll> h(n); vector<int> x(n); for (int i = 0; i < n; i++) { x[i] = m[i].first; h[i] = m[i].second; } build(h, 1, 0, n - 1); ll answer = 0; for (int i = 0; i < n; i++) { ll cur = get(1, 0, n - 1, i); ll destroy = 0; if (cur > 0) destroy = (cur + a - 1) / a; answer += destroy; int kek = upper_bound(x.begin(), x.end(), x[i] + 2 * d) - x.begin() - 1; update(1, 0, n - 1, i, kek, -destroy * a); // cout<<cur<<' '<<destroy<<' '<<kek<<endl; } cout << answer; }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> /*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags #pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX #pragma GCC target("avx2") //Enable AVX*/ using namespace __gnu_pbds; using namespace std; #define vi vector<int> using ll = long long; #define ld long double #define mp make_pair #define what_is(x) cerr << #x << " is " << x << endl; typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int p = 1e9 + 7; int mul(int a, int b) { return (1LL * a * b) % p; } int add(int a, int b) { int s = (a + b); if (s >= p) s -= p; return s; } int sub(int a, int b) { int s = (a + p - b); if (s >= p) s -= p; return s; } int po(int a, int deg) { if (deg == 0) return 1; if (deg % 2 == 1) return mul(a, po(a, deg - 1)); int t = po(a, deg / 2); return mul(t, t); } int inv(int n) { return po(n, p - 2); } vector<int> Z(vector<int> s) { int n = s.size(); vector<int> z(n); int L = 0, R = 0; for (int i = 1; i < n; i++) { if (i > R) { L = R = i; while (R < n && s[R - L] == s[R]) R++; z[i] = R - L; R--; } else { int k = i - L; if (z[k] < R - i + 1) z[i] = z[k]; else { L = i; while (R < n && s[R - L] == s[R]) R++; z[i] = R - L; R--; } } } return z; } mt19937 rnd(time(0)); //******CONVEX HULL TRICK******// /* struct Line { mutable ll k, m, p; bool operator<(const Line& o) const { return k < o.k; } bool operator<(ll x) const { return p < x; } }; struct CHT : multiset<Line, less<>> { // (for doubles, use inf = 1/.0, div(a,b) = a/b) const ll inf = LLONG_MAX; ll div(ll a, ll b) { // floored division return a /b - ((a ^ b) < 0 && a % b); } bool isect(iterator x, iterator y) { if (y == end()) { x->p = inf; return false; } if (x->k == y->k) x->p = x->m > y->m ? inf : -inf; else x->p = div(y->m - x->m, x->k - y->k); return x->p >= y->p; } void add(ll k, ll m) { auto z = insert({k, m, 0}), y = z++, x = y; while (isect(y, z)) z = erase(z); if (x != begin() && isect(--x, y)) isect(x, y = erase(y)); while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y)); } ll query(ll x) { assert(!empty()); auto l = *lower_bound(x); return l.k * x + l.m; } }; */ //******MAXFLOW******// /* typedef vector<int> VI; typedef vector<VI> VVI; const int INF = 1000000000; struct MaxFlow { int N; VVI cap, flow; VI dad, Q; MaxFlow(int N) : N(N), cap(N, VI(N)), flow(N, VI(N)), dad(N), Q(N) {} void AddEdge(int from, int to, int cap) { this->cap[from][to] += cap; } int BlockingFlow(int s, int t) { fill(dad.begin(), dad.end(), -1); dad[s] = -2; int head = 0, tail = 0; Q[tail++] = s; while (head < tail) { int x = Q[head++]; for (int i = 0; i < N; i++) { if (dad[i] == -1 && cap[x][i] - flow[x][i] > 0) { dad[i] = x; Q[tail++] = i; } } } if (dad[t] == -1) return 0; int totflow = 0; for (int i = 0; i < N; i++) { if (dad[i] == -1) continue; int amt = cap[i][t] - flow[i][t]; for (int j = i; amt && j != s; j = dad[j]) amt = min(amt, cap[dad[j]][j] - flow[dad[j]][j]); if (amt == 0) continue; flow[i][t] += amt; flow[t][i] -= amt; for (int j = i; j != s; j = dad[j]) { flow[dad[j]][j] += amt; flow[j][dad[j]] -= amt; } totflow += amt; } return totflow; } int GetMaxFlow(int source, int sink) { int totflow = 0; while (int flow = BlockingFlow(source, sink)) totflow += flow; return totflow; } };*/ //******DSU******// /* struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } DSU (int n) { sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ //******MODULAR FFT******// /* const int root = 646; const int root_1 = 208611436; const int root_pw = 1<<20; void fft (vector<int> & a, bool invert) { int n = (int) a.size(); for (int i=1, j=0; i<n; ++i) { int bit = n >> 1; for (; j>=bit; bit>>=1) j -= bit; j += bit; if (i < j) swap (a[i], a[j]); } for (int len=2; len<=n; len<<=1) { int wlen = invert ? root_1 : root; for (int i=len; i<root_pw; i<<=1) wlen = int (wlen * 1ll * wlen % p); for (int i=0; i<n; i+=len) { int w = 1; for (int j=0; j<len/2; ++j) { int u = a[i+j], v = int (a[i+j+len/2] * 1ll * w % p); a[i+j] = u+v < p ? u+v : u+v-p; a[i+j+len/2] = u-v >= 0 ? u-v : u-v+p; w = int (w * 1ll * wlen % p); } } } if (invert) { int nrev = po(n, p - 2); for (int i=0; i<n; ++i) a[i] = int (a[i] * 1ll * nrev % p); } } void poly_mult(vector < int >& a, vector < int > b) { int s = a.size() + b.size(); int r = 1; while (r < s) r *= 2; int solve1(vector<int> a) { int n = a.size(); int cnt = 0; vector<int> b; vector<int> c; while (true) { int maxx = 0; for (int i = 0; i<n; i++) { if (a[i]>maxx) b.push_back(a[i]); else c.push_back(a[i]); maxx = max(maxx, a[i]); } if (b.size()==n) break; cnt++; a.clear(); for (auto it: c) a.push_back(it); for (auto it: b) a.push_back(it); b.clear(); c.clear(); } return cnt; } int lds(vector<int> a) { int n = a.size(); vector<int> dp(n); int ans = 1; dp[n-1] = 1; for (int i = n-2; i>=0; i--) { for (int j = i+1; j<n; j++) if (a[i]>a[j]) dp[i] = max(dp[i], dp[j]+1); ans = max(ans, dp[i]); } return ans-1; } int solve2(vector<int> a) { return lds(a); } bool check(int n) { vector<int> a; for (int i = 1; i<=n; i++) a.push_back(i); do { if (solve1(a)!=solve2(a)) {for (auto it: a) cout<<it<<' '; cout<<endl; cout<<"Expected "<<solve1(a)<<endl; cout<<"Got "<<solve2(a)<<endl; return 0;} }while (next_permutation(a.begin(), a.end())); cout<<"OK"<<endl; }a.resize(r); b.resize(r); fft(a, false); fft(b, false); for (int j = 0; j < r; j++) { a[j] = mul(a[j], b[j]); } fft(a, true); while (!a.empty() && (a.back() == 0)) a.pop_back(); } */ const int N = 1e6; vector<ll> t(N); void build(vector<ll> &a, int v, int tl, int tr) { if (tl == tr) { t[v] = a[tl]; } else { int tm = (tl + tr) / 2; build(a, v * 2, tl, tm); build(a, v * 2 + 1, tm + 1, tr); t[v] = 0; } } void update(int v, int tl, int tr, int l, int r, ll add) { if (l > r) return; if (l == tl && r == tr) { t[v] += add; } else { int tm = (tl + tr) / 2; update(v * 2, tl, tm, l, min(r, tm), add); update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, add); } } ll get(int v, int tl, int tr, int pos) { if (tl == tr) return t[v]; int tm = (tl + tr) / 2; if (pos <= tm) return t[v] + get(v * 2, tl, tm, pos); else return t[v] + get(v * 2 + 1, tm + 1, tr, pos); } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> m(n); for (int i = 0; i < n; i++) cin >> m[i].first >> m[i].second; sort(m.begin(), m.end()); vector<ll> h(n); vector<int> x(n); for (int i = 0; i < n; i++) { x[i] = m[i].first; h[i] = m[i].second; } build(h, 1, 0, n - 1); ll answer = 0; for (int i = 0; i < n; i++) { ll cur = get(1, 0, n - 1, i); ll destroy = 0; if (cur > 0) destroy = (cur + a - 1) / a; answer += destroy; int kek = upper_bound(x.begin(), x.end(), x[i] + 2 * d) - x.begin() - 1; update(1, 0, n - 1, i, kek, -destroy * a); // cout<<cur<<' '<<destroy<<' '<<kek<<endl; } cout << answer; }
replace
337
338
337
338
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) #define pcnt __builtin_popcountll #define rng(a) a.begin(), a.end() #define sz(x) (int)(x).size() #define v(T) vector<T> #define vv(T) v(v(T)) #define fi first #define se second using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; template <typename T> inline istream &operator>>(istream &i, v(T) & v) { rep(j, sz(v)) i >> v[j]; return i; } template <typename T1, typename T2> inline istream &operator>>(istream &i, pair<T1, T2> &v) { return i >> v.fi >> v.se; } 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; } ll INF = 1001001001; ll LINF = 1001001001001001001ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, d, a; cin >> n >> d >> a; vector<LP> xh(n); rep(i, n) cin >> xh[i].fi >> xh[i].se; sort(rng(xh)); vl ds(n); ll s = 0; ll ans = 0; rep(i, n) { s += ds[i]; if (xh[i].se > s) { ll r = xh[i].se - s; ll c = r / a; if (r % a) c++; s += a * c; ll it = upper_bound(rng(xh), LP(xh[i].fi + 2 * d, LINF)) - xh.begin(); ds[it] -= a * c; ans += c; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) #define pcnt __builtin_popcountll #define rng(a) a.begin(), a.end() #define sz(x) (int)(x).size() #define v(T) vector<T> #define vv(T) v(v(T)) #define fi first #define se second using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; template <typename T> inline istream &operator>>(istream &i, v(T) & v) { rep(j, sz(v)) i >> v[j]; return i; } template <typename T1, typename T2> inline istream &operator>>(istream &i, pair<T1, T2> &v) { return i >> v.fi >> v.se; } 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; } ll INF = 1001001001; ll LINF = 1001001001001001001ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, d, a; cin >> n >> d >> a; vector<LP> xh(n); rep(i, n) cin >> xh[i].fi >> xh[i].se; sort(rng(xh)); vl ds(n + 10); ll s = 0; ll ans = 0; rep(i, n) { s += ds[i]; if (xh[i].se > s) { ll r = xh[i].se - s; ll c = r / a; if (r % a) c++; s += a * c; ll it = upper_bound(rng(xh), LP(xh[i].fi + 2 * d, LINF)) - xh.begin(); ds[it] -= a * c; ans += c; } } cout << ans << endl; }
replace
56
57
56
57
0
p02788
C++
Time Limit Exceeded
// #pragma GCC optimize(2) // #pragma G++ optimize(2) // #pragma comment(linker,"/STACK:102400000,102400000") // #include <bits/stdc++.h> #include <algorithm> #include <array> #include <atomic> #include <bitset> #include <cassert> #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <chrono> #include <cinttypes> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <condition_variable> #include <csetjmp> #include <csignal> #include <cstdalign> #include <cstdarg> #include <cstdbool> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctgmath> #include <ctime> #include <cwchar> #include <cwctype> #include <deque> #include <forward_list> #include <fstream> #include <functional> #include <future> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <mutex> #include <numeric> #include <queue> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <string> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <valarray> #include <vector> // #include <conio.h> // #include <windows.h> using namespace std; typedef long long LL; typedef unsigned int ui; typedef unsigned long long ull; typedef float fl; typedef double ld; typedef long double LD; typedef pair<int, int> pii; #if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \ (WINDOWS) #define lld "%I64d" #define llu "%I64u" #else #define lld "%lld" #define llu "%llu" #endif #define ui(n) ((unsigned int)(n)) #define LL(n) ((long long)(n)) #define ull(n) ((unsigned long long)(n)) #define fl(n) ((float)(n)) #define ld(n) ((double)(n)) #define LD(n) ((long double)(n)) #define char(n) ((char)(n)) #define Bool(n) ((bool)(n)) #define fixpoint(n) fixed << setprecision(n) const int INF = 1061109567; const int NINF = -1044266559; const LL LINF = 4557430888798830399; const ld eps = 1e-15; #define MOD (1000000007) #define PI (3.1415926535897932384626433832795028841971) /* #define MB_LEN_MAX 5 #define SHRT_MIN (-32768) #define SHRT_MAX 32767 #define USHRT_MAX 0xffffU #define INT_MIN (-2147483647 - 1) #define INT_MAX 2147483647 #define UINT_MAX 0xffffffffU #define LONG_MIN (-2147483647L - 1) #define LONG_MAX 2147483647L #define ULONG_MAX 0xffffffffUL #define LLONG_MAX 9223372036854775807ll #define LLONG_MIN (-9223372036854775807ll - 1) #define ULLONG_MAX 0xffffffffffffffffull */ #define MP make_pair #define MT make_tuple #define All(a) (a).begin(), (a).end() #define pall(a) (a).rbegin(), (a).rend() #define Log(x, y) log(x) / log(y) #define SZ(a) ((int)(a).size()) #define rep(i, n) for (int i = 0; i < ((int)(n)); i++) #define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) #define repa(i, a, n) for (int i = ((int)(a)); i < ((int)(n)); i++) #define repa1(i, a, n) for (int i = ((int)(a)); i <= ((int)(n)); i++) #define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--) #define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--) #define repda(i, n, a) for (int i = ((int)(n)); i > ((int)(a)); i--) #define repda1(i, n, a) for (int i = ((int)(n)); i >= ((int)(a)); i--) #define FOR(i, a, n, step) \ for (int i = ((int)(a)); i < ((int)(n)); i += ((int)(step))) #define repv(itr, v) \ for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++) #define repV(i, v) for (auto i : v) #define repE(i, v) for (auto &i : v) #define MS(x, y) memset(x, y, sizeof(x)) #define MC(x) MS(x, 0) #define MINF(x) MS(x, 63) #define MCP(x, y) memcpy(x, y, sizeof(y)) #define sqr(x) ((x) * (x)) #define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end()) #define filein(x) freopen(x, "r", stdin) #define fileout(x) freopen(x, "w", stdout) #define fileio(x) \ freopen(x ".in", "r", stdin); \ freopen(x ".out", "w", stdout) #define filein2(filename, name) ifstream name(filename, ios::in) #define fileout2(filename, name) ofstream name(filename, ios::out) #define file(filename, name) fstream name(filename, ios::in | ios::out) #define Pause system("pause") #define Cls system("cls") #define fs first #define sc second #define PC(x) putchar(x) #define GC(x) x = getchar() #define Endl PC('\n') #define SF scanf #define PF printf #define j0 J0 #define j1 J1 #define jn Jn #define y0 Y0 #define y1 Y1 #define yn Yn inline int Read() { int x = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return w ? -x : x; } inline void Write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) Write(x / 10); putchar(x % 10 + '0'); } inline LL powmod(LL a, LL b) { LL res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res % MOD; } inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; } const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1}; /************************************************************BEGIN************************************************************/ #define int LL const int maxn = 200010; int n, d, a, x[maxn], h[maxn], mon[maxn], bit[maxn], ans; inline void add(int u, int v) { while (u <= n) { bit[u] += v; u += u & -u; } } inline int sum(int u) { int res = 0; while (u) { res += bit[u]; u -= u & -u; } return res; } inline bool cmp(int u, int v) { return x[u] < x[v]; } signed main() { SF("%lld%lld%lld", &n, &d, &a); rep1(i, n) { SF("%lld%lld", &x[i], &h[i]); mon[i] = i; } mon[n + 1] = n + 1; x[n + 1] = INF; sort(mon + 1, mon + n + 1, cmp); rep1(i, n) { rep1(j, n) cerr << sum(j) - sum(j - 1) << ' '; cerr << endl; int hp = h[mon[i]] + sum(i); if (hp > 0) { int att = (hp + a - 1) / a; ans += att; att *= a; int l = i + 1, r = n + 1; // [l,r) while (l < r) { int m = (l + r) / 2; if (x[mon[m]] > x[mon[i]] + 2 * d) r = m; else l = m + 1; } add(i, -att); add(r, att); } } PF("%lld", ans); return 0; } /*************************************************************END**************************************************************/
// #pragma GCC optimize(2) // #pragma G++ optimize(2) // #pragma comment(linker,"/STACK:102400000,102400000") // #include <bits/stdc++.h> #include <algorithm> #include <array> #include <atomic> #include <bitset> #include <cassert> #include <ccomplex> #include <cctype> #include <cerrno> #include <cfenv> #include <cfloat> #include <chrono> #include <cinttypes> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <condition_variable> #include <csetjmp> #include <csignal> #include <cstdalign> #include <cstdarg> #include <cstdbool> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctgmath> #include <ctime> #include <cwchar> #include <cwctype> #include <deque> #include <forward_list> #include <fstream> #include <functional> #include <future> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <mutex> #include <numeric> #include <queue> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <string> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <typeinfo> #include <unordered_map> #include <unordered_set> #include <valarray> #include <vector> // #include <conio.h> // #include <windows.h> using namespace std; typedef long long LL; typedef unsigned int ui; typedef unsigned long long ull; typedef float fl; typedef double ld; typedef long double LD; typedef pair<int, int> pii; #if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \ (WINDOWS) #define lld "%I64d" #define llu "%I64u" #else #define lld "%lld" #define llu "%llu" #endif #define ui(n) ((unsigned int)(n)) #define LL(n) ((long long)(n)) #define ull(n) ((unsigned long long)(n)) #define fl(n) ((float)(n)) #define ld(n) ((double)(n)) #define LD(n) ((long double)(n)) #define char(n) ((char)(n)) #define Bool(n) ((bool)(n)) #define fixpoint(n) fixed << setprecision(n) const int INF = 1061109567; const int NINF = -1044266559; const LL LINF = 4557430888798830399; const ld eps = 1e-15; #define MOD (1000000007) #define PI (3.1415926535897932384626433832795028841971) /* #define MB_LEN_MAX 5 #define SHRT_MIN (-32768) #define SHRT_MAX 32767 #define USHRT_MAX 0xffffU #define INT_MIN (-2147483647 - 1) #define INT_MAX 2147483647 #define UINT_MAX 0xffffffffU #define LONG_MIN (-2147483647L - 1) #define LONG_MAX 2147483647L #define ULONG_MAX 0xffffffffUL #define LLONG_MAX 9223372036854775807ll #define LLONG_MIN (-9223372036854775807ll - 1) #define ULLONG_MAX 0xffffffffffffffffull */ #define MP make_pair #define MT make_tuple #define All(a) (a).begin(), (a).end() #define pall(a) (a).rbegin(), (a).rend() #define Log(x, y) log(x) / log(y) #define SZ(a) ((int)(a).size()) #define rep(i, n) for (int i = 0; i < ((int)(n)); i++) #define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) #define repa(i, a, n) for (int i = ((int)(a)); i < ((int)(n)); i++) #define repa1(i, a, n) for (int i = ((int)(a)); i <= ((int)(n)); i++) #define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--) #define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--) #define repda(i, n, a) for (int i = ((int)(n)); i > ((int)(a)); i--) #define repda1(i, n, a) for (int i = ((int)(n)); i >= ((int)(a)); i--) #define FOR(i, a, n, step) \ for (int i = ((int)(a)); i < ((int)(n)); i += ((int)(step))) #define repv(itr, v) \ for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++) #define repV(i, v) for (auto i : v) #define repE(i, v) for (auto &i : v) #define MS(x, y) memset(x, y, sizeof(x)) #define MC(x) MS(x, 0) #define MINF(x) MS(x, 63) #define MCP(x, y) memcpy(x, y, sizeof(y)) #define sqr(x) ((x) * (x)) #define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end()) #define filein(x) freopen(x, "r", stdin) #define fileout(x) freopen(x, "w", stdout) #define fileio(x) \ freopen(x ".in", "r", stdin); \ freopen(x ".out", "w", stdout) #define filein2(filename, name) ifstream name(filename, ios::in) #define fileout2(filename, name) ofstream name(filename, ios::out) #define file(filename, name) fstream name(filename, ios::in | ios::out) #define Pause system("pause") #define Cls system("cls") #define fs first #define sc second #define PC(x) putchar(x) #define GC(x) x = getchar() #define Endl PC('\n') #define SF scanf #define PF printf #define j0 J0 #define j1 J1 #define jn Jn #define y0 Y0 #define y1 Y1 #define yn Yn inline int Read() { int x = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return w ? -x : x; } inline void Write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) Write(x / 10); putchar(x % 10 + '0'); } inline LL powmod(LL a, LL b) { LL res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res % MOD; } inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; } const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1}; /************************************************************BEGIN************************************************************/ #define int LL const int maxn = 200010; int n, d, a, x[maxn], h[maxn], mon[maxn], bit[maxn], ans; inline void add(int u, int v) { while (u <= n) { bit[u] += v; u += u & -u; } } inline int sum(int u) { int res = 0; while (u) { res += bit[u]; u -= u & -u; } return res; } inline bool cmp(int u, int v) { return x[u] < x[v]; } signed main() { SF("%lld%lld%lld", &n, &d, &a); rep1(i, n) { SF("%lld%lld", &x[i], &h[i]); mon[i] = i; } mon[n + 1] = n + 1; x[n + 1] = INF; sort(mon + 1, mon + n + 1, cmp); rep1(i, n) { int hp = h[mon[i]] + sum(i); if (hp > 0) { int att = (hp + a - 1) / a; ans += att; att *= a; int l = i + 1, r = n + 1; // [l,r) while (l < r) { int m = (l + r) / 2; if (x[mon[m]] > x[mon[i]] + 2 * d) r = m; else l = m + 1; } add(i, -att); add(r, att); } } PF("%lld", ans); return 0; } /*************************************************************END**************************************************************/
delete
243
246
243
243
TLE
p02788
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) using ll = long long; using P = pair<int, int>; const long long MOD = 1e9 + 7; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct Bit { vector<ll> bit[2]; int N; void init(int n) { for (int i = 0; i < 2; i++) bit[i].assign(n + 1, 0); N = n + 1; } ll sub_sum(int p, int i) { ll s = 0; while (0 < i) { s += bit[p].at(i); i -= i & -i; } return s; } // 1-indexed ll sum(int i) { return sub_sum(0, i) + sub_sum(1, i) * i; } // [a, b] ll sum(int a, int b) { return sum(b) - sum(a - 1); } void sub_add(int p, int i, ll v) { while (i <= N) { bit[p].at(i) += v; i += i & -i; } } //[a, b] 1-indexed void add(int a, int b, ll v) { sub_add(0, a, -v * (a - 1)); sub_add(1, a, v); sub_add(0, b + 1, v * b); sub_add(1, b + 1, -v); } }; int main() { int n; ll d, a; cin >> n >> d >> a; vector<pair<ll, ll>> m(n); for (int i = 0; i < n; i++) { int x, h; cin >> x >> h; m.at(i) = make_pair(x, h); } sort(m.begin(), m.end()); auto binary_search = [&](ll x) { int ng = n; int ok = -1; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (m.at(mid).first <= x) ok = mid; else ng = mid; } return ok; }; Bit bit; bit.init(n + 1); for (int i = 0; i < n; i++) { bit.add(i + 1, i + 1, m.at(i).second); } ll cnt = 0; for (int l = 0; l < n; l++) { ll h = bit.sum(l + 1, l + 1); if (h <= 0) continue; int r = binary_search(m.at(l).first + d * 2); ll c = (h + a - 1) / a; cnt += c; bit.add(l + 1, r + 1, c * -a); } cout << cnt << endl; }
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) using ll = long long; using P = pair<int, int>; const long long MOD = 1e9 + 7; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct Bit { vector<ll> bit[2]; int N; void init(int n) { for (int i = 0; i < 2; i++) bit[i].assign(n + 2, 0); N = n + 1; } ll sub_sum(int p, int i) { ll s = 0; while (0 < i) { s += bit[p].at(i); i -= i & -i; } return s; } // 1-indexed ll sum(int i) { return sub_sum(0, i) + sub_sum(1, i) * i; } // [a, b] ll sum(int a, int b) { return sum(b) - sum(a - 1); } void sub_add(int p, int i, ll v) { while (i <= N) { bit[p].at(i) += v; i += i & -i; } } //[a, b] 1-indexed void add(int a, int b, ll v) { sub_add(0, a, -v * (a - 1)); sub_add(1, a, v); sub_add(0, b + 1, v * b); sub_add(1, b + 1, -v); } }; int main() { int n; ll d, a; cin >> n >> d >> a; vector<pair<ll, ll>> m(n); for (int i = 0; i < n; i++) { int x, h; cin >> x >> h; m.at(i) = make_pair(x, h); } sort(m.begin(), m.end()); auto binary_search = [&](ll x) { int ng = n; int ok = -1; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (m.at(mid).first <= x) ok = mid; else ng = mid; } return ok; }; Bit bit; bit.init(n + 1); for (int i = 0; i < n; i++) { bit.add(i + 1, i + 1, m.at(i).second); } ll cnt = 0; for (int l = 0; l < n; l++) { ll h = bit.sum(l + 1, l + 1); if (h <= 0) continue; int r = binary_search(m.at(l).first + d * 2); ll c = (h + a - 1) / a; cnt += c; bit.add(l + 1, r + 1, c * -a); } cout << cnt << endl; }
replace
39
40
39
40
0
p02788
C++
Runtime Error
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; typedef long long int ll; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;} template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;} // clang-format on #include <functional> template <typename T> class SegmentTreeAllOne { using Func = function<T(T, T)>; public: vector<T> data; int n; T init; Func update_func; SegmentTreeAllOne(int _n, T _init, Func up) { init = _init; update_func = up; for (n = 1; n < _n; n *= 2) ; data.resize(2 * n - 1, init); } void update(int l, int r, T val) { for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) { if (!(l & 1)) { data[l] = update_func(data[l], val); } if (!(r & 1)) { data[r - 1] = update_func(data[r - 1], val); } } } T query(int pos) { pos += n - 1; T res = data[pos]; while (pos > 0) { pos = (pos - 1) / 2; res = update_func(res, data[pos]); } return res; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n, d, a; cin >> n >> d >> a; vector<ll> x(n), h(n); REP(i, 0, n) { cin >> x[i] >> h[i]; } vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int t, int s) { if (x[t] != x[s]) return x[t] < x[s]; else return h[t] < h[s]; }); auto sum = [](ll t, ll s) { return t + s; }; SegmentTreeAllOne<ll> segtree(n, 0LL, sum); ll cnt = 0; int p = 0; REP(i, 0, n) { ll res = h[ord[i]] - segtree.query(i); if (res <= 0) continue; while (p < n && x[ord[p]] - 2 * d <= x[ord[i]]) { p++; } ll cn = (res + a - 1) / a; segtree.update(x[ord[i]], x[ord[p - 1]], cn * a); cnt += cn; } cout << cnt << endl; return 0; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; typedef long long int ll; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;} template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;} // clang-format on #include <functional> template <typename T> class SegmentTreeAllOne { using Func = function<T(T, T)>; public: vector<T> data; int n; T init; Func update_func; SegmentTreeAllOne(int _n, T _init, Func up) { init = _init; update_func = up; for (n = 1; n < _n; n *= 2) ; data.resize(2 * n - 1, init); } void update(int l, int r, T val) { for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) { if (!(l & 1)) { data[l] = update_func(data[l], val); } if (!(r & 1)) { data[r - 1] = update_func(data[r - 1], val); } } } T query(int pos) { pos += n - 1; T res = data[pos]; while (pos > 0) { pos = (pos - 1) / 2; res = update_func(res, data[pos]); } return res; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n, d, a; cin >> n >> d >> a; vector<ll> x(n), h(n); REP(i, 0, n) { cin >> x[i] >> h[i]; } vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int t, int s) { if (x[t] != x[s]) return x[t] < x[s]; else return h[t] < h[s]; }); auto sum = [](ll t, ll s) { return t + s; }; SegmentTreeAllOne<ll> segtree(n, 0LL, sum); ll cnt = 0; int p = 0; REP(i, 0, n) { ll res = h[ord[i]] - segtree.query(i); if (res <= 0) continue; while (p < n && x[ord[p]] - 2 * d <= x[ord[i]]) { p++; } ll cn = (res + a - 1) / a; segtree.update(i, p, cn * a); cnt += cn; } cout << cnt << endl; return 0; }
replace
91
92
91
92
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; double getTime() { return clock() / (double)CLOCKS_PER_SEC; } void read(){}; template <typename T, typename... Args> void read(T &a, Args &...args) { cin >> a; read(args...); } void print(){}; template <typename T, typename... Args> void print(T a, Args... args) { cout << a << " \n"[sizeof...(args) == 0]; print(args...); } int main() { int n; read(n); ll d, A; read(d, A); vector<pair<ll, ll>> v(n); for (int i = 0; i < n; i++) { read(v[i].first, v[i].second); v[i].second = (v[i].second + A - 1) / A; } sort(v.begin(), v.end()); vector<ll> pf(n + 1, 0); int j = 0; ll moves = 0; for (int i = 0; i < n; i++) { while (v[i].first + d + d >= v[j].first) j++; ll need = max(0LL, v[i].second - pf[i]); moves += need; pf[i] += need; pf[j] -= need; pf[i + 1] += pf[i]; } print(moves); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; double getTime() { return clock() / (double)CLOCKS_PER_SEC; } void read(){}; template <typename T, typename... Args> void read(T &a, Args &...args) { cin >> a; read(args...); } void print(){}; template <typename T, typename... Args> void print(T a, Args... args) { cout << a << " \n"[sizeof...(args) == 0]; print(args...); } int main() { int n; read(n); ll d, A; read(d, A); vector<pair<ll, ll>> v(n + 1); v[n] = {1e18, 1e18}; for (int i = 0; i < n; i++) { read(v[i].first, v[i].second); v[i].second = (v[i].second + A - 1) / A; } sort(v.begin(), v.end()); vector<ll> pf(n + 1, 0); int j = 0; ll moves = 0; for (int i = 0; i < n; i++) { while (v[i].first + d + d >= v[j].first) j++; ll need = max(0LL, v[i].second - pf[i]); moves += need; pf[i] += need; pf[j] -= need; pf[i + 1] += pf[i]; } print(moves); }
replace
27
28
27
29
-11
p02788
C++
Runtime Error
#include <bits/stdc++.h> // #define DEBUG using namespace std; const int N = 1e2 + 7; const int MOD = 1e9 + 7; const double eps = 1e-11; typedef pair<int, int> pii; struct Node { int x, h; friend bool operator<(const Node &n1, const Node &n2) { return n1.x < n2.x; } friend istream &operator>>(istream &is, Node &nd) { return is >> nd.x >> nd.h; } } b[N]; int n, d, a; int del[N], hhh[N]; inline int getpos(const long long &x) { int l = 1, r = n; while (l < r) { int mid = (l + r) >> 1; if (b[mid].x <= x) l = mid + 1; else r = mid; } return b[l].x > x ? l : n + 1; } inline void solve() { cin >> n >> d >> a; for (int i = 1; i <= n; ++i) cin >> b[i]; sort(b + 1, b + n + 1); long long res = 0; for (int i = 1, j = 1, now = 0, t, k; i <= n; ++i) { while (j <= i) now -= del[j++] * a; if (now >= b[i].h) continue; t = (b[i].h - now) / a + ((b[i].h - now) % a != 0); res += t; now += t * a; del[getpos(1ll * b[i].x + d + d)] += t; } cout << res << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T = 1; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> // #define DEBUG using namespace std; const int N = 2e5 + 7; const int MOD = 1e9 + 7; const double eps = 1e-11; typedef pair<int, int> pii; struct Node { int x, h; friend bool operator<(const Node &n1, const Node &n2) { return n1.x < n2.x; } friend istream &operator>>(istream &is, Node &nd) { return is >> nd.x >> nd.h; } } b[N]; int n, d, a; int del[N], hhh[N]; inline int getpos(const long long &x) { int l = 1, r = n; while (l < r) { int mid = (l + r) >> 1; if (b[mid].x <= x) l = mid + 1; else r = mid; } return b[l].x > x ? l : n + 1; } inline void solve() { cin >> n >> d >> a; for (int i = 1; i <= n; ++i) cin >> b[i]; sort(b + 1, b + n + 1); long long res = 0; for (int i = 1, j = 1, now = 0, t, k; i <= n; ++i) { while (j <= i) now -= del[j++] * a; if (now >= b[i].h) continue; t = (b[i].h - now) / a + ((b[i].h - now) % a != 0); res += t; now += t * a; del[getpos(1ll * b[i].x + d + d)] += t; } cout << res << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T = 1; while (T--) { solve(); } return 0; }
replace
6
7
6
7
0
p02788
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> #include <cassert> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> #include <chrono> #include <random> #include <thread> #include <unordered_map> #include <unordered_set> using namespace std; #define all(c) c.begin(), c.end() #define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ","; os << *it; } return os << "}"; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &v) { os << "{"; os << v.first << ", " << v.second; return os << "}"; } template <typename T> T input() { T x; cin >> x; return x; } template <typename T> vector<T> input_vector(size_t n) { vector<T> x(n); for (int i = 0; i < n; i++) cin >> x[i]; return x; } template <uint_fast64_t MOD> struct mod_int { mod_int() noexcept : m_value(0) {} constexpr mod_int(uint_fast64_t x) noexcept : m_value((x + MOD) % MOD) {} constexpr mod_int(long long x) noexcept : m_value((x + MOD) % MOD) {} constexpr mod_int(int x) noexcept : m_value((x + MOD) % MOD) {} constexpr mod_int operator+(const mod_int rhs) const noexcept { return mod_int(m_value) += rhs; } constexpr mod_int operator-(const mod_int rhs) const noexcept { return mod_int(m_value) -= rhs; } constexpr mod_int operator*(const mod_int rhs) const noexcept { return mod_int(m_value) *= rhs; } constexpr mod_int operator/(const mod_int rhs) const noexcept { return mod_int(m_value) /= rhs; } constexpr mod_int &operator+=(const mod_int rhs) noexcept { m_value += rhs.m_value; if (m_value >= MOD) m_value %= MOD; return *this; } constexpr mod_int operator-=(const mod_int rhs) noexcept { if (m_value < rhs.m_value) m_value += MOD; m_value -= rhs.m_value; return *this; } constexpr mod_int operator*=(const mod_int rhs) noexcept { m_value = m_value * rhs.m_value % MOD; return *this; } constexpr mod_int operator/=(mod_int rhs) noexcept { uint_fast64_t exp = MOD - 2; while (exp > 0) { if (exp % 2 == 1) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } mod_int inv() const noexcept { return mod_int(1) /= *this; } uint_fast64_t &value() { return m_value; } private: uint_fast64_t m_value; }; template <uint_fast64_t MOD> ostream &operator<<(ostream &os, const mod_int<MOD> &v) { return os << v.value(); } template <uint_fast64_t MOD> istream &operator>>(istream &is, mod_int<MOD> &v) { return is >> v.value(); } using ll = long long; const ll MOD = 1000000007; using md = mod_int<MOD>; // --------------------------------------------------------------------------- using point = complex<double>; int my_main(int argc, char **argv) { ios::sync_with_stdio(false); cin.tie(0); ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> v; repeat(i, n) { ll x, h; cin >> x >> h; h = (h % a == 0) ? h / a : (h / a + 1); v.emplace_back(x, h); } v.emplace_back(2000000010LL, 0); sort(all(v)); vector<ll> ps; for (auto p : v) ps.push_back(p.first); ll diff = 0; ll ret = 0; vector<ll> incs(v.size()); for (int i = 0; i < n; i++) { diff += incs[i]; v[i].second += diff; if (v[i].second > 0) { ll need = v[i].second; ret += need; diff -= need; int inc = upper_bound(all(ps), v[i].first + 2 * d) - ps.begin(); incs[inc] += need; } } cout << ret << endl; return 0; } // ---------------------------------------------------------------------------- // Test driver #ifdef DEBUG #define MAY_RUN_TESTCASE #endif #ifdef MAY_RUN_TESTCASE #include <fstream> #if __has_include(<unistd.h>) // Mac, Linux #include <unistd.h> #elif __has_include(<io.h>) // Windows #include <io.h> #else // Other? #error "unistd.h or io.h not found" #endif bool test_file_exists(const std::string &str) { std::ifstream fs(str); return fs.is_open(); } #endif int main(int argc, char **argv) { #ifndef MAY_RUN_TESTCASE return my_main(argc, argv); #else if (argc == 1) { return my_main(argc, argv); } else if (argc == 2) { char *stdin_file = argv[1]; freopen(stdin_file, "r", stdin); return my_main(argc, argv); } else if (argc == 5) { std::string stdin_file = argv[1]; std::string expected_file = argv[2]; std::string stdout_file = argv[3]; std::string stderr_file = argv[4]; if (!test_file_exists(stdin_file)) { std::cerr << stdin_file << " not found" << std::endl; return 3; } if (!test_file_exists(expected_file)) { std::cerr << expected_file << " not found" << std::endl; return 3; } int original_stdin = dup(fileno(stdin)); int original_stdout = dup(fileno(stdout)); int original_stderr = dup(fileno(stderr)); freopen(stdin_file.c_str(), "r", stdin); freopen(stdout_file.c_str(), "w", stdout); freopen(stderr_file.c_str(), "w", stderr); int ret = my_main(argc, argv); fflush(stdout); fflush(stderr); dup2(original_stderr, fileno(stderr)); dup2(original_stdout, fileno(stdout)); dup2(original_stdin, fileno(stdin)); if (ret != 0) { std::cerr << "main returns " << ret << std::endl; return ret; } std::ifstream inp(stdin_file); std::ifstream out(stdout_file); std::ifstream err(stderr_file); std::ifstream exp(expected_file); // Clear is needed if the file is empty. std::cout << "----- input -----" << std::endl; std::cout << inp.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl << std::endl; std::cout << "----- output ----" << std::endl; std::cout << out.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl << std::endl; std::cout << "---- expected ---" << std::endl; std::cout << exp.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl << std::endl; std::cout << "----- stderr ----" << std::endl; std::cout << err.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl; inp.seekg(0); out.seekg(0); exp.seekg(0); err.seekg(0); std::string output_str, expected_str; { std::stringstream output_ss; output_ss << out.rdbuf(); output_str = output_ss.str(); std::stringstream expected_ss; expected_ss << exp.rdbuf(); expected_str = expected_ss.str(); } // Remove trailing spaces output_str.erase(output_str.find_last_not_of(" \n\r\t") + 1); expected_str.erase(expected_str.find_last_not_of(" \n\r\t") + 1); if (output_str == expected_str) return 0; else return 1; } return 1; #endif }
#include <algorithm> #include <array> #include <bitset> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <valarray> #include <vector> #include <cassert> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> #include <chrono> #include <random> #include <thread> #include <unordered_map> #include <unordered_set> using namespace std; #define all(c) c.begin(), c.end() #define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ","; os << *it; } return os << "}"; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &v) { os << "{"; os << v.first << ", " << v.second; return os << "}"; } template <typename T> T input() { T x; cin >> x; return x; } template <typename T> vector<T> input_vector(size_t n) { vector<T> x(n); for (int i = 0; i < n; i++) cin >> x[i]; return x; } template <uint_fast64_t MOD> struct mod_int { mod_int() noexcept : m_value(0) {} constexpr mod_int(uint_fast64_t x) noexcept : m_value((x + MOD) % MOD) {} constexpr mod_int(long long x) noexcept : m_value((x + MOD) % MOD) {} constexpr mod_int(int x) noexcept : m_value((x + MOD) % MOD) {} constexpr mod_int operator+(const mod_int rhs) const noexcept { return mod_int(m_value) += rhs; } constexpr mod_int operator-(const mod_int rhs) const noexcept { return mod_int(m_value) -= rhs; } constexpr mod_int operator*(const mod_int rhs) const noexcept { return mod_int(m_value) *= rhs; } constexpr mod_int operator/(const mod_int rhs) const noexcept { return mod_int(m_value) /= rhs; } constexpr mod_int &operator+=(const mod_int rhs) noexcept { m_value += rhs.m_value; if (m_value >= MOD) m_value %= MOD; return *this; } constexpr mod_int operator-=(const mod_int rhs) noexcept { if (m_value < rhs.m_value) m_value += MOD; m_value -= rhs.m_value; return *this; } constexpr mod_int operator*=(const mod_int rhs) noexcept { m_value = m_value * rhs.m_value % MOD; return *this; } constexpr mod_int operator/=(mod_int rhs) noexcept { uint_fast64_t exp = MOD - 2; while (exp > 0) { if (exp % 2 == 1) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; } mod_int inv() const noexcept { return mod_int(1) /= *this; } uint_fast64_t &value() { return m_value; } private: uint_fast64_t m_value; }; template <uint_fast64_t MOD> ostream &operator<<(ostream &os, const mod_int<MOD> &v) { return os << v.value(); } template <uint_fast64_t MOD> istream &operator>>(istream &is, mod_int<MOD> &v) { return is >> v.value(); } using ll = long long; const ll MOD = 1000000007; using md = mod_int<MOD>; // --------------------------------------------------------------------------- using point = complex<double>; int my_main(int argc, char **argv) { ios::sync_with_stdio(false); cin.tie(0); ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> v; repeat(i, n) { ll x, h; cin >> x >> h; h = (h % a == 0) ? h / a : (h / a + 1); v.emplace_back(x, h); } v.emplace_back(4000000010LL, 0); sort(all(v)); vector<ll> ps; for (auto p : v) ps.push_back(p.first); ll diff = 0; ll ret = 0; vector<ll> incs(v.size()); for (int i = 0; i < n; i++) { diff += incs[i]; v[i].second += diff; if (v[i].second > 0) { ll need = v[i].second; ret += need; diff -= need; int inc = upper_bound(all(ps), v[i].first + 2 * d) - ps.begin(); incs[inc] += need; } } cout << ret << endl; return 0; } // ---------------------------------------------------------------------------- // Test driver #ifdef DEBUG #define MAY_RUN_TESTCASE #endif #ifdef MAY_RUN_TESTCASE #include <fstream> #if __has_include(<unistd.h>) // Mac, Linux #include <unistd.h> #elif __has_include(<io.h>) // Windows #include <io.h> #else // Other? #error "unistd.h or io.h not found" #endif bool test_file_exists(const std::string &str) { std::ifstream fs(str); return fs.is_open(); } #endif int main(int argc, char **argv) { #ifndef MAY_RUN_TESTCASE return my_main(argc, argv); #else if (argc == 1) { return my_main(argc, argv); } else if (argc == 2) { char *stdin_file = argv[1]; freopen(stdin_file, "r", stdin); return my_main(argc, argv); } else if (argc == 5) { std::string stdin_file = argv[1]; std::string expected_file = argv[2]; std::string stdout_file = argv[3]; std::string stderr_file = argv[4]; if (!test_file_exists(stdin_file)) { std::cerr << stdin_file << " not found" << std::endl; return 3; } if (!test_file_exists(expected_file)) { std::cerr << expected_file << " not found" << std::endl; return 3; } int original_stdin = dup(fileno(stdin)); int original_stdout = dup(fileno(stdout)); int original_stderr = dup(fileno(stderr)); freopen(stdin_file.c_str(), "r", stdin); freopen(stdout_file.c_str(), "w", stdout); freopen(stderr_file.c_str(), "w", stderr); int ret = my_main(argc, argv); fflush(stdout); fflush(stderr); dup2(original_stderr, fileno(stderr)); dup2(original_stdout, fileno(stdout)); dup2(original_stdin, fileno(stdin)); if (ret != 0) { std::cerr << "main returns " << ret << std::endl; return ret; } std::ifstream inp(stdin_file); std::ifstream out(stdout_file); std::ifstream err(stderr_file); std::ifstream exp(expected_file); // Clear is needed if the file is empty. std::cout << "----- input -----" << std::endl; std::cout << inp.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl << std::endl; std::cout << "----- output ----" << std::endl; std::cout << out.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl << std::endl; std::cout << "---- expected ---" << std::endl; std::cout << exp.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl << std::endl; std::cout << "----- stderr ----" << std::endl; std::cout << err.rdbuf() << std::endl; std::cout.clear(); std::cout << "-----------------" << std::endl; inp.seekg(0); out.seekg(0); exp.seekg(0); err.seekg(0); std::string output_str, expected_str; { std::stringstream output_ss; output_ss << out.rdbuf(); output_str = output_ss.str(); std::stringstream expected_ss; expected_ss << exp.rdbuf(); expected_str = expected_ss.str(); } // Remove trailing spaces output_str.erase(output_str.find_last_not_of(" \n\r\t") + 1); expected_str.erase(expected_str.find_last_not_of(" \n\r\t") + 1); if (output_str == expected_str) return 0; else return 1; } return 1; #endif }
replace
159
160
159
160
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long struct node { int x, h; } t[100001]; bool cmp(node a, node b) { return a.x < b.x; } signed main() { int n, d, a; scanf("%lld%lld%lld", &n, &d, &a); for (int i = 1; i <= n; i++) scanf("%lld%lld", &t[i].x, &t[i].h); sort(t + 1, t + n + 1, cmp); long long add = 0, ans = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; for (int i = 1; i <= n; i++) { while (!q.empty() && t[i].x - q.top().first > 2 * d) { add -= 1ll * q.top().second * a; q.pop(); } int delta = t[i].h - add; if (delta > 0) { int tmp = (delta + a - 1) / a; ans += tmp; add += tmp * a; q.push(make_pair(t[i].x, tmp)); } } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long struct node { int x, h; } t[1000001]; bool cmp(node a, node b) { return a.x < b.x; } signed main() { int n, d, a; scanf("%lld%lld%lld", &n, &d, &a); for (int i = 1; i <= n; i++) scanf("%lld%lld", &t[i].x, &t[i].h); sort(t + 1, t + n + 1, cmp); long long add = 0, ans = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; for (int i = 1; i <= n; i++) { while (!q.empty() && t[i].x - q.top().first > 2 * d) { add -= 1ll * q.top().second * a; q.pop(); } int delta = t[i].h - add; if (delta > 0) { int tmp = (delta + a - 1) / a; ans += tmp; add += tmp * a; q.push(make_pair(t[i].x, tmp)); } } printf("%lld", ans); return 0; }
replace
5
6
5
6
0
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (long long(i) = 0; (i) < (n); ++(i)) #define ref(i, a, b) for (long long(i) = (a); (i) <= (b); ++(i)) #define endl '\n' #define st first #define nd second #define pb push_back #define mp make_pair const int mx = 1e6 + 5; long long c[mx]; long long n, d, a; int main() { ios_base::sync_with_stdio(false); cin.tie(0); /*freopen(".in", "r", stdin); freopen(".out", "w", stdout); */ cin >> n >> d >> a; vector<pair<long long, long long>> v; for (int i = 0; i < n; ++i) { ll x, y; cin >> x >> y; v.pb(mp(x, y)); } long long ans = 0; sort(v.begin(), v.end()); ll j = 0; for (ll i = 0; i < n; ++i) { j = 0; while (j < n and v[j].first <= v[i].first + 2 * d) ++j; ll need = max((v[i].second - c[i] * a + a - 1) / a, 0ll); ans += need; c[j] = c[j] - need; c[i] += need; c[i + 1] += c[i]; // cout << need <<" "<< i << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (long long(i) = 0; (i) < (n); ++(i)) #define ref(i, a, b) for (long long(i) = (a); (i) <= (b); ++(i)) #define endl '\n' #define st first #define nd second #define pb push_back #define mp make_pair const int mx = 1e6 + 5; long long c[mx]; long long n, d, a; int main() { ios_base::sync_with_stdio(false); cin.tie(0); /*freopen(".in", "r", stdin); freopen(".out", "w", stdout); */ cin >> n >> d >> a; vector<pair<long long, long long>> v; for (int i = 0; i < n; ++i) { ll x, y; cin >> x >> y; v.pb(mp(x, y)); } long long ans = 0; sort(v.begin(), v.end()); ll j = 0; for (ll i = 0; i < n; ++i) { // j=0; while (j < n and v[j].first <= v[i].first + 2 * d) ++j; ll need = max((v[i].second - c[i] * a + a - 1) / a, 0ll); ans += need; c[j] = c[j] - need; c[i] += need; c[i + 1] += c[i]; // cout << need <<" "<< i << endl; } cout << ans << endl; }
replace
30
31
30
31
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define loop(i, a, b) for (int i = (a); i < (b); i++) #define loopb(i, a, b) for (int i = (a); i > (b); --i) typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vl; const int mod = 1e9 + 7; const ll inf = 2e18 + 5; // RUNNING SUMS METHOD int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("fin.txt", "r", stdin); freopen("fout.txt", "w", stdout); #endif int n, d, a; cin >> n >> d >> a; vii monsters; loop(i, 0, n) { int x, h; cin >> x >> h; h = (h + a - 1) / a; // ceil(h/a) monsters.emplace_back(x, h); } assert((int)monsters.size() == n); sort(monsters.begin(), monsters.end()); ll running_sum = 0; vi change(n + 1, 0); ll ans = 0; loop(i, 0, n) { running_sum += change[i]; int x = monsters[i].second - running_sum; if (x <= 0) continue; ans += x; running_sum += x; int lo = i, hi = n - 1, ok; while (lo <= hi) { int mid = (lo + hi) / 2; if (monsters[mid].first <= monsters[i].first + 2LL * d) { ok = mid; lo = mid + 1; } else hi = mid - 1; } change[ok + 1] -= x; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define loop(i, a, b) for (int i = (a); i < (b); i++) #define loopb(i, a, b) for (int i = (a); i > (b); --i) typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vl; const int mod = 1e9 + 7; const ll inf = 2e18 + 5; // RUNNING SUMS METHOD int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, d, a; cin >> n >> d >> a; vii monsters; loop(i, 0, n) { int x, h; cin >> x >> h; h = (h + a - 1) / a; // ceil(h/a) monsters.emplace_back(x, h); } assert((int)monsters.size() == n); sort(monsters.begin(), monsters.end()); ll running_sum = 0; vi change(n + 1, 0); ll ans = 0; loop(i, 0, n) { running_sum += change[i]; int x = monsters[i].second - running_sum; if (x <= 0) continue; ans += x; running_sum += x; int lo = i, hi = n - 1, ok; while (lo <= hi) { int mid = (lo + hi) / 2; if (monsters[mid].first <= monsters[i].first + 2LL * d) { ok = mid; lo = mid + 1; } else hi = mid - 1; } change[ok + 1] -= x; } cout << ans; return 0; }
replace
23
27
23
24
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; ll d, a; cin >> n >> d >> a; vector<pair<ll, ll>> v(n); vector<ll> pos(n), bomb(n); for (int i = 0; i < n; ++i) { ll x, h; cin >> x >> h; v[i] = {x, h}; pos[i] = x; } sort(v.begin(), v.end()); sort(pos.begin(), pos.end()); ll b = (v[0].second % a) == 0 ? (v[0].second / a) : (v[0].second / a) + 1; int idx = upper_bound(pos.begin(), pos.end(), pos[0] + 2 * d) - pos.begin(); bomb[0] = b; bomb[idx] = -b; ll curbomb = a * b; for (int i = 1; i < n; ++i) { ll inx = pos[i], health = v[i].second; if (health > curbomb && bomb[i] == 0) { idx = upper_bound(pos.begin(), pos.end(), inx + 2 * d) - pos.begin(); b = ((health - curbomb) % a) == 0 ? ((health - curbomb) / a) : ((health - curbomb) / a) + 1; curbomb += (a * b); bomb[i] += b; bomb[idx] -= b; } else if (bomb[i] < 0) { ll heal = a * llabs(bomb[i]); curbomb -= heal; bomb[i] = 0; if (health > curbomb) { idx = upper_bound(pos.begin(), pos.end(), inx + 2 * d) - pos.begin(); b = ((health - curbomb) % a) == 0 ? ((health - curbomb) / a) : ((health - curbomb) / a) + 1; curbomb += (a * b); bomb[i] += b; bomb[idx] -= b; } } } for (int i = 1; i < n; ++i) bomb[i] += bomb[i - 1]; // for(auto i:bomb) // cout<<i<<" "; // cout<<endl; cout << *max_element(bomb.begin(), bomb.end()) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; ll d, a; cin >> n >> d >> a; vector<pair<ll, ll>> v(n); vector<ll> pos(n), bomb(n + 1, 0); for (int i = 0; i < n; ++i) { ll x, h; cin >> x >> h; v[i] = {x, h}; pos[i] = x; } sort(v.begin(), v.end()); sort(pos.begin(), pos.end()); ll b = (v[0].second % a) == 0 ? (v[0].second / a) : (v[0].second / a) + 1; int idx = upper_bound(pos.begin(), pos.end(), pos[0] + 2 * d) - pos.begin(); bomb[0] = b; bomb[idx] = -b; ll curbomb = a * b; for (int i = 1; i < n; ++i) { ll inx = pos[i], health = v[i].second; if (health > curbomb && bomb[i] == 0) { idx = upper_bound(pos.begin(), pos.end(), inx + 2 * d) - pos.begin(); b = ((health - curbomb) % a) == 0 ? ((health - curbomb) / a) : ((health - curbomb) / a) + 1; curbomb += (a * b); bomb[i] += b; bomb[idx] -= b; } else if (bomb[i] < 0) { ll heal = a * llabs(bomb[i]); curbomb -= heal; bomb[i] = 0; if (health > curbomb) { idx = upper_bound(pos.begin(), pos.end(), inx + 2 * d) - pos.begin(); b = ((health - curbomb) % a) == 0 ? ((health - curbomb) / a) : ((health - curbomb) / a) + 1; curbomb += (a * b); bomb[i] += b; bomb[idx] -= b; } } } for (int i = 1; i < n; ++i) bomb[i] += bomb[i - 1]; // for(auto i:bomb) // cout<<i<<" "; // cout<<endl; cout << *max_element(bomb.begin(), bomb.end()) << endl; return 0; }
replace
8
9
8
9
0
p02788
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define pie 3.141592653589793238462643383279 #define mod 1000000007 #define INF 1145141919364364 #define int long long #define all(vec) vec.begin(), vec.end() #define P pair<int, int> #define S second #define F first int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } bool prime(int x) { for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x) return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int n, d, a; P p[200000]; int ans; int cnt; queue<P> que; signed main() { cin >> n >> d >> a; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; p[i].second = (p[i].second - 1) / a + 1; } sort(p, p + n); for (int i = 0; i < n; i++) { if (que.size()) { while (1) { P x = que.front(); if (x.first < p[i].first) { cnt -= x.second; que.pop(); } else break; } } if (cnt < p[i].second) { ans += p[i].second - cnt; que.push({p[i].first + d * 2, p[i].second - cnt}); cnt += p[i].second - cnt; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define pie 3.141592653589793238462643383279 #define mod 1000000007 #define INF 1145141919364364 #define int long long #define all(vec) vec.begin(), vec.end() #define P pair<int, int> #define S second #define F first int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } bool prime(int x) { for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x) return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int n, d, a; P p[200000]; int ans; int cnt; queue<P> que; signed main() { cin >> n >> d >> a; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; p[i].second = (p[i].second - 1) / a + 1; } sort(p, p + n); for (int i = 0; i < n; i++) { while (que.size()) { P x = que.front(); if (x.first < p[i].first) { cnt -= x.second; que.pop(); } else break; } if (cnt < p[i].second) { ans += p[i].second - cnt; que.push({p[i].first + d * 2, p[i].second - cnt}); cnt += p[i].second - cnt; } } cout << ans << endl; }
replace
75
84
75
82
0
p02788
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define time_assert(x) \ if (!(x)) \ while (true) int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, d, a; cin >> n >> d >> a; vector<pair<int, int>> monsters; for (int i = 0; i < n; i++) { int x, h; cin >> x >> h; h = (h + a - 1) / a; monsters.emplace_back(x, h); } sort(monsters.begin(), monsters.end()); time_assert((int)monsters.size() == n); int base = 1; while (base < n) { base *= 2; } vector<long long> tree(2 * base); for (int i = 0; i < n; i++) { tree[base + i] = monsters[i].second; } auto get_health = [&](int i) { int total = 0; for (int j = base + i; j >= 1; j /= 2) { total += tree[j]; } return total; }; auto add_interval = [&](int L, int R, int x) { L += base; R += base; tree[L] += x; if (L != R) { tree[R] += x; } while (L + 1 < R) { if (L % 2 == 0) { tree[L + 1] += x; } if (R % 2 == 1) { tree[R - 1] += x; } L /= 2; R /= 2; } }; long long answer = 0; for (int i = 0; i < n; i++) { int my_health = get_health(i); if (my_health <= 0) { // already killed continue; } // find the last monster still hit by a bomb starting here int low = i, high = n - 1; int ok = -1; while (low <= high) { int mid = (low + high) / 2; if (monsters[mid].first <= monsters[i].first + 2 * d) { ok = mid; low = mid + 1; } else { high = mid - 1; } } time_assert(ok != -1); add_interval(i, ok, -my_health); answer += my_health; } cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; #define time_assert(x) \ if (!(x)) \ while (true) int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, d, a; cin >> n >> d >> a; vector<pair<int, int>> monsters; for (int i = 0; i < n; i++) { int x, h; cin >> x >> h; h = (h + a - 1) / a; monsters.emplace_back(x, h); } sort(monsters.begin(), monsters.end()); time_assert((int)monsters.size() == n); int base = 1; while (base < n) { base *= 2; } vector<long long> tree(2 * base); for (int i = 0; i < n; i++) { tree[base + i] = monsters[i].second; } auto get_health = [&](int i) { int total = 0; for (int j = base + i; j >= 1; j /= 2) { total += tree[j]; } return total; }; auto add_interval = [&](int L, int R, int x) { L += base; R += base; tree[L] += x; if (L != R) { tree[R] += x; } while (L + 1 < R) { if (L % 2 == 0) { tree[L + 1] += x; } if (R % 2 == 1) { tree[R - 1] += x; } L /= 2; R /= 2; } }; long long answer = 0; for (int i = 0; i < n; i++) { int my_health = get_health(i); if (my_health <= 0) { // already killed continue; } // find the last monster still hit by a bomb starting here int low = i, high = n - 1; int ok = -1; while (low <= high) { int mid = (low + high) / 2; if (monsters[mid].first <= monsters[i].first + 2LL * d) { ok = mid; low = mid + 1; } else { high = mid - 1; } } time_assert(ok != -1); add_interval(i, ok, -my_health); answer += my_health; } cout << answer << endl; }
replace
67
68
67
68
TLE
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, d, a; cin >> n >> d >> a; vector<pair<int, int>> monsters; for (int i = 0; i < n; ++i) { int x, h; cin >> x >> h; h = (h + a - 1) / a; // number of bombs to drop on monster i to kill it monsters.emplace_back(x, h); } sort(monsters.begin(), monsters.end()); int base = 1; // n = 5 while (base < n) // base = 8 base *= 2; vector<int> tree(2 * base, 0); for (int i = 0; i < n; ++i) tree[base + i] = monsters[i].second; auto getval = [&](int i) { int sum = 0; for (int j = base + i; j >= 1; j /= 2) { sum += tree[j]; } return sum; }; auto addInterval = [&](int l, int r, int val) { l += base; r += base; tree[l] += val; if (l != r) tree[r] += val; while (l + 1 < r) { if (l % 2 == 0) tree[l + 1] += val; if (r % 2) tree[r - 1] += val; l /= 2; r /= 2; } }; long long ans = 0; for (int i = 0; i < n; ++i) { int health = getval(i); if (health <= 0) continue; // binary search for the monsters that will be affected by the diameter of // detonation of bomb int l = i; int r = n - 1; int ok = -1; while (l <= r) { int mid = l + ((r - l) >> 1); if (monsters[mid].first <= monsters[i].first + 2 * d) { ok = mid; l = mid + 1; } else { r = mid - 1; } } assert(ok != -1); addInterval(i, ok, -health); ans += health; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, d, a; cin >> n >> d >> a; vector<pair<int, int>> monsters; for (int i = 0; i < n; ++i) { int x, h; cin >> x >> h; h = (h + a - 1) / a; // number of bombs to drop on monster i to kill it monsters.emplace_back(x, h); } sort(monsters.begin(), monsters.end()); int base = 1; // n = 5 while (base < n) // base = 8 base *= 2; vector<int> tree(2 * base, 0); for (int i = 0; i < n; ++i) tree[base + i] = monsters[i].second; auto getval = [&](int i) { int sum = 0; for (int j = base + i; j >= 1; j /= 2) { sum += tree[j]; } return sum; }; auto addInterval = [&](int l, int r, int val) { l += base; r += base; tree[l] += val; if (l != r) tree[r] += val; while (l + 1 < r) { if (l % 2 == 0) tree[l + 1] += val; if (r % 2) tree[r - 1] += val; l /= 2; r /= 2; } }; long long ans = 0; for (int i = 0; i < n; ++i) { int health = getval(i); if (health <= 0) continue; // binary search for the monsters that will be affected by the diameter of // detonation of bomb int l = i; int r = n - 1; int ok = -1; while (l <= r) { int mid = l + ((r - l) >> 1); if (monsters[mid].first <= (long long)monsters[i].first + 2 * d) { ok = mid; l = mid + 1; } else { r = mid - 1; } } assert(ok != -1); addInterval(i, ok, -health); ans += health; } cout << ans << "\n"; return 0; }
replace
60
61
60
61
0
p02788
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> using ll = long long; using namespace std; template <class Abel> struct BIT { vector<Abel> dat[2]; Abel UNITY_SUM = 0; // to be set /* [1, n] */ BIT(int n) { init(n); } void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); } /* a, b are 1-indexed, [a, b) */ inline void sub_add(int p, int a, Abel x) { for (int i = a; i < (int)dat[p].size(); i += i & -i) dat[p][i] = dat[p][i] + x; } inline void add(int a, int b, Abel x) { sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1)); } /* a is 1-indexed, [a, b) */ inline Abel sub_sum(int p, int a) { Abel res = UNITY_SUM; for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i]; return res; } inline Abel sum(int a, int b) { return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1); } /* debug */ void print() { for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; int main() { int N, D, A; cin >> N >> D >> A; vector<pair<int, int>> map; int a, b; for (int i = 0; i < N; i++) { cin >> a >> b; map.push_back({a, b}); } map.push_back({1000000001, 0}); sort(map.begin(), map.end()); BIT<int> bit(N + 3); for (int i = 0; i < N; i++) { bit.add(i + 1, i + 2, map[i].second); } ll ans = 0; int ed = 0; for (int i = 0; i < N; i++) { if (bit.sum(i + 1, i + 2) > 0) { int range = map[i].first + 2 * D; int numBom = (bit.sum(i + 1, i + 2) + A - 1) / A; ans += numBom; int damage = numBom * A; while (map[ed].first <= range) { ed++; } bit.add(i + 1, ed + 1, -damage); } // cout<<ans<<endl; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <utility> #include <vector> using ll = long long; using namespace std; template <class Abel> struct BIT { vector<Abel> dat[2]; Abel UNITY_SUM = 0; // to be set /* [1, n] */ BIT(int n) { init(n); } void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); } /* a, b are 1-indexed, [a, b) */ inline void sub_add(int p, int a, Abel x) { for (int i = a; i < (int)dat[p].size(); i += i & -i) dat[p][i] = dat[p][i] + x; } inline void add(int a, int b, Abel x) { sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1)); } /* a is 1-indexed, [a, b) */ inline Abel sub_sum(int p, int a) { Abel res = UNITY_SUM; for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i]; return res; } inline Abel sum(int a, int b) { return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1); } /* debug */ void print() { for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ","; cout << endl; } }; int main() { int N, D, A; cin >> N >> D >> A; vector<pair<int, int>> map; int a, b; for (int i = 0; i < N; i++) { cin >> a >> b; map.push_back({a, b}); } map.push_back({1000000001, 0}); sort(map.begin(), map.end()); BIT<int> bit(N + 3); for (int i = 0; i < N; i++) { bit.add(i + 1, i + 2, map[i].second); } ll ans = 0; int ed = 0; for (int i = 0; i < N; i++) { if (bit.sum(i + 1, i + 2) > 0) { int range = map[i].first + 2 * D; int numBom = (bit.sum(i + 1, i + 2) + A - 1) / A; ans += numBom; int damage = numBom * A; while (ed < N && map[ed].first <= range) { ed++; } bit.add(i + 1, ed + 1, -damage); } // cout<<ans<<endl; } cout << ans << endl; return 0; }
replace
78
79
78
79
0
p02788
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3fLL // #define MOD 998244353 #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pint; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pint> vpint; int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1}; const int SIZE = 100050; // ↑templete #define int long long // ↓区間和を求めるSegmentTree struct SegmentTreeSum { private: int n; vector<int> node; public: // 元配列 v をセグメント木で表現する SegmentTreeSum(vector<int> v) { // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく // セグメント木全体で必要なノード数は 2n-1 個である int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, 0); // 最下段に値を入れたあとに、下の段から順番に値を入れる // 値を入れるには、自分の子の 2 値を参照すれば良い for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = (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] = (node[2 * x + 1] + node[2 * x + 2]); } } int getsum(int a, int b, int k = 0, int l = 0, int r = -1) { // 最初に呼び出されたときの対象区間は [0, n) if (r < 0) r = n; // 要求区間と対象区間が交わらない -> 適当に返す if (r <= a || b <= l) return 0; // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う if (a <= l && r <= b) return node[k]; // 要求区間が対象区間の一部を被覆 -> 子について探索を行う // 左側の子を vl ・ 右側の子を vr としている // 新しい対象区間は、現在の対象区間を半分に割ったもの int vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); int vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return (vl + vr); } }; // ↑区間和を求めるSegmentTree signed main() { ll N, D, A; cin >> N >> D >> A; vector<pll> monsters; vll X; for (int i = 0; i < N; i++) { ll x, h; cin >> x >> h; monsters.eb(x, h); X.pb(x); } sort(monsters.begin(), monsters.end()); sort(X.begin(), X.end()); vll ini(SIZE); SegmentTreeSum dam(ini); ll ans = 0; for (int i = 0; i < N; i++) { int x, h; tie(x, h) = monsters[i]; // 現在のモンスタiの体力 ll hp = h - dam.getsum(0, i + 1); // cout<<"!"<<i<<" "<<hp<<endl; if (hp <= 0) continue; // 叩く回数 ll attack = (hp + A - 1) / A; ans += attack; // どこまで届くか? ll right = (upper_bound(X.begin(), X.end(), ll(x + 2 * D)) - X.begin()); // cout<<"right : "<<right<<endl; // //叩く dam.update(i, dam.getsum(i, i + 1) + A * attack); dam.update(right, dam.getsum(right, right + 1) - A * attack); // cout<<"damage"<<endl; // for(int j=0;j<=N;j++) // cout<<dam.getsum(j, j+1)<<" "; // cout<<endl; } cout << ans << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3fLL // #define MOD 998244353 #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pint; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pint> vpint; int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1}; const int SIZE = 200050; // ↑templete #define int long long // ↓区間和を求めるSegmentTree struct SegmentTreeSum { private: int n; vector<int> node; public: // 元配列 v をセグメント木で表現する SegmentTreeSum(vector<int> v) { // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく // セグメント木全体で必要なノード数は 2n-1 個である int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1, 0); // 最下段に値を入れたあとに、下の段から順番に値を入れる // 値を入れるには、自分の子の 2 値を参照すれば良い for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = (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] = (node[2 * x + 1] + node[2 * x + 2]); } } int getsum(int a, int b, int k = 0, int l = 0, int r = -1) { // 最初に呼び出されたときの対象区間は [0, n) if (r < 0) r = n; // 要求区間と対象区間が交わらない -> 適当に返す if (r <= a || b <= l) return 0; // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う if (a <= l && r <= b) return node[k]; // 要求区間が対象区間の一部を被覆 -> 子について探索を行う // 左側の子を vl ・ 右側の子を vr としている // 新しい対象区間は、現在の対象区間を半分に割ったもの int vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); int vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return (vl + vr); } }; // ↑区間和を求めるSegmentTree signed main() { ll N, D, A; cin >> N >> D >> A; vector<pll> monsters; vll X; for (int i = 0; i < N; i++) { ll x, h; cin >> x >> h; monsters.eb(x, h); X.pb(x); } sort(monsters.begin(), monsters.end()); sort(X.begin(), X.end()); vll ini(SIZE); SegmentTreeSum dam(ini); ll ans = 0; for (int i = 0; i < N; i++) { int x, h; tie(x, h) = monsters[i]; // 現在のモンスタiの体力 ll hp = h - dam.getsum(0, i + 1); // cout<<"!"<<i<<" "<<hp<<endl; if (hp <= 0) continue; // 叩く回数 ll attack = (hp + A - 1) / A; ans += attack; // どこまで届くか? ll right = (upper_bound(X.begin(), X.end(), ll(x + 2 * D)) - X.begin()); // cout<<"right : "<<right<<endl; // //叩く dam.update(i, dam.getsum(i, i + 1) + A * attack); dam.update(right, dam.getsum(right, right + 1) - A * attack); // cout<<"damage"<<endl; // for(int j=0;j<=N;j++) // cout<<dam.getsum(j, j+1)<<" "; // cout<<endl; } cout << ans << endl; return 0; }
replace
45
46
45
46
0
p02788
Python
Runtime Error
from bisect import bisect_right n, d, a = map(int, input().split()) xh = sorted(list(map(int, input().split())) for _ in range(n)) x = [0] * (n + 1) h = [0] * (n + 1) s = [0] * (n + 1) for i, (f, g) in enumerate(xh): x[i], h[i] = f, g x[n] = 10**9 + 1 ans = 0 for i in range(n): if i > 0: s[i] += s[i - 1] h[i] -= s[i] if h[i] > 0: num = 0 - -h[i] // a ans += num s[i] += num * a j = bisect_right(x, x[i] + d * 2) s[j] -= num * a print(ans)
from bisect import bisect_right n, d, a = map(int, input().split()) xh = sorted(list(map(int, input().split())) for _ in range(n)) x = [0] * (n + 1) h = [0] * (n + 1) s = [0] * (n + 1) for i, (f, g) in enumerate(xh): x[i], h[i] = f, g x[n] = 10**10 + 1 ans = 0 for i in range(n): if i > 0: s[i] += s[i - 1] h[i] -= s[i] if h[i] > 0: num = 0 - -h[i] // a ans += num s[i] += num * a j = bisect_right(x, x[i] + d * 2) s[j] -= num * a print(ans)
replace
10
11
10
11
0
p02788
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long int sum[200005]; int main() { long long int n, d, a; cin >> n >> d >> a; pair<int, long long int> p[n]; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; p[i].second = (p[i].second + a - 1) / a; } sort(p, p + n); int r[n]; int tmp = n - 1; for (int i = n - 1; i > 0; i--) { while (p[tmp].first + 2 * d >= p[i].first && tmp >= 0) tmp--; r[i] = tmp + 1; } long long int ans = 0; for (int i = 0; i < n; i++) { p[i].second -= (sum[i] - sum[r[i]]); sum[i + 1] = sum[i] + max(0LL, p[i].second); ans += max(0LL, p[i].second); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long int sum[200005]; int main() { long long int n, d, a; cin >> n >> d >> a; pair<int, long long int> p[n]; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; p[i].second = (p[i].second + a - 1) / a; } sort(p, p + n); int r[n]; int tmp = n - 1; for (int i = n - 1; i >= 0; i--) { while (p[tmp].first + 2 * d >= p[i].first && tmp >= 0) tmp--; r[i] = tmp + 1; } long long int ans = 0; for (int i = 0; i < n; i++) { p[i].second -= (sum[i] - sum[r[i]]); sum[i + 1] = sum[i] + max(0LL, p[i].second); ans += max(0LL, p[i].second); } cout << ans << endl; }
replace
14
15
14
15
-11
p02788
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; struct point { long long x, h; } p[1000000001]; bool cmp(point const &p1, point const &p2) { return p1.x < p2.x; } int main() { // 读入数据 long long N, D, A; scanf("%lld%lld%lld", &N, &D, &A); D <<= 1; // 先将半个宽度乘2使之成为左右区间宽度 for (int i = 1; i <= N; i++) { scanf("%lld%lld", &p[i].x, &p[i].h); } sort(p + 1, p + N + 1, cmp); // 按坐标升序 long long tmp = 0; // 炸弹伤害 long long hurt[200001] = {0}; // 记录每个点的伤害 long long ans = 0; // 记录答案 for (int i = 1; i <= N; i++) // 循环处理每个Monster { p[i].h -= tmp; // 先减去上几次投弹的伤害 if (p[i].h > 0) // 第i个还没死,考虑继续炸 { long long n = (p[i].h + A - 1) / A; // 至少还需要炸的次数 long long h = n * A; // 本次投弹伤害 tmp += h; // 更新伤害 ans += n; // 更新答案 long long l = i, r = N + 1; // 二分查找,寻找轰炸点使得i恰好在爆炸范围的左端 while (l < r - 1) { long long mid = (l + r) >> 1; if (p[mid].x - D <= p[i].x) // 更新后能否炸到i l = mid; else r = mid; } hurt[l] += h; // 最终在l处投弹,记录该处伤害 } tmp -= hurt[i]; // 处理完第i个,轰炸区间向右移动,不再计算i点投弹所产生的伤害 } printf("%lld", ans); // 输出答案 return 0; }
#include <algorithm> #include <cstdio> using namespace std; struct point { long long x, h; } p[200001]; bool cmp(point const &p1, point const &p2) { return p1.x < p2.x; } int main() { // 读入数据 long long N, D, A; scanf("%lld%lld%lld", &N, &D, &A); D <<= 1; // 先将半个宽度乘2使之成为左右区间宽度 for (int i = 1; i <= N; i++) { scanf("%lld%lld", &p[i].x, &p[i].h); } sort(p + 1, p + N + 1, cmp); // 按坐标升序 long long tmp = 0; // 炸弹伤害 long long hurt[200001] = {0}; // 记录每个点的伤害 long long ans = 0; // 记录答案 for (int i = 1; i <= N; i++) // 循环处理每个Monster { p[i].h -= tmp; // 先减去上几次投弹的伤害 if (p[i].h > 0) // 第i个还没死,考虑继续炸 { long long n = (p[i].h + A - 1) / A; // 至少还需要炸的次数 long long h = n * A; // 本次投弹伤害 tmp += h; // 更新伤害 ans += n; // 更新答案 long long l = i, r = N + 1; // 二分查找,寻找轰炸点使得i恰好在爆炸范围的左端 while (l < r - 1) { long long mid = (l + r) >> 1; if (p[mid].x - D <= p[i].x) // 更新后能否炸到i l = mid; else r = mid; } hurt[l] += h; // 最终在l处投弹,记录该处伤害 } tmp -= hurt[i]; // 处理完第i个,轰炸区间向右移动,不再计算i点投弹所产生的伤害 } printf("%lld", ans); // 输出答案 return 0; }
replace
5
6
5
6
-11
p02788
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <forward_list> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i)) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1e18) + 1; int main(void) { int n, d, a; vector<P> monster; int x, h; int i, j; int target, targetx, targeth; int mid; ll count; ll ans = 0; vector<int> damage(100010, 0); cin >> n >> d >> a; monster.emplace_back(0, 0); rep(i, 1, n + 1) { cin >> x >> h; monster.emplace_back(x, h); } sort(monster.begin(), monster.end()); rep(i, 1, n + 1) { damage[i] += damage[i - 1]; if (damage[i] < monster[i].second) { target = i; } else { continue; } targetx = monster[target].first; targeth = monster[target].second - damage[target]; count = (targeth + a - 1) / a; ans += count; int ok = 0, ng = n + 1; while (ng - ok > 1) { mid = (ok + ng) / 2; if (monster[mid].first <= targetx + d * 2) { ok = mid; } else { ng = mid; } } damage[target] += count * a; damage[ok + 1] += -count * a; } cout << ans << endl; }
#include <algorithm> #include <cstdio> #include <cstring> #include <forward_list> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i)) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1e18) + 1; int main(void) { int n, d, a; vector<P> monster; int x, h; int i, j; int target, targetx, targeth; int mid; ll count; ll ans = 0; vector<int> damage(200010, 0); cin >> n >> d >> a; monster.emplace_back(0, 0); rep(i, 1, n + 1) { cin >> x >> h; monster.emplace_back(x, h); } sort(monster.begin(), monster.end()); rep(i, 1, n + 1) { damage[i] += damage[i - 1]; if (damage[i] < monster[i].second) { target = i; } else { continue; } targetx = monster[target].first; targeth = monster[target].second - damage[target]; count = (targeth + a - 1) / a; ans += count; int ok = 0, ng = n + 1; while (ng - ok > 1) { mid = (ok + ng) / 2; if (monster[mid].first <= targetx + d * 2) { ok = mid; } else { ng = mid; } } damage[target] += count * a; damage[ok + 1] += -count * a; } cout << ans << endl; }
replace
27
28
27
28
0
p02788
C++
Time Limit Exceeded
// -------------- // Tejas Pandey | // 26 - 01 - 20 | // ATCODER #153 | // -------------- #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define lim 100000000000000000 #define vi vector<int> typedef long long int ll; int main(void) { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { // cout << "Case #" << c-t << ": "; ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> nd(n); for (int i = 0; i < n; i++) cin >> nd[i].first >> nd[i].second; sort(nd.begin(), nd.end()); ll cur = 0, cnt = 0; queue<pair<ll, ll>> qt; for (int i = 0; i < n; i++) { while (!qt.empty() && qt.front().first < nd[i].first) cur -= qt.front().second, qt.pop(); ll ti = 0; while (cur < nd[i].second) cur += a, ti++; cnt += ti; qt.push({nd[i].first + d + d, ti * a}); } cout << cnt << "\n"; } return 0; }
// -------------- // Tejas Pandey | // 26 - 01 - 20 | // ATCODER #153 | // -------------- #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define lim 100000000000000000 #define vi vector<int> typedef long long int ll; int main(void) { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { // cout << "Case #" << c-t << ": "; ll n, d, a; cin >> n >> d >> a; vector<pair<ll, ll>> nd(n); for (int i = 0; i < n; i++) cin >> nd[i].first >> nd[i].second; sort(nd.begin(), nd.end()); ll cur = 0, cnt = 0; queue<pair<ll, ll>> qt; for (int i = 0; i < n; i++) { while (!qt.empty() && qt.front().first < nd[i].first) cur -= qt.front().second, qt.pop(); ll ti = 0; if (cur < nd[i].second) ti = (ll)ceil((nd[i].second - cur) / (a * 1.0)); cur += ti * a; cnt += ti; qt.push({nd[i].first + d + d, ti * a}); } cout << cnt << "\n"; } return 0; }
replace
35
37
35
38
TLE
p02788
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; #define ll long long #define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++) struct Monster { ll x, h; bool operator<(const Monster &other) const { return x < other.x; } }; #define MAX_X 1000000000LL #define INFTY 1e9 ll N, D, E; vector<Monster> M; // 1) // 0 1 2 3 4 5 6 7 8 9 // 2 4 2 // - - - o - - - // - - - o - - - // // 2) // 1 2 3 4 5 6 7 8 9 // 5 4 3 2 1 2 3 4 5 // - - - - o - - - - // - - - - o - - - - // - - - - o - - - - // - - - - o - - - - // - - - - o - - - - // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // 3 3 3 3 3 3 3 3 // - - o - - // - - o - - // - - o - - vector<ll> A, B; void init() { // Nを2の累乗に補正 ll n = 1; while (n < N) n *= 2; N = n; A = vector<ll>(N * 2 - 1, 0); B = vector<ll>(N * 2 - 1, 0); } void addRec(ll a, ll b, ll val, ll n, ll l, ll r) { // a l r b if (a <= l && r <= b) { A.at(n) += val; return; } // l a r b if (l < b && a < r) { B.at(n) += (min(b, r) - max(a, l)) * val; addRec(a, b, val, n * 2 + 1, l, (l + r) / 2); addRec(a, b, val, n * 2 + 2, (l + r) / 2, r); } } void add(ll a, ll b, ll val) { addRec(a, b, val, 0, 0, N); } ll findRec(ll x, ll y, ll n, ll l, ll r) { // i) l r x y // i) x y l r if (r <= x || y <= l) return 0; // iii) x l r y if (x <= l && r <= y) { return A.at(n) * (r - l) + B.at(n); } // iv) x l y r ll res = (min(y, r) - max(x, l)) * A.at(n); res += findRec(x, y, n * 2 + 1, l, (l + r) / 2); res += findRec(x, y, n * 2 + 2, (l + r) / 2, r); return res; } ll find(ll x, ll y) { return findRec(x, y, 0, 0, N); } void dumpRec(ll n, int depth) { if (n >= A.size()) return; for (int i = 0; i < depth; i++) cout << "\t"; cout << "(" << n << ", " << A.at(n) << ", " << B.at(n) << ")" << endl; dumpRec(n * 2 + 1, depth + 1); dumpRec(n * 2 + 2, depth + 1); } void dump() { cout << "====== dump =======" << endl; dumpRec(0, 0); } void input() { cin >> N >> D >> E; ll x, h; for (int i = 0; i < N; i++) { cin >> x >> h; M.push_back({x, h}); } } void solve() { init(); sort(M.begin(), M.end()); ll total = 0; // 10^5 for (ll i = 0; i < M.size(); i++) { auto &m = M.at(i); // log{10^5} ll h = m.h - find(i, i + 1); if (h <= 0) continue; ll count = ceil((double)h / E); total += count; ll max_x = min(m.x + 2 * D, MAX_X); ll max_j = i; while (max_j < M.size() && M.at(max_j).x <= max_x) max_j++; add(i, max_j, count * E); } cout << total << endl; } int main() { input(); solve(); return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; #define ll long long #define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++) struct Monster { ll x, h; bool operator<(const Monster &other) const { return x < other.x; } }; #define MAX_X 1000000000LL #define INFTY 1e9 ll N, D, E; vector<Monster> M; // 1) // 0 1 2 3 4 5 6 7 8 9 // 2 4 2 // - - - o - - - // - - - o - - - // // 2) // 1 2 3 4 5 6 7 8 9 // 5 4 3 2 1 2 3 4 5 // - - - - o - - - - // - - - - o - - - - // - - - - o - - - - // - - - - o - - - - // - - - - o - - - - // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // 3 3 3 3 3 3 3 3 // - - o - - // - - o - - // - - o - - vector<ll> A, B; void init() { // Nを2の累乗に補正 ll n = 1; while (n < N) n *= 2; N = n; A = vector<ll>(N * 2 - 1, 0); B = vector<ll>(N * 2 - 1, 0); } void addRec(ll a, ll b, ll val, ll n, ll l, ll r) { // a l r b if (a <= l && r <= b) { A.at(n) += val; return; } // l a r b if (l < b && a < r) { B.at(n) += (min(b, r) - max(a, l)) * val; addRec(a, b, val, n * 2 + 1, l, (l + r) / 2); addRec(a, b, val, n * 2 + 2, (l + r) / 2, r); } } void add(ll a, ll b, ll val) { addRec(a, b, val, 0, 0, N); } ll findRec(ll x, ll y, ll n, ll l, ll r) { // i) l r x y // i) x y l r if (r <= x || y <= l) return 0; // iii) x l r y if (x <= l && r <= y) { return A.at(n) * (r - l) + B.at(n); } // iv) x l y r ll res = (min(y, r) - max(x, l)) * A.at(n); res += findRec(x, y, n * 2 + 1, l, (l + r) / 2); res += findRec(x, y, n * 2 + 2, (l + r) / 2, r); return res; } ll find(ll x, ll y) { return findRec(x, y, 0, 0, N); } void dumpRec(ll n, int depth) { if (n >= A.size()) return; for (int i = 0; i < depth; i++) cout << "\t"; cout << "(" << n << ", " << A.at(n) << ", " << B.at(n) << ")" << endl; dumpRec(n * 2 + 1, depth + 1); dumpRec(n * 2 + 2, depth + 1); } void dump() { cout << "====== dump =======" << endl; dumpRec(0, 0); } void input() { cin >> N >> D >> E; ll x, h; for (int i = 0; i < N; i++) { cin >> x >> h; M.push_back({x, h}); } } void solve() { init(); sort(M.begin(), M.end()); ll total = 0; // 10^5 for (ll i = 0; i < M.size(); i++) { auto &m = M.at(i); // log{10^5} ll h = m.h - find(i, i + 1); if (h <= 0) continue; ll count = ceil((double)h / E); total += count; ll max_x = min(m.x + 2 * D, MAX_X); ll max_j = upper_bound(M.begin() + i, M.end(), (Monster){max_x, 0}) - M.begin(); add(i, max_j, count * E); } cout << total << endl; } int main() { input(); solve(); return 0; }
replace
126
129
126
128
TLE
p02789
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S, T, U; int A, B; cin >> A >> B; if (A % B == 0) S = "Yes"; else S = "No"; cout << S << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S, T, U; int A, B; cin >> A >> B; if (A - B == 0) S = "Yes"; else S = "No"; cout << S << endl; }
replace
6
7
6
7
0
p02789
Python
Runtime Error
n, m = map(int, input().split()) if n / m == 1: print("Yes") else: print("No")
n, m = map(int, input().split()) if n == m: print("Yes") else: print("No")
replace
2
3
2
3
0
p02789
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; ll mod = 1000000007; template <class Type> Type modpow(Type a, Type n, Type mod) { Type res = 1; while (0 < n) { if (n & 1) { res = res * a % mod; } a = a * a % mod; n >>= 1; } return res; } template <class Type> Type gcd(Type x, Type y) { Type r; if (x < y) swap(x, y); while (0 < y) { r = x % y; x = y; y = r; } return x; } template <class Type> Type lcm(Type x, Type y) { return x * y / gcd(x, y); } template <class Type> bool is_prime(Type x) { if (x == 2) return true; if (x < 2 || x % 2 == 0) return false; for (Type i = 3; i <= sqrt(x); i += 2) { if (x % i == 0) return false; } return true; } template <class Type> vector<bool> eratos(Type n) { vector<bool> isPrime(n + 1, true); isPrime[0] = isPrime[1] = false; for (Type i = 2; i <= n; i++) { if (isPrime[i]) { Type j = i + i; while (j <= n) { isPrime[j] = false; j = j + i; } } } return isPrime; } bool binary_search_judge(vector<int> a, int index, int key) { if (key <= a[index]) return true; else return false; } int binary_search(vector<int> a, int key) { int ng = -1; int ok = a.size(); while (1 < abs(ng - ok)) { int mid = (ng + ok) / 2; if (binary_search_judge(a, mid, key)) ok = mid; else ng = mid; } return a[ok] == key; } int main() { while (true) { } }
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; ll mod = 1000000007; template <class Type> Type modpow(Type a, Type n, Type mod) { Type res = 1; while (0 < n) { if (n & 1) { res = res * a % mod; } a = a * a % mod; n >>= 1; } return res; } template <class Type> Type gcd(Type x, Type y) { Type r; if (x < y) swap(x, y); while (0 < y) { r = x % y; x = y; y = r; } return x; } template <class Type> Type lcm(Type x, Type y) { return x * y / gcd(x, y); } template <class Type> bool is_prime(Type x) { if (x == 2) return true; if (x < 2 || x % 2 == 0) return false; for (Type i = 3; i <= sqrt(x); i += 2) { if (x % i == 0) return false; } return true; } template <class Type> vector<bool> eratos(Type n) { vector<bool> isPrime(n + 1, true); isPrime[0] = isPrime[1] = false; for (Type i = 2; i <= n; i++) { if (isPrime[i]) { Type j = i + i; while (j <= n) { isPrime[j] = false; j = j + i; } } } return isPrime; } bool binary_search_judge(vector<int> a, int index, int key) { if (key <= a[index]) return true; else return false; } int binary_search(vector<int> a, int key) { int ng = -1; int ok = a.size(); while (1 < abs(ng - ok)) { int mid = (ng + ok) / 2; if (binary_search_judge(a, mid, key)) ok = mid; else ng = mid; } return a[ok] == key; } int main() { int n, m; cin >> n >> m; if (n == m) cout << "Yes" << endl; else cout << "No" << endl; }
replace
92
94
92
98
TLE
p02789
C++
Runtime Error
#pragma GCC optimize( \ "Ofast") // Comment optimisations for an interative problem/use endl #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<pll> vpll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef unordered_map<ll, ll> um; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(10); #define sqr(x) ((ll)(x) * (x)) #define reset(a, b) memset(a, b, sizeof(a)) #define f first #define s second #define mp make_pair #define pb push_back #define all(v) v.begin(), v.end() #define alla(arr, sz) arr, arr + sz #define showv(v) \ for (auto it : (v)) \ cout << it << " "; \ newl; #define newl cout << "\n" const ll MAXN = 1e+2 + 7; const ll MOD = 1e+9 + 7, INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; double EPS = 1e-9; double PI = acos(-1); vll adj[MAXN]; ll visit[MAXN] = {}; int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; //<<-----Declare Variable Here------->>// ll t, n; ll i, j; //<<-----Implement Functions Here---->>// //<<-----Start of Main--------------->>// int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE fastio; cin >> n >> t; if (n == t) cout << "Yes"; else cout << "No"; }
#pragma GCC optimize( \ "Ofast") // Comment optimisations for an interative problem/use endl #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<string, string> pss; typedef vector<pll> vpll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef unordered_map<ll, ll> um; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(10); #define sqr(x) ((ll)(x) * (x)) #define reset(a, b) memset(a, b, sizeof(a)) #define f first #define s second #define mp make_pair #define pb push_back #define all(v) v.begin(), v.end() #define alla(arr, sz) arr, arr + sz #define showv(v) \ for (auto it : (v)) \ cout << it << " "; \ newl; #define newl cout << "\n" const ll MAXN = 1e+2 + 7; const ll MOD = 1e+9 + 7, INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; double EPS = 1e-9; double PI = acos(-1); vll adj[MAXN]; ll visit[MAXN] = {}; int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; //<<-----Declare Variable Here------->>// ll t, n; ll i, j; //<<-----Implement Functions Here---->>// //<<-----Start of Main--------------->>// int main() { cin >> n >> t; if (n == t) cout << "Yes"; else cout << "No"; }
delete
57
63
57
57
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using namespace std; using P = pair<int, int>; int main() { int h, a; cin >> h >> a; if (h % a != 0) cout << h / a + 1 << endl; else if (h % a == 0) cout << h / a << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; using namespace std; using P = pair<int, int>; int main() { int n, m; cin >> n >> m; if (n == m) cout << "Yes" << endl; else cout << "No" << endl; }
replace
7
13
7
13
0
p02789
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iostream> #include <map> #include <set> #include <string> #include <vector> // author:Swastik Banerjee using namespace std; typedef long long ll; #define MOD 1000000007 int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE FILE *f1 = freopen("input.txt", "r", stdin); FILE *f2 = freopen("output.txt", "w", stdout); #endif ll a, b; cin >> a >> b; if (a == b) cout << "Yes\n"; else cout << "No\n"; }
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iostream> #include <map> #include <set> #include <string> #include <vector> // author:Swastik Banerjee using namespace std; typedef long long ll; #define MOD 1000000007 int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll a, b; cin >> a >> b; if (a == b) cout << "Yes\n"; else cout << "No\n"; }
delete
21
26
21
21
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long int ull; #define pb push_back #define For(ii, aa, bb) for (ll ii = aa; ii < bb; ii++) #define Rof(ii, aa, bb) for (ll ii = aa; ii >= bb; ii--) #define st first #define nd second #define MP make_pair #define MAX 1000000009 #define MOD 1000000007 #define all(v6) v6.begin(), v6.end() #define IT iterator #define ln "\n" #define F(ii) ((abs(ii) + ii) / 2) #define N 500005 using namespace std; ll n, x; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> x; cout << (n == x ? "Yes" : "No"); }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long int ull; #define pb push_back #define For(ii, aa, bb) for (ll ii = aa; ii < bb; ii++) #define Rof(ii, aa, bb) for (ll ii = aa; ii >= bb; ii--) #define st first #define nd second #define MP make_pair #define MAX 1000000009 #define MOD 1000000007 #define all(v6) v6.begin(), v6.end() #define IT iterator #define ln "\n" #define F(ii) ((abs(ii) + ii) / 2) #define N 500005 using namespace std; ll n, x; int main() { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> x; cout << (n == x ? "Yes" : "No"); }
replace
20
22
20
22
0
p02789
C++
Runtime Error
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; const int MAX_N = int(1e6) + 10; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; typedef long long int ll; typedef unsigned long long int llu; struct fenwick { int lim; long long int *tree; fenwick(int _lim) { lim = _lim; tree = new long long int[lim]; } void init() { for (int i = 0; i < lim; i++) { tree[i] = 0; } } void update(int x, long long int v) { while (x < lim) { tree[x] += v; x += x & (-x); } } long long int query(int x) { long long int ans = 0; while (x > 0) { ans += tree[x]; x -= x & (-x); } return ans; } int _query(int k) { int low = 1; int high = 500000; int ans = 0; int x = k; while (low <= high) { int mid = low + (high - low) / 2; if (query(mid) >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } }; /* struct z_function{ string &txt; int *z; z_function(string &_txt):txt(_txt){ z=new int[1+txt.length()]; } void cal(){ z[0]=0; int l=0; int r=0; for(int i=1;i<txt.length();i++){ // cout<<l<<" "<<r<<endl; if(i>r){ l=i; r=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } // cout<<r<<" "; z[i]=r-l; r=r-1; }else{ if(z[i-l]<r-i+1) z[i]=z[i-l]; else{ l=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } z[i]=r-l; r=r-1; } } } } }; struct palindromic_tree{ map<char,struct palindromic_tree*>m; int length; int end_indx; struct palindromic_tree* suffix; palindromic_tree(int _length,int _end_indx){ length=_length; end_indx=_end_indx; } }; class palindromic_string{ public: string &s; struct palindromic_tree* real_root; struct palindromic_tree* imaginary_root; struct palindromic_tree* curr; long long int *prefix; palindromic_string(string &_s):s(_s){ real_root=new palindromic_tree(0,-1); imaginary_root=new palindromic_tree(-1,-1); curr=real_root; real_root->suffix=imaginary_root;prefix=new long long int[1+s.length()]; imaginary_root->suffix=imaginary_root; } void add(char ch){ int indx=s.size(); struct palindromic_tree* temp=curr; s+=ch; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; if((temp->m).find(ch)!=(temp->m).end()){ curr=(temp->m)[ch]; return; }else{ curr=new palindromic_tree((temp->length)+2,indx); } (temp->m)[ch]=curr; if(curr->length==1){ curr->suffix=real_root; return; }else{ temp=temp->suffix; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; curr->suffix=(temp->m)[ch]; } } void cal(){ prefix[0]=0; long long int p=29LL; for(int i=0;i<s.length();i++){ prefix[i+1]=(prefix[i]+(p*s[i]))%MOD; p=(p*p)%MOD; } } }; struct prime_numbers{ int *seive; int len; prime_numbers(int _len){ len=_len; seive=new int[len+1]; } void init(){ seive[0]=1; seive[1]=1; } void cal(){ for(int i=2;i*i<=len;i++){ for(int j=i*i;j<=len;j+=i){ seive[j]=1; } } } }; */ ll mul(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll c = a * b; if (c >= MOD) c = c % MOD; while (c < 0) c += MOD; return c; } ll add(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll ans = (a + b); if (ans >= MOD) ans = ans % MOD; while (ans < 0) ans += MOD; return ans; } ll power(ll a, ll b, ll c) { ll ans = 1; while (b) { if (b & 1) { ans = mul(ans, a); } a = mul(a, a); b = b / 2; } return ans; } template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << "(" << P.first << ", " << P.second << ")"; return out; } template <class T> istream &operator>>(istream &in, vector<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const vector<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } template <class T> istream &operator>>(istream &in, deque<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const deque<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } mt19937 rnd(time(0)); struct sparse { int table[200005][25]; int n; sparse(int len1) : n(len1) {} void init(int *a) { for (int i = 1; i <= n; i++) { table[i][0] = a[i]; } // cout<<table[1][0]<<endl; for (int j = 1; j < 25; j++) { for (int i = 1; i <= n; i++) { if (i + (1 << j) - 1 <= n) { table[i][j] = __gcd(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]); } } } } int find(int *a, int start, int end) { int dis = end - start + 1; int g = 0; for (int j = 25; j >= 0; j--) { if (dis & (1 << j)) { // cout<<dis<<" "<<table[start][j]<<" "<<j<<endl; g = __gcd(g, table[start][j]); start = start + (1 << j); } } return g; } }; inline ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; } // vector<pair<int,int> >v[1000005]; // ll t[1000005];ll h[1000005]; ;;;;;;multiset<pair<ll,pair<int,pair<ll,ll> > > // >s;ll A,B;bool vis[1000005];ll dis[1000005];int // parent[1000005];vector<int>ans; ll c[1000005]; struct SOS { ll *dp; int limit; vector<int> &arr; SOS(int _limit, vector<int> &v) : arr(v) { limit = _limit; dp = new ll[(1 << limit) + 10]; } void init() { for (int i = 0; i < (1 << limit); i++) { dp[i] = 0; } for (int i = 0; i < arr.size(); i++) { dp[arr[i]]++; } } void build1() { for (int i = 0; i < limit; i++) { for (int j = 0; j < (1 << limit); j++) { if (j & (1 << i)) { dp[j] = add(dp[j], dp[j ^ (1 << i)]); } } } } void build2() { for (int i = 0; i < limit; i++) { for (int j = (1 << limit) - 1; j >= 0; j--) { if (j & (1 << i)) { dp[j ^ (1 << i)] = add(dp[j ^ (1 << i)], dp[j]); } } } } // } }; // string s; int find(int arr[], int x) { while (x != arr[x]) { x = arr[x]; } return x; } void connect(int x, int arr[], int size[], int comp[], int y) { int rootA = find(arr, x); int rootB = find(arr, y); if (rootA == rootB) return; if (size[rootA] < size[rootB]) { arr[rootA] = rootB; size[rootB] += size[rootA]; comp[rootB] = min(comp[rootA], comp[rootB]); } else { arr[rootB] = rootA; size[rootA] += size[rootB]; comp[rootA] = min(comp[rootA], comp[rootB]); } } struct lazylam { ll *tree; int n; lazylam(int size) : n(size) { tree = new ll[4 * n + 1]; } void init() { for (int i = 0; i <= 4 * n; i++) { tree[i] = 0; } } void update(int x, ll v) { upd(1, 1, n, x, v); } void upd(int nd, int st, int en, int x, ll v) { if (st == en) { tree[nd] += v; return; } int mid = (st + en) / 2; if (x <= mid) { upd(2 * nd, st, mid, x, v); } else { upd(2 * nd + 1, mid + 1, en, x, v); } tree[nd] = tree[2 * nd] + tree[2 * nd + 1]; } }; struct graph { vector<int> *v; int n; long long int *values; int *start; int *end; graph(int size) : n(size) { v = new vector<int>[n + 1]; values = new ll[n + 1]; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { cin >> values[i]; } } void dfs() { int gtime = 0; start = new int[n + 1]; end = new int[n + 1]; dfs_start_end(1, 0, gtime); } void dfs_start_end(int i, int p, int &gtime) { gtime++; start[i] = gtime; for (auto it : v[i]) { if (it != p) { dfs_start_end(it, i, gtime); } } end[i] = gtime; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("f.in", "r", stdin); #endif int n, m; cin >> n >> m; if (n == m) cout << "Yes\n"; else cout << "No\n"; }
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; const int MAX_N = int(1e6) + 10; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; typedef long long int ll; typedef unsigned long long int llu; struct fenwick { int lim; long long int *tree; fenwick(int _lim) { lim = _lim; tree = new long long int[lim]; } void init() { for (int i = 0; i < lim; i++) { tree[i] = 0; } } void update(int x, long long int v) { while (x < lim) { tree[x] += v; x += x & (-x); } } long long int query(int x) { long long int ans = 0; while (x > 0) { ans += tree[x]; x -= x & (-x); } return ans; } int _query(int k) { int low = 1; int high = 500000; int ans = 0; int x = k; while (low <= high) { int mid = low + (high - low) / 2; if (query(mid) >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } }; /* struct z_function{ string &txt; int *z; z_function(string &_txt):txt(_txt){ z=new int[1+txt.length()]; } void cal(){ z[0]=0; int l=0; int r=0; for(int i=1;i<txt.length();i++){ // cout<<l<<" "<<r<<endl; if(i>r){ l=i; r=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } // cout<<r<<" "; z[i]=r-l; r=r-1; }else{ if(z[i-l]<r-i+1) z[i]=z[i-l]; else{ l=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } z[i]=r-l; r=r-1; } } } } }; struct palindromic_tree{ map<char,struct palindromic_tree*>m; int length; int end_indx; struct palindromic_tree* suffix; palindromic_tree(int _length,int _end_indx){ length=_length; end_indx=_end_indx; } }; class palindromic_string{ public: string &s; struct palindromic_tree* real_root; struct palindromic_tree* imaginary_root; struct palindromic_tree* curr; long long int *prefix; palindromic_string(string &_s):s(_s){ real_root=new palindromic_tree(0,-1); imaginary_root=new palindromic_tree(-1,-1); curr=real_root; real_root->suffix=imaginary_root;prefix=new long long int[1+s.length()]; imaginary_root->suffix=imaginary_root; } void add(char ch){ int indx=s.size(); struct palindromic_tree* temp=curr; s+=ch; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; if((temp->m).find(ch)!=(temp->m).end()){ curr=(temp->m)[ch]; return; }else{ curr=new palindromic_tree((temp->length)+2,indx); } (temp->m)[ch]=curr; if(curr->length==1){ curr->suffix=real_root; return; }else{ temp=temp->suffix; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; curr->suffix=(temp->m)[ch]; } } void cal(){ prefix[0]=0; long long int p=29LL; for(int i=0;i<s.length();i++){ prefix[i+1]=(prefix[i]+(p*s[i]))%MOD; p=(p*p)%MOD; } } }; struct prime_numbers{ int *seive; int len; prime_numbers(int _len){ len=_len; seive=new int[len+1]; } void init(){ seive[0]=1; seive[1]=1; } void cal(){ for(int i=2;i*i<=len;i++){ for(int j=i*i;j<=len;j+=i){ seive[j]=1; } } } }; */ ll mul(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll c = a * b; if (c >= MOD) c = c % MOD; while (c < 0) c += MOD; return c; } ll add(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll ans = (a + b); if (ans >= MOD) ans = ans % MOD; while (ans < 0) ans += MOD; return ans; } ll power(ll a, ll b, ll c) { ll ans = 1; while (b) { if (b & 1) { ans = mul(ans, a); } a = mul(a, a); b = b / 2; } return ans; } template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << "(" << P.first << ", " << P.second << ")"; return out; } template <class T> istream &operator>>(istream &in, vector<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const vector<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } template <class T> istream &operator>>(istream &in, deque<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const deque<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } mt19937 rnd(time(0)); struct sparse { int table[200005][25]; int n; sparse(int len1) : n(len1) {} void init(int *a) { for (int i = 1; i <= n; i++) { table[i][0] = a[i]; } // cout<<table[1][0]<<endl; for (int j = 1; j < 25; j++) { for (int i = 1; i <= n; i++) { if (i + (1 << j) - 1 <= n) { table[i][j] = __gcd(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]); } } } } int find(int *a, int start, int end) { int dis = end - start + 1; int g = 0; for (int j = 25; j >= 0; j--) { if (dis & (1 << j)) { // cout<<dis<<" "<<table[start][j]<<" "<<j<<endl; g = __gcd(g, table[start][j]); start = start + (1 << j); } } return g; } }; inline ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; } // vector<pair<int,int> >v[1000005]; // ll t[1000005];ll h[1000005]; ;;;;;;multiset<pair<ll,pair<int,pair<ll,ll> > > // >s;ll A,B;bool vis[1000005];ll dis[1000005];int // parent[1000005];vector<int>ans; ll c[1000005]; struct SOS { ll *dp; int limit; vector<int> &arr; SOS(int _limit, vector<int> &v) : arr(v) { limit = _limit; dp = new ll[(1 << limit) + 10]; } void init() { for (int i = 0; i < (1 << limit); i++) { dp[i] = 0; } for (int i = 0; i < arr.size(); i++) { dp[arr[i]]++; } } void build1() { for (int i = 0; i < limit; i++) { for (int j = 0; j < (1 << limit); j++) { if (j & (1 << i)) { dp[j] = add(dp[j], dp[j ^ (1 << i)]); } } } } void build2() { for (int i = 0; i < limit; i++) { for (int j = (1 << limit) - 1; j >= 0; j--) { if (j & (1 << i)) { dp[j ^ (1 << i)] = add(dp[j ^ (1 << i)], dp[j]); } } } } // } }; // string s; int find(int arr[], int x) { while (x != arr[x]) { x = arr[x]; } return x; } void connect(int x, int arr[], int size[], int comp[], int y) { int rootA = find(arr, x); int rootB = find(arr, y); if (rootA == rootB) return; if (size[rootA] < size[rootB]) { arr[rootA] = rootB; size[rootB] += size[rootA]; comp[rootB] = min(comp[rootA], comp[rootB]); } else { arr[rootB] = rootA; size[rootA] += size[rootB]; comp[rootA] = min(comp[rootA], comp[rootB]); } } struct lazylam { ll *tree; int n; lazylam(int size) : n(size) { tree = new ll[4 * n + 1]; } void init() { for (int i = 0; i <= 4 * n; i++) { tree[i] = 0; } } void update(int x, ll v) { upd(1, 1, n, x, v); } void upd(int nd, int st, int en, int x, ll v) { if (st == en) { tree[nd] += v; return; } int mid = (st + en) / 2; if (x <= mid) { upd(2 * nd, st, mid, x, v); } else { upd(2 * nd + 1, mid + 1, en, x, v); } tree[nd] = tree[2 * nd] + tree[2 * nd + 1]; } }; struct graph { vector<int> *v; int n; long long int *values; int *start; int *end; graph(int size) : n(size) { v = new vector<int>[n + 1]; values = new ll[n + 1]; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { cin >> values[i]; } } void dfs() { int gtime = 0; start = new int[n + 1]; end = new int[n + 1]; dfs_start_end(1, 0, gtime); } void dfs_start_end(int i, int p, int &gtime) { gtime++; start[i] = gtime; for (auto it : v[i]) { if (it != p) { dfs_start_end(it, i, gtime); } } end[i] = gtime; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; if (n == m) cout << "Yes\n"; else cout << "No\n"; }
delete
431
435
431
431
0
p02789
C++
Runtime Error
#include <stdio.h> int main() { int n, m; scanf("%d%d", n, m); if (n == m) { printf("Yes"); } else { printf("No"); } }
#include <stdio.h> int main() { int n, m; scanf("%d%d", &n, &m); if (n == m) { printf("Yes"); } else { printf("No"); } }
replace
4
5
4
5
-11
p02789
C++
Runtime Error
/* Auther: Ganesh Bhandarkar # RUN # <<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>> */ #include <bits/stdc++.h> using namespace std; /* KEYWORDS */ #define FASTIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fi first #define se second #define pb push_back #define mk make_pair #define sq(a) (a) * (a) #define rep(i, a, b) for (int i = a; i < b; ++i) /*DATATYPES */ typedef double db; typedef long long ll; typedef vector<int> vi; typedef vector<char> vc; typedef vector<long long> vll; typedef pair<int, int> pi; typedef pair<int, char> pic; typedef pair<char, char> pc; typedef pair<char, int> pci; /*Constants */ const ll mod = 10000000007; /* Booleans */ // bool OE(int n) if(n & 1){ return true; } else false; int main() { // #ifndef OJ // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif #ifndef OJ freopen("C:/Users/KIIT/CP/input.txt", "r", stdin); freopen("C:/Users/KIIT/CP/output.txt", "w", stdout); #endif FASTIO int n, m; cin >> n >> m; if (n > m) { cout << "No"; } else if (n == m) { cout << "Yes"; } return 0; }
/* Auther: Ganesh Bhandarkar # RUN # <<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>> */ #include <bits/stdc++.h> using namespace std; /* KEYWORDS */ #define FASTIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fi first #define se second #define pb push_back #define mk make_pair #define sq(a) (a) * (a) #define rep(i, a, b) for (int i = a; i < b; ++i) /*DATATYPES */ typedef double db; typedef long long ll; typedef vector<int> vi; typedef vector<char> vc; typedef vector<long long> vll; typedef pair<int, int> pi; typedef pair<int, char> pic; typedef pair<char, char> pc; typedef pair<char, int> pci; /*Constants */ const ll mod = 10000000007; /* Booleans */ // bool OE(int n) if(n & 1){ return true; } else false; int main() { // #ifndef OJ // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif FASTIO int n, m; cin >> n >> m; if (n > m) { cout << "No"; } else if (n == m) { cout << "Yes"; } return 0; }
delete
46
51
46
46
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { //* int a, b; cin >> a >> b; //*/ /* vector<int> vec(3); cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ; sort(vec.begin(), vec.end()); //*/ //* if (a == b) { cout << "Yes" << endl; } else { cout << "No" << endl; } //*/ cout << a / b + min(a % b, 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { //* int a, b; cin >> a >> b; //*/ /* vector<int> vec(3); cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ; sort(vec.begin(), vec.end()); //*/ //* if (a == b) { cout << "Yes" << endl; } else { cout << "No" << endl; } //*/ // cout << a / b + min(a % b, 1) << endl; return 0; }
replace
24
25
24
25
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define itn int #define vi vector<int> #define pb push_back #define srt sort(v.begin(), v.end()) // int infiint = std::numeric_limits<int>::max(); // float infiflt = std::numeric_limits<float>::infinity(); void solve() { int n, m; cin >> n >> m; if (n <= m) { cout << "Yes"; } else cout << "No"; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); freopen("input.txt", "rt", stdin); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define itn int #define vi vector<int> #define pb push_back #define srt sort(v.begin(), v.end()) // int infiint = std::numeric_limits<int>::max(); // float infiflt = std::numeric_limits<float>::infinity(); void solve() { int n, m; cin >> n >> m; if (n <= m) { cout << "Yes"; } else cout << "No"; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "rt", stdin); solve(); return 0; }
replace
23
24
23
24
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long void IO() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif std::ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() { int n, m; cin >> n >> m; if (m >= n) { cout << "Yes\n"; } else { cout << "No\n"; } } int main() { IO(); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long void IO() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif std::ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() { int n, m; cin >> n >> m; if (m >= n) { cout << "Yes\n"; } else { cout << "No\n"; } } int main() { // IO(); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
23
24
23
24
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; const ll INF = 1e18; 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 int n, m; cin >> n >> m; if (n == m) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; const ll INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll int n, m; cin >> n >> m; if (n == m) cout << "Yes" << endl; else cout << "No" << endl; }
replace
10
14
10
11
0
p02789
C++
Runtime Error
// HYSO SERIOUS? WHY SO SERIOUS RIOUS? WHY //SO SERIOUS? WHYSO SERIO ERIOUS? WHY SO SERIOUS ? WHY WHY SO SERIOUS? WHY //SOSERIOUSWHYS OSERIOUS? WHY SO SERIOU SERIOUS ERIOUS? WHY SO //SERIOUS? WHYS WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY //SO SE ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO WHY //SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH SERIOUS?WHYSO //SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE ?WHYSOSERIOUS?WHY SO //SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS? OSERIOUS? WHY SO SERIOUS?WHYSOSER // HYSOSERIOUS?WHYSOSERI // SOSERIOUS?W // SER // W #include <iostream> using namespace std; #include <algorithm> #include <bits/stdc++.h> #define ll long long int #define read(a) \ long long int a; \ cin >> a; #define readstr(s) \ string s; \ cin >> s; #define readarr(a, l) \ long long int a[l] = {0}; \ for (ll i = 0; i < l; i++) \ cin >> a[i]; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (ll i = a; i > b; i--) #define ff first #define ss second #define readmtrx(i, j, a, b) \ ll arr[a][b] = {0}; \ for (ll i = 0; i < a; i++) \ for (ll j = 0; j < b; j++) \ cin >> arr[i][j]; #define v(pi) vector<ll> pi #define vp(pi) vector<pair<ll, ll>> pi #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb(p) push_back(p) #define mp make_pair #include <cmath> #include <map> #define mi(lol) map<ll, ll> lol int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif read(a) read(b) if (a == b) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
// HYSO SERIOUS? WHY SO SERIOUS RIOUS? WHY //SO SERIOUS? WHYSO SERIO ERIOUS? WHY SO SERIOUS ? WHY WHY SO SERIOUS? WHY //SOSERIOUSWHYS OSERIOUS? WHY SO SERIOU SERIOUS ERIOUS? WHY SO //SERIOUS? WHYS WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY //SO SE ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO WHY //SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH SERIOUS?WHYSO //SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE ?WHYSOSERIOUS?WHY SO //SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS? OSERIOUS? WHY SO SERIOUS?WHYSOSER // HYSOSERIOUS?WHYSOSERI // SOSERIOUS?W // SER // W #include <iostream> using namespace std; #include <algorithm> #include <bits/stdc++.h> #define ll long long int #define read(a) \ long long int a; \ cin >> a; #define readstr(s) \ string s; \ cin >> s; #define readarr(a, l) \ long long int a[l] = {0}; \ for (ll i = 0; i < l; i++) \ cin >> a[i]; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (ll i = a; i > b; i--) #define ff first #define ss second #define readmtrx(i, j, a, b) \ ll arr[a][b] = {0}; \ for (ll i = 0; i < a; i++) \ for (ll j = 0; j < b; j++) \ cin >> arr[i][j]; #define v(pi) vector<ll> pi #define vp(pi) vector<pair<ll, ll>> pi #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb(p) push_back(p) #define mp make_pair #include <cmath> #include <map> #define mi(lol) map<ll, ll> lol int main() { fast; // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif read(a) read(b) if (a == b) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
replace
51
55
51
55
0
p02789
C++
Runtime Error
// Author :mdragneell #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ull unsigned long long #define ll long long #define ld long double #define pb push_back #define pi pair<int, int> #define pl pair<ll, ll> #define f first #define s second ll const N = 1e5 + 5; ll const mod = 1e9 + 7; ll min(ll x, ll y) { if (x < y) return x; else return y; } ll max(ll x, ll y) { if (x > y) return x; else return y; } ll gcd(ll x, ll y) { if (x == 0) return y; else return gcd(y % x, x); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; struct compare { bool operator()(const pair<ll, ll> &value, const ll &key) { return (value.first < key); } bool operator()(const ll &key, const pair<ll, ll> &value) { return (key < value.first); } }; bool compare1(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first < b.first) return true; else if (a.first == b.first) return (a.second > b.second); else return false; } ll powmod(ll x, ll y) { ll res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x) % mod; y >>= 1; if (y <= 0) break; x = (x * x) % mod; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll tt = 1; // cin>>tt; while (tt--) { ll n, m; cin >> n >> m; if (n == m) cout << "Yes" << endl; else cout << "No" << endl; } }
// Author :mdragneell #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ull unsigned long long #define ll long long #define ld long double #define pb push_back #define pi pair<int, int> #define pl pair<ll, ll> #define f first #define s second ll const N = 1e5 + 5; ll const mod = 1e9 + 7; ll min(ll x, ll y) { if (x < y) return x; else return y; } ll max(ll x, ll y) { if (x > y) return x; else return y; } ll gcd(ll x, ll y) { if (x == 0) return y; else return gcd(y % x, x); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; struct compare { bool operator()(const pair<ll, ll> &value, const ll &key) { return (value.first < key); } bool operator()(const ll &key, const pair<ll, ll> &value) { return (key < value.first); } }; bool compare1(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first < b.first) return true; else if (a.first == b.first) return (a.second > b.second); else return false; } ll powmod(ll x, ll y) { ll res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x) % mod; y >>= 1; if (y <= 0) break; x = (x * x) % mod; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ ll tt = 1; // cin>>tt; while (tt--) { ll n, m; cin >> n >> m; if (n == m) cout << "Yes" << endl; else cout << "No" << endl; } }
replace
89
93
89
93
0
p02789
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() #define endl "\n" #define deb(x) cout << #x << " : " << x << endl; template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << " "; return out; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &i : a) in >> i; return in; } signed 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 int n, m; cin >> n >> m; cout << (n == m ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() #define endl "\n" #define deb(x) cout << #x << " : " << x << endl; template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << " "; return out; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &i : a) in >> i; return in; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; cout << (n == m ? "Yes" : "No"); }
delete
21
25
21
21
0
p02789
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { // Your code here! string a, b; cin >> a >> b; int a1 = stoi(a); int b2 = stoi(b); int result = a1 / b2; if (result == 1) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <iostream> using namespace std; int main(void) { // Your code here! string n, m; cin >> n >> m; int n1 = stoi(n); int m1 = stoi(m); if (n1 == 0) { cout << "No" << endl; } int result = m1 / n1; if (result == 1) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
4
9
4
12
0
p02790
C++
Runtime Error
#include <iostream> #include <string> using namespace std; string replicate(string s, int n) { string ret = ""; for (int i = 0; i < n; i++) { ret += s; } } int main() { int a, b; cin >> a >> b; string s = replicate(to_string(a), b); string t = replicate(to_string(b), a); cout << (s < t ? s : t) << endl; return 0; }
#include <iostream> #include <string> using namespace std; string replicate(string s, int n) { string ret = ""; for (int i = 0; i < n; i++) { ret += s; } return ret; } int main() { int a, b; cin >> a >> b; string s = replicate(to_string(a), b); string t = replicate(to_string(b), a); cout << (s < t ? s : t) << endl; return 0; }
insert
10
10
10
11
-11
p02790
Python
Runtime Error
a, b = [input() for i in range(2)] a_array = [] for i in range(int(b)): a_array.append(a) a_str = "".join(a_array) b_array = [] for i in range(int(a)): b_array.append(b) b_str = "".join(b_array) if a_str < b_str: print(a_str) elif b_str < a_str: print(b_str) else: print(a_str)
a, b = input().split() a_array = [] for i in range(int(b)): a_array.append(a) a_str = "".join(a_array) b_array = [] for i in range(int(a)): b_array.append(b) b_str = "".join(b_array) if a_str < b_str: print(a_str) elif b_str < a_str: print(b_str) else: print(a_str)
replace
0
1
0
2
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02790/Python/s069499411.py", line 1, in <module> a, b = [input() for i in range(2)] File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02790/Python/s069499411.py", line 1, in <listcomp> a, b = [input() for i in range(2)] EOFError: EOF when reading a line
p02790
Python
Runtime Error
data = input().split() a = data[0] b = data[1] ans = min(a, b) * max(a, b) print(ans)
data = input().split() a = data[0] b = data[1] ans = min(a, b) * int(max(a, b)) print(ans)
replace
5
6
5
6
TypeError: can't multiply sequence by non-int of type 'str'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02790/Python/s088084103.py", line 6, in <module> ans = min(a, b) * max(a, b) TypeError: can't multiply sequence by non-int of type 'str'
p02790
Python
Runtime Error
# -*- coding: utf-8 -*- # 入力を整数に変換して受け取る def input_int(): return int(input()) # マイナス1した値を返却 def int1(x): return int(x) - 1 # 半角スペース区切り入力をIntに変換してMapで受け取る def input_to_int_map(): return map(int, input().split()) # 半角スペース区切り入力をIntに変換して受け取る def input_to_int_tuple(): return tuple(map(int, input().split())) # 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る def input_to_int_tuple_minus1(): return tuple(map(int1, input().split())) def main(): a, b = input_to_int_map() import itertools _a = itertools.repeat(str(a), b) _b = itertools.repeat(str(b), a) ret = _b if _a < _b: ret = _a return ret if __name__ == "__main__": print(main())
# -*- coding: utf-8 -*- # 入力を整数に変換して受け取る def input_int(): return int(input()) # マイナス1した値を返却 def int1(x): return int(x) - 1 # 半角スペース区切り入力をIntに変換してMapで受け取る def input_to_int_map(): return map(int, input().split()) # 半角スペース区切り入力をIntに変換して受け取る def input_to_int_tuple(): return tuple(map(int, input().split())) # 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る def input_to_int_tuple_minus1(): return tuple(map(int1, input().split())) def main(): a, b = input_to_int_map() import itertools _a = "".join(itertools.repeat(str(a), b)) _b = "".join(itertools.repeat(str(b), a)) ret = _b if _a < _b: ret = _a return ret if __name__ == "__main__": print(main())
replace
32
34
32
34
TypeError: '<' not supported between instances of 'itertools.repeat' and 'itertools.repeat'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02790/Python/s395813013.py", line 42, in <module> print(main()) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02790/Python/s395813013.py", line 35, in main if _a < _b: TypeError: '<' not supported between instances of 'itertools.repeat' and 'itertools.repeat'
p02790
C++
Runtime Error
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; const int MAX_N = int(1e6) + 10; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; typedef long long int ll; typedef unsigned long long int llu; struct fenwick { int lim; long long int *tree; fenwick(int _lim) { lim = _lim; tree = new long long int[lim]; } void init() { for (int i = 0; i < lim; i++) { tree[i] = 0; } } void update(int x, long long int v) { while (x < lim) { tree[x] += v; x += x & (-x); } } long long int query(int x) { long long int ans = 0; while (x > 0) { ans += tree[x]; x -= x & (-x); } return ans; } int _query(int k) { int low = 1; int high = 500000; int ans = 0; int x = k; while (low <= high) { int mid = low + (high - low) / 2; if (query(mid) >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } }; /* struct z_function{ string &txt; int *z; z_function(string &_txt):txt(_txt){ z=new int[1+txt.length()]; } void cal(){ z[0]=0; int l=0; int r=0; for(int i=1;i<txt.length();i++){ // cout<<l<<" "<<r<<endl; if(i>r){ l=i; r=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } // cout<<r<<" "; z[i]=r-l; r=r-1; }else{ if(z[i-l]<r-i+1) z[i]=z[i-l]; else{ l=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } z[i]=r-l; r=r-1; } } } } }; struct palindromic_tree{ map<char,struct palindromic_tree*>m; int length; int end_indx; struct palindromic_tree* suffix; palindromic_tree(int _length,int _end_indx){ length=_length; end_indx=_end_indx; } }; class palindromic_string{ public: string &s; struct palindromic_tree* real_root; struct palindromic_tree* imaginary_root; struct palindromic_tree* curr; long long int *prefix; palindromic_string(string &_s):s(_s){ real_root=new palindromic_tree(0,-1); imaginary_root=new palindromic_tree(-1,-1); curr=real_root; real_root->suffix=imaginary_root;prefix=new long long int[1+s.length()]; imaginary_root->suffix=imaginary_root; } void add(char ch){ int indx=s.size(); struct palindromic_tree* temp=curr; s+=ch; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; if((temp->m).find(ch)!=(temp->m).end()){ curr=(temp->m)[ch]; return; }else{ curr=new palindromic_tree((temp->length)+2,indx); } (temp->m)[ch]=curr; if(curr->length==1){ curr->suffix=real_root; return; }else{ temp=temp->suffix; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; curr->suffix=(temp->m)[ch]; } } void cal(){ prefix[0]=0; long long int p=29LL; for(int i=0;i<s.length();i++){ prefix[i+1]=(prefix[i]+(p*s[i]))%MOD; p=(p*p)%MOD; } } }; struct prime_numbers{ int *seive; int len; prime_numbers(int _len){ len=_len; seive=new int[len+1]; } void init(){ seive[0]=1; seive[1]=1; } void cal(){ for(int i=2;i*i<=len;i++){ for(int j=i*i;j<=len;j+=i){ seive[j]=1; } } } }; */ ll mul(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll c = a * b; if (c >= MOD) c = c % MOD; while (c < 0) c += MOD; return c; } ll add(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll ans = (a + b); if (ans >= MOD) ans = ans % MOD; while (ans < 0) ans += MOD; return ans; } ll power(ll a, ll b, ll c) { ll ans = 1; while (b) { if (b & 1) { ans = mul(ans, a); } a = mul(a, a); b = b / 2; } return ans; } template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << "(" << P.first << ", " << P.second << ")"; return out; } template <class T> istream &operator>>(istream &in, vector<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const vector<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } template <class T> istream &operator>>(istream &in, deque<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const deque<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } mt19937 rnd(time(0)); struct sparse { int table[200005][25]; int n; sparse(int len1) : n(len1) {} void init(int *a) { for (int i = 1; i <= n; i++) { table[i][0] = a[i]; } // cout<<table[1][0]<<endl; for (int j = 1; j < 25; j++) { for (int i = 1; i <= n; i++) { if (i + (1 << j) - 1 <= n) { table[i][j] = __gcd(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]); } } } } int find(int *a, int start, int end) { int dis = end - start + 1; int g = 0; for (int j = 25; j >= 0; j--) { if (dis & (1 << j)) { // cout<<dis<<" "<<table[start][j]<<" "<<j<<endl; g = __gcd(g, table[start][j]); start = start + (1 << j); } } return g; } }; inline ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; } // vector<pair<int,int> >v[1000005]; // ll t[1000005];ll h[1000005]; ;;;;;;multiset<pair<ll,pair<int,pair<ll,ll> > > // >s;ll A,B;bool vis[1000005];ll dis[1000005];int // parent[1000005];vector<int>ans; ll c[1000005]; struct SOS { ll *dp; int limit; vector<int> &arr; SOS(int _limit, vector<int> &v) : arr(v) { limit = _limit; dp = new ll[(1 << limit) + 10]; } void init() { for (int i = 0; i < (1 << limit); i++) { dp[i] = 0; } for (int i = 0; i < arr.size(); i++) { dp[arr[i]]++; } } void build1() { for (int i = 0; i < limit; i++) { for (int j = 0; j < (1 << limit); j++) { if (j & (1 << i)) { dp[j] = add(dp[j], dp[j ^ (1 << i)]); } } } } void build2() { for (int i = 0; i < limit; i++) { for (int j = (1 << limit) - 1; j >= 0; j--) { if (j & (1 << i)) { dp[j ^ (1 << i)] = add(dp[j ^ (1 << i)], dp[j]); } } } } // } }; // string s; int find(int arr[], int x) { while (x != arr[x]) { x = arr[x]; } return x; } void connect(int x, int arr[], int size[], int comp[], int y) { int rootA = find(arr, x); int rootB = find(arr, y); if (rootA == rootB) return; if (size[rootA] < size[rootB]) { arr[rootA] = rootB; size[rootB] += size[rootA]; comp[rootB] = min(comp[rootA], comp[rootB]); } else { arr[rootB] = rootA; size[rootA] += size[rootB]; comp[rootA] = min(comp[rootA], comp[rootB]); } } struct lazylam { ll *tree; int n; lazylam(int size) : n(size) { tree = new ll[4 * n + 1]; } void init() { for (int i = 0; i <= 4 * n; i++) { tree[i] = 0; } } void update(int x, ll v) { upd(1, 1, n, x, v); } void upd(int nd, int st, int en, int x, ll v) { if (st == en) { tree[nd] += v; return; } int mid = (st + en) / 2; if (x <= mid) { upd(2 * nd, st, mid, x, v); } else { upd(2 * nd + 1, mid + 1, en, x, v); } tree[nd] = tree[2 * nd] + tree[2 * nd + 1]; } }; struct graph { vector<int> *v; int n; long long int *values; int *start; int *end; graph(int size) : n(size) { v = new vector<int>[n + 1]; values = new ll[n + 1]; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { cin >> values[i]; } } void dfs() { int gtime = 0; start = new int[n + 1]; end = new int[n + 1]; dfs_start_end(1, 0, gtime); } void dfs_start_end(int i, int p, int &gtime) { gtime++; start[i] = gtime; for (auto it : v[i]) { if (it != p) { dfs_start_end(it, i, gtime); } } end[i] = gtime; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("f.in", "r", stdin); #endif int n, m; cin >> n >> m; string str1 = ""; string str2 = ""; for (int i = 1; i <= m; i++) { str1 += to_string(n); // cout<<str1<<endl; } for (int i = 1; i <= n; i++) { str2 += to_string(m); } if (str1.compare(str2) < 0) cout << str1 << endl; else cout << str2 << endl; }
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; const int MAX_N = int(1e6) + 10; const long long int MOD = 1e9 + 7; const long long int INF = 1e18; typedef long long int ll; typedef unsigned long long int llu; struct fenwick { int lim; long long int *tree; fenwick(int _lim) { lim = _lim; tree = new long long int[lim]; } void init() { for (int i = 0; i < lim; i++) { tree[i] = 0; } } void update(int x, long long int v) { while (x < lim) { tree[x] += v; x += x & (-x); } } long long int query(int x) { long long int ans = 0; while (x > 0) { ans += tree[x]; x -= x & (-x); } return ans; } int _query(int k) { int low = 1; int high = 500000; int ans = 0; int x = k; while (low <= high) { int mid = low + (high - low) / 2; if (query(mid) >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } }; /* struct z_function{ string &txt; int *z; z_function(string &_txt):txt(_txt){ z=new int[1+txt.length()]; } void cal(){ z[0]=0; int l=0; int r=0; for(int i=1;i<txt.length();i++){ // cout<<l<<" "<<r<<endl; if(i>r){ l=i; r=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } // cout<<r<<" "; z[i]=r-l; r=r-1; }else{ if(z[i-l]<r-i+1) z[i]=z[i-l]; else{ l=i; while(r<txt.length() && txt[r]==txt[r-l]){ r++; } z[i]=r-l; r=r-1; } } } } }; struct palindromic_tree{ map<char,struct palindromic_tree*>m; int length; int end_indx; struct palindromic_tree* suffix; palindromic_tree(int _length,int _end_indx){ length=_length; end_indx=_end_indx; } }; class palindromic_string{ public: string &s; struct palindromic_tree* real_root; struct palindromic_tree* imaginary_root; struct palindromic_tree* curr; long long int *prefix; palindromic_string(string &_s):s(_s){ real_root=new palindromic_tree(0,-1); imaginary_root=new palindromic_tree(-1,-1); curr=real_root; real_root->suffix=imaginary_root;prefix=new long long int[1+s.length()]; imaginary_root->suffix=imaginary_root; } void add(char ch){ int indx=s.size(); struct palindromic_tree* temp=curr; s+=ch; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; if((temp->m).find(ch)!=(temp->m).end()){ curr=(temp->m)[ch]; return; }else{ curr=new palindromic_tree((temp->length)+2,indx); } (temp->m)[ch]=curr; if(curr->length==1){ curr->suffix=real_root; return; }else{ temp=temp->suffix; while(indx-temp->length-1<0 || s[indx-temp->length-1]!=s[indx]) temp=temp->suffix; curr->suffix=(temp->m)[ch]; } } void cal(){ prefix[0]=0; long long int p=29LL; for(int i=0;i<s.length();i++){ prefix[i+1]=(prefix[i]+(p*s[i]))%MOD; p=(p*p)%MOD; } } }; struct prime_numbers{ int *seive; int len; prime_numbers(int _len){ len=_len; seive=new int[len+1]; } void init(){ seive[0]=1; seive[1]=1; } void cal(){ for(int i=2;i*i<=len;i++){ for(int j=i*i;j<=len;j+=i){ seive[j]=1; } } } }; */ ll mul(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll c = a * b; if (c >= MOD) c = c % MOD; while (c < 0) c += MOD; return c; } ll add(ll a, ll b) { if (a >= MOD) a = a % MOD; while (a < 0) a += MOD; if (b >= MOD) b = b % MOD; while (b < 0) b += MOD; ll ans = (a + b); if (ans >= MOD) ans = ans % MOD; while (ans < 0) ans += MOD; return ans; } ll power(ll a, ll b, ll c) { ll ans = 1; while (b) { if (b & 1) { ans = mul(ans, a); } a = mul(a, a); b = b / 2; } return ans; } template <class T1, class T2> istream &operator>>(istream &in, pair<T1, T2> &P) { in >> P.first >> P.second; return in; } template <class T1, class T2> ostream &operator<<(ostream &out, const pair<T1, T2> &P) { out << "(" << P.first << ", " << P.second << ")"; return out; } template <class T> istream &operator>>(istream &in, vector<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const vector<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } template <class T> istream &operator>>(istream &in, deque<T> &arr) { for (auto &x : arr) in >> x; return in; } template <class T> ostream &operator<<(ostream &out, const deque<T> &arr) { for (auto &x : arr) out << x << ' '; cout << "\n"; return out; } mt19937 rnd(time(0)); struct sparse { int table[200005][25]; int n; sparse(int len1) : n(len1) {} void init(int *a) { for (int i = 1; i <= n; i++) { table[i][0] = a[i]; } // cout<<table[1][0]<<endl; for (int j = 1; j < 25; j++) { for (int i = 1; i <= n; i++) { if (i + (1 << j) - 1 <= n) { table[i][j] = __gcd(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]); } } } } int find(int *a, int start, int end) { int dis = end - start + 1; int g = 0; for (int j = 25; j >= 0; j--) { if (dis & (1 << j)) { // cout<<dis<<" "<<table[start][j]<<" "<<j<<endl; g = __gcd(g, table[start][j]); start = start + (1 << j); } } return g; } }; inline ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; } // vector<pair<int,int> >v[1000005]; // ll t[1000005];ll h[1000005]; ;;;;;;multiset<pair<ll,pair<int,pair<ll,ll> > > // >s;ll A,B;bool vis[1000005];ll dis[1000005];int // parent[1000005];vector<int>ans; ll c[1000005]; struct SOS { ll *dp; int limit; vector<int> &arr; SOS(int _limit, vector<int> &v) : arr(v) { limit = _limit; dp = new ll[(1 << limit) + 10]; } void init() { for (int i = 0; i < (1 << limit); i++) { dp[i] = 0; } for (int i = 0; i < arr.size(); i++) { dp[arr[i]]++; } } void build1() { for (int i = 0; i < limit; i++) { for (int j = 0; j < (1 << limit); j++) { if (j & (1 << i)) { dp[j] = add(dp[j], dp[j ^ (1 << i)]); } } } } void build2() { for (int i = 0; i < limit; i++) { for (int j = (1 << limit) - 1; j >= 0; j--) { if (j & (1 << i)) { dp[j ^ (1 << i)] = add(dp[j ^ (1 << i)], dp[j]); } } } } // } }; // string s; int find(int arr[], int x) { while (x != arr[x]) { x = arr[x]; } return x; } void connect(int x, int arr[], int size[], int comp[], int y) { int rootA = find(arr, x); int rootB = find(arr, y); if (rootA == rootB) return; if (size[rootA] < size[rootB]) { arr[rootA] = rootB; size[rootB] += size[rootA]; comp[rootB] = min(comp[rootA], comp[rootB]); } else { arr[rootB] = rootA; size[rootA] += size[rootB]; comp[rootA] = min(comp[rootA], comp[rootB]); } } struct lazylam { ll *tree; int n; lazylam(int size) : n(size) { tree = new ll[4 * n + 1]; } void init() { for (int i = 0; i <= 4 * n; i++) { tree[i] = 0; } } void update(int x, ll v) { upd(1, 1, n, x, v); } void upd(int nd, int st, int en, int x, ll v) { if (st == en) { tree[nd] += v; return; } int mid = (st + en) / 2; if (x <= mid) { upd(2 * nd, st, mid, x, v); } else { upd(2 * nd + 1, mid + 1, en, x, v); } tree[nd] = tree[2 * nd] + tree[2 * nd + 1]; } }; struct graph { vector<int> *v; int n; long long int *values; int *start; int *end; graph(int size) : n(size) { v = new vector<int>[n + 1]; values = new ll[n + 1]; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { cin >> values[i]; } } void dfs() { int gtime = 0; start = new int[n + 1]; end = new int[n + 1]; dfs_start_end(1, 0, gtime); } void dfs_start_end(int i, int p, int &gtime) { gtime++; start[i] = gtime; for (auto it : v[i]) { if (it != p) { dfs_start_end(it, i, gtime); } } end[i] = gtime; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; string str1 = ""; string str2 = ""; for (int i = 1; i <= m; i++) { str1 += to_string(n); // cout<<str1<<endl; } for (int i = 1; i <= n; i++) { str2 += to_string(m); } if (str1.compare(str2) < 0) cout << str1 << endl; else cout << str2 << endl; }
delete
431
435
431
431
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02790
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; char a, b; int main() { cin >> a >> b; int ia = atoi((const char *)a); int ib = atoi((const char *)b); if (a < b) { for (int i = 0; i < ib; ++i) { cout << a; } cout << endl; } else { for (int i = 0; i < ia; ++i) { cout << b; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; char a, b; int main() { cin >> a >> b; int ia = a - '0'; int ib = b - '0'; if (a < b) { for (int i = 0; i < ib; ++i) { cout << a; } cout << endl; } else { for (int i = 0; i < ia; ++i) { cout << b; } cout << endl; } }
replace
7
9
7
9
-11
p02790
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { int p, q; cin >> p >> q; int cnt; if (p > q) { cnt = 1; } else if (q > p) { cnt = 0; } int r = q, s = p; for (int i = 0; i <= p; i = i * 10) { r = r * (10 ^ i); } for (int i = 0; i <= q; i++) { s = s * (10 ^ i); } if (cnt == 0) { cout << s << endl; } else if (cnt == 1) { cout << r << endl; } }
#include <bits/stdc++.h> using namespace std; int main(void) { int p, q; cin >> p >> q; if (p == q || p > q) { int x = 0; for (int i = 0; i < p; i++) { x = (x * 10) + q; } cout << x << endl; } else { int x = 0; for (int i = 0; i < q; i++) { x = (x * 10) + p; } cout << x << endl; } }
replace
5
22
5
17
TLE
p02790
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; const ll INF = 1e18; 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 int a, b; cin >> a >> b; ll int r = min(a, b), s = max(a, b); while (s != 0) { cout << r; s--; } }
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; const ll INF = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll int a, b; cin >> a >> b; ll int r = min(a, b), s = max(a, b); while (s != 0) { cout << r; s--; } }
replace
10
14
10
11
TLE
p02790
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string A, B; int i = 0, temp; string result; do { temp = (int)(A[i] - '0') - (int)(B[i] - '0'); if (temp < 0) result = A; else if (temp > 0) result = B; i++; } while (temp == 0); cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; string result = ""; cin >> a >> b; if (a >= b) cout << result.append(a, (char)(b + '0')) << endl; else cout << result.append(b, (char)(a + '0')) << endl; return 0; }
replace
4
17
4
11
0
p02790
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef unsigned long long int ull; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; #define int ll #define pb push_back #define mp make_pair #define xx first #define yy second #define all(a) a.begin(), a.end() #define vi vector<int> #define vpi vector<pii> #define pii pair<int, int> #define present(DT, val) (DT.find(val) != DT.end()) // for set and map #define cpresent(DT, val) (find(all(DT), val) != DT.end()) // vectors #define input "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt" #define output "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt" #define error "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt" #define IO() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 2e18 #define MOD 1000000007 #define clr(x) memset(x, 0, sizeof(x)) #define init(x, a) memset(x, a, sizeof(x)) #define out(a) \ for (auto i : a) \ cout << i << ' '; \ cout << '\n' #define cpy(a, b) memcpy(a, b, sizeof(b)) #define is(a) to_string(a) #define ci(a, c) a - c #define debug(i) cout << "point :" << i << '\n'; #define setd(val, n) cout << fixed << setprecision(n) << val << '\n' void solve() { string a, b, c, d; cin >> a >> b; c = string(ci(b[0], '0'), a[0]); d = string(ci(a[0], '0'), b[0]); if (c < d) cout << c << '\n'; else cout << d << '\n'; } signed main() { IO(); #ifndef ONLINE_JUDGE freopen(input, "r", stdin); freopen(output, "w", stdout); freopen(error, "w", stderr); #endif int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef unsigned long long int ull; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; #define int ll #define pb push_back #define mp make_pair #define xx first #define yy second #define all(a) a.begin(), a.end() #define vi vector<int> #define vpi vector<pii> #define pii pair<int, int> #define present(DT, val) (DT.find(val) != DT.end()) // for set and map #define cpresent(DT, val) (find(all(DT), val) != DT.end()) // vectors #define input "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt" #define output "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt" #define error "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt" #define IO() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 2e18 #define MOD 1000000007 #define clr(x) memset(x, 0, sizeof(x)) #define init(x, a) memset(x, a, sizeof(x)) #define out(a) \ for (auto i : a) \ cout << i << ' '; \ cout << '\n' #define cpy(a, b) memcpy(a, b, sizeof(b)) #define is(a) to_string(a) #define ci(a, c) a - c #define debug(i) cout << "point :" << i << '\n'; #define setd(val, n) cout << fixed << setprecision(n) << val << '\n' void solve() { string a, b, c, d; cin >> a >> b; c = string(ci(b[0], '0'), a[0]); d = string(ci(a[0], '0'), b[0]); if (c < d) cout << c << '\n'; else cout << d << '\n'; } signed main() { IO(); int t = 1; // cin>>t; while (t--) solve(); return 0; }
delete
58
63
58
58
-6
p02790
C++
Runtime Error
// Author :mdragneell #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ull unsigned long long #define ll long long #define ld long double #define pb push_back #define pi pair<int, int> #define pl pair<ll, ll> #define f first #define s second ll const N = 1e5 + 5; ll const mod = 1e9 + 7; ll min(ll x, ll y) { if (x < y) return x; else return y; } ll max(ll x, ll y) { if (x > y) return x; else return y; } ll gcd(ll x, ll y) { if (x == 0) return y; else return gcd(y % x, x); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; struct compare { bool operator()(const pair<ll, ll> &value, const ll &key) { return (value.first < key); } bool operator()(const ll &key, const pair<ll, ll> &value) { return (key < value.first); } }; bool compare1(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first < b.first) return true; else if (a.first == b.first) return (a.second > b.second); else return false; } ll powmod(ll x, ll y) { ll res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x) % mod; y >>= 1; if (y <= 0) break; x = (x * x) % mod; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll tt = 1; // cin>>tt; while (tt--) { ll n, m; cin >> n >> m; if (n > m) swap(n, m); for (int i = 0; i < m; i++) cout << n; cout << endl; } }
// Author :mdragneell #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ull unsigned long long #define ll long long #define ld long double #define pb push_back #define pi pair<int, int> #define pl pair<ll, ll> #define f first #define s second ll const N = 1e5 + 5; ll const mod = 1e9 + 7; ll min(ll x, ll y) { if (x < y) return x; else return y; } ll max(ll x, ll y) { if (x > y) return x; else return y; } ll gcd(ll x, ll y) { if (x == 0) return y; else return gcd(y % x, x); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; struct compare { bool operator()(const pair<ll, ll> &value, const ll &key) { return (value.first < key); } bool operator()(const ll &key, const pair<ll, ll> &value) { return (key < value.first); } }; bool compare1(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first < b.first) return true; else if (a.first == b.first) return (a.second > b.second); else return false; } ll powmod(ll x, ll y) { ll res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x) % mod; y >>= 1; if (y <= 0) break; x = (x * x) % mod; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ ll tt = 1; // cin>>tt; while (tt--) { ll n, m; cin >> n >> m; if (n > m) swap(n, m); for (int i = 0; i < m; i++) cout << n; cout << endl; } }
replace
89
93
89
93
TLE
p02790
C++
Runtime Error
#include <bits/stdc++.h> //*************** Constraints are always Imaginary,I'm real ************** using namespace std; #define int long long #define MP make_pair #define PB push_back #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define fi first #define se second typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPII; typedef vector<VI> VVI; typedef map<int, int> MPII; typedef set<int> SETI; typedef multiset<int> MSETI; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a, b, rep; string ans, who; cin >> a >> b; if (a == b) { rep = a, who = to_string(a); } else { who = to_string(min(a, b)); rep = max(a, b); } for (int i = 1; i <= rep; i++) { ans += who; } cout << ans; return 0; }
#include <bits/stdc++.h> //*************** Constraints are always Imaginary,I'm real ************** using namespace std; #define int long long #define MP make_pair #define PB push_back #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define fi first #define se second typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<PII> VPII; typedef vector<VI> VVI; typedef map<int, int> MPII; typedef set<int> SETI; typedef multiset<int> MSETI; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int a, b, rep; string ans, who; cin >> a >> b; if (a == b) { rep = a, who = to_string(a); } else { who = to_string(min(a, b)); rep = max(a, b); } for (int i = 1; i <= rep; i++) { ans += who; } cout << ans; return 0; }
replace
20
24
20
24
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02790
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define N 100005 #define mod 998244353 #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define prec(n) fixed << setprecision(n) #define mii unordered_map<int, int> #define mll unordered_map<ll, ll> #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define pb push_backP #define mp make_pair #define pp pop_back #define vii vector<int> #define vll vector<ll> #define vpp vector<pii> #define all(c) c.begin(), c.end() #define tr(it, c) for (it = c.begin(); it != c.end(); it++) int inf = INT_MAX; ll modulo(ll num, ll MOD = mod) { return ((num % MOD) + MOD) % MOD; } // for negative integer ll power(ll b, ll e, ll MOD = mod) { ll ans = 1; while (e) { if (e % 2) ans = (ans * b) % MOD; b = (b * b) % MOD; e /= 2; } return ans; } ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); } ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } int main() { boost; #ifndef ONLINE_JUDGE freopen("D:/Disk D/Work/c++ workspace/input.txt", "r", stdin); freopen("D:/Disk D/Work/c++ workspace/output.txt", "w", stdout); #endif int a, b; cin >> a >> b; if (a < b) { for (int i = 0; i < b; ++i) { cout << a; } } else { for (int i = 0; i < a; ++i) { cout << b; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define N 100005 #define mod 998244353 #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define prec(n) fixed << setprecision(n) #define mii unordered_map<int, int> #define mll unordered_map<ll, ll> #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define pb push_backP #define mp make_pair #define pp pop_back #define vii vector<int> #define vll vector<ll> #define vpp vector<pii> #define all(c) c.begin(), c.end() #define tr(it, c) for (it = c.begin(); it != c.end(); it++) int inf = INT_MAX; ll modulo(ll num, ll MOD = mod) { return ((num % MOD) + MOD) % MOD; } // for negative integer ll power(ll b, ll e, ll MOD = mod) { ll ans = 1; while (e) { if (e % 2) ans = (ans * b) % MOD; b = (b * b) % MOD; e /= 2; } return ans; } ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); } ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } int main() { boost; int a, b; cin >> a >> b; if (a < b) { for (int i = 0; i < b; ++i) { cout << a; } } else { for (int i = 0; i < a; ++i) { cout << b; } } return 0; }
delete
46
50
46
46
0