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>
using namespace std;
int w[300], c[300], f[300010];
int V, n, mx;
int main() {
scanf("%d%d", &V, &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &w[i], &c[i]);
mx = max(mx, w[i]);
}
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = w[i]; j <= V + mx; j++)
f[j] = min(f[j], f[j - w[i]] + c[i]);
int ans = f[V];
for (int i = V + 1; i <= V + mx; ++i) {
ans = min(f[i], ans);
}
printf("%d\n", ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int w[300010], c[300010], f[300010];
int V, n, mx;
int main() {
scanf("%d%d", &V, &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &w[i], &c[i]);
mx = max(mx, w[i]);
}
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = w[i]; j <= V + mx; j++)
f[j] = min(f[j], f[j - w[i]] + c[i]);
int ans = f[V];
for (int i = V + 1; i <= V + mx; ++i) {
ans = min(f[i], ans);
}
printf("%d\n", ans);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> (i)) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPI(i, x) for (int i = 1; i <= x; i++)
#define FORI(i, m, n) for (int i = m; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FORA(i, n) for (auto &&i : n)
#define POW(a, b) ((int)(pow(a, b) + .5))
#define DUMPOUT cerr
// 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 << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(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 << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
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__)
#define PRINTARR(x, y) \
cerr << #x << "=\n"; \
for (auto itr = x; itr != y; itr++) \
cerr << *itr << " "; \
cerr << endl;
#define PRINTARR2(x, i0, i1) \
cerr << #x << "=\n"; \
for (int ii0 = 0; ii0 < i0; ii0++) { \
for (int ii1 = 0; ii1 < i1; ii1++) \
cerr << x[ii0][ii1] << " "; \
cerr << endl; \
}
#else
#define DEB if (false)
#define DUMP(...)
#define PRINTARR(x, y)
#define PRINTARR2(x, i0, i1)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
/*
[&] { return;
}();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる.
//*/
#define MAXN 21000
int a[MAXN], b[MAXN];
int dp[110][MAXN];
// int dpN[MAXN];
signed main() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int H, N;
cin >> H >> N;
REP(i, N) { cin >> a[i] >> b[i]; }
// dpN[0] = 0;
fill((int *)dp[0], (int *)dp[N + 1], INF);
REPZ(i, N) dp[i][0] = 0;
REP(i, N) {
REP(j, H + 10100) {
if (j < a[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
}
}
PRINTARR(&dp[i][0], &dp[i][100]);
}
PRINTARR(&dp[N][0], &dp[N][100]);
int ans = INF;
FORI(i, H, H + 10010) { chmin(ans, dp[N][i]); }
print(ans);
} | #include <bits/stdc++.h>
using namespace std;
#define BIT(n) (1LL << (n))
#define BITF(n, i) (((n) >> (i)) & 1)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define REPI(i, x) for (int i = 1; i <= x; i++)
#define FORI(i, m, n) for (int i = m; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define REPZ(i, x) for (int i = 0; i <= x; i++)
#define FORA(i, n) for (auto &&i : n)
#define POW(a, b) ((int)(pow(a, b) + .5))
#define DUMPOUT cerr
// 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 << "{";
REP(i, (int)vec.size())
os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
os << "}";
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
FORA(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 << "{";
FORA(itr, set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
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__)
#define PRINTARR(x, y) \
cerr << #x << "=\n"; \
for (auto itr = x; itr != y; itr++) \
cerr << *itr << " "; \
cerr << endl;
#define PRINTARR2(x, i0, i1) \
cerr << #x << "=\n"; \
for (int ii0 = 0; ii0 < i0; ii0++) { \
for (int ii1 = 0; ii1 < i1; ii1++) \
cerr << x[ii0][ii1] << " "; \
cerr << endl; \
}
#else
#define DEB if (false)
#define DUMP(...)
#define PRINTARR(x, y)
#define PRINTARR2(x, i0, i1)
#endif
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
/*
[&] { return;
}();下のスラッシュを2つ追加しただけ.上のスラッシュを2つにすれば外れる.
//*/
#define MAXN 21000
int a[MAXN], b[MAXN];
int dp[1100][MAXN];
// int dpN[MAXN];
signed main() {
cin.tie(0), ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int H, N;
cin >> H >> N;
REP(i, N) { cin >> a[i] >> b[i]; }
// dpN[0] = 0;
fill((int *)dp[0], (int *)dp[N + 1], INF);
REPZ(i, N) dp[i][0] = 0;
REP(i, N) {
REP(j, H + 10100) {
if (j < a[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
}
}
PRINTARR(&dp[i][0], &dp[i][100]);
}
PRINTARR(&dp[N][0], &dp[N][100]);
int ans = INF;
FORI(i, H, H + 10010) { chmin(ans, dp[N][i]); }
print(ans);
} | replace | 128 | 129 | 128 | 129 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int dp[14010][10010];
int main() {
int H, N;
cin >> H >> N;
int A[1010], B[1010];
for (int i = 1; i <= N; i++) {
cin >> A[i] >> B[i];
}
vector<int> P, Q;
for (int i = 1; i <= N; i++) {
int nowA = A[i];
int nowB = B[i];
P.push_back(nowA);
Q.push_back(nowB);
while (nowA < H) {
nowA <<= 1;
P.push_back(nowA);
nowB <<= 1;
Q.push_back(nowB);
}
}
for (int i = 0; i <= P.size(); i++) {
for (int j = 0; j <= H; j++) {
dp[i][j] = 1e9 + 7;
}
}
dp[0][0] = 0;
for (int i = 0; i < P.size(); i++) {
for (int j = 0; j <= H; j++) {
if (dp[i][j] == 1e9 + 7)
continue;
dp[i + 1][min(j + P[i], H)] =
min(dp[i + 1][min(j + P[i], H)], dp[i][j] + Q[i]);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[P.size()][H] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int dp[15010][10010];
int main() {
int H, N;
cin >> H >> N;
int A[1010], B[1010];
for (int i = 1; i <= N; i++) {
cin >> A[i] >> B[i];
}
vector<int> P, Q;
for (int i = 1; i <= N; i++) {
int nowA = A[i];
int nowB = B[i];
P.push_back(nowA);
Q.push_back(nowB);
while (nowA < H) {
nowA <<= 1;
P.push_back(nowA);
nowB <<= 1;
Q.push_back(nowB);
}
}
for (int i = 0; i <= P.size(); i++) {
for (int j = 0; j <= H; j++) {
dp[i][j] = 1e9 + 7;
}
}
dp[0][0] = 0;
for (int i = 0; i < P.size(); i++) {
for (int j = 0; j <= H; j++) {
if (dp[i][j] == 1e9 + 7)
continue;
dp[i + 1][min(j + P[i], H)] =
min(dp[i + 1][min(j + P[i], H)], dp[i][j] + Q[i]);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[P.size()][H] << endl;
} | replace | 2 | 3 | 2 | 3 | -11 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll h, n;
cin >> h >> n;
vector<ll> a(n);
vector<ll> b(n);
rep(i, n) cin >> a[i] >> b[i];
ll dp[10010];
ll INF = 1e9;
rep(i, 10010) { dp[i] = INF; }
dp[0] = 0;
for (int i = 1; i <= h; i++) {
for (int j = 0; j <= n; j++) {
chmin(dp[i], dp[i - a[j]] + b[j]);
}
}
dunk(dp[h]);
}
| #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll h, n;
cin >> h >> n;
vector<ll> a(n);
vector<ll> b(n);
rep(i, n) cin >> a[i] >> b[i];
ll dp[10010];
ll INF = 1e9;
rep(i, 10010) { dp[i] = INF; }
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= h; j++) {
chmin(dp[min(j + a[i], h)], dp[j] + b[i]);
}
}
dunk(dp[h]);
} | replace | 28 | 31 | 28 | 31 | 0 | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll H, N;
cin >> H >> N;
vll A(N), B(N);
vvll dp(N + 1, vll(H + 1, INF));
for (int i = 0; i < N; i++) {
cin >> A.at(i) >> B.at(i);
}
for (int i = 0; i <= N; i++) {
dp.at(i).at(0) = 0LL;
}
for (int i = 1; i <= H; i++) {
dp.at(1).at(i) = (i + A.at(0) - 1) / A.at(0) * B.at(0);
}
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
for (int k = 0; k <= i; k++) {
chmin(dp.at(i + 1).at(j), dp.at(k).at(j));
}
if (j - A.at(i) >= 0) {
chmin(dp.at(i + 1).at(j), dp.at(i + 1).at(j - A.at(i)) + B.at(i));
} else {
chmin(dp.at(i + 1).at(j), B.at(i));
}
}
}
cout << dp.at(N).at(H) << endl;
} | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll H, N;
cin >> H >> N;
vll A(N), B(N);
vvll dp(N + 1, vll(H + 1, INF));
for (int i = 0; i < N; i++) {
cin >> A.at(i) >> B.at(i);
}
for (int i = 0; i <= N; i++) {
dp.at(i).at(0) = 0LL;
}
for (int i = 1; i <= H; i++) {
dp.at(1).at(i) = (i + A.at(0) - 1) / A.at(0) * B.at(0);
}
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
chmin(dp.at(i + 1).at(j), dp.at(i).at(j));
if (j - A.at(i) >= 0) {
chmin(dp.at(i + 1).at(j), dp.at(i + 1).at(j - A.at(i)) + B.at(i));
} else {
chmin(dp.at(i + 1).at(j), B.at(i));
}
}
}
cout << dp.at(N).at(H) << endl;
} | replace | 48 | 51 | 48 | 49 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N);
vector<int> B(N);
int maxA = 0;
for (int i = 0; i < N; i++) {
cin >> A.at(i) >> B.at(i);
if (A.at(i) > maxA) {
maxA = A.at(i);
}
}
cerr << "maxA " << maxA << endl;
int l = H + maxA + 1;
int bigM = 1000000000;
vector<int> dp(l, bigM);
dp[0] = 0;
// initialize
for (int i = 0; i < l; i++) {
if (dp[i] == bigM)
continue;
for (int j = 0; j < N; j++) {
int nd = i + A.at(j);
int nb = dp[i] + B.at(j);
if (nb < dp[nd]) {
dp[nd] = nb;
}
}
}
int ans = dp[H];
for (int i = H; i < l; i++) {
// cerr << i << " " << dp[i] << endl;
if (dp[i] < ans)
ans = dp[i];
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N);
vector<int> B(N);
int maxA = 0;
for (int i = 0; i < N; i++) {
cin >> A.at(i) >> B.at(i);
if (A.at(i) > maxA) {
maxA = A.at(i);
}
}
cerr << "maxA " << maxA << endl;
int l = H + maxA + 1;
int bigM = 1000000000;
vector<int> dp(l, bigM);
dp[0] = 0;
// initialize
for (int i = 0; i <= H; i++) {
if (dp[i] == bigM)
continue;
for (int j = 0; j < N; j++) {
int nd = i + A.at(j);
int nb = dp[i] + B.at(j);
if (nb < dp[nd]) {
dp[nd] = nb;
}
}
}
int ans = dp[H];
for (int i = H; i < l; i++) {
// cerr << i << " " << dp[i] << endl;
if (dp[i] < ans)
ans = dp[i];
}
cout << ans << endl;
}
| replace | 24 | 25 | 24 | 25 | -6 | maxA 8
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>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
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; }
int main() {
ll h, n;
cin >> h >> n;
vl a(n + 1);
vl b(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
ll dp[n + 1][h + 1];
dp[0][0] = 0;
for (ll i = 1; i <= h; i++) {
dp[0][i] = INF;
}
for (ll i = 1; i <= n; i++) {
rep(j, a[i]) {
if (dp[i - 1][j] > b[i]) {
dp[i][j] = b[i];
} else {
dp[i][j] = dp[i - 1][j];
}
}
for (ll j = a[i]; j <= h; j++) {
if (dp[i - 1][j] > dp[i][j - a[i]] + b[i]) {
dp[i][j] = dp[i][j - a[i]] + b[i];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
print(dp[n][h]);
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
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; }
int main() {
ll h, n;
cin >> h >> n;
vl a(n + 1);
vl b(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
ll dp[n + 1][h + 1];
dp[0][0] = 0;
for (ll i = 1; i <= h; i++) {
dp[0][i] = INF;
}
for (ll i = 1; i <= n; i++) {
rep(j, a[i]) {
if (dp[i - 1][j] > b[i]) {
dp[i][j] = b[i];
} else {
dp[i][j] = dp[i - 1][j];
}
if (j == h) {
break;
}
}
for (ll j = a[i]; j <= h; j++) {
if (dp[i - 1][j] > dp[i][j - a[i]] + b[i]) {
dp[i][j] = dp[i][j - a[i]] + b[i];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
print(dp[n][h]);
} | insert | 54 | 54 | 54 | 57 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
int cnt = 0;
for (auto &elem : a) {
if (cnt++)
cout << ' ';
cout << elem;
}
cout << endl;
}
int main() {
int h, n;
cin >> h >> n;
vi a(n), b(n);
REP(i, n) cin >> a[i] >> b[i];
vi dp(h + 1, INF);
dp[h] = 0;
for (int i = h; i > 0; --i) {
if (dp[i] == INF) {
} else {
REP(j, n) {
if (i - a[j] < 0)
dp[0] = min(dp[0], dp[i] + b[j]);
else
dp[i - a[i]] = min(dp[i - a[i]], dp[i] + b[i]);
}
}
}
cout << dp[0] << endl;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
int cnt = 0;
for (auto &elem : a) {
if (cnt++)
cout << ' ';
cout << elem;
}
cout << endl;
}
int main() {
int h, n;
cin >> h >> n;
vi a(n), b(n);
REP(i, n) cin >> a[i] >> b[i];
vi dp(h + 1, INF);
dp[h] = 0;
for (int i = h; i > 0; --i) {
if (dp[i] == INF) {
} else {
REP(j, n) {
if (i - a[j] < 0)
dp[0] = min(dp[0], dp[i] + b[j]);
else
dp[i - a[j]] = min(dp[i - a[j]], dp[i] + b[j]);
}
}
}
cout << dp[0] << endl;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
struct P {
int a, b;
};
template <class T> void chmin(T &a, T b) {
if (b < a)
a = b;
}
int main() {
int h, n;
cin >> h >> n;
vector<P> p(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
p[i] = {a, b};
}
vector<int> dp(h + 1, 1 << 30); // 体力をj減らせる最小の魔力消費
dp[0] = 0;
for (int i = 0; i < n; i++) {
int a = p[i].a;
int b = p[i].b;
for (int j = 0; j < a; j++) {
chmin(dp[j], b);
}
for (int j = a; j <= h; j++) {
chmin(dp[j], dp[j - a] + b);
}
}
cout << dp[h] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
struct P {
int a, b;
};
template <class T> void chmin(T &a, T b) {
if (b < a)
a = b;
}
int main() {
int h, n;
cin >> h >> n;
vector<P> p(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
p[i] = {a, b};
}
vector<int> dp(h + 1, 1 << 30); // 体力をj減らせる最小の魔力消費
dp[0] = 0;
for (int i = 0; i < n; i++) {
int a = p[i].a;
int b = p[i].b;
for (int j = 0; j <= min(a, h); j++) {
chmin(dp[j], b);
}
for (int j = a; j <= h; j++) {
chmin(dp[j], dp[j - a] + b);
}
}
cout << dp[h] << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f;
const ll maxh = 11111;
const ll maxn = 1010;
ll a[maxn], b[maxn];
ll dp[maxh];
int main() {
ios::sync_with_stdio(false);
ll h, n;
while (~scanf("%lld%lld", &h, &n)) {
for (ll i = 0; i < n; i++)
scanf("%lld%lld", &a[i], &b[i]);
memset(dp, inf, sizeof(dp));
dp[0] = 0;
for (ll i = 0; i < n; i++)
for (ll j = 0; j <= h; j++) {
dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
}
ll minn = inf;
for (ll i = h; i < maxh; i++) {
minn = min(minn, dp[i]);
}
printf("%lld\n", minn);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1000000010;
const ll maxh = 5e4 + 10;
const ll maxn = 1010;
ll a[maxn], b[maxn];
ll dp[maxh];
int main() {
ios::sync_with_stdio(false);
ll h, n;
while (~scanf("%lld%lld", &h, &n)) {
for (ll i = 0; i < n; i++)
scanf("%lld%lld", &a[i], &b[i]);
memset(dp, inf, sizeof(dp));
dp[0] = 0;
for (ll i = 0; i < n; i++)
for (ll j = 0; j <= h; j++) {
dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
}
ll minn = inf;
for (ll i = h; i < maxh; i++) {
minn = min(minn, dp[i]);
}
printf("%lld\n", minn);
}
return 0;
}
| replace | 3 | 5 | 3 | 5 | 0 | |
p02787 | C++ | Time Limit Exceeded | // Created by conan1024hao in 2019.
// Copyright © 2019 conan1024hao. All rights reserved.
// 専用ライブラリです、自由にコピーして構いません。
// 感谢看我的代码!Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize("O3")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define chmax(x, y) x = mmax(x, y)
#define chmin(x, y) x = mmin(x, y)
#define all(x) (x).begin(), (x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
// using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
ll cmp1(pair<ll, string> a, pair<ll, string> b) {
if (a.fi != b.fi)
return a.fi < b.fi;
else
return a.se < b.se;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int main() { // 問題をちゃんと見ろ!!!!!!!!!!!!!!!!! llか??????????统一类型
// memset()!!!!!!!!!!!! ペナを減らせ!!!!!!!!!!!!!
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
ll h, n;
cin >> h >> n;
vector<ll> a(n + 1), b(n + 1);
ll amax = 0;
for (ll i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
chmax(amax, a[i]);
}
ll dp[1001][10001];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= h; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
ll ans = INF;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= h; j++) {
chmin(dp[i][j], dp[i - 1][j]);
if (j >= a[i]) {
chmin(dp[i][j], dp[i][j - a[i]] + b[i]);
}
for (ll j = h; j - a[i] <= h; j++) {
chmin(ans, dp[i][j - a[i]] + b[i]);
}
}
}
cout << ans << endl;
//-------------------------------
return 0;
}
//---------------------------------------------------------------------------
| // Created by conan1024hao in 2019.
// Copyright © 2019 conan1024hao. All rights reserved.
// 専用ライブラリです、自由にコピーして構いません。
// 感谢看我的代码!Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize("O3")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define chmax(x, y) x = mmax(x, y)
#define chmin(x, y) x = mmin(x, y)
#define all(x) (x).begin(), (x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
// using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
ll cmp1(pair<ll, string> a, pair<ll, string> b) {
if (a.fi != b.fi)
return a.fi < b.fi;
else
return a.se < b.se;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int main() { // 問題をちゃんと見ろ!!!!!!!!!!!!!!!!! llか??????????统一类型
// memset()!!!!!!!!!!!! ペナを減らせ!!!!!!!!!!!!!
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
ll h, n;
cin >> h >> n;
vector<ll> a(n + 1), b(n + 1);
ll amax = 0;
for (ll i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
chmax(amax, a[i]);
}
ll dp[1001][10001];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= h; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
ll ans = INF;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= h; j++) {
chmin(dp[i][j], dp[i - 1][j]);
if (j >= a[i]) {
chmin(dp[i][j], dp[i][j - a[i]] + b[i]);
}
}
for (ll j = h; j - a[i] <= h; j++) {
chmin(ans, dp[i][j - a[i]] + b[i]);
}
}
cout << ans << endl;
//-------------------------------
return 0;
}
//---------------------------------------------------------------------------
| replace | 94 | 97 | 94 | 97 | TLE | |
p02787 | C++ | Time Limit Exceeded | // Created by conan1024hao in 2019.
// Copyright © 2019 conan1024hao. All rights reserved.
// 専用ライブラリです、自由にコピーして構いません。
// 感谢看我的代码!Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize("O3")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define chmax(x, y) x = mmax(x, y)
#define chmin(x, y) x = mmin(x, y)
#define all(x) (x).begin(), (x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
// using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
ll cmp1(pair<ll, string> a, pair<ll, string> b) {
if (a.fi != b.fi)
return a.fi < b.fi;
else
return a.se < b.se;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int main() { // 問題をちゃんと見ろ!!!!!!!!!!!!!!!!! llか??????????统一类型
// memset()!!!!!!!!!!!! ペナを減らせ!!!!!!!!!!!!!
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
ll h, n;
cin >> h >> n;
vector<ll> a(n + 1), b(n + 1);
ll amax = 0;
for (ll i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
chmax(amax, a[i]);
}
ll dp1[100001];
ll ans = INF;
// 初期化 求最小值就这样 最大值反着来即可 不要多逼逼
for (ll i = 0; i <= 10000 + amax; i++)
dp1[i] = INF;
dp1[0] = 0;
// dp[i] 为了消灭i体力所需要的最小魔法值
for (ll i = 1; i <= n; i++) {
for (ll j = a[i]; j <= h + amax; j++) { // j可以直接从a[j]开始
// chmin(dp1[j],dp1[j-a[i]]+b[i]);
ll ncnt = j / a[i];
for (int k = 0; k <= ncnt; k++)
chmin(dp1[j], dp1[j - k * a[i]] + b[i] * k);
}
}
// 打h到h+amax之间的最小ans 可以理解吧
for (ll i = h; i <= h + amax; i++)
chmin(ans, dp1[i]);
cout << ans << endl;
//-------------------------------
return 0;
}
//---------------------------------------------------------------------------
| // Created by conan1024hao in 2019.
// Copyright © 2019 conan1024hao. All rights reserved.
// 専用ライブラリです、自由にコピーして構いません。
// 感谢看我的代码!Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize("O3")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define chmax(x, y) x = mmax(x, y)
#define chmin(x, y) x = mmin(x, y)
#define all(x) (x).begin(), (x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
// using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
ll cmp1(pair<ll, string> a, pair<ll, string> b) {
if (a.fi != b.fi)
return a.fi < b.fi;
else
return a.se < b.se;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int main() { // 問題をちゃんと見ろ!!!!!!!!!!!!!!!!! llか??????????统一类型
// memset()!!!!!!!!!!!! ペナを減らせ!!!!!!!!!!!!!
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
ll h, n;
cin >> h >> n;
vector<ll> a(n + 1), b(n + 1);
ll amax = 0;
for (ll i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
chmax(amax, a[i]);
}
ll dp1[100001];
ll ans = INF;
// 初期化 求最小值就这样 最大值反着来即可 不要多逼逼
for (ll i = 0; i <= 10000 + amax; i++)
dp1[i] = INF;
dp1[0] = 0;
// dp[i] 为了消灭i体力所需要的最小魔法值
for (ll i = 1; i <= n; i++) {
for (ll j = a[i]; j <= h + amax; j++) { // j可以直接从a[j]开始
chmin(dp1[j], dp1[j - a[i]] + b[i]);
/*ll ncnt=j/a[i];
for(int k=0;k<=ncnt;k++)
chmin(dp1[j],dp1[j-k*a[i]]+b[i]*k);*///因为是从小到大遍历过来的所以不需要这个步骤
}
}
// 打h到h+amax之间的最小ans 可以理解吧
for (ll i = h; i <= h + amax; i++)
chmin(ans, dp1[i]);
cout << ans << endl;
//-------------------------------
return 0;
}
//---------------------------------------------------------------------------
| replace | 91 | 95 | 91 | 95 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int cut(int x) {
if (x > 0) {
return x;
} else {
return 0;
}
}
int main(void) {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
vector<int> dp(h + 1, 1000000000);
for (int i = 0; i < n; ++i) {
dp[h] = 0;
}
for (int h_i = h; h_i > -1; --h_i) {
for (int i = 0; i < n; ++i) {
if (dp[h_i] != 1000000000) {
for (int i_next = 0; i_next < n; ++i_next) {
dp[cut(h_i - a[i])] = min(dp[cut(h_i - a[i])], dp[h_i] + b[i]);
}
}
}
}
cout << dp[0] << endl;
/*
vector<pair<double, int>> eff(n, pair<double, int>());
for(int i = 0;i < n;++i){
eff[i].first = (double)b[i] / (double)a[i];
//cout << eff[i].first << endl;
eff[i].second = i;
}
sort(eff.begin(), eff.end());
int ans=0;
int eff_i = 0;
do{
ans += h/a[eff[eff_i].second] * b[eff[eff_i].second];
h = h%a[eff[eff_i].second];
eff_i++;
cout << h << " " << ans << endl;
}while(h > 0 && eff_i < n);
cout << endl;
cout << ans << endl;
if(h > 0){
int min_cost = 1000000000;
int min_i;
for(int i = 0;i < n;++i){
int cost = (int)ceil((double)h/(double)a[i]) * b[i];
cout << cost << endl;
if(min_cost > cost){
min_cost = cost;
min_i = i;
}
}
ans += min_cost;
}
/*
int min_b = 1000000000;
if(h > 0){
for(int i = 0;i < n;++i){
if(min_b > b[i] && h-a[i] <= 0){
min_b = b[i];
}
}
ans += min_b;
}*/
/*
int min_cost = 1000000000;
int min_i;
for(int i = 0;i < n;++i){
int cost = (int)ceil((double)h/(double)a[i]) * b[i];
if(min_cost > cost){
min_cost = cost;
min_i = i;
}
}
ans += min_cost;
*/
// cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define ll long long
int cut(int x) {
if (x > 0) {
return x;
} else {
return 0;
}
}
int main(void) {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
vector<int> dp(h + 1, 1000000000);
for (int i = 0; i < n; ++i) {
dp[h] = 0;
}
for (int h_i = h; h_i > -1; --h_i) {
for (int i = 0; i < n; ++i) {
if (dp[h_i] != 1000000000) {
dp[cut(h_i - a[i])] = min(dp[cut(h_i - a[i])], dp[h_i] + b[i]);
}
}
}
cout << dp[0] << endl;
/*
vector<pair<double, int>> eff(n, pair<double, int>());
for(int i = 0;i < n;++i){
eff[i].first = (double)b[i] / (double)a[i];
//cout << eff[i].first << endl;
eff[i].second = i;
}
sort(eff.begin(), eff.end());
int ans=0;
int eff_i = 0;
do{
ans += h/a[eff[eff_i].second] * b[eff[eff_i].second];
h = h%a[eff[eff_i].second];
eff_i++;
cout << h << " " << ans << endl;
}while(h > 0 && eff_i < n);
cout << endl;
cout << ans << endl;
if(h > 0){
int min_cost = 1000000000;
int min_i;
for(int i = 0;i < n;++i){
int cost = (int)ceil((double)h/(double)a[i]) * b[i];
cout << cost << endl;
if(min_cost > cost){
min_cost = cost;
min_i = i;
}
}
ans += min_cost;
}
/*
int min_b = 1000000000;
if(h > 0){
for(int i = 0;i < n;++i){
if(min_b > b[i] && h-a[i] <= 0){
min_b = b[i];
}
}
ans += min_b;
}*/
/*
int min_cost = 1000000000;
int min_i;
for(int i = 0;i < n;++i){
int cost = (int)ceil((double)h/(double)a[i]) * b[i];
if(min_cost > cost){
min_cost = cost;
min_i = i;
}
}
ans += min_cost;
*/
// cout << ans << endl;
return 0;
} | replace | 36 | 39 | 36 | 37 | TLE | |
p02787 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int H, N;
cin >> H >> N;
int dp[H + 1];
const int INF = 1 << 30;
fill(dp, dp + H, INF);
dp[H] = 0;
while (N--) {
int a, b;
cin >> a >> b;
for (int i = H; i >= a; i--)
dp[i - a] = min(dp[i - a], b + dp[i]);
for (int i = a - 1; i >= 0; i--)
dp[0] = min(dp[0], b + dp[i]);
}
cout << dp[0] << endl;
}
| #include <iostream>
using namespace std;
int main() {
int H, N;
cin >> H >> N;
int dp[H + 1];
const int INF = 1 << 30;
fill(dp, dp + H, INF);
dp[H] = 0;
while (N--) {
int a, b;
cin >> a >> b;
for (int i = H; i >= a; i--)
dp[i - a] = min(dp[i - a], b + dp[i]);
for (int i = min(H, a - 1); i >= 0; i--)
dp[0] = min(dp[0], b + dp[i]);
}
cout << dp[0] << endl;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LL long long
#define maxn 200010
#define inf 0x3f3f3f3f3f3f
using namespace std;
LL dp[10010];
LL a[1010], b[1010];
int main() {
int n, w;
cin >> w >> n;
LL ma = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
ma = max(ma, b[i]);
}
for (int i = 0; i <= w + ma; ++i) {
dp[i] = inf;
}
for (int i = 0; i <= w + ma; ++i) {
if (i % a[0] == 0) {
dp[i] = b[0] * (i / a[0]);
}
}
for (int i = 1; i < n; ++i) {
for (int j = a[i]; j <= w + ma; ++j) {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
}
}
LL ans = inf;
for (int i = w; i <= w + ma; ++i) {
ans = min(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define LL long long
#define maxn 200010
#define inf 0x3f3f3f3f3f3f
using namespace std;
LL dp[100010];
LL a[1010], b[1010];
int main() {
int n, w;
cin >> w >> n;
LL ma = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
ma = max(ma, b[i]);
}
for (int i = 0; i <= w + ma; ++i) {
dp[i] = inf;
}
for (int i = 0; i <= w + ma; ++i) {
if (i % a[0] == 0) {
dp[i] = b[0] * (i / a[0]);
}
}
for (int i = 1; i < n; ++i) {
for (int j = a[i]; j <= w + ma; ++j) {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
}
}
LL ans = inf;
for (int i = w; i <= w + ma; ++i) {
ans = min(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02787 | C++ | Runtime Error | #include <array>
#include <cstdio>
constexpr int inf = 1e9 + 334 + 810 + 1919;
constexpr int MAX_H = 1000;
std::array<int, MAX_H + 1> DP;
int readInt(void) {
char c;
do {
c = getchar_unlocked();
} while (c < '0');
int res = 0;
do {
res = 10 * res + c - '0';
c = getchar_unlocked();
} while (c >= '0');
return res;
}
int main(void) {
int H, n;
H = readInt();
n = readInt();
for (int i = 0; i < H; ++i)
DP[i] = inf;
DP[H] = 0;
for (int _ = 0; _ < n; ++_) {
int a, b;
a = readInt();
b = readInt();
int i;
for (i = H; i >= a; --i)
if (DP[i - a] > DP[i] + b)
DP[i - a] = DP[i] + b;
for (; i; --i)
if (DP[0] > DP[i] + b)
DP[0] = DP[i] + b;
}
printf("%d\n", DP[0]);
return 0;
} | #include <array>
#include <cstdio>
constexpr int inf = 1e9 + 334 + 810 + 1919;
constexpr int MAX_H = 1e4;
std::array<int, MAX_H + 1> DP;
int readInt(void) {
char c;
do {
c = getchar_unlocked();
} while (c < '0');
int res = 0;
do {
res = 10 * res + c - '0';
c = getchar_unlocked();
} while (c >= '0');
return res;
}
int main(void) {
int H, n;
H = readInt();
n = readInt();
for (int i = 0; i < H; ++i)
DP[i] = inf;
DP[H] = 0;
for (int _ = 0; _ < n; ++_) {
int a, b;
a = readInt();
b = readInt();
int i;
for (i = H; i >= a; --i)
if (DP[i - a] > DP[i] + b)
DP[i - a] = DP[i] + b;
for (; i; --i)
if (DP[0] > DP[i] + b)
DP[0] = DP[i] + b;
}
printf("%d\n", DP[0]);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
pll A[105];
ll dp[105][10005];
int main() {
ll H, N;
cin >> H >> N;
REP(i, N) { cin >> A[i].first >> A[i].second; }
REP(i, N + 1) {
REP(j, H + 1) { dp[i][j] = INF; }
}
dp[0][0] = 0;
REP(i, N) {
REP(j, H + 1) {
dp[i + 1][j] = std::min(dp[i][j], dp[i + 1][j]);
ll d = std::min(H, j + A[i].first);
dp[i + 1][d] = std::min(dp[i + 1][d], dp[i + 1][j] + A[i].second);
}
}
cout << dp[N][H] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
pll A[1005];
ll dp[1005][10005];
int main() {
ll H, N;
cin >> H >> N;
REP(i, N) { cin >> A[i].first >> A[i].second; }
REP(i, N + 1) {
REP(j, H + 1) { dp[i][j] = INF; }
}
dp[0][0] = 0;
REP(i, N) {
REP(j, H + 1) {
dp[i + 1][j] = std::min(dp[i][j], dp[i + 1][j]);
ll d = std::min(H, j + A[i].first);
dp[i + 1][d] = std::min(dp[i + 1][d], dp[i + 1][j] + A[i].second);
}
}
cout << dp[N][H] << endl;
return 0;
} | replace | 14 | 16 | 14 | 16 | 0 | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(), (c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {
cerr << str << " : " << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
int idx = str.find(',');
cerr << str.substr(0, idx) << " : " << t << ", ";
dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &p) {
os << "[ ";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, const set<T> &p) {
os << "[ ";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const map<S, T> &p) {
os << "[ ";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> void prc(T a, T b) {
cerr << "[";
for (T i = a; i != b; ++i) {
if (i != a)
cerr << ", ";
cerr << *i;
}
cerr << "]\n";
}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//
bool cmp(const pair<int, int> a, const pair<int, int> b) {
int x = a.first * b.second, y = b.first * a.second;
return x > y;
}
vector<pair<int, int>> v;
map<pair<int, int>, int> store;
int f(int j, int h) {
if (j >= (int)v.size())
return M;
if (store.find({j, h}) != store.end())
return store[{j, h}];
int ans = M;
int ini_h = h;
// ans += (h/v[i].first)*v[i].second;
// h = h%v[i].first;
// int z = v[i].second;
// if(!h) z = 0;
// pr(i, h, ans + z);
// ans = ans + z;
for (int i = 0;; i++) {
if (v[j].first * i > h) {
int t = (h / v[j].first) * v[j].second;
if (h % v[j].first)
t += v[j].second;
ans = min(ans, t);
break;
}
int temp = v[j].first * i;
int at = v[j].second * i + f(j + 1, h - temp);
ans = min(ans, at);
}
store[{j, h}] = ans;
return ans;
// return min(ans + min(z, f(i+1, h)), f(i+1, ini_h));
}
int32_t main() {
fastio;
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int h, n;
cin >> h >> n;
v.resize(n);
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
}
sort(all(v), cmp);
cout << f(0, h) << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(), (c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {
cerr << str << " : " << t << "\n";
}
template <class T, class... S> void dbs(string str, T t, S... s) {
int idx = str.find(',');
cerr << str.substr(0, idx) << " : " << t << ", ";
dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &p) {
os << "[ ";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> ostream &operator<<(ostream &os, const set<T> &p) {
os << "[ ";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class S, class T>
ostream &operator<<(ostream &os, const map<S, T> &p) {
os << "[ ";
for (auto &it : p)
os << it << " ";
return os << "]";
}
template <class T> void prc(T a, T b) {
cerr << "[";
for (T i = a; i != b; ++i) {
if (i != a)
cerr << ", ";
cerr << *i;
}
cerr << "]\n";
}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//
bool cmp(const pair<int, int> a, const pair<int, int> b) {
int x = a.first * b.second, y = b.first * a.second;
return x > y;
}
vector<pair<int, int>> v;
map<pair<int, int>, int> store;
int f(int j, int h) {
if (j >= (int)v.size())
return M;
if (store.find({j, h}) != store.end())
return store[{j, h}];
int ans = M;
int ini_h = h;
// ans += (h/v[i].first)*v[i].second;
// h = h%v[i].first;
// int z = v[i].second;
// if(!h) z = 0;
// pr(i, h, ans + z);
// ans = ans + z;
for (int i = 0;; i++) {
if (v[j].first * i > h) {
int t = (h / v[j].first) * v[j].second;
if (h % v[j].first)
t += v[j].second;
ans = min(ans, t);
break;
}
int temp = v[j].first * i;
int at = v[j].second * i + f(j + 1, h - temp);
ans = min(ans, at);
}
store[{j, h}] = ans;
return ans;
// return min(ans + min(z, f(i+1, h)), f(i+1, ini_h));
}
int32_t main() {
fastio;
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int h, n;
cin >> h >> n;
v.resize(n);
for (int i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
}
vector<int> knapsack(h + 1, M);
knapsack[h] = 0;
for (int i = 0; i < n; i++) {
for (int j = h; j >= 0; j--) {
if (knapsack[j] != M) {
int z = max(0LL, j - v[i].first);
knapsack[z] = min(knapsack[z], knapsack[j] + v[i].second);
}
}
}
cout << knapsack[0] << "\n";
return 0;
}
| replace | 106 | 108 | 106 | 118 | TLE | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
// #define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
int dp[10010];
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
rep(i, 10010) dp[i] = INF;
dp[0] = 0;
rep(i, N) rep(j, H + 1) {
if (j >= A[i])
dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
if (j == H)
repr(k, j - A[i], j) dp[j] = min(dp[j], dp[k] + B[i]);
}
cout << dp[H] << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
// #define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
int dp[10010];
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
rep(i, 10010) dp[i] = INF;
dp[0] = 0;
rep(i, N) rep(j, H + 1) {
if (j >= A[i])
dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
if (j == H)
repr(k, max(0, j - A[i]), j) dp[j] = min(dp[j], dp[k] + B[i]);
}
cout << dp[H] << endl;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, 1e18));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < a[i - 1]; ++j) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j], dp[i - 1][0] + b[i - 1]);
}
for (int j = a[i - 1]; j <= h; ++j) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]);
}
}
cout << dp[n][h] << "\n";
return 0;
}
| #include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(h + 1, 1e18));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < min(h + 1, a[i - 1]); ++j) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j], dp[i - 1][0] + b[i - 1]);
}
for (int j = a[i - 1]; j <= h; ++j) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]);
}
}
cout << dp[n][h] << "\n";
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define endl "\n"
#define all(v) v.begin(), v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vecin(v) \
for (int i = 0; i < (int)v.size(); i++) \
cin >> v[i];
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
int z00 = 1;
for (int i = 0; i < y00; i++) {
z00 *= x00;
}
return z00;
}
int keta(int x00) {
int z00 = x00;
int w00 = 0;
while (z00 != 0) {
z00 /= 10;
w00++;
}
return w00;
}
int krag(double xx) { return INF - (int)(INF - xx); }
int modinv(int a, int m) {
int b = m, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int modpow(int a, int n) {
int res = 1;
while (n > 0) {
if (n & 1)
res *a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int com(int xx, int yy) {
int zz = 1;
for (int i = xx; i > xx - yy; i--) {
zz *= i;
zz %= mod;
}
for (int i = 1; i <= yy; i++) {
zz *= modinv(i, mod);
zz %= mod;
}
return zz;
}
int gcd(int xx, int yy) {
int p = xx;
int q = yy;
if (q > p)
swap(p, q);
while (p % q != 0) {
p %= q;
swap(p, q);
}
return q;
}
int lcm(int xx, int yy) { return xx * yy / gcd(xx, yy); }
bool prime(int xx) {
int a = xx;
for (int i = 2; i * i <= xx; i++) {
if (xx % i == 0) {
return 0;
}
}
return 1;
}
signed main() {
int h, n, i = 0;
cin >> h >> n;
vector<pair<int, int>> vec(n);
rep(i, n) { cin >> vec[i].first >> vec[i].second; }
vector<int> DP(50000000, 0); // 魔力をiとしDP[i]をダメージとする
DP[0] = 0;
while (1) {
i++;
rep(j, n) {
if (i - vec[j].second >= 0) {
DP[i] = max(DP[i], DP[i - vec[j].second] + vec[j].first);
if (DP[i] >= h) {
cout << i << endl;
return 0;
}
}
}
}
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define int long long
#define endl "\n"
#define all(v) v.begin(), v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vecin(v) \
for (int i = 0; i < (int)v.size(); i++) \
cin >> v[i];
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
int z00 = 1;
for (int i = 0; i < y00; i++) {
z00 *= x00;
}
return z00;
}
int keta(int x00) {
int z00 = x00;
int w00 = 0;
while (z00 != 0) {
z00 /= 10;
w00++;
}
return w00;
}
int krag(double xx) { return INF - (int)(INF - xx); }
int modinv(int a, int m) {
int b = m, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
int modpow(int a, int n) {
int res = 1;
while (n > 0) {
if (n & 1)
res *a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int com(int xx, int yy) {
int zz = 1;
for (int i = xx; i > xx - yy; i--) {
zz *= i;
zz %= mod;
}
for (int i = 1; i <= yy; i++) {
zz *= modinv(i, mod);
zz %= mod;
}
return zz;
}
int gcd(int xx, int yy) {
int p = xx;
int q = yy;
if (q > p)
swap(p, q);
while (p % q != 0) {
p %= q;
swap(p, q);
}
return q;
}
int lcm(int xx, int yy) { return xx * yy / gcd(xx, yy); }
bool prime(int xx) {
int a = xx;
for (int i = 2; i * i <= xx; i++) {
if (xx % i == 0) {
return 0;
}
}
return 1;
}
signed main() {
int h, n, i = 0;
cin >> h >> n;
vector<pair<int, int>> vec(n);
rep(i, n) { cin >> vec[i].first >> vec[i].second; }
vector<int> DP(100000000, 0); // 魔力をiとしDP[i]をダメージとする
DP[0] = 0;
while (1) {
i++;
rep(j, n) {
if (i - vec[j].second >= 0) {
DP[i] = max(DP[i], DP[i - vec[j].second] + vec[j].first);
if (DP[i] >= h) {
cout << i << endl;
return 0;
}
}
}
}
}
| replace | 119 | 120 | 119 | 120 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02787 | C++ | Time Limit Exceeded | #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>;
const int INF = 1001001001;
int main() {
int h, n;
cin >> h >> n;
vector<vector<int>> ab(n, vector<int>(2, 0));
for (auto &v : ab) {
cin >> v[0] >> v[1];
}
vector<vector<int>> dp(n + 1, vector<int>(h + 1, INF));
rep(j, h + 1) { dp[0][j] = ((j + ab[0][0] - 1) / ab[0][0]) * ab[0][1]; }
rep(i, n) {
rep(j, h + 1) {
int t = j / ab[i][0];
rep(k, t + 2) {
if (i == 0)
continue;
dp[i][j] = min(min(dp[min(i - 1, n)][j],
dp[i][max(j - k * ab[i][0], 0)] + k * ab[i][1]),
dp[i][j]);
}
}
}
cout << dp[n - 1][h] << 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;
using P = pair<int, int>;
const int INF = 1001001001;
int main() {
int h, n;
cin >> h >> n;
vector<vector<int>> ab(n, vector<int>(2, 0));
for (auto &v : ab) {
cin >> v[0] >> v[1];
}
vector<vector<int>> dp(n + 1, vector<int>(h + 1, INF));
rep(j, h + 1) { dp[0][j] = ((j + ab[0][0] - 1) / ab[0][0]) * ab[0][1]; }
rep(i, n) {
rep(j, h + 1) {
if (i == 0)
continue;
dp[i][j] =
min(min(dp[min(i - 1, n)][j], dp[i][max(j - ab[i][0], 0)] + ab[i][1]),
dp[i][j]);
}
}
cout << dp[n - 1][h] << endl;
return 0;
}
| replace | 22 | 30 | 22 | 27 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
#define i_7 (long long)(1e9 + 7)
// #define i_7 998'244'353
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
long long po(long a, long b) {
if (b == 0) {
return 1;
}
long long z = po(a, b / 2);
z = mod(z * z);
if (b % 2 != 0) {
z = mod(a * z);
}
return z;
}
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= std::sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
std::swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
// using namespace std;
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;
int main() {
using namespace std;
int h, n;
cin >> h >> n;
int a[n], b[n];
REP(i, n) { cin >> a[i] >> b[i]; }
int dp[h + 1][n];
fill(dp[0], dp[h + 1], 1'000'000'000);
REP(i, n) {
REP(j, h + 1) {
if (j == 0) {
dp[j][i] = 0;
continue;
}
if (i == 0) {
dp[j][i] = ((j + a[i] - 1) / a[i]) * b[i];
continue;
}
int q = h / a[i];
REP(x, q + 1) {
dp[j][i] = min(dp[j][i], dp[j - x * a[i]][i - 1] + x * b[i]);
}
}
}
int ans = dp[h][n - 1];
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
#define i_7 (long long)(1e9 + 7)
// #define i_7 998'244'353
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
long long po(long a, long b) {
if (b == 0) {
return 1;
}
long long z = po(a, b / 2);
z = mod(z * z);
if (b % 2 != 0) {
z = mod(a * z);
}
return z;
}
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= std::sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
std::swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
// using namespace std;
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;
int main() {
using namespace std;
int h, n;
cin >> h >> n;
int a[n], b[n];
REP(i, n) { cin >> a[i] >> b[i]; }
int dp[h + 1][n];
fill(dp[0], dp[h + 1], 1'000'000'000);
REP(i, n) {
REP(j, h + 1) {
if (j == 0) {
dp[j][i] = 0;
continue;
}
if (i == 0) {
dp[j][i] = ((j + a[i] - 1) / a[i]) * b[i];
continue;
}
dp[j][i] = min(dp[j][i], dp[j][i - 1]);
if (j - a[i] >= 0) {
dp[j][i] = min(dp[j][i], dp[j - a[i]][i] + b[i]);
} else {
dp[j][i] = min(dp[j][i], b[i]);
}
}
}
int ans = dp[h][n - 1];
cout << ans << endl;
return 0;
}
| replace | 85 | 88 | 85 | 90 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define pque priority_queue
#define rep(i, l, r) for (i = (l); i <= (r); ++i)
#define per(i, l, r) for (i = (l); i >= (r); --i)
#define REP(i, l, r) for (i = (l); i < (r); ++i)
#define PER(i, l, r) for (i = (l); i > (r); --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template <class IT> inline void cmax(IT &a, IT b) {
if (a < b)
a = b;
}
template <class IT> inline void cmin(IT &a, IT b) {
if (b < a)
a = b;
}
const int N = 10005, inf = 1000000000;
int dp[N];
int main() {
int h, n, a, b, i, ans = inf;
scanf("%d%d", &h, &n);
REP(i, 1, h) dp[i] = inf;
while (n--) {
scanf("%d%d", &a, &b);
REP(i, a, h) cmin(dp[i], dp[i - a] + b);
REP(i, h - a, h) cmin(ans, dp[i] + b);
// REP(i, 0 ,h)printf("%d ",dp[i]);printf("ans=%d\n",ans);
}
printf("%d", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define pque priority_queue
#define rep(i, l, r) for (i = (l); i <= (r); ++i)
#define per(i, l, r) for (i = (l); i >= (r); --i)
#define REP(i, l, r) for (i = (l); i < (r); ++i)
#define PER(i, l, r) for (i = (l); i > (r); --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template <class IT> inline void cmax(IT &a, IT b) {
if (a < b)
a = b;
}
template <class IT> inline void cmin(IT &a, IT b) {
if (b < a)
a = b;
}
const int N = 10005, inf = 1000000000;
int dp[N];
int main() {
int h, n, a, b, i, ans = inf;
scanf("%d%d", &h, &n);
REP(i, 1, h) dp[i] = inf;
while (n--) {
scanf("%d%d", &a, &b);
REP(i, a, h) cmin(dp[i], dp[i - a] + b);
REP(i, max(h - a, 0), h) cmin(ans, dp[i] + b);
// REP(i, 0 ,h)printf("%d ",dp[i]);printf("ans=%d\n",ans);
}
printf("%d", ans);
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;
const int INF = 1001001001;
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
vector<vector<int>> dp(n + 1, vector<int>(1001, INF));
dp[0][0] = 0;
rep(i, n) {
for (int j = 0; j <= h; ++j) {
int nj = min(a[i] + j, h);
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
dp[i + 1][nj] = min(dp[i + 1][nj], dp[i + 1][j] + b[i]);
}
}
cout << dp[n][h] << endl;
} | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;
const int INF = 1001001001;
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
vector<vector<int>> dp(n + 1, vector<int>(h + 1, INF));
dp[0][0] = 0;
rep(i, n) {
for (int j = 0; j <= h; ++j) {
int nj = min(a[i] + j, h);
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
dp[i + 1][nj] = min(dp[i + 1][nj], dp[i + 1][j] + b[i]);
}
}
cout << dp[n][h] << endl;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p02787 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
struct magic {
int a, b;
};
int main() {
int h, n;
const int h_max = 1e9;
cin >> h >> n;
vector<magic> v(n);
for (auto &vi : v)
cin >> vi.a >> vi.b;
vector<int> mpv(h + 1, h_max);
mpv.at(0) = 0;
for (const auto &vi : v) {
for (int j = vi.a; j < h; j++)
mpv.at(j) = min(mpv.at(j - vi.a) + vi.b, mpv.at(j));
for (int j = 0; j < vi.a; j++)
mpv.at(h) = min(mpv.at(h - vi.a + j) + vi.b, mpv.at(h));
}
cout << mpv.at(h) << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
struct magic {
int a, b;
};
int main() {
int h, n;
const int h_max = 1e9;
cin >> h >> n;
vector<magic> v(n);
for (auto &vi : v)
cin >> vi.a >> vi.b;
vector<int> mpv(h + 1, h_max);
mpv.at(0) = 0;
for (const auto &vi : v) {
for (int j = vi.a; j < h; j++)
mpv.at(j) = min(mpv.at(j - vi.a) + vi.b, mpv.at(j));
// for(int j=0; j<vi.a; j++) mpv.at(h) = min(mpv.at(h-vi.a+j)+vi.b,
// mpv.at(h)); // ここにバグが入るのんだろう。
for (int j = max(h - vi.a, 0); j < h; j++)
mpv.at(h) = min(mpv.at(j) + vi.b, mpv.at(h));
}
cout << mpv.at(h) << endl;
return 0;
} | replace | 22 | 24 | 22 | 26 | 0 | |
p02787 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int h, n, res = 1e9;
vector<vector<int>> f;
int main() {
cin >> h >> n;
f.resize(2 * h + 1, vector<int>(n + 1, 1e9));
f[0][0] = 0;
for (int i = 1, a, b; i <= n; ++i) {
cin >> a >> b;
for (int j = 0; j <= 2e4; ++j) {
f[j][i] = f[j][i - 1];
if (j >= a)
f[j][i] = min(f[j][i], f[j - a][i] + b);
if (j >= h)
res = min(res, f[j][i]);
}
}
cout << res;
} | #include <iostream>
#include <vector>
using namespace std;
int h, n, res = 1e9;
vector<vector<int>> f;
int main() {
cin >> h >> n;
f.resize(2e4 + 1, vector<int>(n + 1, 1e9));
f[0][0] = 0;
for (int i = 1, a, b; i <= n; ++i) {
cin >> a >> b;
for (int j = 0; j <= 2e4; ++j) {
f[j][i] = f[j][i - 1];
if (j >= a)
f[j][i] = min(f[j][i], f[j - a][i] + b);
if (j >= h)
res = min(res, f[j][i]);
}
}
cout << res;
} | replace | 10 | 11 | 10 | 11 | -11 | |
p02787 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for (int i = 0; i < n; ++i)
#define rep(i, n) for (int i = 1; i <= n; ++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()
using namespace std;
using P = pair<ll, ll>;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
/**
* Usage:
*
* G[from].push_back(Edge(to, weight));
* using Graph = vector<vector<Edge>>;
*
*/
struct Edge {
int to;
ll weight;
Edge(int t, ll w) : to(t), weight(w) {}
};
/**
* Usage:
*
* chmin(old, new);
* chmax(old, new);
*
*/
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> void printv(vector<T> &v) {
if (v.size() == 0) {
cout << "\n";
return;
}
Rep(i, v.size()) { cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n'); }
}
int H, N;
int a[1100], b[1100];
int dp[1010][20010];
int main() {
cin >> H >> N;
rep(i, N) { cin >> a[i] >> b[i]; }
Rep(i, 1010) {
Rep(j, 20010) { dp[i][j] = INF; }
}
dp[0][0] = 0;
rep(i, N) {
Rep(j, 20000) {
chmin(dp[i][j], dp[i - 1][j]);
if (dp[i - 1][j] != INF) {
int ct = 1;
while (true) {
int k = j + a[i] * ct;
chmin(dp[i][k], dp[i - 1][j] + b[i] * ct);
if (k >= H)
break;
ct++;
}
}
}
}
int ans = INF;
for (int j = H; j <= 20000; ++j) {
chmin(ans, dp[N][j]);
}
cout << ans << "\n";
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for (int i = 0; i < n; ++i)
#define rep(i, n) for (int i = 1; i <= n; ++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()
using namespace std;
using P = pair<ll, ll>;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
/**
* Usage:
*
* G[from].push_back(Edge(to, weight));
* using Graph = vector<vector<Edge>>;
*
*/
struct Edge {
int to;
ll weight;
Edge(int t, ll w) : to(t), weight(w) {}
};
/**
* Usage:
*
* chmin(old, new);
* chmax(old, new);
*
*/
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> void printv(vector<T> &v) {
if (v.size() == 0) {
cout << "\n";
return;
}
Rep(i, v.size()) { cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n'); }
}
int H, N;
int a[1100], b[1100];
int dp[1010][20010];
int main() {
cin >> H >> N;
rep(i, N) { cin >> a[i] >> b[i]; }
Rep(i, 1010) {
Rep(j, 20010) { dp[i][j] = INF; }
}
dp[0][0] = 0;
rep(i, N) {
Rep(j, 20000) {
if (j < a[i]) {
chmin(dp[i][j], dp[i - 1][j]);
} else {
chmin(dp[i][j], min(dp[i - 1][j], dp[i][j - a[i]] + b[i]));
}
}
}
int ans = INF;
for (int j = H; j <= 20000; ++j) {
chmin(ans, dp[N][j]);
}
cout << ans << "\n";
}
| replace | 92 | 103 | 92 | 96 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int h, n;
cin >> h >> n;
vector<int> a, b;
rep(i, n) {
int A, B;
cin >> A >> B;
a.push_back(A);
b.push_back(B);
}
vector<int> dp(h, 0);
dp[0] = 0;
rep2(i, 1, h + 1) {
int mincos = INT32_MAX;
rep(j, n) {
if (i <= a[j]) {
mincos = min(mincos, b[j]);
} else {
mincos = min(mincos, dp[i - a[j]] + b[j]);
}
}
dp[i] = mincos;
}
cout << dp[h] << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int h, n;
cin >> h >> n;
vector<int> a, b;
rep(i, n) {
int A, B;
cin >> A >> B;
a.push_back(A);
b.push_back(B);
}
vector<int> dp(h + 1, 0);
dp[0] = 0;
rep2(i, 1, h + 1) {
int mincos = INT32_MAX;
rep(j, n) {
if (i <= a[j]) {
mincos = min(mincos, b[j]);
} else {
mincos = min(mincos, dp[i - a[j]] + b[j]);
}
}
dp[i] = mincos;
}
cout << dp[h] << endl;
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int h, n;
cin >> h >> n;
int a[n], b[n];
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
int dp[h + 5];
for (int i = 0; i < h + 5; ++i) {
dp[i] = 200000000;
}
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= a[i]; ++j) {
dp[j] = min(dp[j], b[i]);
}
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < n; ++j) {
if (i + a[j] <= h) {
dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
}
}
}
cout << dp[h] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int h, n;
cin >> h >> n;
int a[n], b[n];
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
int dp[100005];
for (int i = 0; i < h + 5; ++i) {
dp[i] = 200000000;
}
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= a[i]; ++j) {
dp[j] = min(dp[j], b[i]);
}
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < n; ++j) {
if (i + a[j] <= h) {
dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
}
}
}
cout << dp[h] << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INF 100000000
int main() {
int H, N;
cin >> H >> N;
vector<pair<int, int>> magic(N);
int damage, point;
for (int i = 0; i < N; i++) {
cin >> damage >> point;
magic[i] = make_pair(damage, point);
}
vector<vector<int>> dp(N + 1, vector<int>(2001, INF));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int h = 0; h < 20001; h++) {
if (h >= magic[i].first) {
dp[i + 1][h] =
min(dp[i][h], dp[i + 1][h - magic[i].first] + magic[i].second);
} else {
dp[i + 1][h] = dp[i][h];
}
}
}
int ans = INF;
for (int i = H; i < 20001; i++)
ans = min(ans, dp[N][i]);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INF 100000000
int main() {
int H, N;
cin >> H >> N;
vector<pair<int, int>> magic(N);
int damage, point;
for (int i = 0; i < N; i++) {
cin >> damage >> point;
magic[i] = make_pair(damage, point);
}
vector<vector<int>> dp(N + 1, vector<int>(20001, INF));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int h = 0; h < 20001; h++) {
if (h >= magic[i].first) {
dp[i + 1][h] =
min(dp[i][h], dp[i + 1][h - magic[i].first] + magic[i].second);
} else {
dp[i + 1][h] = dp[i][h];
}
}
}
int ans = INF;
for (int i = H; i < 20001; i++)
ans = min(ans, dp[N][i]);
cout << ans << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | -11 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
int dp[10010];
int main() {
int h, n, a[110], b[110];
cin >> h >> n;
REP(i, n) cin >> a[i] >> b[i];
REP(i, h + 1) dp[i] = 1e9;
dp[0] = 0;
REP(i, n) {
// REP(j,h+1)cout<<dp[j]<<" ";cout<<endl;
REP(j, h) {
int to = min(h, j + a[i]);
dp[to] = min(dp[to], dp[j] + b[i]);
}
}
// REP(i,h+1)cout<<dp[i]<<" ";cout<<endl;
cout << dp[h] << endl;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
int dp[10010];
int main() {
int h, n, a[1010], b[1010];
cin >> h >> n;
REP(i, n) cin >> a[i] >> b[i];
REP(i, h + 1) dp[i] = 1e9;
dp[0] = 0;
REP(i, n) {
// REP(j,h+1)cout<<dp[j]<<" ";cout<<endl;
REP(j, h) {
int to = min(h, j + a[i]);
dp[to] = min(dp[to], dp[j] + b[i]);
}
}
// REP(i,h+1)cout<<dp[i]<<" ";cout<<endl;
cout << dp[h] << endl;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, n, ans, i, j;
double cur;
cin >> h >> n;
vector<pair<int, int>> a(n);
vector<int> dp(h + 1, 1000000000);
for (i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
dp[0] = 0;
for (i = 0; i < n; i++) {
for (j = 1; j <= a[i].first; j++) {
dp[j] = min(dp[j], a[i].second);
}
for (j = a[i].first + 1; j <= h; j++) {
dp[j] = min(dp[j], dp[j - a[i].first] + a[i].second);
}
}
cout << dp[h] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, n, ans, i, j;
double cur;
cin >> h >> n;
vector<pair<int, int>> a(n);
vector<int> dp(h + 1, 1000000000);
for (i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
a[i].first = min(a[i].first, h);
}
dp[0] = 0;
for (i = 0; i < n; i++) {
for (j = 1; j <= a[i].first; j++) {
dp[j] = min(dp[j], a[i].second);
}
for (j = a[i].first + 1; j <= h; j++) {
dp[j] = min(dp[j], dp[j - a[i].first] + a[i].second);
}
}
cout << dp[h] << endl;
} | insert | 12 | 12 | 12 | 13 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<ll, ll> pi;
const int MAXN = 1005, INF = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll h, n;
cin >> h >> n;
vector<pi> spells(n);
for (int i = 0; i < n; ++i)
cin >> spells[i].f >> spells[i].s;
vector<ll> dp(MAXN, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= h; ++j) {
if (j >= spells[i].f) {
dp[j] = min(dp[j], dp[j - spells[i].f] + spells[i].s);
} else {
dp[j] = min(dp[j], spells[i].s);
}
}
}
cout << dp[h];
// for (int i = 0; i <= 10; ++i) cout << dp[i] << ' ';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<ll, ll> pi;
const int MAXN = 50000005, INF = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll h, n;
cin >> h >> n;
vector<pi> spells(n);
for (int i = 0; i < n; ++i)
cin >> spells[i].f >> spells[i].s;
vector<ll> dp(MAXN, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= h; ++j) {
if (j >= spells[i].f) {
dp[j] = min(dp[j], dp[j - spells[i].f] + spells[i].s);
} else {
dp[j] = min(dp[j], spells[i].s);
}
}
}
cout << dp[h];
// for (int i = 0; i <= 10; ++i) cout << dp[i] << ' ';
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02787 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T> using v = vector<T>;
template <class T, class U> using p = pair<T, U>;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 1; i <= n; ++i)
template <class T> T read() {
T x{};
cin >> x;
return x;
}
template <class T> v<T> read(int N) {
v<T> x(N);
REP(i, N) cin >> x[i];
return x;
}
template <class T> void write(const T &x) { cout << x << endl; }
void write(double x) { printf("%.15f\n", x); }
const ull MOD = 1000'000'007;
const ll NMAX = 1000;
const ll HMAX = 10000;
ll dp[NMAX + 10][HMAX + 10] = {};
ll N = 0;
ll H = 0;
ll A[NMAX] = {};
ll B[NMAX] = {};
ll COST[HMAX + 10] = {};
ll solve(ll h) {
if (h <= 0) {
return 0;
}
if (COST[h] > 0) {
return COST[h];
}
ll cost = 1e15;
for (ll i = 0; i < N; ++i) {
for (ll j = 1; j <= A[i]; ++j) {
cost = min(cost, B[i] + solve(h - j));
}
}
COST[h] = cost;
return cost;
}
int main() {
cin >> H >> N;
REP(i, N) { cin >> A[i] >> B[i]; }
write(solve(H));
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T> using v = vector<T>;
template <class T, class U> using p = pair<T, U>;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 1; i <= n; ++i)
template <class T> T read() {
T x{};
cin >> x;
return x;
}
template <class T> v<T> read(int N) {
v<T> x(N);
REP(i, N) cin >> x[i];
return x;
}
template <class T> void write(const T &x) { cout << x << endl; }
void write(double x) { printf("%.15f\n", x); }
const ull MOD = 1000'000'007;
const ll NMAX = 1000;
const ll HMAX = 10000;
ll dp[NMAX + 10][HMAX + 10] = {};
ll N = 0;
ll H = 0;
ll A[NMAX] = {};
ll B[NMAX] = {};
ll COST[HMAX + 10] = {};
ll solve(ll h) {
if (h <= 0) {
return 0;
}
if (COST[h] > 0) {
return COST[h];
}
ll cost = 1e15;
for (ll i = 0; i < N; ++i) {
cost = min(cost, B[i] + solve(h - A[i]));
}
COST[h] = cost;
return cost;
}
int main() {
cin >> H >> N;
REP(i, N) { cin >> A[i] >> B[i]; }
write(solve(H));
}
| replace | 66 | 69 | 66 | 67 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int h, n;
int main() {
cin >> h >> n;
vector<int> a(n, 0), b(n, 0);
rep(i, n) cin >> a[i] >> b[i];
vector<int> dp(n + 1, inf);
// 配るDP
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < h + 1; j++) {
int nj = min(j + a[i], h);
dp[nj] = min(dp[nj], dp[j] + b[i]);
}
}
/*
rep(i,n+1){
rep(j,h+1) cout<<dp[i][j]<<" ";
cout<<endl;
}*/
cout << dp[h] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int h, n;
int main() {
cin >> h >> n;
vector<int> a(n, 0), b(n, 0);
rep(i, n) cin >> a[i] >> b[i];
vector<int> dp(h + 1, inf);
// 配るDP
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < h + 1; j++) {
int nj = min(j + a[i], h);
dp[nj] = min(dp[nj], dp[j] + b[i]);
}
}
/*
rep(i,n+1){
rep(j,h+1) cout<<dp[i][j]<<" ";
cout<<endl;
}*/
cout << dp[h] << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | -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 _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
int main() {
int H, N;
cin >> H >> N;
vi A(N), B(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
vector<ll> dp(H + 1, LINF);
dp[H] = 0;
for (int i = H; i >= 1; i--) {
for (int j = 0; j < N; j++) {
if (i + A[j] <= H) {
dp[i] = min(dp[i], dp[i + A[j]] + B[j]);
}
}
}
ll res = LINF;
for (int i = 0; i < N; i++) {
for (int j = 1; j <= A[i]; j++) {
res = min(res, dp[j] + B[i]);
}
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const ll LINF = 1LL << 60;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
int main() {
int H, N;
cin >> H >> N;
vi A(N), B(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
vector<ll> dp(H + 1, LINF);
dp[H] = 0;
for (int i = H; i >= 1; i--) {
for (int j = 0; j < N; j++) {
if (i + A[j] <= H) {
dp[i] = min(dp[i], dp[i + A[j]] + B[j]);
}
}
}
ll res = LINF;
for (int i = 0; i < N; i++) {
for (int j = 1; j <= min(A[i], H); j++) {
res = min(res, dp[j] + B[i]);
}
}
cout << res << endl;
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p02787 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
const int Maxn = 1000;
const int Maxm = 10000;
const int Inf = 0x3f3f3f3f;
int a[Maxn + 5], b[Maxn + 5];
int n, h;
int f[Maxm << 1 | 5];
int mn(int a, int b) { return a < b ? a : b; }
int main() {
scanf("%d%d", &h, &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
}
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= h + Maxm; j++) {
f[j + a[i]] = mn(f[j + a[i]], f[j] + b[i]);
}
}
int ans = Inf;
for (int i = h; i <= h + Maxm; i++) {
ans = mn(ans, f[i]);
}
printf("%d\n", ans);
return 0;
}
| #include <cstdio>
#include <cstring>
const int Maxn = 1000;
const int Maxm = 10000;
const int Inf = 0x3f3f3f3f;
int a[Maxn + 5], b[Maxn + 5];
int n, h;
int f[Maxm << 1 | 5];
int mn(int a, int b) { return a < b ? a : b; }
int main() {
scanf("%d%d", &h, &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
}
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= h + Maxm - a[i]; j++) {
f[j + a[i]] = mn(f[j + a[i]], f[j] + b[i]);
}
}
int ans = Inf;
for (int i = h; i <= h + Maxm; i++) {
ans = mn(ans, f[i]);
}
printf("%d\n", ans);
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
using namespace std;
int read() {
int ans = 0, f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return ans * f;
}
const int N = 1e4 + 5;
int h, n, a[N], b[N], dp[N * 2], ans, all;
int main() {
memset(dp, 0x7f, sizeof(dp));
ans = 0x7fffffff;
h = read();
n = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
b[i] = read();
all += a[i];
}
dp[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = a[i]; j <= h * 10; ++j) {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
if (j >= h)
ans = min(ans, dp[j]);
}
printf("%d", ans);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
using namespace std;
int read() {
int ans = 0, f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return ans * f;
}
const int N = 1e4 + 5;
int h, n, a[N], b[N], dp[N * 10], ans, all;
int main() {
memset(dp, 0x7f, sizeof(dp));
ans = 0x7fffffff;
h = read();
n = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
b[i] = read();
all += a[i];
}
dp[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = a[i]; j <= h * 10; ++j) {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
if (j >= h)
ans = min(ans, dp[j]);
}
printf("%d", ans);
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;
void print(vector<vector<int>> a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
void print(vector<vector<long long int>> a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
void print(vector<int> a) {
int n = a.size();
for (int j = 0; j < n; j++) {
if (j != n - 1)
cout << a[j] << " ";
else
cout << a[j] << endl;
}
}
void print(set<int> a) {
for (auto x : a)
cout << x << " ";
cout << endl;
}
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n);
vector<int> b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
vector<vector<int>> dp(n + 1, vector<int>(h + 1, inf));
dp[0][0] = 0;
rep(i, n) {
rep(j, a[i] + 1) {
if (j == 0) {
dp[i + 1][j] = 0;
} else
dp[i + 1][j] = b[i];
}
}
rep(i, n) {
rep(j, h + 1) {
// rep2(k,max(j-a[i],0),j){
// if (k >= 0){
// dp[i + 1][j] = min({dp[i + 1][j], dp[i][j], dp[i + 1][k]
// + b[i]}); } else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
// }
if (j - a[i] >= 0)
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
else
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n][h] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;
void print(vector<vector<int>> a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
void print(vector<vector<long long int>> a) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].size(); j++) {
cout << a[i][j] << " ";
}
cout << endl;
}
}
void print(vector<int> a) {
int n = a.size();
for (int j = 0; j < n; j++) {
if (j != n - 1)
cout << a[j] << " ";
else
cout << a[j] << endl;
}
}
void print(set<int> a) {
for (auto x : a)
cout << x << " ";
cout << endl;
}
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n);
vector<int> b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
vector<vector<int>> dp(n + 1, vector<int>(h + 1, inf));
dp[0][0] = 0;
rep(i, n) {
rep(j, min(h + 1, a[i] + 1)) {
if (j == 0) {
dp[i + 1][j] = 0;
} else
dp[i + 1][j] = b[i];
}
}
rep(i, n) {
rep(j, h + 1) {
// rep2(k,max(j-a[i],0),j){
// if (k >= 0){
// dp[i + 1][j] = min({dp[i + 1][j], dp[i][j], dp[i + 1][k]
// + b[i]}); } else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
// }
if (j - a[i] >= 0)
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
else
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n][h] << endl;
return 0;
} | replace | 65 | 66 | 65 | 66 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define pb emplace_back
#define re return
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265359;
ll x, n;
pair<int, int> a[1000];
ll dp[10050];
ll solve(ll h) {
if (!h)
re 0;
if (dp[h] != -1)
re dp[h];
ll ans = 1e18;
for (int i = 0; i < n; i++)
ans = min(ans, a[i].se + solve(h - a[i].fi));
dp[h] = ans;
re ans;
}
int main() {
// freopen("distance.in", "r", stdin);
// freopen("distance.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> x >> n;
for (int i = 0; i < n; i++)
cin >> a[i].fi >> a[i].se;
memset(dp, -1, sizeof(dp));
cout << solve(x);
}
/// ACTUAL CODE STARTS HERE:
// I'm red in soul
/*
▄▀▀▀▄
▄███▀░◐░░░▌
▌░░░░░▐
▐░░░░░▐
▌░░░░░▐▄▄
▌░░░░▄▀▒▒▀▀▀▀▄
▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
▌▌░▌▌
▌▌░▌▌
▄▄▌▌▄▌▌ */
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define pb emplace_back
#define re return
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265359;
ll x, n;
pair<int, int> a[1000];
ll dp[10050];
ll solve(ll h) {
if (h <= 0)
re 0;
if (dp[h] != -1)
re dp[h];
ll ans = 1e18;
for (int i = 0; i < n; i++)
ans = min(ans, a[i].se + solve(h - a[i].fi));
dp[h] = ans;
re ans;
}
int main() {
// freopen("distance.in", "r", stdin);
// freopen("distance.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> x >> n;
for (int i = 0; i < n; i++)
cin >> a[i].fi >> a[i].se;
memset(dp, -1, sizeof(dp));
cout << solve(x);
}
/// ACTUAL CODE STARTS HERE:
// I'm red in soul
/*
▄▀▀▀▄
▄███▀░◐░░░▌
▌░░░░░▐
▐░░░░░▐
▌░░░░░▐▄▄
▌░░░░▄▀▒▒▀▀▀▀▄
▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
▌▌░▌▌
▌▌░▌▌
▄▄▌▌▄▌▌ */
| replace | 31 | 32 | 31 | 32 | 0 | |
p02787 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using Graph = vector<vector<int>>;
typedef long long ll;
using Graph = vector<vector<pair<ll, ll>>>;
const int mod = 1e+9 + 7;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const ll INF = 1e10;
int main() {
ll h, n;
cin >> h >> n;
vector<ll> dp(n + 1, INF);
dp[0] = 0;
rep(i, n) {
ll a, b;
cin >> a >> b;
rep(j, h + 1) {
int idx = min(j + a, h);
dp[idx] = min(dp[idx], dp[j] + b);
}
}
cout << dp[h] << endl;
}
| // #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using Graph = vector<vector<int>>;
typedef long long ll;
using Graph = vector<vector<pair<ll, ll>>>;
const int mod = 1e+9 + 7;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const ll INF = 1e10;
int main() {
ll h, n;
cin >> h >> n;
vector<ll> dp(h + 1, INF);
dp[0] = 0;
rep(i, n) {
ll a, b;
cin >> a >> b;
rep(j, h + 1) {
int idx = min(j + a, h);
dp[idx] = min(dp[idx], dp[j] + b);
}
}
cout << dp[h] << endl;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <fstream>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(), (a).end()
#define INF_INT (1 << 30)
#define INF_LL (1ll << 62)
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[1010][10100], H, N;
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
int main() {
cin >> H >> N;
ll A[N], B[N];
rep(i, N) { cin >> A[i] >> B[i]; }
rep(i, N) rep(j, 10100) if (j) dp[i][j] = 10000000;
rep(i, N) {
rep(j, H + 1) {
if (j < A[i])
dp[i][j] = min(dp[i - 1][j], B[i]);
else
dp[i][j] = min(min(dp[i - 1][j], dp[i - 1][j - A[i]] + B[i]),
dp[i][j - A[i]] + B[i]);
}
}
out(dp[N - 1][H]);
} | #include <algorithm>
#include <fstream>
#include <iostream>
#include <limits>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(), (a).end()
#define INF_INT (1 << 30)
#define INF_LL (1ll << 62)
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[1010][10100], H, N;
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
int main() {
cin >> H >> N;
ll A[N], B[N];
rep(i, N) { cin >> A[i] >> B[i]; }
rep(i, N) rep(j, 10010) if (j) dp[i][j] = 10000000;
repi(j, 1, H + 1) {
if (j < A[0])
dp[0][j] = B[0];
else
dp[0][j] = dp[0][j - A[0]] + B[0];
}
repi(i, 1, N) {
rep(j, H + 1) {
if (j < A[i])
dp[i][j] = min(dp[i - 1][j], B[i]);
else
dp[i][j] = min(min(dp[i - 1][j], dp[i - 1][j - A[i]] + B[i]),
dp[i][j - A[i]] + B[i]);
}
}
out(dp[N - 1][H]);
} | replace | 53 | 55 | 53 | 61 | -11 | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>
#include <time.h>
#define pb push_back
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / __gcd((a), (b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define ign cin.ignore();
#define o_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define o_setll \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// member functions :
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set
using namespace std;
using namespace __gnu_pbds;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
ll dp[20010];
ll wt[1010], val[1010];
ll n, W;
void KnapSack(ll n, ll W, ll maxi) {
for (ll i = 0; i < n; i++)
for (ll j = 0; j < W + maxi; j++) {
for (ll k = 1;; k++) {
if (j + k * wt[i] >= W + maxi)
break;
dp[j + k * wt[i]] = min(dp[j + k * wt[i]], k * val[i] + dp[j]);
}
}
}
int main() {
IOS ll maxi = -1;
for (int i = 0; i < 20010; i++) {
dp[i] = 1e12;
}
dp[0] = 0;
ll W, n;
cin >> W >> n;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
maxi = max(maxi, wt[i]);
}
KnapSack(n, W, maxi);
ll mini = LLONG_MAX;
for (ll i = W; i < W + maxi; i++) {
mini = min(mini, dp[i]);
}
cout << mini << "\n";
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>
#include <time.h>
#define pb push_back
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / __gcd((a), (b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define ign cin.ignore();
#define o_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define o_setll \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// member functions :
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set
using namespace std;
using namespace __gnu_pbds;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
ll dp[20010];
ll wt[1010], val[1010];
ll n, W;
void KnapSack(ll n, ll W, ll maxi) {
for (ll i = 0; i < n; i++)
for (ll j = 0; j < W + maxi; j++) {
if (j + wt[i] >= W + maxi)
break;
dp[j + wt[i]] = min(dp[j + wt[i]], val[i] + dp[j]);
}
}
int main() {
IOS ll maxi = -1;
for (int i = 0; i < 20010; i++) {
dp[i] = 1e12;
}
dp[0] = 0;
ll W, n;
cin >> W >> n;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
maxi = max(maxi, wt[i]);
}
KnapSack(n, W, maxi);
ll mini = LLONG_MAX;
for (ll i = W; i < W + maxi; i++) {
mini = min(mini, dp[i]);
}
cout << mini << "\n";
return 0;
}
| replace | 91 | 96 | 91 | 94 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n - 1; i >= 0; i--)
typedef long long ll;
#define INF 1e18
int main() {
ll h;
cin >> h;
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
REP(i, n) {
cin >> a[i];
cin >> b[i];
}
vector<ll> m(h + 1, INF);
m[0] = 0;
FOR(i, 0, h) {
REP(j, n) {
FOR(k, i + 1, i + a[j] + 1) {
if (k > h)
break;
m[k] = min(m[k], m[i] + b[j]);
}
}
// cout << "m: "; REP(i,(signed)m.size()) cout<<m[i]<<" "; cout << endl;
// //----------cout----------//
}
cout << m[h] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n - 1; i >= 0; i--)
typedef long long ll;
#define INF 1e18
int main() {
ll h;
cin >> h;
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> b(n);
REP(i, n) {
cin >> a[i];
cin >> b[i];
}
vector<ll> m(h + 1, INF);
m[0] = 0;
REP(j, n) {
FOR(k, 1, a[j] + 1) {
if (k > h)
break;
m[k] = min(m[k], b[j]);
}
}
// cout << "m: "; REP(i,(signed)m.size()) cout<<m[i]<<" "; cout << endl;
// //----------cout----------//
REP(i, h) {
FOR(j, 1, h) {
if (j + i > h)
break;
m[j + i] = min(m[j + i], m[i] + m[j]);
}
// cout << "m: "; REP(i,(signed)m.size()) cout<<m[i]<<" "; cout << endl;
// //----------cout----------//
}
cout << m[h] << endl;
return 0;
} | replace | 29 | 36 | 29 | 43 | TLE | |
p02787 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P std::pair<int, int>
#define PiP std::pair<int, std::pair<int, int>>
#define all(v) v.begin(), v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T, vector<T>, greater<T>>
using namespace std;
template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x != 1;
}
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; }
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 = mod) {
int res = 1;
x %= m;
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 get_rand(int MIN, int MAX) {
std::random_device rnd;
std::mt19937 mt32(rnd());
std::uniform_int_distribution<int> engine(MIN, MAX);
return engine(mt32);
}
struct BIT {
vector<int> bit;
int n;
BIT(int x) {
bit.resize(x + 1, 0);
n = x;
}
void add(int x, int y) {
while (x <= n) {
bit[x] += y;
x += x & -x;
}
}
int sum(int x) {
int res = 0;
while (x > 0) {
res += bit[x];
x -= x & -x;
}
return res;
}
};
struct UnionFind {
vector<int> par, size;
UnionFind(int x) {
par.resize(x);
size.resize(x, 1);
rep(i, x) par[i] = i;
}
int find(int x) {
if (par[x] == x)
return x;
return par[x] = find(par[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
int consize(int x) { return size[find(x)]; }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (size[x] < size[y]) {
par[x] = y;
size[y] += size[x];
} else {
par[y] = x;
size[x] += size[y];
}
}
};
struct Tree {
int size;
vector<int> par, depth;
vector<int> doubling[30];
vector<vector<int>> G;
int root = 0;
Tree(int x) {
par.resize(x);
depth.resize(x);
rep(i, 30) { doubling[i].resize(x, -1); }
G.resize(x);
size = x;
}
void add_edge(int x, int y) {
G[x].push_back(y);
G[y].push_back(x);
}
void dfs(int x) {
for (int i : G[x]) {
if (depth[i] == -1) {
depth[i] = depth[x] + 1;
doubling[0][i] = x;
dfs(i);
}
}
}
void init() {
rep(i, size) depth[i] = -1;
depth[root] = 0;
dfs(root);
rep(i, 29) {
rep(j, size) {
if (doubling[i][j] == -1)
doubling[i + 1][j] = -1;
else
doubling[i + 1][j] = doubling[i][doubling[i][j]];
}
}
}
int lca(int x, int y) {
if (depth[x] > depth[y])
swap(x, y);
for (int i = 29; i >= 0; i--) {
if ((depth[y] - depth[x]) >> i & 1) {
y = doubling[i][y];
}
}
if (x == y)
return x;
for (int i = 29; i >= 0; i--) {
if (doubling[i][x] != doubling[i][y]) {
x = doubling[i][x];
y = doubling[i][y];
}
}
return doubling[0][x];
}
};
struct RollingHash {
int Base = 283;
const int MASK30 = (1ll << 30) - 1;
const int MASK31 = (1ll << 31) - 1;
const int MOD = (1ll << 61) - 1;
vector<int> hash, power;
int calcmod(int val) {
val = (val & MOD) + (val >> 61);
if (val > MOD)
val -= MOD;
return val;
}
int mul(int x, int y) {
int xu = x >> 31;
int xd = x & MASK31;
int yu = y >> 31;
int yd = y & MASK31;
int mid = xd * yu + xu * yd;
int midu = mid >> 30;
int midd = mid & MASK30;
return calcmod(xu * yu * 2 + midu + (midd << 31) + xd * yd);
}
RollingHash(string s) {
// Base=get_rand(1<<7,1<<8);
int sz = s.size();
hash.resize(sz + 1, 0);
power.resize(sz + 1, 1);
rep(i, sz) {
hash[i + 1] = (mul(hash[i], Base) + s[i]) % MOD;
power[i + 1] = mul(power[i], Base) % MOD;
}
}
int get(int l, int r) {
int res = (hash[r] - mul(hash[l], power[r - l]) + MOD) % MOD;
return res;
}
int lcp(int x, int y) {
int len = min(hash.size() - y, hash.size() - x);
int ok = 0, ng = len + 1;
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (get(x, x + mid) == get(y, y + mid))
ok = mid;
else
ng = mid;
}
return ok;
}
};
struct Segtree {
int size = 1;
vector<int> dat, lazy;
Segtree(int x) {
while (size < x)
size *= 2;
dat.resize(size * 2 - 1, inf);
lazy.resize(size * 2 - 1, inf);
}
void eval(int k, int l, int r) {
chmin(dat[k], lazy[k]);
if (r - l > 1) {
chmin(lazy[k * 2 + 1], lazy[k]);
chmin(lazy[k * 2 + 2], lazy[k]);
}
lazy[k] = inf;
}
void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = size;
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
chmin(lazy[k], x);
eval(k, l, r);
return;
}
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
int query(int a, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = size;
eval(k, l, r);
if (r - l == 1) {
return dat[k];
}
if (a < (l + r) / 2) {
return query(a, k * 2 + 1, l, (l + r) / 2);
}
return query(a, k * 2 + 2, (l + r) / 2, r);
}
};
template <class T> vector<int> KMP(vector<T> target, vector<T> pattern) {
vector<int> table(pattern.size() + 1);
table[0] = 0;
int j = 0;
REP(i, (int)pattern.size()) {
if (pattern[i] == pattern[j]) {
table[i] = j++;
} else {
table[i] = j;
j = 0;
}
}
table[pattern.size()] = j;
j = 0;
vector<int> res;
int i = 0;
while (i < target.size()) {
if (j < pattern.size() && target[i] == pattern[j]) {
i++;
j++;
} else {
if (!j)
i++;
j = table[j];
}
if (j == pattern.size())
res.push_back(i - j);
}
return res;
}
int perm[1000005];
void init_perm() {
perm[0] = 1;
REP(i, 1000005)
perm[i] = perm[i - 1] * i % mod;
}
int nCk(int x, int y) {
return perm[x] * mod_pow(perm[x - y], mod - 2) % mod *
mod_pow(perm[y], mod - 2) % mod;
}
/*--------Library Zone!--------*/
int H, N;
int dp[1005][200005];
int a[1005], b[1005];
signed main() {
cin >> H >> N;
rep(i, N) cin >> a[i] >> b[i];
rep(i, N + 1) rep(j, H + 10001) dp[i][j] = inf;
dp[0][0] = 0;
rep(i, N) {
rep(j, H + 10001) {
chmin(dp[i + 1][j], dp[i][j]);
if (j >= a[i]) {
chmin(dp[i + 1][j], dp[i + 1][j - a[i]] + b[i]);
}
}
}
int ans = inf;
for (int i = H; i <= H + 10000; i++)
chmin(ans, dp[N][i]);
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P std::pair<int, int>
#define PiP std::pair<int, std::pair<int, int>>
#define all(v) v.begin(), v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T, vector<T>, greater<T>>
using namespace std;
template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x != 1;
}
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; }
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 = mod) {
int res = 1;
x %= m;
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 get_rand(int MIN, int MAX) {
std::random_device rnd;
std::mt19937 mt32(rnd());
std::uniform_int_distribution<int> engine(MIN, MAX);
return engine(mt32);
}
struct BIT {
vector<int> bit;
int n;
BIT(int x) {
bit.resize(x + 1, 0);
n = x;
}
void add(int x, int y) {
while (x <= n) {
bit[x] += y;
x += x & -x;
}
}
int sum(int x) {
int res = 0;
while (x > 0) {
res += bit[x];
x -= x & -x;
}
return res;
}
};
struct UnionFind {
vector<int> par, size;
UnionFind(int x) {
par.resize(x);
size.resize(x, 1);
rep(i, x) par[i] = i;
}
int find(int x) {
if (par[x] == x)
return x;
return par[x] = find(par[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
int consize(int x) { return size[find(x)]; }
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (size[x] < size[y]) {
par[x] = y;
size[y] += size[x];
} else {
par[y] = x;
size[x] += size[y];
}
}
};
struct Tree {
int size;
vector<int> par, depth;
vector<int> doubling[30];
vector<vector<int>> G;
int root = 0;
Tree(int x) {
par.resize(x);
depth.resize(x);
rep(i, 30) { doubling[i].resize(x, -1); }
G.resize(x);
size = x;
}
void add_edge(int x, int y) {
G[x].push_back(y);
G[y].push_back(x);
}
void dfs(int x) {
for (int i : G[x]) {
if (depth[i] == -1) {
depth[i] = depth[x] + 1;
doubling[0][i] = x;
dfs(i);
}
}
}
void init() {
rep(i, size) depth[i] = -1;
depth[root] = 0;
dfs(root);
rep(i, 29) {
rep(j, size) {
if (doubling[i][j] == -1)
doubling[i + 1][j] = -1;
else
doubling[i + 1][j] = doubling[i][doubling[i][j]];
}
}
}
int lca(int x, int y) {
if (depth[x] > depth[y])
swap(x, y);
for (int i = 29; i >= 0; i--) {
if ((depth[y] - depth[x]) >> i & 1) {
y = doubling[i][y];
}
}
if (x == y)
return x;
for (int i = 29; i >= 0; i--) {
if (doubling[i][x] != doubling[i][y]) {
x = doubling[i][x];
y = doubling[i][y];
}
}
return doubling[0][x];
}
};
struct RollingHash {
int Base = 283;
const int MASK30 = (1ll << 30) - 1;
const int MASK31 = (1ll << 31) - 1;
const int MOD = (1ll << 61) - 1;
vector<int> hash, power;
int calcmod(int val) {
val = (val & MOD) + (val >> 61);
if (val > MOD)
val -= MOD;
return val;
}
int mul(int x, int y) {
int xu = x >> 31;
int xd = x & MASK31;
int yu = y >> 31;
int yd = y & MASK31;
int mid = xd * yu + xu * yd;
int midu = mid >> 30;
int midd = mid & MASK30;
return calcmod(xu * yu * 2 + midu + (midd << 31) + xd * yd);
}
RollingHash(string s) {
// Base=get_rand(1<<7,1<<8);
int sz = s.size();
hash.resize(sz + 1, 0);
power.resize(sz + 1, 1);
rep(i, sz) {
hash[i + 1] = (mul(hash[i], Base) + s[i]) % MOD;
power[i + 1] = mul(power[i], Base) % MOD;
}
}
int get(int l, int r) {
int res = (hash[r] - mul(hash[l], power[r - l]) + MOD) % MOD;
return res;
}
int lcp(int x, int y) {
int len = min(hash.size() - y, hash.size() - x);
int ok = 0, ng = len + 1;
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (get(x, x + mid) == get(y, y + mid))
ok = mid;
else
ng = mid;
}
return ok;
}
};
struct Segtree {
int size = 1;
vector<int> dat, lazy;
Segtree(int x) {
while (size < x)
size *= 2;
dat.resize(size * 2 - 1, inf);
lazy.resize(size * 2 - 1, inf);
}
void eval(int k, int l, int r) {
chmin(dat[k], lazy[k]);
if (r - l > 1) {
chmin(lazy[k * 2 + 1], lazy[k]);
chmin(lazy[k * 2 + 2], lazy[k]);
}
lazy[k] = inf;
}
void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = size;
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
chmin(lazy[k], x);
eval(k, l, r);
return;
}
update(a, b, x, k * 2 + 1, l, (l + r) / 2);
update(a, b, x, k * 2 + 2, (l + r) / 2, r);
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
int query(int a, int k = 0, int l = 0, int r = -1) {
if (r == -1)
r = size;
eval(k, l, r);
if (r - l == 1) {
return dat[k];
}
if (a < (l + r) / 2) {
return query(a, k * 2 + 1, l, (l + r) / 2);
}
return query(a, k * 2 + 2, (l + r) / 2, r);
}
};
template <class T> vector<int> KMP(vector<T> target, vector<T> pattern) {
vector<int> table(pattern.size() + 1);
table[0] = 0;
int j = 0;
REP(i, (int)pattern.size()) {
if (pattern[i] == pattern[j]) {
table[i] = j++;
} else {
table[i] = j;
j = 0;
}
}
table[pattern.size()] = j;
j = 0;
vector<int> res;
int i = 0;
while (i < target.size()) {
if (j < pattern.size() && target[i] == pattern[j]) {
i++;
j++;
} else {
if (!j)
i++;
j = table[j];
}
if (j == pattern.size())
res.push_back(i - j);
}
return res;
}
int perm[1000005];
void init_perm() {
perm[0] = 1;
REP(i, 1000005)
perm[i] = perm[i - 1] * i % mod;
}
int nCk(int x, int y) {
return perm[x] * mod_pow(perm[x - y], mod - 2) % mod *
mod_pow(perm[y], mod - 2) % mod;
}
/*--------Library Zone!--------*/
int H, N;
int dp[1005][20005];
int a[1005], b[1005];
signed main() {
cin >> H >> N;
rep(i, N) cin >> a[i] >> b[i];
rep(i, N + 1) rep(j, H + 10001) dp[i][j] = inf;
dp[0][0] = 0;
rep(i, N) {
rep(j, H + 10001) {
chmin(dp[i + 1][j], dp[i][j]);
if (j >= a[i]) {
chmin(dp[i + 1][j], dp[i + 1][j - a[i]] + b[i]);
}
}
}
int ans = inf;
for (int i = H; i <= H + 10000; i++)
chmin(ans, dp[N][i]);
cout << ans << endl;
}
| replace | 308 | 309 | 308 | 309 | MLE | |
p02787 | C++ | Time Limit Exceeded | // #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
typedef int64_t ll;
#define endl '\n'
#define int ll
ll mod = 1e17;
ll mod1 = 1e9 + 5;
ll power(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0)
return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;
else
return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %
mod;
}
// using namespace __gnu_pbds;
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>,
// rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set
int h, n;
pair<int, int> p[1000 + 1];
int dp[20001][1001];
vector<pair<double, int>> v;
int solve(int sum, int i) {
if (sum >= h)
return 0;
if (i == n + 1) {
return 1e15;
}
int &res = dp[sum][i];
if (res != -1)
return res;
res = 1e15;
int ind = v[i - 1].second;
int init = (h - sum) / (p[ind].first);
for (int j = max(init - 10, (ll)0); j <= h; ++j) {
res =
min(res, (p[ind].second) * j + solve((p[ind].first) * j + sum, i + 1));
}
return res;
}
int32_t main() {
IOS
cin >>
h >> n;
for (int i = 1; i <= n; ++i)
cin >> p[i].first >> p[i].second;
for (int i = 1; i <= n; ++i) {
double x = (double)p[i].first / (double)p[i].second;
v.push_back({x, i});
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
memset(dp, -1, sizeof(dp));
cout << solve(0, 1);
} | // #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
typedef int64_t ll;
#define endl '\n'
#define int ll
ll mod = 1e17;
ll mod1 = 1e9 + 5;
ll power(ll a, ll b) {
if (b == 0)
return 1;
else if (b % 2 == 0)
return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;
else
return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %
mod;
}
// using namespace __gnu_pbds;
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>,
// rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set
int h, n;
pair<int, int> p[1000 + 1];
int dp[20001][1001];
vector<pair<double, int>> v;
int solve(int sum, int i) {
if (sum >= h)
return 0;
if (i == n + 1) {
return 1e15;
}
int &res = dp[sum][i];
if (res != -1)
return res;
res = 1e15;
int ind = v[i - 1].second;
int init = (h - sum) / (p[ind].first);
for (int j = max(init - 10, (ll)0); j <= (h - sum) / (p[ind].first) + 10;
++j) {
res =
min(res, (p[ind].second) * j + solve((p[ind].first) * j + sum, i + 1));
}
return res;
}
int32_t main() {
IOS
cin >>
h >> n;
for (int i = 1; i <= n; ++i)
cin >> p[i].first >> p[i].second;
for (int i = 1; i <= n; ++i) {
double x = (double)p[i].first / (double)p[i].second;
v.push_back({x, i});
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
memset(dp, -1, sizeof(dp));
cout << solve(0, 1);
} | replace | 69 | 70 | 69 | 71 | TLE | |
p02787 | C++ | Runtime Error | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author Kamol Paul
*/
#include <fstream>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define long long long
typedef pair<long, long> pii;
class ECrestedIbisVsMonster {
public:
static bool cmp(pii a, pii b) {
return (a.second / a.first) > (b.second / b.first);
}
void solve(std::istream &in, std::ostream &out) {
long h, n;
in >> h >> n;
vector<pair<long, long>> data(n);
for (auto &x : data)
in >> x.first >> x.second;
sort(data.begin(), data.end(), cmp);
long tk[h + 100];
for (int i = 0; i <= h + 10; i++) {
tk[i] = LONG_MAX;
}
tk[0] = 0;
for (int i = 0; i < n; i++) {
long cost = data[i].second;
long cover = data[i].first;
for (int j = 1; j < cover; j++) {
tk[j] = min(tk[j], cost);
}
for (int j = cover; j <= h; j++) {
tk[j] = min(tk[j], (tk[j - cover]) + cost);
}
}
out << tk[h] << endl;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ECrestedIbisVsMonster solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
| /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author Kamol Paul
*/
#include <fstream>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define long long long
typedef pair<long, long> pii;
class ECrestedIbisVsMonster {
public:
static bool cmp(pii a, pii b) {
return (a.second / a.first) > (b.second / b.first);
}
void solve(std::istream &in, std::ostream &out) {
long h, n;
in >> h >> n;
vector<pair<long, long>> data(n);
for (auto &x : data)
in >> x.first >> x.second;
sort(data.begin(), data.end(), cmp);
long tk[h + 100];
for (int i = 0; i <= h + 10; i++) {
tk[i] = LONG_MAX;
}
tk[0] = 0;
for (int i = 0; i < n; i++) {
long cost = data[i].second;
long cover = data[i].first;
for (int j = 1; j < cover && j <= h; j++) {
tk[j] = min(tk[j], cost);
}
for (int j = cover; j <= h; j++) {
tk[j] = min(tk[j], (tk[j - cover]) + cost);
}
}
out << tk[h] << endl;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ECrestedIbisVsMonster solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
// freopen("input.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h, n, i, j;
cin >> h >> n;
int a[n + 2], b[n + 2];
int dp[10003];
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (j = 0; j < h; j++) {
dp[min(a[i] + j, h)] = min(min(dp[a[i] + j], h), dp[j] + b[i]);
}
}
cout << dp[h];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
// freopen("input.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h, n, i, j;
cin >> h >> n;
int a[n + 2], b[n + 2];
int dp[10003];
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (j = 0; j < h; j++) {
dp[min(a[i] + j, h)] = min(dp[min(a[i] + j, h)], dp[j] + b[i]);
}
}
cout << dp[h];
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
using namespace std;
ll dp[10005]; // dp[i] := HPをi減らす時の最小の魔力消費量
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll H, N;
cin >> H >> N;
vector<ll> A(N), B(N);
rep(i, N) { cin >> A[i] >> B[i]; }
rep(i, 1e4 + 5) dp[i] = 1e18;
dp[0] = 0;
rep(a, 1e2) {
for (int j = 0; j <= 1e4; j++) {
rep(i, N) {
if (j - A[i] >= 0)
dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
}
}
}
ll ans = 1e18;
for (int i = 1e4 + 4; i >= H; i--) {
ans = min(ans, dp[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
using namespace std;
ll dp[10005]; // dp[i] := HPをi減らす時の最小の魔力消費量
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll H, N;
cin >> H >> N;
vector<ll> A(N), B(N);
rep(i, N) { cin >> A[i] >> B[i]; }
rep(i, 1e4 + 5) dp[i] = 1e18;
dp[0] = 0;
rep(a, 1e1) {
for (int j = 0; j <= 1e4; j++) {
rep(i, N) {
if (j - A[i] >= 0)
dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
}
}
}
ll ans = 1e18;
for (int i = 1e4 + 4; i >= H; i--) {
ans = min(ans, dp[i]);
}
cout << ans << endl;
} | replace | 21 | 22 | 21 | 22 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a.at(i) >> b.at(i);
vector<int> dp(2 * pow(10, 9));
for (int i = 0; i < pow(10, 9); i++) {
if (dp.at(i) >= h) {
cout << i << endl;
break;
}
for (int j = 0; j < n; j++) {
if (dp.at(i) + a.at(j) > dp.at(i + b.at(j)))
dp.at(i + b.at(j)) = dp.at(i) + a.at(j);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a.at(i) >> b.at(i);
vector<int> dp(2 * pow(10, 8));
for (int i = 0; i < 10 + pow(10, 8); i++) {
if (dp.at(i) >= h) {
cout << i << endl;
break;
}
for (int j = 0; j < n; j++) {
if (dp.at(i) + a.at(j) > dp.at(i + b.at(j)))
dp.at(i + b.at(j)) = dp.at(i) + a.at(j);
}
}
return 0;
} | replace | 11 | 13 | 11 | 13 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#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 ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
const ll INF = (1ll << 60);
map<ll, ll> mp;
bool isok(ll h, ll k, ll n, vector<tuple<double, ll, ll>> &tp) {
ll ans = 0;
rep(i, n) {
auto cura = (get<1>(tp[i]));
auto curb = (get<2>(tp[i]));
cerr << (cura) << " " << (k / curb) << endl;
ans += (cura) * (k / curb);
k -= curb * (k / curb);
if (ans >= h) {
break;
}
}
cerr << ans << " " << k << endl;
return ans >= h;
}
ll f(ll h, vector<ll> &a, vector<ll> &b) {
// cerr << h << endl;
if (h <= 0) {
return 0;
}
// cerr << "count " << h << endl;
if (mp.count(h) == 1) {
return mp[h];
}
// cerr << "done " << h << endl;
ll ans = INF;
rep(i, a.size()) {
rep(j, 1, 1 + (h + a[i] - 1) / a[i]) {
ll tmp = f(h - j * a[i], a, b) + j * b[i];
ans = min(ans, tmp);
}
}
// cerr << ans << endl;
mp[h] = ans;
return ans;
}
int main(int argc, char const *argv[]) {
ll h, n;
cin >> h >> n;
vector<ll> a(n), b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
cout << f(h, a, b) << endl;
return 0;
}
| #include <bits/stdc++.h>
#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 ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
const ll INF = (1ll << 60);
map<ll, ll> mp;
bool isok(ll h, ll k, ll n, vector<tuple<double, ll, ll>> &tp) {
ll ans = 0;
rep(i, n) {
auto cura = (get<1>(tp[i]));
auto curb = (get<2>(tp[i]));
cerr << (cura) << " " << (k / curb) << endl;
ans += (cura) * (k / curb);
k -= curb * (k / curb);
if (ans >= h) {
break;
}
}
cerr << ans << " " << k << endl;
return ans >= h;
}
ll f(ll h, vector<ll> &a, vector<ll> &b) {
// cerr << h << endl;
if (h <= 0) {
return 0;
}
// cerr << "count " << h << endl;
if (mp.count(h) == 1) {
return mp[h];
}
// cerr << "done " << h << endl;
ll ans = INF;
rep(i, a.size()) {
rep(j, 1, 1 + (h + a[i] - 1) / a[i]) {
ll tmp = f(h - j * a[i], a, b) + j * b[i];
ans = min(ans, tmp);
}
}
// cerr << ans << endl;
mp[h] = ans;
return ans;
}
int main(int argc, char const *argv[]) {
ll h, n;
cin >> h >> n;
vector<ll> a(n), b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
vector<ll> dp(h + 1, INF);
dp[0] = 0;
rep(i, n) {
auto next = dp;
rep(j, h + 1) {
// cerr << j << " " << a[i] << endl;
if (j - a[i] < 0) {
dp[j] = min(dp[j], b[i]);
} else {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
}
}
for (ll j = h - 1; j >= 0; j--) {
if (dp[j] > dp[j + 1])
dp[j] = dp[j + 1];
}
// rep(j, h + 1) cerr << dp[j] << " ";
// cerr << endl;
// dp = next;
}
cout << dp[h] << endl;
return 0;
}
| replace | 68 | 69 | 68 | 90 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int H, N;
cin >> H >> N;
vector<int> dp(10000 + 1000, 999999999999);
vector<int> A(N);
vector<int> B(N);
dp[0] = 0;
for (int i = 0; i < N; i++)
cin >> A[i] >> B[i];
for (int j = 0; j <= H; j++) {
for (int i = 0; i < N; i++) {
dp[j + A[i]] = min(dp[j + A[i]], dp[j] + B[i]);
}
}
int maxA = *max_element(A.begin(), A.end());
int ans = dp[H];
for (int i = 0; i <= maxA; i++) {
ans = min(ans, dp[H + i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int H, N;
cin >> H >> N;
vector<int> dp(100000 + 1000, 999999999999);
vector<int> A(N);
vector<int> B(N);
dp[0] = 0;
for (int i = 0; i < N; i++)
cin >> A[i] >> B[i];
for (int j = 0; j <= H; j++) {
for (int i = 0; i < N; i++) {
dp[j + A[i]] = min(dp[j + A[i]], dp[j] + B[i]);
}
}
int maxA = *max_element(A.begin(), A.end());
int ans = dp[H];
for (int i = 0; i <= maxA; i++) {
ans = min(ans, dp[H + i]);
}
cout << ans << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, h;
cin >> h >> n;
vector<pair<int, int>> vp(n);
for (auto &p : vp) {
int x, y;
cin >> x >> y;
p = {x, y};
}
vector<int> dists(h + 1, MOD);
dists[h] = 0;
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
pq;
pq.push({dists[h], h});
while (!pq.empty()) {
auto cur = pq.top();
pq.pop();
int x = cur.second;
for (auto &p : vp) {
int y = max(0, x - p.first);
if (dists[y] > dists[x] + p.second) {
dists[y] = dists[x] + p.second;
pq.push({dists[y], y});
}
}
}
cout << dists[0];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
// const int MOD=998244353;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, h;
cin >> h >> n;
vector<pair<int, int>> vp(n);
for (auto &p : vp) {
int x, y;
cin >> x >> y;
p = {x, y};
}
vector<int> dists(h + 1, MOD);
dists[h] = 0;
for (int i = h - 1; i >= 0; i--) {
for (auto p : vp) {
int y = min(h, i + p.first);
dists[i] = min(dists[i], dists[y] + p.second);
}
}
priority_queue<pair<int, int>, vector<pair<int, int>>,
greater<pair<int, int>>>
pq;
pq.push({dists[h], h});
while (!pq.empty()) {
auto cur = pq.top();
pq.pop();
int x = cur.second;
for (auto &p : vp) {
int y = max(0, x - p.first);
if (dists[y] > dists[x] + p.second) {
dists[y] = dists[x] + p.second;
pq.push({dists[y], y});
}
}
}
cout << dists[0];
return 0;
}
| insert | 25 | 25 | 25 | 32 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int A[10100], B[10100], n, dp[10110][1010];
int fun(int a, int b) {
if (a <= 0)
return 0;
if (b == n)
return 1e9;
if (dp[a][b] != -1)
return dp[a][b];
return min(B[b] + fun(a - A[b], b), fun(a, b + 1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int h;
cin >> h >> n;
for (int i = 0; i < n; i++)
cin >> A[i] >> B[i];
memset(dp, -1, sizeof(dp));
cout << fun(h, 0) << '\n';
} | #include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int A[10100], B[10100], n, dp[10110][1010];
int fun(int a, int b) {
if (a <= 0)
return 0;
if (b == n)
return 1e9;
if (dp[a][b] != -1)
return dp[a][b];
return min(B[b] + fun(a - A[b], b), fun(a, b + 1));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int h;
cin >> h >> n;
for (int i = 0; i < n; i++)
cin >> A[i] >> B[i];
for (int i = 0; i < n; i++)
dp[0][i] = 0;
for (int i = 1; i <= h; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = 1e9;
dp[i][j] = min(B[j] + dp[max(0, i - A[j])][j], dp[i][j]);
if (j)
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
}
cout << dp[h][n - 1] << '\n';
} | replace | 23 | 25 | 23 | 34 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
rep(i, n) cin >> a.at(i) >> b.at(i);
int dp[h + 1];
rep(i, h) dp[i] = 2000000000;
dp[h] = 0;
rep(i, n) {
for (int j = h - a.at(i); j >= 0; j--)
dp[j] = min(dp[j], dp[a.at(i) + j] + b.at(i));
for (int j = a.at(i) - 1; j > 0; j--)
dp[0] = min(dp[0], dp[j] + b.at(i));
}
cout << dp[0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
rep(i, n) cin >> a.at(i) >> b.at(i);
int dp[h + 1];
rep(i, h) dp[i] = 2000000000;
dp[h] = 0;
rep(i, n) {
if (a.at(i) > h) {
dp[0] = min(dp[0], b.at(i));
continue;
}
for (int j = h - a.at(i); j >= 0; j--)
dp[j] = min(dp[j], dp[a.at(i) + j] + b.at(i));
for (int j = a.at(i) - 1; j > 0; j--)
dp[0] = min(dp[0], dp[j] + b.at(i));
}
cout << dp[0] << endl;
} | insert | 18 | 18 | 18 | 22 | 0 | |
p02787 | C++ | Time Limit Exceeded | #pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for (int i = 0; i < n; i++)
const int inf9 = 1e9;
const lint inf18 = 1e18;
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
int ans = 0;
for (U i : text) {
ans += (i == character);
}
return ans;
}
lint power(lint base, lint exponent, lint module) {
if (exponent % 2) {
return power(base, exponent - 1, module) * base % module;
} else if (exponent) {
lint root_ans = power(base, exponent / 2, module);
return root_ans * root_ans % module;
} else {
return 1;
}
}
struct position {
double y, x;
};
position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
double euclidean(position first, position second) {
return sqrt((second.x - first.x) * (second.x - first.x) +
(second.y - first.y) * (second.y - first.y));
}
double euclidean(double first, double second) {
return sqrt(first * first + second * second);
}
template <class T, class U> string to_string(pair<T, U> x) {
return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr> void array_output(itr start, itr goal) {
string ans;
for (auto i = start; i != goal; i++)
ans += to_string(*i) + ",";
if (!ans.empty())
ans.pop_back();
cout << ans << endl;
}
template <class itr> void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
template <class T> T gcd(T a, T b) {
if (a && b) {
return gcd(min(a, b), max(a, b) % min(a, b));
} else {
return a;
}
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
struct combination {
vector<lint> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2, mod);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
lint P(int n, int r) {
if (r < 0 || n < r)
return 0;
return (fact[n] * inv[n - r] % mod);
}
lint C(int p, int q) {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
template <class itr> bool next_sequence(itr first, itr last, int max_bound) {
itr now = last;
while (now != first) {
now--;
(*now)++;
if ((*now) == max_bound) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
template <class itr, class itr2>
bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2) {
itr now = last;
itr2 now2 = last2;
while (now != first) {
now--, now2--;
(*now)++;
if ((*now) == (*now2)) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
inline int at(lint i, int j) { return (i >> j) & 1; }
int H, N;
vector<lint> A, B;
lint dp[1010][10101];
lint attack(int now, lint health) {
if (health <= 0) {
return 0;
}
if (now == N) {
return inf18;
}
if (dp[now][health] != -1) {
return dp[now][health];
}
return min(attack(now + 1, health), attack(now, health - A[now]) + B[now]);
}
int main() {
cin >> H >> N;
A.resize(N);
B.resize(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
memset(dp, -1, sizeof(dp));
cout << attack(0, H) << endl;
}
| #pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for (int i = 0; i < n; i++)
const int inf9 = 1e9;
const lint inf18 = 1e18;
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T = string, class U = char>
int character_count(T text, U character) {
int ans = 0;
for (U i : text) {
ans += (i == character);
}
return ans;
}
lint power(lint base, lint exponent, lint module) {
if (exponent % 2) {
return power(base, exponent - 1, module) * base % module;
} else if (exponent) {
lint root_ans = power(base, exponent / 2, module);
return root_ans * root_ans % module;
} else {
return 1;
}
}
struct position {
double y, x;
};
position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
double euclidean(position first, position second) {
return sqrt((second.x - first.x) * (second.x - first.x) +
(second.y - first.y) * (second.y - first.y));
}
double euclidean(double first, double second) {
return sqrt(first * first + second * second);
}
template <class T, class U> string to_string(pair<T, U> x) {
return to_string(x.first) + "," + to_string(x.second);
}
string to_string(string x) { return x; }
template <class itr> void array_output(itr start, itr goal) {
string ans;
for (auto i = start; i != goal; i++)
ans += to_string(*i) + ",";
if (!ans.empty())
ans.pop_back();
cout << ans << endl;
}
template <class itr> void cins(itr first, itr last) {
for (auto i = first; i != last; i++) {
cin >> (*i);
}
}
template <class T> T gcd(T a, T b) {
if (a && b) {
return gcd(min(a, b), max(a, b) % min(a, b));
} else {
return a;
}
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
struct combination {
vector<lint> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2, mod);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
lint P(int n, int r) {
if (r < 0 || n < r)
return 0;
return (fact[n] * inv[n - r] % mod);
}
lint C(int p, int q) {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
template <class itr> bool next_sequence(itr first, itr last, int max_bound) {
itr now = last;
while (now != first) {
now--;
(*now)++;
if ((*now) == max_bound) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
template <class itr, class itr2>
bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2) {
itr now = last;
itr2 now2 = last2;
while (now != first) {
now--, now2--;
(*now)++;
if ((*now) == (*now2)) {
(*now) = 0;
} else {
return true;
}
}
return false;
}
inline int at(lint i, int j) { return (i >> j) & 1; }
int H, N;
vector<lint> A, B;
lint dp[1010][10101];
lint attack(int now, lint health) {
if (health <= 0) {
return 0;
}
if (now == N) {
return inf18;
}
if (dp[now][health] != -1) {
return dp[now][health];
}
return dp[now][health] = min(attack(now + 1, health),
attack(now, health - A[now]) + B[now]);
}
int main() {
cin >> H >> N;
A.resize(N);
B.resize(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
memset(dp, -1, sizeof(dp));
cout << attack(0, H) << endl;
}
| replace | 148 | 149 | 148 | 150 | TLE | |
p02787 | Python | Runtime Error | import sys
import numpy as np
h, n = list(map(int, input().split()))
INF = 10**18
dp = np.full(h + 10001, INF, dtype=np.int64)
dp[0] = 0
for line in sys.stdin:
a, b = map(int, line.split())
for s in range(0, h, a):
sa = s + a
s2a = s + 2 * a
dp[sa:s2a] = np.minimum(dp[sa:s2a], dp[s:sa] + b)
print(dp[h:].min())
| import sys
import numpy as np
h, n = map(int, input().split())
ab = np.array(sys.stdin.read().split(), dtype=np.int64)
aaa = ab[0::2]
bbb = ab[1::2]
dp = np.zeros(10001, dtype=np.int64)
for i in range(1, h + 1):
dp[i] = (dp[i - aaa] + bbb).min()
print(dp[h])
| replace | 3 | 14 | 3 | 12 | TLE | |
p02787 | Python | Time Limit Exceeded | H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]
max_magic = 0
for a, _ in magic:
max_magic = max(max_magic, a)
amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0
ret = float("inf")
for amt in range(1, amount + max_magic):
t = [dp[amt - a] + b if amt - a >= 0 else float("inf") for a, b in magic]
dp[amt] = min(t)
if amt >= H:
ret = min(dp[amt], ret)
print(ret)
| H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]
max_magic = 0
for a, _ in magic:
max_magic = max(max_magic, a)
amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0
ret = float("inf")
for amt in range(1, amount + max_magic):
t = [dp[amt - a] + b if amt - a >= 0 else float("inf") for a, b in magic]
dp[amt] = min(t)
if amt >= H:
ret = min(dp[amt], ret)
print(ret)
| insert | 16 | 16 | 16 | 17 | TLE | |
p02787 | Python | Time Limit Exceeded | import sys
import functools
def inpl():
return list(map(int, input().split()))
@functools.lru_cache(maxsize=None)
def solve(h):
if h <= 0:
return 0
ret_val = float("inf")
for a, b in AB:
ret_val = min(ret_val, b + solve(h - a))
return ret_val
sys.setrecursionlimit(100000)
H, N = inpl()
AB = [inpl() for i in range(N)]
AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)
# print(AB)
print(solve(H))
| import sys
import functools
def inpl():
return list(map(int, input().split()))
@functools.lru_cache(maxsize=None)
def solve(h):
if h <= 0:
return 0
ret_val = float("inf")
for a, b in AB:
val = b + solve(h - a)
if val < ret_val:
ret_val = val
else:
break
return ret_val
sys.setrecursionlimit(100000)
H, N = inpl()
AB = [inpl() for i in range(N)]
AB.sort(key=lambda ab: (ab[0] / ab[1], -ab[0]), reverse=True)
# print(AB)
print(solve(H))
| replace | 15 | 16 | 15 | 20 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(v) (v).begin(), (v).end()
#define sp cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int h, n;
int a[10005], b[10005];
int dp[1005][10005];
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> n;
rep(i, n) cin >> a[i] >> b[i];
repe(j, h) dp[0][j] = ceil((double)j / a[0]) * b[0];
// repe(i, n) {
// repe(j, h) { cout << dp[i][j] << " "; }
// cout << endl;
// }
// cout << endl;
FOR(i, 1, n) {
repe(j, h) {
dp[i][j] = min(
int(ceil((double)j / a[i]) * b[i]),
min(dp[i - 1][j],
min(dp[i - 1][j - a[i]] + b[i],
min(dp[i - 1][j - 2 * a[i]] + 2 * b[i],
min(dp[i - 1][j - 3 * a[i]] + 3 * b[i],
min(dp[i - 1][j - 4 * a[i]] + 4 * b[i],
min(dp[i - 1][j - 5 * a[i]] + 5 * b[i],
min(dp[i - 1][j - 6 * a[i]] + 6 * b[i],
min(dp[i - 1][j - 7 * a[i]] + 7 * b[i],
min(dp[i - 1][j - 8 * a[i]] +
8 * b[i],
min(dp[i - 1][j - 9 * a[i]] +
9 * b[i],
min(dp[i - 1][j - 10 * a[i]] +
10 * b[i],
min(dp[i - 1]
[j - 11 * a[i]] +
11 * b[i],
min(dp[i - 1]
[j -
12 * a[i]] +
12 * b[i],
min(dp[i - 1]
[j -
13 *
a[i]] +
13 * b[i],
min(dp[i - 1]
[j -
14 *
a[i]] +
14 *
b[i],
dp[i - 1]
[j -
15 *
a[i]] +
15 *
b[i]))))))))))))))));
}
}
// repe(i, n) {
// repe(j, h) { cout << dp[i][j] << " "; }
// cout << endl;
// }
cout << dp[n - 1][h] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(v) (v).begin(), (v).end()
#define sp cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int h, n;
int a[10005], b[10005];
int dp[1005][10005];
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> n;
rep(i, n) cin >> a[i] >> b[i];
repe(j, h) dp[0][j] = ceil((double)j / a[0]) * b[0];
// repe(i, n) {
// repe(j, h) { cout << dp[i][j] << " "; }
// cout << endl;
// }
// cout << endl;
FOR(i, 1, n) {
repe(j, h) { dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i]); }
}
// repe(i, n) {
// repe(j, h) { cout << dp[i][j] << " "; }
// cout << endl;
// }
cout << dp[n - 1][h] << endl;
return 0;
} | replace | 35 | 77 | 35 | 36 | 0 | |
p02787 | C++ | Runtime Error | #define HAVE_STRUCT_TIMESPEC
#include <bits/stdc++.h>
using namespace std;
int a[1007], b[1007], f[1007];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int h, n;
cin >> h >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i] >> b[i];
for (int i = 1; i <= h; ++i)
f[i] = 1e9;
f[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= h; ++j) {
int x = max(0, j - a[i]);
f[j] = min(f[j], f[x] + b[i]);
}
cout << f[h];
return 0;
}
| #define HAVE_STRUCT_TIMESPEC
#include <bits/stdc++.h>
using namespace std;
int a[10007], b[10007], f[10007];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int h, n;
cin >> h >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i] >> b[i];
for (int i = 1; i <= h; ++i)
f[i] = 1e9;
f[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= h; ++j) {
int x = max(0, j - a[i]);
f[j] = min(f[j], f[x] + b[i]);
}
cout << f[h];
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define all(n) (n).begin(), (n).end()
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
} else {
return 0;
}
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
} else {
return 0;
}
}
template <class T> inline T GCD(T a, T b) {
T c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
template <class T> inline T LCM(T a, T b) { return a * b / GCD(a, b); }
int main() {
ll h, n;
cin >> h >> n;
ll a[1010], b[1010];
FOR(i, n) { cin >> a[i] >> b[i]; }
ll dp[20010];
FOR(i, 20010) dp[i] = MOD;
dp[0] = 0;
for (int i = 0; i < h; i++) {
FOR(j, n) { chmin(dp[i + a[j]], dp[i] + b[j]); }
}
ll ans = MOD;
for (int i = h; i < 200010; i++) {
chmin(ans, dp[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define all(n) (n).begin(), (n).end()
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
} else {
return 0;
}
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
} else {
return 0;
}
}
template <class T> inline T GCD(T a, T b) {
T c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
template <class T> inline T LCM(T a, T b) { return a * b / GCD(a, b); }
int main() {
ll h, n;
cin >> h >> n;
ll a[1010], b[1010];
FOR(i, n) { cin >> a[i] >> b[i]; }
ll dp[20010];
FOR(i, 20010) dp[i] = MOD;
dp[0] = 0;
for (int i = 0; i < h; i++) {
FOR(j, n) { chmin(dp[i + a[j]], dp[i] + b[j]); }
}
ll ans = MOD;
for (int i = h; i < 20010; i++) {
chmin(ans, dp[i]);
}
cout << ans << endl;
} | replace | 46 | 47 | 46 | 47 | -11 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
typedef long long ll;
const ll mod = 1000000007;
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
int main() {
ll h, n;
cin >> h >> n;
ll inf = mod;
vector<ll> a(n), b(n);
for (ll i = 0; i < n; ++i)
cin >> a[i] >> b[i];
ll dp[6 * h + 1][n + 1];
for (ll j = 0; j <= 6 * h; ++j) {
for (ll i = 0; i < n + 1; ++i) {
if (j == 0) {
dp[j][i] = 0;
} else {
dp[j][i] = inf;
}
}
}
ll out = inf;
for (ll j = 1; j <= 6 * h; ++j) {
for (ll i = 1; i <= n; ++i) {
if (j - a[i - 1] >= 0) {
dp[j][i] = min(dp[j - a[i - 1]][i] + b[i - 1], dp[j][i - 1]);
} else {
dp[j][i] = dp[j][i - 1];
}
}
if (j >= h)
out = min(out, dp[j][n]);
}
/*for(int i=0;i<=n;++i){
cout << dp[h][i] << " ";
}*/
// cout << endl;
cout << out << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
typedef long long ll;
const ll mod = 1000000007;
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
int main() {
ll h, n;
cin >> h >> n;
ll inf = mod;
vector<ll> a(n), b(n);
for (ll i = 0; i < n; ++i)
cin >> a[i] >> b[i];
vector<vector<ll>> dp(6 * h + 1, vector<ll>(n + 1, inf));
for (ll i = 0; i < n + 1; ++i)
dp[0][i] = 0;
ll out = inf;
for (ll j = 1; j <= 6 * h; ++j) {
for (ll i = 1; i <= n; ++i) {
if (j - a[i - 1] >= 0) {
dp[j][i] = min(dp[j - a[i - 1]][i] + b[i - 1], dp[j][i - 1]);
} else {
dp[j][i] = dp[j][i - 1];
}
}
if (j >= h)
out = min(out, dp[j][n]);
}
/*for(int i=0;i<=n;++i){
cout << dp[h][i] << " ";
}*/
// cout << endl;
cout << out << endl;
return 0;
}
| replace | 14 | 24 | 14 | 17 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
const long long INF = 1 << 29;
const int MOD = 1000000007;
long long ruizyou(long long m, long long n) {
if (m == 0)
return 0;
if (m == 1)
return 1;
long long ans = 1;
long long tmp = m;
for (int i = 0; i <= 30; i++) {
if (n & (1 << i)) {
ans *= tmp;
ans %= MOD;
}
tmp *= tmp;
tmp %= MOD;
}
return ans;
}
long long kaizyou(long long x) {
if (x == 0)
return 1;
return x * kaizyou(x - 1) % MOD;
}
long long comb(long long x, long long y) {
long long bunsi = kaizyou(x);
long long bunbo = kaizyou(x - y) * kaizyou(y) % MOD;
return bunsi * ruizyou(bunbo, MOD - 2) % MOD;
}
struct unionfind {
vector<int> par;
vector<int> hukasa;
unionfind(int n) {
par = vector<int>(n);
hukasa = vector<int>(n, 0);
for (int i = 0; i < n; i++) {
par.at(i) = i;
}
}
int root(int x) {
if (par.at(x) == x)
return x;
return root(par.at(x));
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
if (hukasa.at(rx) >= hukasa.at(ry)) {
par.at(ry) = rx;
hukasa.at(rx) = max(hukasa.at(ry) + 1, hukasa.at(rx));
} else {
par.at(rx) = ry;
}
}
bool same(int x, int y) { return root(x) == root(y); }
};
int ctoi(char a) { return a - '0'; }
long long gcd(long long a, long long b) {
long long c = max(a, b);
long long d = min(a, b);
if (d % c == 0)
return c;
return gcd(c, d % c);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a.at(i) >> b.at(i);
vector<int> dp(10001, INF);
for (int i = 0; i < n; i++) {
if (dp.at(a.at(i)) > b.at(i))
dp.at(a.at(i)) = b.at(i);
}
// for(int i=1;i<=h;i++)cout << dp.at(i) << ' ';
// cout << endl;
for (int i = 10000; i > 0; i--) {
if (dp.at(i) > dp.at(i + 1))
dp.at(i) = dp.at(i + 1);
}
// for(int i=1;i<=h;i++)cout << dp.at(i) << ' ';
// cout << endl;
for (int i = 2; i <= h; i++) {
for (int j = 1; j < i; j++) {
dp.at(i) = min(dp.at(i), dp.at(i - j) + dp.at(j));
}
}
// for(int i=1;i<=h;i++)cout << dp.at(i) << ' ';
// cout << endl;
cout << dp.at(h) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
const long long INF = 1 << 29;
const int MOD = 1000000007;
long long ruizyou(long long m, long long n) {
if (m == 0)
return 0;
if (m == 1)
return 1;
long long ans = 1;
long long tmp = m;
for (int i = 0; i <= 30; i++) {
if (n & (1 << i)) {
ans *= tmp;
ans %= MOD;
}
tmp *= tmp;
tmp %= MOD;
}
return ans;
}
long long kaizyou(long long x) {
if (x == 0)
return 1;
return x * kaizyou(x - 1) % MOD;
}
long long comb(long long x, long long y) {
long long bunsi = kaizyou(x);
long long bunbo = kaizyou(x - y) * kaizyou(y) % MOD;
return bunsi * ruizyou(bunbo, MOD - 2) % MOD;
}
struct unionfind {
vector<int> par;
vector<int> hukasa;
unionfind(int n) {
par = vector<int>(n);
hukasa = vector<int>(n, 0);
for (int i = 0; i < n; i++) {
par.at(i) = i;
}
}
int root(int x) {
if (par.at(x) == x)
return x;
return root(par.at(x));
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
if (hukasa.at(rx) >= hukasa.at(ry)) {
par.at(ry) = rx;
hukasa.at(rx) = max(hukasa.at(ry) + 1, hukasa.at(rx));
} else {
par.at(rx) = ry;
}
}
bool same(int x, int y) { return root(x) == root(y); }
};
int ctoi(char a) { return a - '0'; }
long long gcd(long long a, long long b) {
long long c = max(a, b);
long long d = min(a, b);
if (d % c == 0)
return c;
return gcd(c, d % c);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a.at(i) >> b.at(i);
vector<int> dp(10001, INF);
for (int i = 0; i < n; i++) {
if (dp.at(a.at(i)) > b.at(i))
dp.at(a.at(i)) = b.at(i);
}
// for(int i=1;i<=h;i++)cout << dp.at(i) << ' ';
// cout << endl;
for (int i = 9999; i > 0; i--) {
if (dp.at(i) > dp.at(i + 1))
dp.at(i) = dp.at(i + 1);
}
// for(int i=1;i<=h;i++)cout << dp.at(i) << ' ';
// cout << endl;
for (int i = 2; i <= h; i++) {
for (int j = 1; j < i; j++) {
dp.at(i) = min(dp.at(i), dp.at(i - j) + dp.at(j));
}
}
// for(int i=1;i<=h;i++)cout << dp.at(i) << ' ';
// cout << endl;
cout << dp.at(h) << endl;
} | replace | 85 | 86 | 85 | 86 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 10001) >= this->size() (which is 10001)
|
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) { /* {{{ */
if (a > b) {
a = b;
return true;
}
return false;
} /* }}} */
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
vector<vector<int>> dp(N + 1, vector<int>(H + 1, 1e9));
dp[0][0] = 0;
for (int j = 1; j <= A[0]; j++) {
dp[0][j] = B[0];
}
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
chmin(dp[i + 1][j], dp[i][j]);
int v = dp[i][j] + B[i];
if (j + A[i] < H) {
chmin(dp[i][j + A[i]], v);
chmin(dp[i + 1][j + A[i]], v);
} else {
chmin(dp[i][H], v);
chmin(dp[i + 1][H], v);
}
}
}
cout << dp[N][H] << endl;
return 0;
}
/* vim:set fdm=marker: */
| #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) { /* {{{ */
if (a > b) {
a = b;
return true;
}
return false;
} /* }}} */
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
}
vector<vector<int>> dp(N + 1, vector<int>(H + 1, 1e9));
dp[0][0] = 0;
for (int j = 1; j <= A[0]; j++) {
if (j <= H) {
dp[0][j] = B[0];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
chmin(dp[i + 1][j], dp[i][j]);
int v = dp[i][j] + B[i];
if (j + A[i] < H) {
chmin(dp[i][j + A[i]], v);
chmin(dp[i + 1][j + A[i]], v);
} else {
chmin(dp[i][H], v);
chmin(dp[i + 1][H], v);
}
}
}
cout << dp[N][H] << endl;
return 0;
}
/* vim:set fdm=marker: */
| replace | 22 | 23 | 22 | 25 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], dp[maxn];
const int inf = 1e15;
const int till = 3e4;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
#ifdef LOCAL_DEFINE
freopen("in.txt", "rt", stdin);
#endif
for (int i = 0; i < maxn; ++i)
dp[i] = inf;
int h, n;
cin >> h >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i] >> b[i];
dp[0] = 0;
for (int i = 0; i <= till; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
}
}
int ans = inf;
for (int i = h; i <= till; ++i)
ans = min(ans, dp[i]);
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn], dp[maxn];
const int inf = 1e15;
const int till = 3e4;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(9);
#ifdef LOCAL_DEFINE
freopen("in.txt", "rt", stdin);
#endif
for (int i = 0; i < maxn; ++i)
dp[i] = inf;
int h, n;
cin >> h >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i] >> b[i];
dp[0] = 0;
for (int i = 0; i <= till; ++i) {
for (int j = 1; j <= n; ++j) {
if (i - a[j] >= 0)
dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
}
}
int ans = inf;
for (int i = h; i <= till; ++i)
ans = min(ans, dp[i]);
cout << ans << '\n';
return 0;
}
| replace | 30 | 31 | 30 | 32 | 0 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define rep(i, s, n) for (ll i = s; i < (n); ++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
// constexpr ll MOD = (998244353);
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
template <class T> vector<vector<T>> vvt(T init, ll m, ll n) {
vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
return move(ans);
}
template <class T> vector<T> vt(T init, ll n) {
vector<T> ans = vector<T>(n, init);
return move(ans);
}
template <class T> T maxVec(vector<T> &v) {
T ans = -INF;
rep(i, 0, v.size()) { ans = max(ans, v[i]); }
return ans;
}
// 素数判定
bool judge(ll n) {
for (ll i = 2; i * i <= n; i++)
if (n %= i)
return false;
return true;
}
template <class C> void print(const C &c, std::ostream &os = std::cout) {
std::copy(std::begin(c), std::end(c),
std::ostream_iterator<typename C::value_type>(os, ", "));
os << std::endl;
}
ll count(ll n, ll r) {
ll ans = 0, check = 1;
rep(i, 0, r) {
if ((n & check) > 0) {
ans++;
}
check = check << 1;
}
return ans;
}
bool sortreverse(ll a, ll b) { return a > b; }
bool kansu(pll a, pll b) { return a.first < b.first; }
ll kiriage(ll a, ll b) {
if (a % b == 0)
return a / b;
return a / b + 1;
}
ll dp[10010], maryoku[10010];
int main() {
ll h, n;
cin >> h >> n;
vl a(n), b(n);
rep(i, 0, n) { cin >> a[i] >> b[i]; }
dp[h] = 0;
rep(i, 0, 10010) {
if (i == h)
continue;
dp[i] = 100000000000;
}
for (ll i = 1; i < h + 1; i++) {
ll ref = INF, ma = 0;
for (ll j = 0; j < n; j++) {
if (ref > dp[h - i + a[j]] + b[j]) {
ref = dp[h - i + a[j]] + b[j];
}
}
dp[h - i] = ref;
}
ll ans = INF;
rep(i, 0, n) {
rep(j, 0, a[i] + 1) { ans = min(ans, dp[j] + b[i]); }
}
printf("%lld\n", ans);
} | #include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <queue>
#include <stdio.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define rep(i, s, n) for (ll i = s; i < (n); ++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
// constexpr ll MOD = (998244353);
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
template <class T> vector<vector<T>> vvt(T init, ll m, ll n) {
vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
return move(ans);
}
template <class T> vector<T> vt(T init, ll n) {
vector<T> ans = vector<T>(n, init);
return move(ans);
}
template <class T> T maxVec(vector<T> &v) {
T ans = -INF;
rep(i, 0, v.size()) { ans = max(ans, v[i]); }
return ans;
}
// 素数判定
bool judge(ll n) {
for (ll i = 2; i * i <= n; i++)
if (n %= i)
return false;
return true;
}
template <class C> void print(const C &c, std::ostream &os = std::cout) {
std::copy(std::begin(c), std::end(c),
std::ostream_iterator<typename C::value_type>(os, ", "));
os << std::endl;
}
ll count(ll n, ll r) {
ll ans = 0, check = 1;
rep(i, 0, r) {
if ((n & check) > 0) {
ans++;
}
check = check << 1;
}
return ans;
}
bool sortreverse(ll a, ll b) { return a > b; }
bool kansu(pll a, pll b) { return a.first < b.first; }
ll kiriage(ll a, ll b) {
if (a % b == 0)
return a / b;
return a / b + 1;
}
ll dp[40010];
int main() {
ll h, n;
cin >> h >> n;
vl a(n), b(n);
rep(i, 0, n) { cin >> a[i] >> b[i]; }
dp[h] = 0;
rep(i, 0, 10010) {
if (i == h)
continue;
dp[i] = 100000000000;
}
for (ll i = 1; i < h + 1; i++) {
ll ref = INF, ma = 0;
for (ll j = 0; j < n; j++) {
if (ref > dp[h - i + a[j]] + b[j]) {
ref = dp[h - i + a[j]] + b[j];
}
}
dp[h - i] = ref;
}
ll ans = INF;
rep(i, 0, n) {
rep(j, 0, a[i] + 1) { ans = min(ans, dp[j] + b[i]); }
}
printf("%lld\n", ans);
} | replace | 75 | 76 | 75 | 76 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)
struct Mystruct {
long long atack;
long long mp;
double cost;
Mystruct(long long input_a, long long input_b) {
atack = input_a;
mp = input_b;
cost = input_a * 1.0 / input_b;
}
bool operator<(const Mystruct &another) const {
if (cost == another.cost) {
return mp < another.mp;
}
return cost < another.cost; // 年齢を比較
};
};
int main() {
int h, n;
cin >> h >> n;
vector<Mystruct> magics;
REP(i, n) {
long long atack, mp;
cin >> atack >> mp;
magics.push_back(Mystruct(atack, mp));
}
long long MAX = pow(10, 9);
vector<long long> dp(MAX, 0);
// cout << MAX << endl;
long long mp = 1;
while (true) {
long long temp_max = 0;
REP(i, n) {
long long temp = 0;
if (mp - magics[i].mp >= 0) {
temp = dp[mp - magics[i].mp] + magics[i].atack;
}
temp_max = max(temp_max, temp);
}
dp[mp] = temp_max;
// cout << temp_max << endl;
if (dp[mp] >= h) {
ANS(mp);
break;
}
mp++;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)
struct Mystruct {
long long atack;
long long mp;
double cost;
Mystruct(long long input_a, long long input_b) {
atack = input_a;
mp = input_b;
cost = input_a * 1.0 / input_b;
}
bool operator<(const Mystruct &another) const {
if (cost == another.cost) {
return mp < another.mp;
}
return cost < another.cost; // 年齢を比較
};
};
int main() {
int h, n;
cin >> h >> n;
vector<Mystruct> magics;
REP(i, n) {
long long atack, mp;
cin >> atack >> mp;
magics.push_back(Mystruct(atack, mp));
}
long long MAX = pow(10, 8);
vector<long long> dp(MAX, 0);
// cout << MAX << endl;
long long mp = 1;
while (true) {
long long temp_max = 0;
REP(i, n) {
long long temp = 0;
if (mp - magics[i].mp >= 0) {
temp = dp[mp - magics[i].mp] + magics[i].atack;
}
temp_max = max(temp_max, temp);
}
dp[mp] = temp_max;
// cout << temp_max << endl;
if (dp[mp] >= h) {
ANS(mp);
break;
}
mp++;
}
return 0;
}
| replace | 44 | 45 | 44 | 45 | -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;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
ll h, n;
cin >> h >> n;
vector<pair<ll, ll>> ab(n);
rep(i, n) cin >> ab[i].first >> ab[i].second;
vector<ll> dp(1e9, 0);
for (ll i = 0; i <= 1e9; i++) {
rep(j, n) {
if (i - ab[j].second >= 0) {
dp[i] = max(dp[i], dp[i - ab[j].second] + ab[j].first);
}
}
if (dp[i] >= h) {
cout << i << endl;
return 0;
}
}
// for (ll i = 0; i <= h; i++) {
// if (dp[i] >= h) {
// cout << i << endl;
// return 0;
// }
// }
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
ll h, n;
cin >> h >> n;
vector<pair<ll, ll>> ab(n);
rep(i, n) cin >> ab[i].first >> ab[i].second;
vector<ll> dp(1e8, 0);
for (ll i = 0; i <= 1e8; i++) {
rep(j, n) {
if (i - ab[j].second >= 0) {
dp[i] = max(dp[i], dp[i - ab[j].second] + ab[j].first);
}
}
if (dp[i] >= h) {
cout << i << endl;
return 0;
}
}
// for (ll i = 0; i <= h; i++) {
// if (dp[i] >= h) {
// cout << i << endl;
// return 0;
// }
// }
} | replace | 11 | 13 | 11 | 13 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;
int main() {
ll h, n, k, d;
in2(h, n);
vector<ll> a(n), b(n), c(h + 1, 1000000000);
rep(i, n) in2(a[i], b[i]);
c[0] = 0;
rep2(i, 1, h + 1) {
rep(j, n) {
k = 1;
while (i - (k - 1) * a[j] > 0) {
d = max(i - k * a[j], 0ll);
c[i] = min(c[i], c[d] + k * b[j]);
k++;
}
}
}
out(c[h]);
memi;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;
int main() {
ll h, n, k, d;
in2(h, n);
vector<ll> a(n), b(n), c(h + 1, 1000000000);
rep(i, n) in2(a[i], b[i]);
c[0] = 0;
rep2(i, 1, h + 1) {
rep(j, n) {
d = max(i - a[j], 0ll);
c[i] = min(c[i], c[d] + b[j]);
}
}
out(c[h]);
memi;
} | replace | 24 | 30 | 24 | 26 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef long long ll;
int dp[150000000];
int main() {
int H, N;
int A[10000], B[10000];
scanf("%d %d", &H, &N);
for (int i = 0; i < N; i++) {
scanf("%d %d", &A[i], &B[i]);
}
int jCount = 1000000;
if (N <= 10) {
jCount *= 150;
}
// for(int i = 0; i < N+1; i++){
for (int j = 0; j < jCount; j++) {
dp[j] = 0;
}
// }
for (int i = 1; i < N + 1; i++) {
for (int j = 0; j < jCount; j++) {
if (j >= B[i - 1]) {
int tmp = dp[j - B[i - 1]] + A[i - 1];
dp[j] = max(dp[j], tmp);
} else {
// dp[j] = dp[j];
}
}
}
ll min = 9999999999;
for (int j = 0; j < jCount; j++) {
if (dp[j] >= H) {
if (j < min) {
min = j;
}
}
}
printf("%lld\n", min);
return 0;
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
typedef long long ll;
int dp[150000000];
int main() {
int H, N;
int A[10000], B[10000];
scanf("%d %d", &H, &N);
for (int i = 0; i < N; i++) {
scanf("%d %d", &A[i], &B[i]);
}
int jCount = 1000000;
if (N <= 10) {
jCount *= 110;
}
// for(int i = 0; i < N+1; i++){
for (int j = 0; j < jCount; j++) {
dp[j] = 0;
}
// }
for (int i = 1; i < N + 1; i++) {
for (int j = 0; j < jCount; j++) {
if (j >= B[i - 1]) {
int tmp = dp[j - B[i - 1]] + A[i - 1];
dp[j] = max(dp[j], tmp);
} else {
// dp[j] = dp[j];
}
}
}
ll min = 9999999999;
for (int j = 0; j < jCount; j++) {
if (dp[j] >= H) {
if (j < min) {
min = j;
}
}
}
printf("%lld\n", min);
return 0;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p02787 | Python | Runtime Error | n, m = map(int, input().split())
dmg = []
cost = []
for i in range(m):
a, b = map(int, input().split())
dmg.append(a)
cost.append(b)
inf = 10**9
dp = [inf] * 10001
dp[0] = 0
for i in range(m):
for j in range(n):
if dp[j] != inf:
dp[j + dmg[i]] = min(dp[j + dmg[i]], dp[j] + cost[i])
print(min(dp[n:]))
| n, m = map(int, input().split())
dmg = []
cost = []
for i in range(m):
a, b = map(int, input().split())
dmg.append(a)
cost.append(b)
inf = 10**9
dp = [inf] * 30000
dp[0] = 0
for i in range(m):
for j in range(n):
if dp[j] != inf:
dp[j + dmg[i]] = min(dp[j + dmg[i]], dp[j] + cost[i])
print(min(dp[n:]))
| replace | 10 | 11 | 10 | 11 | 0 | |
p02787 | C++ | Time Limit Exceeded | // #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 10000009
#define INF (ll)1e18
#define pll pair<ll, ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
#define repr(i, n) repr2(i, n, 0)
#define repr2(i, m, n) for (ll i = m; i >= (n); i--)
#define get(n) \
ll(n); \
scanf("%lld", &(n));
#define get2(n, k) \
ll(n), (k); \
scanf("%lld%lld", &(n), &(k));
#define get3(n, m, k) \
ll(n), (m), (k); \
scanf("%lld%lld%lld", &(n), &(m), &(k));
#define gets(s) \
string(s); \
cin >> (s);
#define ALL(c) (c).begin(), (c).end()
#define fill_nums(A, n) \
vector<ll> A((n)); \
for (ll i = 0; i < n; i++) \
scanf("%lld", &A[i]);
#define fill_edges(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
adj[b - 1].pb(a - 1); \
}
#define fill_direct(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
}
#define StarBurstStream \
ios_base::sync_with_stdio(false); \
cin.tie(0); // cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp \
{ \
cout << "No\n"; \
return 0; \
}
#define debug_vec(vec, n) \
{ \
rep(idxi, n) cout << vec[idxi] << " "; \
cout << "\n"; \
}
#define debug_pvec(vec, n) \
{ \
rep(idxi, n) cout << vec[idxi].fi << "-" << vec[idxi].se << " "; \
cout << "\n"; \
}
#define debug_set(seta) \
{ \
cout << seta.size() << "\n"; \
for (auto idxi : seta) \
cout << idxi << " "; \
cout << "\n"; \
}
#define debug_map(mappa) \
{ \
cout << mappa.size() << "\n"; \
for (auto idxi : mappa) \
cout << idxi.fi << "-" << idxi.se << " "; \
cout << "\n"; \
}
#define debug_vecvec(vec, n) \
{ \
rep(idxi, n) { \
for (auto idxi2 : vec[idxi]) \
cout << idxi2 << " "; \
cout << "\n"; \
} \
}
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// ============================================================
ll dp[Nmax], dp2[Nmax];
int main() {
rep(i, Nmax) dp[i] = INF;
dp[0] = 0;
get2(h, n);
// rep(i,Nmax) dp2[i] = dp[i];
rep(i, n) {
get2(a, b);
rep(i, Nmax) if (i + a < Nmax) dp[i + a] = min(dp[i + a], dp[i] + b);
}
ll mini = INF;
rep2(i, h, Nmax) mini = min(dp[i], mini);
printf("%lld\n", mini);
return 0;
} | // #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 10000009
#define INF (ll)1e18
#define pll pair<ll, ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
#define repr(i, n) repr2(i, n, 0)
#define repr2(i, m, n) for (ll i = m; i >= (n); i--)
#define get(n) \
ll(n); \
scanf("%lld", &(n));
#define get2(n, k) \
ll(n), (k); \
scanf("%lld%lld", &(n), &(k));
#define get3(n, m, k) \
ll(n), (m), (k); \
scanf("%lld%lld%lld", &(n), &(m), &(k));
#define gets(s) \
string(s); \
cin >> (s);
#define ALL(c) (c).begin(), (c).end()
#define fill_nums(A, n) \
vector<ll> A((n)); \
for (ll i = 0; i < n; i++) \
scanf("%lld", &A[i]);
#define fill_edges(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
adj[b - 1].pb(a - 1); \
}
#define fill_direct(adj, m) \
for (ll i = 0; i < m; i++) { \
ll a, b; \
scanf("%lld %lld", &a, &b); \
adj[a - 1].pb(b - 1); \
}
#define StarBurstStream \
ios_base::sync_with_stdio(false); \
cin.tie(0); // cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp \
{ \
cout << "No\n"; \
return 0; \
}
#define debug_vec(vec, n) \
{ \
rep(idxi, n) cout << vec[idxi] << " "; \
cout << "\n"; \
}
#define debug_pvec(vec, n) \
{ \
rep(idxi, n) cout << vec[idxi].fi << "-" << vec[idxi].se << " "; \
cout << "\n"; \
}
#define debug_set(seta) \
{ \
cout << seta.size() << "\n"; \
for (auto idxi : seta) \
cout << idxi << " "; \
cout << "\n"; \
}
#define debug_map(mappa) \
{ \
cout << mappa.size() << "\n"; \
for (auto idxi : mappa) \
cout << idxi.fi << "-" << idxi.se << " "; \
cout << "\n"; \
}
#define debug_vecvec(vec, n) \
{ \
rep(idxi, n) { \
for (auto idxi2 : vec[idxi]) \
cout << idxi2 << " "; \
cout << "\n"; \
} \
}
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// ============================================================
ll dp[Nmax], dp2[Nmax];
int main() {
rep(i, Nmax) dp[i] = INF;
dp[0] = 0;
get2(h, n);
// rep(i,Nmax) dp2[i] = dp[i];
rep(i, n) {
get2(a, b);
rep(i, h + 1) if (i + a < Nmax) dp[i + a] = min(dp[i + a], dp[i] + b);
}
ll mini = INF;
rep2(i, h, Nmax) mini = min(dp[i], mini);
printf("%lld\n", mini);
return 0;
} | replace | 117 | 118 | 117 | 118 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2e9;
// const ll INF = 9e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++)
cin >> A[i] >> B[i];
int amin = INF;
for (int i = 0; i < N; i++)
amin = min(amin, A[i]);
vector<int> dp(H + 10, INF);
dp[0] = 0;
for (int i = 0; i <= H / amin; i++) {
for (int j = 0; j < H; j++) {
for (int k = 0; k < N; k++) {
int nj = min(j + A[k], H);
dp[nj] = min(dp[nj], dp[j] + B[k]);
}
}
}
cout << dp[H] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2e9;
// const ll INF = 9e18;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++)
cin >> A[i] >> B[i];
int amin = INF;
for (int i = 0; i < N; i++)
amin = min(amin, A[i]);
vector<int> dp(H + 10, INF);
dp[0] = 0;
for (int j = 0; j < H; j++) {
for (int k = 0; k < N; k++) {
int nj = min(j + A[k], H);
dp[nj] = min(dp[nj], dp[j] + B[k]);
}
}
cout << dp[H] << "\n";
} | replace | 20 | 26 | 20 | 24 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
* For DEBUG
* https://github.com/ta7uw/cpp-pyprint
*/
#include "cpp-pyprint/pyprint.h"
#endif
void Main() {
int H, N;
cin >> H >> N;
vector<int> A, B;
rep(i, N) {
int a, b;
cin >> a >> b;
A.push_back(a);
B.push_back(b);
}
int a_max = *max_element(A.begin(), A.end());
vector<ll> dp; // dp[H] is final goal, but cost for dp[H + 1], dp[H + 2], ...,
// dp[H + a_max - 1] might be sometimes smaller
rep(i, H + a_max - 1) {
if (i == 0) {
dp.push_back(0);
continue;
}
ll min_cost = MOD;
rep(j, N) {
if (i - A.at(j) >= 0) {
if (min_cost > (B.at(j) + dp.at(i - A.at(j)))) {
min_cost = B.at(j) + dp.at(i - A.at(j));
}
}
}
dp.push_back(min_cost);
}
ll ans = MOD;
for (int i = H; i <= H + a_max - 1; i++) {
if (dp.at(i) < ans) {
ans = dp.at(i);
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
* For DEBUG
* https://github.com/ta7uw/cpp-pyprint
*/
#include "cpp-pyprint/pyprint.h"
#endif
void Main() {
int H, N;
cin >> H >> N;
vector<int> A, B;
rep(i, N) {
int a, b;
cin >> a >> b;
A.push_back(a);
B.push_back(b);
}
int a_max = *max_element(A.begin(), A.end());
vector<ll> dp; // dp[H] is final goal, but cost for dp[H + 1], dp[H + 2], ...,
// dp[H + a_max - 1] might be sometimes smaller
rep(i, H + a_max) {
if (i == 0) {
dp.push_back(0);
continue;
}
ll min_cost = MOD;
rep(j, N) {
if (i - A.at(j) >= 0) {
if (min_cost > (B.at(j) + dp.at(i - A.at(j)))) {
min_cost = B.at(j) + dp.at(i - A.at(j));
}
}
}
dp.push_back(min_cost);
}
ll ans = MOD;
for (int i = H; i <= H + a_max - 1; i++) {
if (dp.at(i) < ans) {
ans = dp.at(i);
}
}
cout << ans << endl;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
}
| replace | 40 | 41 | 40 | 41 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 16) >= this->size() (which is 16)
|
p02787 | C++ | Time Limit Exceeded | // Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std;
int h, n;
const int M = 1e3;
int a[M][2];
ll dp[M][10001];
ll solve(int idx = 0, int rem = h) {
if (rem <= 0)
return 0;
if (idx >= n)
return 1e12;
// cout << idx <<" " << rem <<"\n";
ll &ret = dp[idx][rem];
if (~ret)
return ret;
ret = 1e12;
ll curcost = 0;
int currem = rem;
while (rem) {
rem -= a[idx][0];
curcost += a[idx][1];
ret = min(ret, curcost + solve(idx + 1, rem));
rem = max(0, rem);
}
rem = currem;
ret = min(ret, solve(idx + 1, rem));
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
scanf("%d%d", &h, &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", a[i], a[i] + 1);
}
printf("%lld\n", solve());
}
| // Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std;
int h, n;
const int M = 1e3;
int a[M][2];
ll dp[M][10001];
ll solve(int idx = 0, int rem = h) {
if (rem <= 0)
return 0;
if (idx >= n)
return 1e12;
// cout << idx <<" " << rem <<"\n";
ll &ret = dp[idx][rem];
if (~ret)
return ret;
ret = solve(idx + 1, rem);
ret = min(ret, a[idx][1] + solve(idx, rem - a[idx][0]));
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
scanf("%d%d", &h, &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", a[i], a[i] + 1);
}
printf("%lld\n", solve());
}
| replace | 24 | 36 | 24 | 26 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1010, M = 20010;
int n, m;
int a[N], b[N];
int f[M];
int main() {
scanf("%d%d", &m, &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = m + a[i]; j >= 0; j--)
for (int k = 0; k <= j / a[i]; k++)
f[j] = min(f[j], f[j - k * a[i]] + k * b[i]);
int res = 0x3f3f3f3f;
for (int i = m; i < M; i++)
res = min(res, f[i]);
printf("%d\n", res);
return 0;
}
| #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1010, M = 20010;
int n, m;
int a[N], b[N];
int f[M];
int main() {
scanf("%d%d", &m, &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
memset(f, 0x3f, sizeof f);
f[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = a[i]; j <= m + a[i]; j++)
f[j] = min(f[j], f[j - a[i]] + b[i]);
int res = 0x3f3f3f3f;
for (int i = m; i < M; i++)
res = min(res, f[i]);
printf("%d\n", res);
return 0;
} | replace | 25 | 28 | 25 | 27 | TLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \
<< " = " << (z) << endl
#define showv(v) \
rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i, v.size()) printf("%d\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\n", t[i])
#define incl(v, x) find(rng(v), x) != v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1 << 30) - 1;
const ll INFLL = (1LL << 62) - 1;
#define dame \
{ \
puts("No"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
inline int in() {
int x;
scanf("%d", &x);
return x;
}
// cout << fixed << setprecision(10);
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dp[50001];
int main() {
int h, n;
cin >> h >> n;
vi a(n), b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
rep(i, 100000) dp[i] = INF;
dp[0] = 0;
rep(i, h + 1) {
rep(j, n) {
if (dp[i] == INF)
continue;
chmin(dp[i + a[j]], dp[i] + b[j]);
}
}
int ans = INF;
for (int i = h; i < h + *max_element(rng(a)); ++i) {
chmin(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x, y) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x, y, z) \
cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \
<< " = " << (z) << endl
#define showv(v) \
rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ')
#define showv2(v) rep(j, v.size()) showv(v[j])
#define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ')
#define showt2(t, r, c) rep(j, r) showt(t[j], c)
#define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i, v.size()) printf("%d\n", v[i])
#define printt(t, n) rep(i, n) printf("%d\n", t[i])
#define incl(v, x) find(rng(v), x) != v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1 << 30) - 1;
const ll INFLL = (1LL << 62) - 1;
#define dame \
{ \
puts("No"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
inline int in() {
int x;
scanf("%d", &x);
return x;
}
// cout << fixed << setprecision(10);
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dp[50001];
int main() {
int h, n;
cin >> h >> n;
vi a(n), b(n);
rep(i, n) { cin >> a[i] >> b[i]; }
rep(i, 50000) dp[i] = INF;
dp[0] = 0;
rep(i, h + 1) {
rep(j, n) {
if (dp[i] == INF)
continue;
chmin(dp[i + a[j]], dp[i] + b[j]);
}
}
int ans = INF;
for (int i = h; i < h + *max_element(rng(a)); ++i) {
chmin(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | replace | 88 | 89 | 88 | 89 | -11 | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define RREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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 * b) / gcd(a, b); }
int solve() {
int h, n;
cin >> h >> n;
vector<int> dp(100000, INF);
vector<pair<int, int>> v(n);
rep(i, n) {
int a, b;
cin >> a >> b;
v[i].first = a;
v[i].second = b;
}
dp[0] = 0;
rep(i, h + 1) {
rep(j, n) {
int a = v[j].first, b = v[j].second;
if (i - a < 0)
dp[i] = min(dp[i], b);
dp[i] = min(dp[i], dp[i - a] + b);
}
}
cout << dp[h] << endl;
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cout << fixed;cout << setprecision(16);
solve();
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define RREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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 * b) / gcd(a, b); }
int solve() {
int h, n;
cin >> h >> n;
vector<int> dp(100000, INF);
vector<pair<int, int>> v(n);
rep(i, n) {
int a, b;
cin >> a >> b;
v[i].first = a;
v[i].second = b;
}
dp[0] = 0;
rep(i, h + 1) {
rep(j, n) {
int a = v[j].first, b = v[j].second;
if (i - a < 0)
dp[i] = min(dp[i], b);
else
dp[i] = min(dp[i], dp[i - a] + b);
}
}
cout << dp[h] << endl;
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cout << fixed;cout << setprecision(16);
solve();
return 0;
} | replace | 66 | 67 | 66 | 68 | -11 | |
p02787 | C++ | Time Limit Exceeded | #pragma region
#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; i--)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline bool CHMAX(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool CHMIN(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
template <class T> inline void in(T &t) { cin >> t; }
template <class T, class... Ts> inline void in(T &t, Ts &...ts) {
cin >> t;
in(ts...);
}
template <class T> inline void out(T t) { cout << t << "\n"; }
template <class T, class... Ts> inline void out(T t, Ts... ts) {
cout << t << " ";
out(ts...);
}
template <typename T = int> vector<T> mv(size_t a) { return vector<T>(a); }
template <typename T = int, typename... Ts> auto mv(size_t a, Ts... ts) {
return vector<decltype(mv<T>(ts...))>(a, mv<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
for (auto &e : t)
fill(e, v);
}
constexpr long long INF = 1e18;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
// 二項係数ライブラリ
template <class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef() {}
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
init(n);
}
constexpr void init(int n) noexcept {
fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
int MOD = fact_[0].getmod();
for (int i = 2; i < n; i++) {
fact_[i] = fact_[i - 1] * i;
inv_[i] = -inv_[MOD % i] * (MOD / i);
finv_[i] = finv_[i - 1] * inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0)
return 0;
return fact_[n] * finv_[k] * finv_[n - k];
}
constexpr T fact(int n) const noexcept {
if (n < 0)
return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if (n < 0)
return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if (n < 0)
return 0;
return finv_[n];
}
};
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);
#pragma endregion
signed main() {
int H, N;
in(H, N);
auto a = mv(N), b = a;
REP(i, N) in(a[i], b[i]);
auto dp = mv(N + 1, H + 1);
fill(dp, INF);
dp[0][0] = 0;
REP(i, N) {
REP(j, H + 1) {
CHMIN(dp[i + 1], dp[i]);
CHMIN(dp[i + 1][min(H, j + a[i])], dp[i + 1][j] + b[i]);
}
}
out(dp[N][H]);
} | #pragma region
#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; i--)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline bool CHMAX(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool CHMIN(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
template <class T> inline void in(T &t) { cin >> t; }
template <class T, class... Ts> inline void in(T &t, Ts &...ts) {
cin >> t;
in(ts...);
}
template <class T> inline void out(T t) { cout << t << "\n"; }
template <class T, class... Ts> inline void out(T t, Ts... ts) {
cout << t << " ";
out(ts...);
}
template <typename T = int> vector<T> mv(size_t a) { return vector<T>(a); }
template <typename T = int, typename... Ts> auto mv(size_t a, Ts... ts) {
return vector<decltype(mv<T>(ts...))>(a, mv<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
for (auto &e : t)
fill(e, v);
}
constexpr long long INF = 1e18;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
// 二項係数ライブラリ
template <class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef() {}
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
init(n);
}
constexpr void init(int n) noexcept {
fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
int MOD = fact_[0].getmod();
for (int i = 2; i < n; i++) {
fact_[i] = fact_[i - 1] * i;
inv_[i] = -inv_[MOD % i] * (MOD / i);
finv_[i] = finv_[i - 1] * inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0)
return 0;
return fact_[n] * finv_[k] * finv_[n - k];
}
constexpr T fact(int n) const noexcept {
if (n < 0)
return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if (n < 0)
return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if (n < 0)
return 0;
return finv_[n];
}
};
const int MOD = 1000000007;
// const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
// bc.init(500050);
#pragma endregion
signed main() {
int H, N;
in(H, N);
auto a = mv(N), b = a;
REP(i, N) in(a[i], b[i]);
auto dp = mv(N + 1, H + 1);
fill(dp, INF);
dp[0][0] = 0;
REP(i, N) {
REP(j, H + 1) {
CHMIN(dp[i + 1][j], dp[i][j]);
CHMIN(dp[i + 1][min(H, j + a[i])], dp[i + 1][j] + b[i]);
}
}
out(dp[N][H]);
} | replace | 176 | 177 | 176 | 177 | TLE | |
p02787 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e4;
int main() {
int h, n;
cin >> h >> n;
vvint dp(1005, vint(10005, inf));
dp[0][0] = 0;
REP(i, n + 1) {
int a, b;
cin >> a >> b;
rep(j, 10005) {
chmin(dp[i][j], dp[i - 1][j]);
for (int k = max(0, j - a); k <= j - 1; k++) {
chmin(dp[i][j], dp[i][k] + b);
}
}
}
cout << dp[n][h] << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e4;
int main() {
int h, n;
cin >> h >> n;
vvint dp(1005, vint(10005, inf));
dp[0][0] = 0;
REP(i, n + 1) {
int a, b;
cin >> a >> b;
rep(j, 10005) {
chmin(dp[i][j], dp[i - 1][j]);
chmin(dp[i][j], dp[i][max(j - a, 0)] + b);
}
}
cout << dp[n][h] << endl;
} | replace | 41 | 44 | 41 | 42 | TLE | |
p02787 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> dp(10000, vector<int>(10000, 999999999));
vector<int> A(10000), B(10000);
int H, N;
void input() {
cin >> H >> N;
for (int i = 0; i < N; i++) {
cin >> A.at(i) >> B.at(i);
}
return;
}
void DP() {
dp.at(0).at(0) = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
if (A.at(i) >=
j) { // 今考える魔法が与えるダメージが体力j以上のとき(=一撃で倒せるとき)
dp.at(i + 1).at(j) = min(dp.at(i).at(j), B.at(i));
} else {
dp.at(i + 1).at(j) =
min(dp.at(i).at(j), dp.at(i + 1).at(j - A.at(i)) + B.at(i));
}
}
}
return;
}
void output() {
cout << dp.at(N).at(H) << endl;
return;
}
int main() {
input();
DP();
output();
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> dp(10010, vector<int>(10010, 999999999));
vector<int> A(10010), B(10010);
int H, N;
void input() {
cin >> H >> N;
for (int i = 0; i < N; i++) {
cin >> A.at(i) >> B.at(i);
}
return;
}
void DP() {
dp.at(0).at(0) = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= H; j++) {
if (A.at(i) >=
j) { // 今考える魔法が与えるダメージが体力j以上のとき(=一撃で倒せるとき)
dp.at(i + 1).at(j) = min(dp.at(i).at(j), B.at(i));
} else {
dp.at(i + 1).at(j) =
min(dp.at(i).at(j), dp.at(i + 1).at(j - A.at(i)) + B.at(i));
}
}
}
return;
}
void output() {
cout << dp.at(N).at(H) << endl;
return;
}
int main() {
input();
DP();
output();
return 0;
} | replace | 5 | 7 | 5 | 7 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02787 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
int dp[n + 1][h + 100001];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= h + 10000; ++j) {
dp[i][j] = 1e9;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= h + 10000; ++j) {
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
}
}
int ans = 1e9;
for (int i = h; i <= h + 10000; ++i) {
ans = min(ans, dp[n][i]);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
int dp[n + 1][h + 10001];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= h + 10000; ++j) {
dp[i][j] = 1e9;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= h + 10000; ++j) {
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
}
}
int ans = 1e9;
for (int i = h; i <= h + 10000; ++i) {
ans = min(ans, dp[n][i]);
}
cout << ans << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p02787 | C++ | Memory Limit Exceeded | #include "bits/stdc++.h"
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i)
#define MSVC_UNKO(x) x
#define rep(...) \
MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__))
#define all(c) c.begin(), c.end()
#define write(x) cout << (x) << '\n'
using namespace std;
typedef long long ll;
template <class T> using vv = vector<vector<T>>;
template <class T> auto vvec(int n, int m, T v) {
return vv<T>(n, vector<T>(m, v));
}
constexpr int INF = 1 << 29, MOD = int(1e9) + 7;
constexpr ll LINF = 1LL << 60;
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(10);
};
} aaaa;
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
rep(i, N) {
for (int a = A[i], b = B[i]; a < H;) {
a *= 2, b *= 2;
A.push_back(a);
B.push_back(b);
N++;
}
}
vv<int> dp = vvec(N + 1, 4e4 + 1, INF);
dp[0][0] = 0;
rep(i, N) rep(h, 0, 2e4 + 1) {
dp[i + 1][h + A[i]] = dp[i][h] + B[i];
dp[i + 1][h] = min(dp[i + 1][h], dp[i][h]);
}
int ans = INF;
rep(h, H, 2e4 + 1) ans = min(ans, dp[N][h]);
write(ans);
} | #include "bits/stdc++.h"
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i)
#define MSVC_UNKO(x) x
#define rep(...) \
MSVC_UNKO(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__))
#define all(c) c.begin(), c.end()
#define write(x) cout << (x) << '\n'
using namespace std;
typedef long long ll;
template <class T> using vv = vector<vector<T>>;
template <class T> auto vvec(int n, int m, T v) {
return vv<T>(n, vector<T>(m, v));
}
constexpr int INF = 1 << 29, MOD = int(1e9) + 7;
constexpr ll LINF = 1LL << 60;
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(10);
};
} aaaa;
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
rep(i, N) cin >> A[i] >> B[i];
vector<int> dp(2e4 + 1, INF);
dp[0] = 0;
rep(i, N) rep(h, H + 1) { dp[h + A[i]] = min(dp[h + A[i]], dp[h] + B[i]); }
write(*min_element(dp.begin() + H, dp.end()));
} | replace | 31 | 49 | 31 | 35 | MLE | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 5000;
long long dp[N];
int a[N], b[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int h, n;
cin >> h >> n;
for (int i = 0; i < h; ++i) {
dp[i] = 1e18;
}
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; ++i) {
for (int j = h; j >= 0; --j) {
int v = max(0, j - a[i]);
dp[v] = min(dp[v], dp[j] + b[i]);
}
}
cout << dp[0];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
long long dp[N];
int a[N], b[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int h, n;
cin >> h >> n;
for (int i = 0; i < h; ++i) {
dp[i] = 1e18;
}
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; ++i) {
for (int j = h; j >= 0; --j) {
int v = max(0, j - a[i]);
dp[v] = min(dp[v], dp[j] + b[i]);
}
}
cout << dp[0];
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02787 | Python | Runtime Error | def main():
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [0] + [0] * h
for i in range(1, h + 1):
dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])
if __name__ == "__main__":
main()
| def main():
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
amax = max(a for a, b in ab)
dp = [0] + [0] * (h + amax)
for i in range(1, h + 1):
dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])
if __name__ == "__main__":
main()
| replace | 4 | 5 | 4 | 6 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
int h, n, a, b, dp[MAXN];
int main() {
scanf("%d%d", &h, &n);
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a, &b);
for (int i = a; i <= h; i++) {
dp[i] = min(dp[i], dp[i - a] + b);
}
for (int i = h - a; i <= h; i++) {
dp[h] = min(dp[h], dp[i] + b);
}
}
printf("%d\n", dp[h]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
int h, n, a, b, dp[MAXN];
int main() {
scanf("%d%d", &h, &n);
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a, &b);
for (int i = a; i <= h; i++) {
dp[i] = min(dp[i], dp[i - a] + b);
}
for (int i = max(h - a, 0); i <= h; i++) {
dp[h] = min(dp[h], dp[i] + b);
}
}
printf("%d\n", dp[h]);
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
const int MOD = 1e9 + 7;
const int N = 1e4 + 10;
const int INF = 1e9 + 5;
int d[N];
int main(void) {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int h, n;
scanf("%d %d", &h, &n);
for (int i = 0; i <= h; i++)
d[i] = INF;
d[0] = 0;
while (n--) {
int value, cost;
scanf("%d %d", &value, &cost);
for (int i = 0; i <= h; ++i) {
int j = min(h, i + value);
d[j] = min(d[j], d[i] + cost);
}
}
printf("%d\n", d[h]);
return false;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
const int MOD = 1e9 + 7;
const int N = 1e4 + 10;
const int INF = 1e9 + 5;
int d[N];
int main(void) {
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
#endif
int h, n;
scanf("%d %d", &h, &n);
for (int i = 0; i <= h; i++)
d[i] = INF;
d[0] = 0;
while (n--) {
int value, cost;
scanf("%d %d", &value, &cost);
for (int i = 0; i <= h; ++i) {
int j = min(h, i + value);
d[j] = min(d[j], d[i] + cost);
}
}
printf("%d\n", d[h]);
return false;
}
| replace | 59 | 60 | 59 | 60 | -11 | |
p02787 | Python | Runtime Error | H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])
dp = [0] * (H + 1)
for h in range(1, H + 1):
dp[h] = min([dp[h - a] + b for a, b in AB])
print(dp[-1])
| H, N = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])
dp = [0] * (H + 1)
for h in range(1, H + 1):
dp[h] = min([dp[max(h - a, 0)] + b for a, b in AB])
print(dp[-1])
| replace | 6 | 7 | 6 | 7 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
int dp[11000];
int h, n;
const int INF = 1001001001;
int main() {
cin >> h >> n;
rep(j, h + 1) dp[j] = INF;
dp[0] = 0;
rep(i, n) {
int a, b;
cin >> a >> b;
rep(j, h + 1) { dp[j] = min(dp[j], dp[j - a] + b); }
}
cout << dp[h] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
int dp[11000];
int h, n;
const int INF = 1001001001;
int main() {
cin >> h >> n;
rep(j, h + 1) dp[j] = INF;
dp[0] = 0;
rep(i, n) {
int a, b;
cin >> a >> b;
rep(j, h + 1) { dp[min(j + a, h)] = min(dp[min(j + a, h)], dp[j] + b); }
}
cout << dp[h] << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02787 | Python | Runtime Error | import sys
def solve(h, n, ab):
ab.sort(key=lambda x: x[1] / x[0])
INF = 10**18
cache = {}
# とりあえず一番コスパいいやつだけを使った結果を暫定最良値としておく
best = ((h - 1) // ab[0][0] + 1) * ab[0][1]
def dp(k, i=0, cost=0):
nonlocal best
if k <= 0:
return cost
if (k, i) in cache:
return cache[k, i] + cost
a, b = ab[i]
if k / a * b + cost >= best:
# どう足掻いても残りでbestより良い結果は得られない
return INF
c = (k - 1) // a + 1
if i == n - 1:
ret = cost + b * c
else:
ret = min(dp(k - a * j, i + 1, cost + b * j) for j in range(c + 1))
cache[k, i] = ret - cost
best = min(best, ret)
return ret
dp(h)
return best
sys.setrecursionlimit(1001)
h, n = map(int, input().split())
ab = [tuple(map(int, line.split())) for line in sys.stdin]
print(solve(h, n, ab))
| import sys
def solve(h, n, ab):
ab.sort(key=lambda x: x[1] / x[0])
INF = 10**18
cache = {}
# とりあえず一番コスパいいやつだけを使った結果を暫定最良値としておく
best = ((h - 1) // ab[0][0] + 1) * ab[0][1]
def dp(k, i=0, cost=0):
nonlocal best
if k <= 0:
return cost
if (k, i) in cache:
return cache[k, i] + cost
a, b = ab[i]
if k / a * b + cost >= best:
# どう足掻いても残りでbestより良い結果は得られない
return INF
c = (k - 1) // a + 1
if i == n - 1:
ret = cost + b * c
else:
ret = min(dp(k - a * j, i + 1, cost + b * j) for j in range(c + 1))
cache[k, i] = ret - cost
best = min(best, ret)
return ret
dp(h)
return best
sys.setrecursionlimit(10001)
h, n = map(int, input().split())
ab = [tuple(map(int, line.split())) for line in sys.stdin]
print(solve(h, n, ab))
| replace | 33 | 34 | 33 | 34 | 0 | |
p02787 | Python | Runtime Error | h, n, *L = map(int, open(0).read().split())
dp = [0] * (h + 1)
for i in range(1, h + 1):
dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(L)] * 2))
print(dp[h])
| h, n, *L = map(int, open(0).read().split())
dp = [0] * (h + 99999)
for i in range(1, h + 1):
dp[i] = min(dp[i - a] + b for a, b in zip(*[iter(L)] * 2))
print(dp[h])
| replace | 1 | 2 | 1 | 2 | 0 | |
p02787 | Python | Runtime Error | def main():
h, n = map(int, input().split())
magic_list = []
for _ in range(n):
a, b = map(int, input().split())
magic_list.append((a, b))
ans = solve(h, magic_list)
print(ans)
def solve(h, magic_list):
# 1-origin
dp = [0] * (h + 1)
# time O(HN)
for hp in range(1, h + 1):
dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)
return dp[h]
main()
| def main():
h, n = map(int, input().split())
magic_list = []
for _ in range(n):
a, b = map(int, input().split())
magic_list.append((a, b))
ans = solve(h, magic_list)
print(ans)
def solve(h, magic_list):
# 1-origin
max_attack = max(magic_list)[0]
dp = [0] * (h + max_attack)
# time O(HN)
for hp in range(1, h + 1):
dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)
return dp[h]
main()
| replace | 14 | 15 | 14 | 16 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
int maxA = 0;
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
maxA = max(maxA, A[i]);
}
int Hmax = H + maxA + 1;
vector<vector<int>> dp(N, vector<int>(Hmax, 1e9));
for (int h = 0; h <= Hmax; h++) {
dp[0][h] = (h + A[0] - 1) / A[0] * B[0];
}
for (int i = 0; i < N - 1; i++)
for (int h = 0; h <= Hmax; h++) {
dp[i + 1][h] = dp[i][h];
if (h - A[i + 1] >= 0)
dp[i + 1][h] = min(dp[i + 1][h], dp[i + 1][h - A[i + 1]] + B[i + 1]);
}
int ans = 1e9;
for (int h = H; h <= Hmax; h++) {
ans = min(ans, dp[N - 1][h]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main() {
int H, N;
cin >> H >> N;
vector<int> A(N), B(N);
int maxA = 0;
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i];
maxA = max(maxA, A[i]);
}
int Hmax = H + maxA + 1;
vector<vector<int>> dp(N, vector<int>(Hmax + 1, 1e9));
for (int h = 0; h <= Hmax; h++) {
dp[0][h] = (h + A[0] - 1) / A[0] * B[0];
}
for (int i = 0; i < N - 1; i++)
for (int h = 0; h <= Hmax; h++) {
dp[i + 1][h] = dp[i][h];
if (h - A[i + 1] >= 0)
dp[i + 1][h] = min(dp[i + 1][h], dp[i + 1][h - A[i + 1]] + B[i + 1]);
}
int ans = 1e9;
for (int h = H; h <= Hmax; h++) {
ans = min(ans, dp[N - 1][h]);
}
cout << ans << endl;
} | replace | 16 | 17 | 16 | 17 | -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 <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
constexpr LL kInf = 1e18;
template <typename T> istream &operator>>(istream &is, vector<T> &vs) {
for (T &v : vs)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
for (const T &v : vs)
os << v << " ";
return os;
}
int main() {
LL H, N;
cin >> H >> N;
vector<vector<LL>> dp(N + 1, vector<LL>(H + 1, kInf));
for (int i = 0; i <= N; ++i)
dp[i][H] = 0;
for (int i = 1; i <= N; ++i) {
LL A, B;
cin >> A >> B;
for (int j = H - 1; j > H - A; --j) {
dp[i][j] = min(dp[i - 1][j], B);
}
for (int j = H - A; j >= 0; --j) {
dp[i][j] = min(dp[i - 1][j], dp[i][j + A] + B);
}
}
cout << dp[N][0] << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
constexpr LL kInf = 1e18;
template <typename T> istream &operator>>(istream &is, vector<T> &vs) {
for (T &v : vs)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
for (const T &v : vs)
os << v << " ";
return os;
}
int main() {
LL H, N;
cin >> H >> N;
vector<vector<LL>> dp(N + 1, vector<LL>(H + 1, kInf));
for (int i = 0; i <= N; ++i)
dp[i][H] = 0;
for (int i = 1; i <= N; ++i) {
LL A, B;
cin >> A >> B;
for (int j = H - 1; j >= max(0LL, H - A - 1); --j) {
dp[i][j] = min(dp[i - 1][j], B);
}
for (int j = H - A; j >= 0; --j) {
dp[i][j] = min(dp[i - 1][j], dp[i][j + A] + B);
}
}
cout << dp[N][0] << endl;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p02787 | Python | Runtime Error | h, n = map(int, input().split())
a = []
b = []
for i in range(n):
a_, b_ = map(int, input().split())
a.append(a_)
b.append(b_)
dp = [float("inf")] * (h + 1010)
dp[0] = 0
for i in range(h + 1):
for j in range(n):
dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
print(min(dp[h:]))
| h, n = map(int, input().split())
a = []
b = []
for i in range(n):
a_, b_ = map(int, input().split())
a.append(a_)
b.append(b_)
dp = [float("inf")] * (h + 10010)
dp[0] = 0
for i in range(h + 1):
for j in range(n):
dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
print(min(dp[h:]))
| replace | 8 | 9 | 8 | 9 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pi>
const int N = 1005;
int dp[10 * N], a[N], b[N];
int main() {
int h, n;
cin >> h >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int j = 1; j <= h + 10000; j++)
dp[j] = mod;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j <= h + 10000; j++) {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
// cout<<j<<" "<<dp[j]<<"\n";
}
}
for (int i = h + 1; i <= h + 10000; i++)
dp[h] = min(dp[h], dp[i]);
if (dp[h] >= mod / 2)
dp[h] = -1;
cout << dp[h];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pi>
const int N = 1005;
int dp[20 * N], a[N], b[N];
int main() {
int h, n;
cin >> h >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int j = 1; j <= h + 10000; j++)
dp[j] = mod;
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = a[i]; j <= h + 10000; j++) {
dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
// cout<<j<<" "<<dp[j]<<"\n";
}
}
for (int i = h + 1; i <= h + 10000; i++)
dp[h] = min(dp[h], dp[i]);
if (dp[h] >= mod / 2)
dp[h] = -1;
cout << dp[h];
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(), (x).end()
#define int long long
#define fr first
#define sc second
#define vc vector
#define endl '\n'
#define pii pair<int, int>
#define msi map<string, int>
#define mii map<int, int>
#define psi pair<string, int>
#define pis pair<int, string>
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define LSB(i) ((i) & -(i))
template <typename T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int H = 1e4 + 5;
const int N = 1e3 + 3;
int n, h;
int dp[N];
int a[N], b[N];
int dynamic(int health) {
if (health <= 0)
return 0;
if (dp[health] != -1)
return dp[health];
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
ans = min(ans, dynamic(health - a[i]) + b[i]);
}
dp[health] = ans;
return ans;
}
void solve() {
mem1(dp);
cin >> h >> n;
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
cout << dynamic(h);
}
signed main() {
ios_base::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
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/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(), (x).end()
#define int long long
#define fr first
#define sc second
#define vc vector
#define endl '\n'
#define pii pair<int, int>
#define msi map<string, int>
#define mii map<int, int>
#define psi pair<string, int>
#define pis pair<int, string>
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define LSB(i) ((i) & -(i))
template <typename T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int H = 1e4 + 5;
const int N = 1e3 + 3;
int n, h;
int dp[H];
int a[N], b[N];
int dynamic(int health) {
if (health <= 0)
return 0;
if (dp[health] != -1)
return dp[health];
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
ans = min(ans, dynamic(health - a[i]) + b[i]);
}
dp[health] = ans;
return ans;
}
void solve() {
mem1(dp);
cin >> h >> n;
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
cout << dynamic(h);
}
signed main() {
ios_base::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p02787 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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;
}
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
EACH(it, P) { s << "<" << *it << "> "; }
return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
return s << endl;
}
template <class T> void show(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << " ";
}
cerr << "\n";
}
typedef long long ll;
int dp[10010];
int a[1010], b[1010];
signed main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
vector<pair<double, double>> v(n);
REP(i, n)
cin >> a[i] >> b[i];
vector<pair<double, double>> p(n);
int cnt = 0;
for (int i = 0; i <= 10000; i++) {
dp[i] = INF;
}
// cerr << dp[0] << endl;
for (int i = 0; i < n; i++) {
dp[0] = min(dp[0], b[i]);
}
// cerr << dp[0] << endl;
// dp[0] = 0;
dp[0] = 0;
for (int i = 0; i <= h; i++) {
bool ok = false;
for (int j = 0; j < n; j++) {
dp[i + a[j]] = min(dp[i] + b[j], dp[i + a[j]]);
ok = true;
}
}
/* for (int i = 0; i <= h; i++)
{
cerr << dp[i] << endl;
}*/
int ans = INF;
for (int i = h; i <= 10000; i++) {
ans = min(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) \
for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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;
}
template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) {
return s << '<' << P.first << ", " << P.second << '>';
}
template <class T> ostream &operator<<(ostream &s, vector<T> P) {
for (int i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) {
for (int i = 0; i < P.size(); ++i) {
s << endl << P[i];
}
return s << endl;
}
template <class T> ostream &operator<<(ostream &s, set<T> P) {
EACH(it, P) { s << "<" << *it << "> "; }
return s << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) {
EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
return s << endl;
}
template <class T> void show(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << " ";
}
cerr << "\n";
}
typedef long long ll;
int dp[100010];
int a[1010], b[1010];
signed main() {
int h, n;
cin >> h >> n;
vector<int> a(n), b(n);
vector<pair<double, double>> v(n);
REP(i, n)
cin >> a[i] >> b[i];
vector<pair<double, double>> p(n);
int cnt = 0;
for (int i = 0; i <= 10000; i++) {
dp[i] = INF;
}
// cerr << dp[0] << endl;
for (int i = 0; i < n; i++) {
dp[0] = min(dp[0], b[i]);
}
// cerr << dp[0] << endl;
// dp[0] = 0;
dp[0] = 0;
for (int i = 0; i <= h; i++) {
bool ok = false;
for (int j = 0; j < n; j++) {
dp[i + a[j]] = min(dp[i] + b[j], dp[i + a[j]]);
ok = true;
}
}
/* for (int i = 0; i <= h; i++)
{
cerr << dp[i] << endl;
}*/
int ans = INF;
for (int i = h; i <= 10000; i++) {
ans = min(ans, dp[i]);
}
cout << ans << endl;
return 0;
} | replace | 59 | 60 | 59 | 60 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.