feat: usaco
This commit is contained in:
parent
659cac6af3
commit
00d23dc313
106 changed files with 2569 additions and 52 deletions
|
|
@ -5,4 +5,4 @@ CompileFlags:
|
|||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
- -Wno-unknown-pragmas -std=c++23
|
||||
|
|
|
|||
|
|
@ -7,60 +7,69 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
using i32 = int32_t;
|
||||
using u32 = uint32_t;
|
||||
using i64 = int64_t;
|
||||
using u64 = uint64_t;
|
||||
using f64 = double;
|
||||
using f128 = long double;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using vec = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using arr = std::array<T, N>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
#define ff first
|
||||
#define ss second
|
||||
|
||||
#ifdef LOCAL
|
||||
#define db(...) std::print(__VA_ARGS__)
|
||||
#define dbln(...) std::println(__VA_ARGS__)
|
||||
#else
|
||||
#define db(...)
|
||||
#define dbln(...)
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
u32 n;
|
||||
cin >> n;
|
||||
vec<ll> a(n);
|
||||
for (auto& e : a) {
|
||||
vector<u64> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
}
|
||||
|
||||
auto rec = [&](auto&& self, int i, ll l, ll r) {
|
||||
if (i == n) {
|
||||
return abs(r - l);
|
||||
// auto dfs = [&](u32 i, u64 s1, auto&& self) -> u64 {
|
||||
// if (i == n) {
|
||||
// return max(s1, s2) - min(s1, s2);
|
||||
// }
|
||||
//
|
||||
// return min(self(i + 1, s1 + a[i], self),
|
||||
// self(i + 1, s1,self));
|
||||
// };
|
||||
//
|
||||
// cout << dfs(0, 0, dfs) << '\n';
|
||||
|
||||
u64 total = accumulate(all(a), 0LL);
|
||||
u64 ans = total;
|
||||
for (u64 mask = 0; mask < (1LL << n); ++mask) {
|
||||
u64 sum = 0;
|
||||
for (u64 bit = 0; bit < n; ++bit) {
|
||||
if (mask & (1LL << bit)) {
|
||||
sum += a[bit];
|
||||
}
|
||||
}
|
||||
|
||||
return min(self(self, i + 1, l + a[i], r), self(self, i + 1, l, r + a[i]));
|
||||
};
|
||||
|
||||
cout << rec(rec, 0, 0, 0);
|
||||
ans = min(ans, max(total - sum, sum) - min(total - sum, sum));
|
||||
}
|
||||
cout << ans << '\n';
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
solve();
|
||||
u32 tc = 1;
|
||||
// cin >> tc;
|
||||
|
||||
for (u32 t = 0; t < tc; ++t) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
-Wunused
|
||||
-Woverloaded-virtual
|
||||
-Wconversion
|
||||
-Wsign-conversion
|
||||
-Wmisleading-indentation
|
||||
-Wduplicated-cond
|
||||
-Wduplicated-branches
|
||||
|
|
@ -28,4 +27,4 @@
|
|||
-Wdouble-promotion
|
||||
-Wundef
|
||||
-DLOCAL
|
||||
-std=c++20
|
||||
-std=c++23
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
3
|
||||
7 7 100
|
||||
5
|
||||
3 2 7 4 1
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
86
|
||||
1
|
||||
|
||||
[code]: 0
|
||||
[time]: 3.65114 ms
|
||||
[time]: 4.19974 ms
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
.PHONY: run debug clean setup init
|
||||
|
||||
VERSION ?= 20
|
||||
|
||||
SRC = $(word 2,$(MAKECMDGOALS))
|
||||
|
||||
.SILENT:
|
||||
|
|
@ -17,9 +19,8 @@ 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 .
|
||||
test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . && echo -std=c++$(VERSION) >>compile_flags.txt
|
||||
test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . && echo -e "\t\t-std=c++$(VERSION)" >>.clangd
|
||||
|
||||
init:
|
||||
make setup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue