feat(cses): more dp
This commit is contained in:
parent
3153490991
commit
e0a8333591
32 changed files with 1052 additions and 0 deletions
9
cses/dynamic-programming/.clang-format
Normal file
9
cses/dynamic-programming/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
BasedOnStyle: Google
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortCompoundRequirementOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLambdasOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
34
cses/dynamic-programming/.clangd
Normal file
34
cses/dynamic-programming/.clangd
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add:
|
||||||
|
-O2
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
-Wshadow
|
||||||
|
-Wformat=2
|
||||||
|
-Wfloat-equal
|
||||||
|
-Wlogical-op
|
||||||
|
-Wshift-overflow=2
|
||||||
|
-Wnon-virtual-dtor
|
||||||
|
-Wold-style-cast
|
||||||
|
-Wcast-qual
|
||||||
|
-Wuseless-cast
|
||||||
|
-Wno-sign-promotion
|
||||||
|
-Wcast-align
|
||||||
|
-Wunused
|
||||||
|
-Woverloaded-virtual
|
||||||
|
-Wconversion
|
||||||
|
-Wsign-conversion
|
||||||
|
-Wmisleading-indentation
|
||||||
|
-Wduplicated-cond
|
||||||
|
-Wduplicated-branches
|
||||||
|
-Wlogical-op
|
||||||
|
-Wnull-dereference
|
||||||
|
-Wformat=2
|
||||||
|
-Wformat-overflow
|
||||||
|
-Wformat-truncation
|
||||||
|
-Wdouble-promotion
|
||||||
|
-Wundef
|
||||||
|
-DLOCAL
|
||||||
|
-std=c++20
|
||||||
|
-Wno-unknown-pragmas
|
||||||
114
cses/dynamic-programming/array-description.cc
Normal file
114
cses/dynamic-programming/array-description.cc
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
static constexpr u64 MOD = 1e9 + 7;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u32 n, m;
|
||||||
|
cin >> n >> m;
|
||||||
|
vec<i64> a(n);
|
||||||
|
for (auto& e : a)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
vec<i64> prev(m + 1, 0);
|
||||||
|
if (a[0] != 0) {
|
||||||
|
prev[a[0]] = 1;
|
||||||
|
} else {
|
||||||
|
for (u32 i = 1; i <= m; ++i)
|
||||||
|
prev[i] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (u32 i = 2; i <= n; ++i) {
|
||||||
|
vec<i64> cur(m + 1, 0);
|
||||||
|
if (a[i - 1] == 0) {
|
||||||
|
for (u32 x = 1; x <= m; ++x) {
|
||||||
|
for (i64 delta = -1; delta <= 1; ++delta) {
|
||||||
|
if (1 <= x + delta && x + delta <= m)
|
||||||
|
cur[x] = (cur[x] + prev[x + delta]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i64 delta = -1; delta <= 1; ++delta) {
|
||||||
|
if (1 <= a[i - 1] + delta && a[i - 1] + delta <= m)
|
||||||
|
cur[a[i - 1]] = (cur[a[i - 1]] + prev[a[i - 1] + delta]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev = cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
i64 ans = 0;
|
||||||
|
for (auto e : prev) {
|
||||||
|
ans = (ans + e) % MOD;
|
||||||
|
}
|
||||||
|
cout << ans << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
93
cses/dynamic-programming/book-shop.cc
Normal file
93
cses/dynamic-programming/book-shop.cc
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n, x;
|
||||||
|
cin >> n >> x;
|
||||||
|
vec<u64> pages(n), prices(n);
|
||||||
|
for (auto& e : prices)
|
||||||
|
cin >> e;
|
||||||
|
for (auto& e : pages)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
vec<u64> dp(x + 1, 0);
|
||||||
|
|
||||||
|
for (u64 i = 1; i <= n; ++i) {
|
||||||
|
for (u64 j = x; j >= 1; --j) {
|
||||||
|
if (j >= prices[i - 1])
|
||||||
|
dp[j] = max(dp[j], dp[j - prices[i - 1]] + pages[i - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << dp[x] << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
96
cses/dynamic-programming/coin-combinations-i.cc
Normal file
96
cses/dynamic-programming/coin-combinations-i.cc
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
static constexpr u64 MOD = 1e9 + 7;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n, x;
|
||||||
|
cin >> n >> x;
|
||||||
|
vec<u64> c(n);
|
||||||
|
for (auto& e : c)
|
||||||
|
cin >> e;
|
||||||
|
sort(all(c));
|
||||||
|
|
||||||
|
vec<u64> distinct(x + 1, 0);
|
||||||
|
distinct[0] = 1;
|
||||||
|
|
||||||
|
for (u64 i = 1; i <= x; ++i) {
|
||||||
|
for (u64 j = 0; j < n && c[j] <= i; ++j) {
|
||||||
|
if (distinct[i - c[j]] != 0) {
|
||||||
|
distinct[i] = (distinct[i] + distinct[i - c[j]]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << distinct[x] << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
94
cses/dynamic-programming/coin-combinations-ii.cc
Normal file
94
cses/dynamic-programming/coin-combinations-ii.cc
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
static constexpr u64 MOD = 1e9 + 7;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n, x;
|
||||||
|
cin >> n >> x;
|
||||||
|
vec<u64> c(n);
|
||||||
|
for (auto& e : c) {
|
||||||
|
cin >> e;
|
||||||
|
}
|
||||||
|
sort(all(c));
|
||||||
|
|
||||||
|
vec<u64> ways(x + 1, 0);
|
||||||
|
ways[0] = 1;
|
||||||
|
for (u32 i = 0; i < n; ++i) {
|
||||||
|
for (u64 j = c[i]; j <= x; ++j) {
|
||||||
|
ways[j] = (ways[j] + ways[j - c[i]]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ways[x] << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
31
cses/dynamic-programming/compile_flags.txt
Normal file
31
cses/dynamic-programming/compile_flags.txt
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
-O2
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
-Wshadow
|
||||||
|
-Wformat=2
|
||||||
|
-Wfloat-equal
|
||||||
|
-Wlogical-op
|
||||||
|
-Wshift-overflow=2
|
||||||
|
-Wnon-virtual-dtor
|
||||||
|
-Wold-style-cast
|
||||||
|
-Wcast-qual
|
||||||
|
-Wuseless-cast
|
||||||
|
-Wno-sign-promotion
|
||||||
|
-Wcast-align
|
||||||
|
-Wunused
|
||||||
|
-Woverloaded-virtual
|
||||||
|
-Wconversion
|
||||||
|
-Wsign-conversion
|
||||||
|
-Wmisleading-indentation
|
||||||
|
-Wduplicated-cond
|
||||||
|
-Wduplicated-branches
|
||||||
|
-Wlogical-op
|
||||||
|
-Wnull-dereference
|
||||||
|
-Wformat=2
|
||||||
|
-Wformat-overflow
|
||||||
|
-Wformat-truncation
|
||||||
|
-Wdouble-promotion
|
||||||
|
-Wundef
|
||||||
|
-DLOCAL
|
||||||
|
-std=c++23
|
||||||
12
cses/dynamic-programming/debug_flags.txt
Normal file
12
cses/dynamic-programming/debug_flags.txt
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
-g3
|
||||||
|
-fsanitize=address,undefined
|
||||||
|
-fsanitize=float-divide-by-zero
|
||||||
|
-fsanitize=float-cast-overflow
|
||||||
|
-fno-sanitize-recover=all
|
||||||
|
-fstack-protector-all
|
||||||
|
-fstack-usage
|
||||||
|
-fno-omit-frame-pointer
|
||||||
|
-fno-inline
|
||||||
|
-ffunction-sections
|
||||||
|
-D_GLIBCXX_DEBUG
|
||||||
|
-D_GLIBCXX_DEBUG_PEDANTIC
|
||||||
90
cses/dynamic-programming/dice-combinations.cc
Normal file
90
cses/dynamic-programming/dice-combinations.cc
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db
|
||||||
|
#define dbln
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
constexpr u64 MOD = 1e9 + 7;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
u64 six = 6;
|
||||||
|
vec<u64> toss(n + 1, 0);
|
||||||
|
toss[0] = 1;
|
||||||
|
for (u64 i = 1; i <= n; ++i) {
|
||||||
|
for (u64 j = 1; j <= min(six, i); ++j) {
|
||||||
|
toss[i] = (toss[i] + toss[i - j]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << toss[n] << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
97
cses/dynamic-programming/grid-paths.cc
Normal file
97
cses/dynamic-programming/grid-paths.cc
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
static constexpr u64 MOD = 1e9 + 7;
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n;
|
||||||
|
cin >> n;
|
||||||
|
vec<string> board(n);
|
||||||
|
for (auto& e : board)
|
||||||
|
cin >> e;
|
||||||
|
|
||||||
|
vec<u64> moves(n + 1, 0);
|
||||||
|
moves[1] = board[0][0] == '.';
|
||||||
|
|
||||||
|
for (u64 r = 1; r <= n; ++r) {
|
||||||
|
for (u64 c = 1; c <= n; ++c) {
|
||||||
|
if (board[r - 1][c - 1] == '*') {
|
||||||
|
moves[c] = 0;
|
||||||
|
} else {
|
||||||
|
moves[c] = (moves[c - 1] + moves[c]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << moves[n] << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
2
cses/dynamic-programming/io/array-description.in
Normal file
2
cses/dynamic-programming/io/array-description.in
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
10 3
|
||||||
|
0 0 0 0 0 0 0 0 0 0
|
||||||
4
cses/dynamic-programming/io/array-description.out
Normal file
4
cses/dynamic-programming/io/array-description.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
8119
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 3.31473 ms
|
||||||
3
cses/dynamic-programming/io/book-shop.in
Normal file
3
cses/dynamic-programming/io/book-shop.in
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
4 10
|
||||||
|
4 8 5 3
|
||||||
|
5 12 8 1
|
||||||
4
cses/dynamic-programming/io/book-shop.out
Normal file
4
cses/dynamic-programming/io/book-shop.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
13
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.72617 ms
|
||||||
2
cses/dynamic-programming/io/coin-combinations-i.in
Normal file
2
cses/dynamic-programming/io/coin-combinations-i.in
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
3 9
|
||||||
|
2 3 5
|
||||||
4
cses/dynamic-programming/io/coin-combinations-i.out
Normal file
4
cses/dynamic-programming/io/coin-combinations-i.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
8
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.17066 ms
|
||||||
2
cses/dynamic-programming/io/coin-combinations-ii.in
Normal file
2
cses/dynamic-programming/io/coin-combinations-ii.in
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
3 9
|
||||||
|
2 3 5
|
||||||
4
cses/dynamic-programming/io/coin-combinations-ii.out
Normal file
4
cses/dynamic-programming/io/coin-combinations-ii.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
3
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.31561 ms
|
||||||
1
cses/dynamic-programming/io/dice-combinations.in
Normal file
1
cses/dynamic-programming/io/dice-combinations.in
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
3
|
||||||
4
cses/dynamic-programming/io/dice-combinations.out
Normal file
4
cses/dynamic-programming/io/dice-combinations.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
4
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.10962 ms
|
||||||
5
cses/dynamic-programming/io/grid-paths.in
Normal file
5
cses/dynamic-programming/io/grid-paths.in
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
4
|
||||||
|
....
|
||||||
|
.*..
|
||||||
|
...*
|
||||||
|
*...
|
||||||
4
cses/dynamic-programming/io/grid-paths.out
Normal file
4
cses/dynamic-programming/io/grid-paths.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
3
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.26126 ms
|
||||||
2
cses/dynamic-programming/io/minimizing-coins.in
Normal file
2
cses/dynamic-programming/io/minimizing-coins.in
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
1 1000000
|
||||||
|
1
|
||||||
4
cses/dynamic-programming/io/minimizing-coins.out
Normal file
4
cses/dynamic-programming/io/minimizing-coins.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
1000000
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 5.76615 ms
|
||||||
1
cses/dynamic-programming/io/removing-digits.in
Normal file
1
cses/dynamic-programming/io/removing-digits.in
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
27
|
||||||
4
cses/dynamic-programming/io/removing-digits.out
Normal file
4
cses/dynamic-programming/io/removing-digits.out
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
5
|
||||||
|
|
||||||
|
[code]: 0
|
||||||
|
[time]: 4.68349 ms
|
||||||
28
cses/dynamic-programming/makefile
Normal file
28
cses/dynamic-programming/makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
.PHONY: run debug clean setup init
|
||||||
|
|
||||||
|
SRC = $(word 2,$(MAKECMDGOALS))
|
||||||
|
|
||||||
|
.SILENT:
|
||||||
|
|
||||||
|
run:
|
||||||
|
sh scripts/run.sh $(SRC)
|
||||||
|
|
||||||
|
debug:
|
||||||
|
sh scripts/debug.sh $(SRC)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build/*
|
||||||
|
|
||||||
|
setup:
|
||||||
|
test -d build || mkdir -p build
|
||||||
|
test -d io || mkdir -p io
|
||||||
|
test -d scripts || mkdir -p scripts
|
||||||
|
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt .
|
||||||
|
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd .
|
||||||
|
test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format .
|
||||||
|
|
||||||
|
init:
|
||||||
|
make setup
|
||||||
|
|
||||||
|
%:
|
||||||
|
@:
|
||||||
98
cses/dynamic-programming/minimizing-coins.cc
Normal file
98
cses/dynamic-programming/minimizing-coins.cc
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n, x;
|
||||||
|
cin >> n >> x;
|
||||||
|
vec<u64> c(n);
|
||||||
|
|
||||||
|
for (auto& e : c)
|
||||||
|
cin >> e;
|
||||||
|
sort(all(c));
|
||||||
|
|
||||||
|
vec<i64> make(x + 1, MAX<i64>);
|
||||||
|
make[0] = 0;
|
||||||
|
|
||||||
|
for (u64 i = 1; i <= x; ++i) {
|
||||||
|
for (u32 j = 0; j < n && c[j] <= i; ++j) {
|
||||||
|
if (make[i - c[j]] != MAX<i64>)
|
||||||
|
make[i] = min(make[i], 1 + make[i - c[j]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (make[x] == MAX<i64>) {
|
||||||
|
cout << "-1\n";
|
||||||
|
} else {
|
||||||
|
cout << make[x] << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
95
cses/dynamic-programming/removing-digits.cc
Normal file
95
cses/dynamic-programming/removing-digits.cc
Normal file
|
|
@ -0,0 +1,95 @@
|
||||||
|
#include <bits/stdc++.h> // {{{
|
||||||
|
|
||||||
|
// https://codeforces.com/blog/entry/96344
|
||||||
|
|
||||||
|
#pragma GCC optimize("O2,unroll-loops")
|
||||||
|
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using i32 = int32_t;
|
||||||
|
using u32 = uint32_t;
|
||||||
|
using i64 = int64_t;
|
||||||
|
using u64 = uint64_t;
|
||||||
|
using d64 = double;
|
||||||
|
using d128 = long double;
|
||||||
|
template <typename T>
|
||||||
|
using vec = std::vector<T>;
|
||||||
|
template <typename T, size_t N>
|
||||||
|
using arr = std::array<T, N>;
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
using pai = std::pair<T1, T2>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MIN = std::numeric_limits<T>::min();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr T MAX = std::numeric_limits<T>::max();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sc(auto&& x) {
|
||||||
|
return static_cast<T>(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] static T sz(auto&& x) {
|
||||||
|
return static_cast<T>(x.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NO() {
|
||||||
|
std::cout << "NO\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
static void YES() {
|
||||||
|
std::cout << "YES\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#define all(x) (x).begin(), (x).end()
|
||||||
|
#define rall(x) (x).rbegin(), (x).rend()
|
||||||
|
|
||||||
|
#ifdef LOCAL
|
||||||
|
#define db(...) std::print(__VA_ARGS__)
|
||||||
|
#define dbln(...) std::println(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define db(...)
|
||||||
|
#define dbln(...)
|
||||||
|
#endif
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
void solve() {
|
||||||
|
u64 n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
auto biggest = [](u64 x) -> u64 {
|
||||||
|
u64 ans = 0;
|
||||||
|
while (x) {
|
||||||
|
ans = max(ans, x % 10);
|
||||||
|
x /= 10;
|
||||||
|
}
|
||||||
|
return ans;
|
||||||
|
};
|
||||||
|
|
||||||
|
u64 ans = 0;
|
||||||
|
|
||||||
|
while (n) {
|
||||||
|
++ans;
|
||||||
|
n -= biggest(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() { // {{{
|
||||||
|
cin.tie(nullptr)->sync_with_stdio(false);
|
||||||
|
cin.exceptions(cin.failbit);
|
||||||
|
|
||||||
|
int tc = 1;
|
||||||
|
// cin >> tc;
|
||||||
|
|
||||||
|
for (int t = 0; t < tc; ++t) {
|
||||||
|
solve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
29
cses/dynamic-programming/scripts/debug.sh
Normal file
29
cses/dynamic-programming/scripts/debug.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./scripts/utils.sh
|
||||||
|
|
||||||
|
SRC="$1"
|
||||||
|
BASE=$(basename "$SRC" .cc)
|
||||||
|
INPUT="${BASE}.in"
|
||||||
|
OUTPUT="${BASE}.out"
|
||||||
|
DBG_BIN="${BASE}.debug"
|
||||||
|
|
||||||
|
test -d build || mkdir -p build
|
||||||
|
test -d io || mkdir -p io
|
||||||
|
|
||||||
|
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||||
|
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||||
|
|
||||||
|
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||||
|
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||||
|
|
||||||
|
INPUT="io/$INPUT"
|
||||||
|
OUTPUT="io/$OUTPUT"
|
||||||
|
DBG_BIN="build/$DBG_BIN"
|
||||||
|
|
||||||
|
compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt
|
||||||
|
CODE=$?
|
||||||
|
test $CODE -gt 0 && exit $CODE
|
||||||
|
|
||||||
|
execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT"
|
||||||
|
exit $?
|
||||||
29
cses/dynamic-programming/scripts/run.sh
Normal file
29
cses/dynamic-programming/scripts/run.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./scripts/utils.sh
|
||||||
|
|
||||||
|
SRC="$1"
|
||||||
|
BASE=$(basename "$SRC" .cc)
|
||||||
|
INPUT="${BASE}.in"
|
||||||
|
OUTPUT="${BASE}.out"
|
||||||
|
RUN_BIN="${BASE}.run"
|
||||||
|
|
||||||
|
test -d build || mkdir -p build
|
||||||
|
test -d io || mkdir -p io
|
||||||
|
|
||||||
|
test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/"
|
||||||
|
test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/"
|
||||||
|
|
||||||
|
test -f "io/$INPUT" || touch "io/$INPUT"
|
||||||
|
test -f "io/$OUTPUT" || touch "io/$OUTPUT"
|
||||||
|
|
||||||
|
INPUT="io/$INPUT"
|
||||||
|
OUTPUT="io/$OUTPUT"
|
||||||
|
RUN_BIN="build/$RUN_BIN"
|
||||||
|
|
||||||
|
compile_source "$SRC" "$RUN_BIN" "$OUTPUT" ""
|
||||||
|
CODE=$?
|
||||||
|
test $CODE -gt 0 && exit $CODE
|
||||||
|
|
||||||
|
execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT"
|
||||||
|
exit $?
|
||||||
53
cses/dynamic-programming/scripts/utils.sh
Normal file
53
cses/dynamic-programming/scripts/utils.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
execute_binary() {
|
||||||
|
binary="$1"
|
||||||
|
input="$2"
|
||||||
|
output="$3"
|
||||||
|
|
||||||
|
start=$(date '+%s.%N')
|
||||||
|
timeout 2s ./"$binary" <"$input" >"$output" 2>&1
|
||||||
|
CODE=$?
|
||||||
|
end=$(date '+%s.%N')
|
||||||
|
truncate -s "$(head -n 1000 "$output" | wc -c)" "$output"
|
||||||
|
|
||||||
|
if [ $CODE -ge 124 ]; then
|
||||||
|
MSG=''
|
||||||
|
case $CODE in
|
||||||
|
124) MSG='TIMEOUT' ;;
|
||||||
|
128) MSG='SIGILL' ;;
|
||||||
|
130) MSG='SIGABRT' ;;
|
||||||
|
131) MSG='SIGBUS' ;;
|
||||||
|
136) MSG='SIGFPE' ;;
|
||||||
|
135) MSG='SIGSEGV' ;;
|
||||||
|
137) MSG='SIGPIPE' ;;
|
||||||
|
139) MSG='SIGTERM' ;;
|
||||||
|
esac
|
||||||
|
[ $CODE -ne 124 ] && sed -i '$d' "$output"
|
||||||
|
test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output"
|
||||||
|
else
|
||||||
|
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output
|
||||||
|
return $CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
compile_source() {
|
||||||
|
src="$1"
|
||||||
|
bin="$2"
|
||||||
|
output="$3"
|
||||||
|
flags="$4"
|
||||||
|
|
||||||
|
test -f "$bin" && rm "$bin" || true
|
||||||
|
g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output"
|
||||||
|
CODE=$?
|
||||||
|
|
||||||
|
if [ $CODE -gt 0 ]; then
|
||||||
|
printf '\n[code]: %s' "$CODE" >>"$output"
|
||||||
|
return $CODE
|
||||||
|
else
|
||||||
|
echo '' >"$output"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue