feat: usaco

This commit is contained in:
Barrett Ruth 2025-04-30 16:28:40 -04:00
parent 659cac6af3
commit 00d23dc313
106 changed files with 2569 additions and 52 deletions

View file

@ -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;
}