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

@ -5,4 +5,4 @@ CompileFlags:
- -Wpedantic
- -Wshadow
- -DLOCAL
- -Wno-unknown-pragmas
- -Wno-unknown-pragmas -std=c++23

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

View file

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

View file

@ -1,2 +1,2 @@
3
7 7 100
5
3 2 7 4 1

View file

@ -1,3 +1,4 @@
86
1
[code]: 0
[time]: 3.65114 ms
[time]: 4.19974 ms

View file

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

View file

@ -0,0 +1,37 @@
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
-Wno-unknown-pragmas
-std=c++23
-std=c++17
-std=c++17
-std=c++17

View file

@ -0,0 +1,126 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 201703L
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, typename U> [[nodiscard]] T sc(U &&u) {
return static_cast<T>(std::forward<U>(u));
}
template <typename T, typename C> [[nodiscard]] T sz(C const &c) {
return static_cast<T>(c.size());
}
#endif
#if defined(LOCAL) && __cplusplus >= 201703L
#define db(...) std::print(__VA_ARGS__)
#define dbln(...) std::println(__VA_ARGS__)
#else
#define db(...)
#define dbln(...)
#endif
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()
#define ff first
#define ss second
// }}}
struct ac {
u32 l, r;
i32 p, m;
// NOTE: copied from AI - order doesn't matter, just need to consider all
// permutations
bool operator<(ac const &o) const {
return tie(l, r, p, m) < tie(o.l, o.r, o.p, m);
}
};
void solve() {
u32 N, M;
cin >> N >> M;
vector<i32> to_cool(101, 0);
u32 l, r, c, m;
for (u32 i = 0; i < N; ++i) {
cin >> l >> r >> c;
for (u32 j = l; j <= r; ++j) {
to_cool[j] = c;
}
}
vector<ac> acs;
for (u32 i = 0; i < M; ++i) {
cin >> l >> r >> c >> m;
acs.emplace_back(ac{l, r, c, m});
}
sort(all(acs));
u32 ans = MAX<u32>;
for (u32 mask = 0; mask < 1LL << M; ++mask) {
u32 tc = MAX<u32>;
auto temps = to_cool;
u32 cost = 0;
// subsets != permutation/order
// want to track use/lack of use
for (u32 bit = 0; bit < M; ++bit) {
if (!(mask & (1 << bit)))
continue;
auto &a = acs[bit];
cost += a.m;
for (u32 j = a.l; j <= min((u32)100, a.r); ++j) {
temps[j] -= a.p;
}
if (all_of(all(temps), [](i32 e) { return e <= 0; })) {
ans = min(ans, cost);
break;
}
}
ans = min(ans, tc);
}
cout << ans << endl;
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "air-cownditioning-ii"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,100 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n, B;
cin >> n >> B;
vector<pair<u32, u32>> pts(n);
vector<u32> horiz_placements, vert_placements;
for (u32 i = 0; i < n; ++i) {
cin >> pts[i].ff >> pts[i].ss;
vert_placements.emplace_back(pts[i].ff + 1);
horiz_placements.emplace_back(pts[i].ss + 1);
}
u64 ans = numeric_limits<u64>::max();
for (auto vp : vert_placements) {
for (auto hp : horiz_placements) {
u64 tl = 0, tr = 0, bl = 0, br = 0;
for (auto &[x, y] : pts) {
if (x < vp && y > hp)
++tl;
if (x > vp && y > hp)
++tr;
if (x < vp && y < hp)
++bl;
if (x > vp && y < hp)
++br;
}
ans = min(ans, max({tl, tr, bl, br}));
}
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "balancing"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View 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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
string s;
cin >> s;
array<pair<u32, u32>, 26> enter_exit{};
for (u32 i = 0; i < s.size(); ++i) {
u32 j = s[i] - 'A';
if (enter_exit[j].ff == 0) {
enter_exit[j].ff = i + 1;
} else {
enter_exit[j].ss = i + 1;
}
}
u32 ans = 0;
for (u32 r = 0; r < enter_exit.size(); ++r) {
for (u32 l = 0; l < r; ++l) {
if (enter_exit[l].ff < enter_exit[r].ff &&
enter_exit[r].ff < enter_exit[l].ss &&
enter_exit[l].ss < enter_exit[r].ss ||
enter_exit[r].ff < enter_exit[l].ff &&
enter_exit[l].ff < enter_exit[r].ss &&
enter_exit[r].ss < enter_exit[l].ss) {
++ans;
}
}
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "circlecross"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -16,7 +16,6 @@
-Wunused
-Woverloaded-virtual
-Wconversion
-Wsign-conversion
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
@ -28,3 +27,4 @@
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++17

View file

@ -0,0 +1,91 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n, m;
cin >> n >> m;
array<vector<string>, 2> cows{vector<string>(n), vector<string>(n)};
for (auto &e : cows)
for (auto &g : e)
cin >> g;
u32 ans = 0;
for (u32 col = 0; col < m; ++col) {
unordered_set<char> plain;
for (u32 i = 0; i < n; ++i)
plain.insert(cows[0][i][col]);
u32 i;
for (i = 0; i < n; ++i)
if (plain.find(cows[1][i][col]) != plain.end()) {
break;
}
ans += i == n;
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "cownomics"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,14 @@
-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
-DLOCAL
-std=c++20

View file

@ -0,0 +1,87 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n, k;
cin >> n >> k;
vector<u64> diamonds(n);
for (auto &e : diamonds)
cin >> e;
sort(all(diamonds));
u32 r = 0;
u32 ans = 0;
for (u32 l = 0; l < n; ++l) {
while (r < n && diamonds[r] - diamonds[l] <= k) {
++r;
}
ans = max(ans, r - l);
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "diamond"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,102 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 k, n;
cin >> k >> n;
vector<vector<u32>> rounds(k, vector<u32>(n));
for (auto &e : rounds)
for (auto &g : e)
cin >> g;
u32 ans = 0;
auto consistent = [&](u32 c1, u32 c2) {
for (u32 i = 0; i < k; ++i) {
bool found_c2 = false;
for (u32 j = 0; j < n; ++j) {
if (rounds[i][j] == c1 && found_c2) {
return false;
}
found_c2 |= rounds[i][j] == c2;
}
}
return true;
};
for (u32 i = 1; i <= n; ++i) {
for (u32 j = 1; j < i; ++j) {
if (consistent(i, j) || consistent(j, i))
++ans;
}
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "gymnastics"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,7 @@
2 4
1 5 2
7 9 3
2 9 2 3
1 6 2 8
1 2 4 2
6 9 1 5

View file

@ -0,0 +1,4 @@
10
[code]: 0
[time]: 4.50897 ms

View file

@ -0,0 +1,8 @@
7 10
7 3
5 5
9 7
3 1
7 7
5 3
9 1

View file

@ -0,0 +1,4 @@
2
[code]: 0
[time]: 5.50079 ms

View file

@ -0,0 +1 @@
ABCCABDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ

View file

@ -0,0 +1,4 @@
1
[code]: 0
[time]: 4.23932 ms

View file

@ -0,0 +1,7 @@
3 8
AATCCCAT
GATTGCAA
GGTCGCAA
ACTCCCAG
ACTCGCAT
ACTTCCAT

View file

@ -0,0 +1,4 @@
1
[code]: 0
[time]: 4.05145 ms

View file

@ -0,0 +1,6 @@
5 3
1
6
4
3
1

View file

@ -0,0 +1,4 @@
4
[code]: 0
[time]: 4.07553 ms

View file

@ -0,0 +1,4 @@
3 4
4 1 2 3
4 1 3 2
4 2 1 3

View file

@ -0,0 +1,4 @@
4
[code]: 0
[time]: 4.5898 ms

View file

@ -0,0 +1,4 @@
3
Buttercup must be milked beside Bella
Blue must be milked beside Bella
Sue must be milked beside Beatrice

View file

@ -0,0 +1,11 @@
Beatrice
Sue
Belinda
Bessie
Betsy
Blue
Bella
Buttercup
[code]: 0
[time]: 5.91278 ms

View file

@ -0,0 +1,3 @@
3
321 -15 -525
404 373 990

View file

@ -0,0 +1,4 @@
1059112
[code]: 0
[time]: 4.35638 ms

View file

@ -0,0 +1 @@
17 25 77

View file

@ -0,0 +1,4 @@
76
[code]: 0
[time]: 3.78871 ms

View file

@ -0,0 +1,7 @@
3
6
1 2 3 1 1 1
3
2 2 3
5
0 0 0 0 0

View file

@ -0,0 +1,6 @@
3
2
0
[code]: 0
[time]: 3.57866 ms

View file

@ -0,0 +1,3 @@
1 1
1 3
4 3

View file

@ -0,0 +1,8 @@
4
ABBB
CCCC
CCCC
CCCC
[code]: 0
[time]: 11.8504 ms

View file

@ -0,0 +1,5 @@
4 3
1100
7 1 2
5 2 3
6 2 4

View file

@ -0,0 +1,4 @@
1 1 Infinity
[code]: 0
[time]: 4.76265 ms

View file

@ -0,0 +1,116 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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
// }}}
vector<string> names;
void solve() {
u32 n;
cin >> n;
vector<pair<string, string>> constraints(n);
string word, first, last;
for (u32 i = 0; i < n; ++i) {
cin >> constraints[i].ff;
for (u32 j = 0; j < 4; ++j)
cin >> word;
cin >> constraints[i].ss;
}
vector<string> ans(8, "Z");
do {
bool good = true;
for (auto &[a, b] : constraints) {
bool ok = false;
for (i32 j = 0; j < 8; ++j) {
if (names[j] == a && (j + 1 < 8 && names[j + 1] == b ||
j - 1 >= 0 && names[j - 1] == b)) {
ok = true;
break;
}
}
if (!ok) {
good = false;
break;
}
}
if (good && names < ans) {
ans = names;
}
} while (next_permutation(names.begin(), names.end()));
for (auto &e : ans)
cout << e << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
names = {"Bessie", "Buttercup", "Belinda", "Beatrice",
"Bella", "Blue", "Betsy", "Sue"};
sort(all(names));
#define PROBLEM_NAME "lineup"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -1,5 +1,7 @@
.PHONY: run debug clean setup init
VERSION ?= 20
SRC = $(word 2,$(MAKECMDGOALS))
.SILENT:
@ -17,8 +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 .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

View file

@ -0,0 +1,92 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n;
cin >> n;
vector<pair<i64, i64>> pts(n);
for (i32 i = 0; i < n; ++i)
cin >> pts[i].ff;
for (i32 i = 0; i < n; ++i)
cin >> pts[i].ss;
i64 ans = MIN<i64>;
for (u32 i = 0; i < n; ++i) {
for (u32 j = 0; j < i; ++j) {
ans = max(ans, (pts[i].ff - pts[j].ff) * (pts[i].ff - pts[j].ff) +
(pts[i].ss - pts[j].ss) * (pts[i].ss - pts[j].ss));
}
}
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;
}
// }}}

View file

@ -0,0 +1,82 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u64 x, y, m;
cin >> x >> y >> m;
u64 ans = 0;
for (u32 x_uses = 0; x_uses <= m / x; ++x_uses) {
for (u32 y_uses = 0; y_uses <= (m - x_uses * x) / y; ++y_uses) {
u64 used = x_uses * x + y_uses * y;
ans = max(ans, used);
}
}
cout << ans << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "pails"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,31 @@
#!/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" @mem_debug_flags.txt
CODE=$?
test $CODE -gt 0 && exit $CODE
# Use ulimit to restrict memory to 256MB (262144 KB)
# This will run the binary with memory restrictions
execute_binary_with_memory_limit "$DBG_BIN" "$INPUT" "$OUTPUT" 262144
exit $?

View 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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n;
cin >> n;
vector<u64> a(n);
for (auto &e : a)
cin >> e;
u64 big = *max_element(all(a));
u64 ub = accumulate(all(a), 0LL);
for (u64 target = big; target <= ub; ++target) {
u32 last = 0, moves = 0;
u64 total = 0;
bool bad = false;
for (u32 i = 0; i < n && !bad; ++i) {
total += a[i];
if (total == target) {
moves += i - last;
last = i + 1;
total = 0;
} else if (i == n - 1 && total != target || total > target) {
bad = true;
}
}
if (!bad) {
cout << moves + n - last << endl;
return;
}
}
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "sleeping-in-class"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#endif
u32 t;
cin >> t;
while (t--)
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,187 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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 print(u32 n, u32 x1, u32 y1, u32 x2, u32 y2, u32 x3, u32 y3) {
vector<vector<char>> board(n, vector<char>(n, '.'));
for (u32 i = 0; i < y1; ++i) {
for (u32 j = 0; j < x1; ++j) {
board[i][j] = 'A';
}
}
u32 sr = 0, sc = x1;
if (x1 == n) {
sr = y1;
sc = 0;
}
for (u32 i = 0; i < y2; ++i) {
for (u32 j = 0; j < x2; ++j) {
board[sr + i][sc + j] = 'B';
}
}
bool done = false;
for (u32 i = 0; !done && i < n; ++i) {
for (u32 j = 0; j < n; ++j) {
if (board[i][j] == '.') {
sr = i;
sc = j;
done = true;
break;
}
}
}
for (u32 i2 = 0; i2 < y3; ++i2) {
for (u32 j2 = 0; j2 < x3; ++j2) {
board[sr + i2][sc + j2] = 'C';
}
}
cout << n << endl;
for (const auto &row : board) {
for (char c : row) {
cout << c;
}
cout << '\n';
}
}
void solve() {
u32 x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
u32 area = x1 * y1 + x2 * y2 + x3 * y3;
if (ceil(sqrt(area)) != floor(sqrt(area))) {
cout << "-1\n";
return;
}
u32 n = sqrt(area);
if (x1 != n) {
swap(x1, y1);
}
if (x1 == n) {
if (y2 + y3 == n) {
swap(x2, y2);
swap(x3, y3);
print(n, x1, y1, x2, y2, x3, y3);
return;
} else if (x2 + y3 == n) {
swap(x3, y3);
print(n, x1, y1, x2, y2, x3, y3);
return;
} else if (y2 + x3 == n) {
swap(x2, y2);
print(n, x1, y1, x2, y2, x3, y3);
return;
} else if (x2 + x3 == n) {
print(n, x1, y1, x2, y2, x3, y3);
return;
} else if (x2 == n && y2 + y3 == n - y1 || x3 == n && y2 + y3 == n - y1) {
print(n, x1, y1, x2, y2, x3, y3);
return;
} else if (y2 == n && x2 + y3 == n - y1) {
print(n, x1, y1, y2, x2, x3, y3);
return;
} else if (y2 == n && x2 + x3 == n - y1) {
swap(x2, y2);
swap(x3, y3);
print(n, x1, y1, x2, y2, x3, y3);
return;
} else if (y3 == n && y2 + x3 == n - y1) {
print(n, x1, y1, y2, x2, y3, x3);
return;
}
}
if (x1 + x2 != n) {
swap(x2, y2);
}
if (x1 + x2 == n) {
if (y1 + y3 != n) {
swap(x3, y3);
}
if (y1 + y3 == n) {
print(n, x1, y1, x2, y2, x3, y3);
return;
}
}
if (x1 + x3 != n)
swap(x3, y3);
if (x1 + x3 == n) {
if (y1 + y2 != n) {
swap(x2, y2);
}
if (y1 + y2 == n) {
print(n, x1, y1, x2, y2, x3, y3);
return;
}
}
cout << "-1\n";
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
// cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,168 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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
// }}}
vector<pair<i32, i32>> trace(251);
void solve() {
/*
- # cows patient 0
- k bounds
1. sort by time to "sim" interactions
- say x and y shake; unless wek one is sick, wedk consequences
(i.e. who gets sick)
- only ONE starts out
- guess ONE cow is patient zero, run sim
- guess all k from 0 to 251?, taking min of low bound, max of high bound
k = 250 -> infinity
bsearch <- no (if can achieve state w/ k=i, doesn't mean k=i-1, nor k=i+1)
NOTE: only candidates for patient zero are initial set 0s, since cows stay sick
*/
u32 n, t;
cin >> n >> t;
string state;
cin >> state;
state = '0' + state;
u32 t_;
for (u32 i = 0; i < t; ++i) {
cin >> t_;
cin >> trace[t_].ff >> trace[t_].ss;
// NOTE: forgot the one-indexin
}
u32 lb = numeric_limits<u32>::max(), ub = 0;
u32 count = 0;
/*
a bunch of cows shake hooves because the gay USACO (usa computing olympiad)
just decided to theme everything cows
and for some K, a cow can only transmit what you have (STDs)
after at most K hooveshakes
but i misread it as saying that if they contract what you have (an STD)
they can only transmit the STD up to K days later
not after they have sex k times (which is what you do, let k approach
infinity)
ok. then, after that, i missed k=0 basecase
then, after that
basically, i only counted when someone transmitted an std & infecting someone
instead, i should've counted the cow having sex with ANYONE, even if they already
have an std, it still counts as a handshake
core note: once realize wrong, reexamine entire problem solution (has rpercussions) rather than what u see is wrong
*/
for (u32 i = 1; i <= n; ++i) {
bool zero = false;
for (u32 k = 0; k <= 250; ++k) {
vector<u32> shakes(n + 1, 0);
string cur_state(n + 1, '0');
cur_state[i] = '1';
for (t_ = 1; t_ <= 250; ++t_) {
auto [a, b] = trace[t_];
if (a == 0) {
continue;
}
if (cur_state[a] == '1') {
++shakes[a];
}
if (cur_state[b] == '1') {
++shakes[b];
}
if (cur_state[a] == '0' && cur_state[b] == '1' && shakes[b] <= k) {
cur_state[a] = '1';
} else if (cur_state[b] == '0' && cur_state[a] == '1' &&
shakes[a] <= k) {
cur_state[b] = '1';
}
}
if (cur_state == state) {
zero = true;
lb = min(lb, k);
ub = max(ub, k);
}
}
count += zero;
}
cout << count << ' ' << lb << ' ' << (ub == 250 ? "Infinity" : to_string(ub))
<< '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "tracing"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,35 @@
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
-Wno-unknown-pragmas
-std=c++17
-std=c++17

View file

@ -0,0 +1,30 @@
-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
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++17

View file

@ -0,0 +1,5 @@
4
on 1 1
none 10 14
none 11 15
off 2 3

View file

@ -0,0 +1,5 @@
10 13
8 12
[code]: 0
[time]: 3.91054 ms

View file

@ -0,0 +1,29 @@
.PHONY: run debug clean setup init
VERSION ?= 20
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 . && 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
%:
@:

View 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 $?

View 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 $?

View 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
}

View file

@ -0,0 +1,122 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n;
cin >> n;
string type;
i64 l, r;
vector<tuple<string, i64, i64>> segments;
for (u32 i = 0; i < n; ++i) {
cin >> type >> l >> r;
segments.emplace_back(type, l, r);
}
i64 lb = 0, ub = 1e9;
for (auto it = segments.rbegin(); it != segments.rend(); ++it) {
tie(type, l, r) = *it;
if (type == "none") {
lb = max(lb, l);
ub = min(ub, r);
} else if (type == "off") {
lb += l;
ub += r;
} else if (type == "on") {
lb = max(lb - r, (i64)0);
ub = max(ub - l, (i64)0);
}
}
cout << lb << ' ' << ub << '\n';
lb = 0, ub = 1e9;
for (auto& segment : segments) {
// NOTE: how does this work?
tie(type, l, r) = segment;
if (type == "none") {
lb = max(lb, l);
ub = min(ub, r);
} else if (type == "off") {
lb = max(lb - r, (i64)0);
ub = max(ub - l, (i64)0);
} else if (type == "on") {
lb += l;
ub += r;
}
}
cout << lb << ' ' << ub << '\n';
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "traffic"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#else
freopen(PROBLEM_NAME ".in", "r", stdin);
freopen(PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,37 @@
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
-Wno-unknown-pragmas
-std=c++23
-std=c++23
-std=c++17
-std=c++17

View file

@ -0,0 +1,30 @@
-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
-Wmisleading-indentation
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wnull-dereference
-Wformat=2
-Wformat-overflow
-Wformat-truncation
-Wdouble-promotion
-Wundef
-DLOCAL
-std=c++17

View 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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n;
cin >> n;
vector<u64> a(n);
for (auto &e : a)
cin >> e;
sort(all(a));
u64 ans = 0, charge = 1e9;
// for (u32 i = 0; i < n; ++i) {
// auto it = lower_bound(all(a), a[i]);
//
// u32 cnt = distance(it, a.end());
// if (cnt * a[i] > ans) {
// ans = cnt * a[i];
// charge = a[i];
// } else if (cnt * a[i] == ans) {
// charge = min(charge, a[i]);
// }
// }
for (u32 i = 0; i < n; ++i) {
if (ans < (n - i) * a[i]) {
ans = (n - i) * a[i];
charge = a[i];
} else if (ans == (n - i) * a[i]) {
charge = min(charge, a[i]);
}
}
cout << ans << ' ' << charge;
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
#define PROBLEM_NAME "cow-college"
#ifdef LOCAL
freopen("io/" PROBLEM_NAME ".in", "r", stdin);
freopen("io/" PROBLEM_NAME ".out", "w", stdout);
#endif
solve();
return 0;
}
// }}}

View file

@ -0,0 +1,14 @@
-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
-DLOCAL
-std=c++20

View file

@ -0,0 +1,80 @@
#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 f64 = double;
using f128 = long double;
#if __cplusplus >= 202002L
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());
}
#endif
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()
#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() {
u32 n;
cin >> n;
vector<u32> a(n);
for (auto &e : a)
cin >> e;
sort(all(a));
u32 ans = 0;
for (u32 i = 0; i < n;) {
++ans;
while (i + 1 < n && a[i + 1] == a[i])
++i;
++i;
}
cout << ans << endl;
}
int main() { // {{{
cin.tie(nullptr)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
u32 tc = 1;
// cin >> tc;
for (u32 t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -0,0 +1,2 @@
4
1 6 4 6

View file

@ -0,0 +1,3 @@
12 4
[code]: 0
[time]: 4.01235 ms

View file

@ -0,0 +1,2 @@
10
5 9 5 5 10 9 3 1 8 8

View file

@ -0,0 +1,4 @@
6
[code]: 0
[time]: 4.40502 ms

View file

@ -0,0 +1,2 @@
4
1 2 3 4 5 6 100 1000

View file

@ -0,0 +1,3 @@
3
[code]: 0
[time]: 3.99446 ms

View file

@ -0,0 +1,8 @@
7
Bessie 1
Elsie 1
Daisy 2
Gertie 2
Annabelle 3
Maggie 4
Henrietta 4

View file

@ -0,0 +1,3 @@
Tie
[code]: 0
[time]: 3.75843 ms

Some files were not shown because too many files have changed in this diff Show more