diff --git a/codeforces/1032/.clangd b/codeforces/1032/.clangd index 7b2523e..c9330f1 100644 --- a/codeforces/1032/.clangd +++ b/codeforces/1032/.clangd @@ -37,3 +37,7 @@ CompileFlags: -e -std=c++23 -e -std=c++23 -e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/1032/e.cc b/codeforces/1032/e.cc new file mode 100644 index 0000000..1647d06 --- /dev/null +++ b/codeforces/1032/e.cc @@ -0,0 +1,102 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 +// }}} + +random_device rd; +mt19937 engine(rd()); + +void solve() { + u64 l, r; + cin >> l >> r; + + uniform_int_distribution<> dist(l, r); + + u64 ans = 20; + + for (u32 i = 0; i < 200; ++i) { + u64 candidate = dist(engine); + u64 L = l, R = r; + u64 cur = 0; + + for (u64 X = candidate; X > 0; R /= 10, X /= 10) { + cur += X % 10 == R % 10; + } + for (u64 X = candidate; L > 0; L /= 10, X /= 10) { + cur += X % 10 == L % 10; + } + + ans = min(ans, cur); + } + + println("{}", ans); +} + +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; +} +// }}} diff --git a/codeforces/1032/f.cc b/codeforces/1032/f.cc new file mode 100644 index 0000000..907e12a --- /dev/null +++ b/codeforces/1032/f.cc @@ -0,0 +1,109 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 +// }}} + +u64 count_subarrays(i64 s, i64 x, vec& a) { + u64 ans = 0; + map> pref; + pref[0].push_back(-1); + i64 acc = 0; + i32 last_bad = -1; + + for (u32 r = 0; r < a.size(); ++r) { + acc += a[r]; + if (a[r] > x) + last_bad = r; + + i64 target = acc - s; + auto& indices = pref[target]; + auto it = lower_bound(indices.begin(), indices.end(), last_bad); + ans += (u64)distance(it, indices.end()); + + pref[acc].push_back(r); + } + + return ans; +} + +void solve() { + u32 n; + i64 s, x; + cin >> n >> s >> x; + vec a(n); + for (auto& e : a) + cin >> e; + + auto X = count_subarrays(s, x, a); + auto Y = count_subarrays(s, x - 1, a); + println("{}", X - Y); +} + +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; +} +// }}} diff --git a/codeforces/1032/g.cc b/codeforces/1032/g.cc new file mode 100644 index 0000000..8f80e5a --- /dev/null +++ b/codeforces/1032/g.cc @@ -0,0 +1,116 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 s; + cin >> s; + + /* + + f(x) -> max # 0/1s in x + + count f(s[l: r]) for all l <= r + + formulate it + + + f(s[l:r]) + + f(s[0:0]) + f(s[0:1]) + f(s[0:2]) + f(s[0:3]) + f(s[0:4]) + ... + f(s[1:1]) + f(s[1:2]) + f(s[1:3]) + f(s[1:4]) + ... + + one idea: sum f(s[l:r]) = sum min(prefix[0][l][r], prefix[1][l][r]) + + |prefix[0][l][r] - prefix[1][l[r]]| = sum + sum + + first term: + = (i + 1) * (n - i), take min + + min doesn't work, since varies + + must leverage: max(x, y) = (x + y + |x-y|)/2 = sum x + y + for all i: + cnts[s[i] == 0] += (i + 1) * (n - i) + + + div. by 2 after + + second term: |x-y| in an aggregate way + + + + ret (first + second) / 2 + */ +} + +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; +} +// }}} diff --git a/codeforces/1032/io/e.out b/codeforces/1032/io/e.out index faa29df..b8f273c 100644 --- a/codeforces/1032/io/e.out +++ b/codeforces/1032/io/e.out @@ -1,18 +1,18 @@ -1 2 -2 1 -5 0 -15 3 -18 2 -199 3 -899 5 -1990 4 -6309 7 -12445 6 -19987 5 -746824 7 -900990999 14 -999999999 18 +2 +1 +0 +3 +2 +2 +1 +3 +3 +4 +3 +5 +12 +18 [code]: 0 -[time]: 2.56085 ms +[time]: 4.14038 ms [debug]: false \ No newline at end of file diff --git a/codeforces/1032/io/f.in b/codeforces/1032/io/f.in new file mode 100644 index 0000000..1097bc3 --- /dev/null +++ b/codeforces/1032/io/f.in @@ -0,0 +1,19 @@ +9 +1 0 0 +0 +1 -2 -1 +-2 +3 -1 -1 +-1 1 -1 +6 -3 -2 +-1 -1 -1 -2 -1 -1 +8 3 2 +2 2 -1 -2 3 -1 2 2 +9 6 3 +1 2 3 1 2 3 1 2 3 +13 7 3 +0 -1 3 3 3 -2 1 2 2 3 -1 0 3 +2 -2 -1 +-2 -1 +2 -2 -1 +-1 -2 diff --git a/codeforces/1032/io/f.out b/codeforces/1032/io/f.out new file mode 100644 index 0000000..40b6b2f --- /dev/null +++ b/codeforces/1032/io/f.out @@ -0,0 +1,13 @@ +1 +0 +2 +0 +2 +7 +8 +0 +0 + +[code]: 0 +[time]: 2.81596 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1032/io/g.in b/codeforces/1032/io/g.in new file mode 100644 index 0000000..243ff0e --- /dev/null +++ b/codeforces/1032/io/g.in @@ -0,0 +1,13 @@ +6 +1 +0 +2 +01 +4 +0110 +6 +110001 +8 +10011100 +11 +01011011100 diff --git a/codeforces/1032/io/g.out b/codeforces/1032/io/g.out new file mode 100644 index 0000000..222d20b --- /dev/null +++ b/codeforces/1032/io/g.out @@ -0,0 +1,4 @@ + +[code]: 0 +[time]: 2.58684 ms +[debug]: false diff --git a/codeforces/1032/proof.qmd b/codeforces/1032/proof.qmd new file mode 100644 index 0000000..fd889e4 --- /dev/null +++ b/codeforces/1032/proof.qmd @@ -0,0 +1,8 @@ +# hello + + +l, r <= 10^9 + +so ~ 10^9 candidates + +minimize the digit xor diff --git a/codeforces/1034/.clang-format b/codeforces/1034/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1034/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1034/.clangd b/codeforces/1034/.clangd new file mode 100644 index 0000000..7b2523e --- /dev/null +++ b/codeforces/1034/.clangd @@ -0,0 +1,39 @@ +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 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/1034/a.cc b/codeforces/1034/a.cc new file mode 100644 index 0000000..357c274 --- /dev/null +++ b/codeforces/1034/a.cc @@ -0,0 +1,92 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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() { + // NOTE: had as size 3 and there was no heap buffer overflow warning + // causing wrong submission + vec f(4, 0); + u32 n; + cin >> n; + + for (i32 i = 0; i < n; ++i) { + ++f[i % 4]; + } + + if (f[0] != f[3] || f[2] != f[1]) { + cout << "Alice\n"; + return; + } + + cout << "Bob\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; +} +// }}} diff --git a/codeforces/1034/b.cc b/codeforces/1034/b.cc new file mode 100644 index 0000000..7d552ac --- /dev/null +++ b/codeforces/1034/b.cc @@ -0,0 +1,114 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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, j, k; + cin >> n >> j >> k; + + vec a(n); + for (auto& e : a) + cin >> e; + + u32 strength = a[j - 1]; + u32 same = 0, less = 0, greater = 0; + + // sorting unecessary + // sort(all(a)); + + for (u32 i = 0; i < n; ++i) { + if (a[i] < strength) { + ++less; + } + + if (a[i] == strength) { + ++same; + } + + if (a[i] > strength) { + ++greater; + } + } + + u32 eliminated = less; + if (same > 0) + eliminated += same - 1; + if (greater > 0) + eliminated += greater - 1; + + if (eliminated >= n - k) { + YES(); + } else { + NO(); + } +} + +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; +} +// }}} diff --git a/codeforces/1034/c.cc b/codeforces/1034/c.cc new file mode 100644 index 0000000..463514e --- /dev/null +++ b/codeforces/1034/c.cc @@ -0,0 +1,106 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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() { + i32 n; + cin >> n; + vec a(n); + for (auto& e : a) + cin >> e; + + string ans(a.size(), '0'); + + auto small = *min_element(all(a)); + auto big = *max_element(all(a)); + + vec prefix(n, a[0]); + vec suffix(n, a[n - 1]); + + for (u32 i = 1; i < n; ++i) { + prefix[i] = min(prefix[i - 1], a[i]); + } + for (i32 i = n - 2; i >= 0; --i) { + suffix[i] = max(suffix[i + 1], a[i]); + } + + for (i32 i = 0; i < n; ++i) { + if (a[i] == suffix[i]) { + ans[i] = '1'; + } else if (a[i] == prefix[i]) { + ans[i] = '1'; + } + } + + println("{}", ans); +} + +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; +} +// }}} diff --git a/codeforces/1034/compile_flags.txt b/codeforces/1034/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/1034/compile_flags.txt @@ -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 +-Wmisleading-indentation +-Wduplicated-cond +-Wduplicated-branches +-Wlogical-op +-Wnull-dereference +-Wformat=2 +-Wformat-overflow +-Wformat-truncation +-Wdouble-promotion +-Wundef +-DLOCAL +-std=c++23 +-std=c++23 diff --git a/codeforces/1034/d.cc b/codeforces/1034/d.cc new file mode 100644 index 0000000..ec21d4c --- /dev/null +++ b/codeforces/1034/d.cc @@ -0,0 +1,90 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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; + string s; + cin >> s; + + u32 ones = 0; + for (auto c : s) + ones += c == '1'; + + if (ones <= k || k > (u32)ceil(n / 2.0) - (n & 1)) { + println("Alice"); + } else { + println("Bob"); + } +} + +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; +} +// }}} diff --git a/codeforces/1034/debug_flags.txt b/codeforces/1034/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/1034/debug_flags.txt @@ -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++23 diff --git a/codeforces/1034/e.cc b/codeforces/1034/e.cc new file mode 100644 index 0000000..f46d34d --- /dev/null +++ b/codeforces/1034/e.cc @@ -0,0 +1,77 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 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; +} +// }}} diff --git a/codeforces/1034/io/a.in b/codeforces/1034/io/a.in new file mode 100644 index 0000000..6a75dbf --- /dev/null +++ b/codeforces/1034/io/a.in @@ -0,0 +1,6 @@ +5 +2 +4 +5 +7 +100 diff --git a/codeforces/1034/io/a.out b/codeforces/1034/io/a.out new file mode 100644 index 0000000..e491754 --- /dev/null +++ b/codeforces/1034/io/a.out @@ -0,0 +1,9 @@ +Alice +Bob +Alice +Alice +Bob + +[code]: 0 +[time]: 2.6536 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1034/io/b.in b/codeforces/1034/io/b.in new file mode 100644 index 0000000..4feb537 --- /dev/null +++ b/codeforces/1034/io/b.in @@ -0,0 +1,7 @@ +3 +5 2 3 +3 2 4 4 1 +5 4 1 +5 3 4 5 2 +6 1 1 +1 2 3 4 5 6 diff --git a/codeforces/1034/io/b.out b/codeforces/1034/io/b.out new file mode 100644 index 0000000..b2caf3e --- /dev/null +++ b/codeforces/1034/io/b.out @@ -0,0 +1,10 @@ +YES +YES +NO +3 +4 +4 + +[code]: 0 +[time]: 2.38109 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1034/io/c.in b/codeforces/1034/io/c.in new file mode 100644 index 0000000..67e5e05 --- /dev/null +++ b/codeforces/1034/io/c.in @@ -0,0 +1,7 @@ +3 +6 +1 3 5 4 7 2 +4 +13 10 12 20 +7 +1 2 3 4 5 6 7 diff --git a/codeforces/1034/io/c.out b/codeforces/1034/io/c.out new file mode 100644 index 0000000..c315f4f --- /dev/null +++ b/codeforces/1034/io/c.out @@ -0,0 +1,7 @@ +100011 +1101 +1000001 + +[code]: 0 +[time]: 2.47598 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1034/io/d.in b/codeforces/1034/io/d.in new file mode 100644 index 0000000..e38de64 --- /dev/null +++ b/codeforces/1034/io/d.in @@ -0,0 +1,13 @@ +6 +5 2 +11011 +7 4 +1011011 +6 1 +010000 +4 1 +1111 +8 3 +10110110 +6 4 +111111 diff --git a/codeforces/1034/io/d.out b/codeforces/1034/io/d.out new file mode 100644 index 0000000..0f96251 --- /dev/null +++ b/codeforces/1034/io/d.out @@ -0,0 +1,10 @@ +Bob +Alice +Alice +Bob +Bob +Alice + +[code]: 0 +[time]: 2.39968 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1034/io/e.in b/codeforces/1034/io/e.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/1034/io/e.out b/codeforces/1034/io/e.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/1034/makefile b/codeforces/1034/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/1034/makefile @@ -0,0 +1,30 @@ +.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 .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 + +%: + @: diff --git a/codeforces/1034/scripts/debug.sh b/codeforces/1034/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/1034/scripts/debug.sh @@ -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" true +exit $? diff --git a/codeforces/1034/scripts/run.sh b/codeforces/1034/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/1034/scripts/run.sh @@ -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 $? diff --git a/codeforces/1034/scripts/utils.sh b/codeforces/1034/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/1034/scripts/utils.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +execute_binary() { + binary="$1" + input="$2" + output="$3" + is_debug="$4" + + start=$(date '+%s.%N') + if [ -n "$is_debug" ]; then + asan="$(ldconfig -p | grep libasan.so | head -n1 | awk '{print $4}')" + LD_PRELOAD="$asan" timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + else + timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + fi + 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 + test -n "$is_debug" && is_debug_string=true || is_debug_string=false + printf '\n[debug]: %s' "$is_debug_string" >>$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 +} diff --git a/codeforces/1037/.clang-format b/codeforces/1037/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1037/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/1037/.clangd b/codeforces/1037/.clangd new file mode 100644 index 0000000..8d85aa9 --- /dev/null +++ b/codeforces/1037/.clangd @@ -0,0 +1,42 @@ +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 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/1037/.null-ls_118668_c.cc b/codeforces/1037/.null-ls_118668_c.cc new file mode 100644 index 0000000..b176282 --- /dev/null +++ b/codeforces/1037/.null-ls_118668_c.cc @@ -0,0 +1,76 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 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; +} diff --git a/codeforces/1037/.null-ls_161868_c.cc b/codeforces/1037/.null-ls_161868_c.cc new file mode 100644 index 0000000..8381a1d --- /dev/null +++ b/codeforces/1037/.null-ls_161868_c.cc @@ -0,0 +1,62 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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() { + +} diff --git a/codeforces/1037/.null-ls_183251_c.cc b/codeforces/1037/.null-ls_183251_c.cc new file mode 100644 index 0000000..45de929 --- /dev/null +++ b/codeforces/1037/.null-ls_183251_c.cc @@ -0,0 +1,73 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 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(); + } diff --git a/codeforces/1037/.null-ls_466333_c.cc b/codeforces/1037/.null-ls_466333_c.cc new file mode 100644 index 0000000..a58dabe --- /dev/null +++ b/codeforces/1037/.null-ls_466333_c.cc @@ -0,0 +1,61 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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() { + diff --git a/codeforces/1037/.null-ls_497923_c.cc b/codeforces/1037/.null-ls_497923_c.cc new file mode 100644 index 0000000..ab58ade --- /dev/null +++ b/codeforces/1037/.null-ls_497923_c.cc @@ -0,0 +1,71 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + u32 tc = 1; + cin >> tc; + + for (u32 t = 0; t < tc; ++t) { diff --git a/codeforces/1037/.null-ls_726190_c.cc b/codeforces/1037/.null-ls_726190_c.cc new file mode 100644 index 0000000..c57c398 --- /dev/null +++ b/codeforces/1037/.null-ls_726190_c.cc @@ -0,0 +1,64 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 main() { diff --git a/codeforces/1037/.null-ls_739113_c.cc b/codeforces/1037/.null-ls_739113_c.cc new file mode 100644 index 0000000..d539506 --- /dev/null +++ b/codeforces/1037/.null-ls_739113_c.cc @@ -0,0 +1,60 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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() { diff --git a/codeforces/1037/.null-ls_783881_c.cc b/codeforces/1037/.null-ls_783881_c.cc new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/codeforces/1037/.null-ls_783881_c.cc @@ -0,0 +1 @@ + diff --git a/codeforces/1037/.null-ls_878331_c.cc b/codeforces/1037/.null-ls_878331_c.cc new file mode 100644 index 0000000..d989d60 --- /dev/null +++ b/codeforces/1037/.null-ls_878331_c.cc @@ -0,0 +1,77 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 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; +} +// } diff --git a/codeforces/1037/.null-ls_952410_c.cc b/codeforces/1037/.null-ls_952410_c.cc new file mode 100644 index 0000000..2257c09 --- /dev/null +++ b/codeforces/1037/.null-ls_952410_c.cc @@ -0,0 +1,58 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 +// }}} diff --git a/codeforces/1037/a.cc b/codeforces/1037/a.cc new file mode 100644 index 0000000..47ffe9d --- /dev/null +++ b/codeforces/1037/a.cc @@ -0,0 +1,86 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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 x; + cin >> x; + + u32 ans = x % 10; + while (x) { + ans = min(ans, x % 10); + x /= 10; + } + + println("{}", ans); +} + +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; +} +// }}} diff --git a/codeforces/1037/b.cc b/codeforces/1037/b.cc new file mode 100644 index 0000000..9dd8b73 --- /dev/null +++ b/codeforces/1037/b.cc @@ -0,0 +1,100 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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; + vec a(n); + for (auto& e : a) + cin >> e; + + u32 time_climbing = 0; + u32 ans = 0; + + for (u32 i = 0; i < n; ++i) { + if (a[i] == 1) { + time_climbing = 0; + } else { + ++time_climbing; + } + + if (time_climbing == k) { + ++ans; + ++i; + time_climbing = 0; + } + } + + println("{}", ans); +} + +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; +} +// }}} diff --git a/codeforces/1037/c.cc b/codeforces/1037/c.cc new file mode 100644 index 0000000..11a0be0 --- /dev/null +++ b/codeforces/1037/c.cc @@ -0,0 +1,102 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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; + + vec h(n); + for (auto& e : h) + cin >> e; + + u64 level = 1; + u64 height = h[k - 1]; + + sort(all(h)); + + h.erase(unique(all(h)), h.end()); + u32 index = distance(h.begin(), upper_bound(all(h), height)) - 1; + + while (height < h.back()) { + if (h[index + 1] - h[index] <= height - level + 1) { + level += h[index + 1] - h[index]; + height = h[++index]; + } else { + NO(); + return; + } + } + + YES(); +} + +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; +} +// }}} diff --git a/codeforces/1037/compile_flags.txt b/codeforces/1037/compile_flags.txt new file mode 100644 index 0000000..04a3a2a --- /dev/null +++ b/codeforces/1037/compile_flags.txt @@ -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 +-Wmisleading-indentation +-Wduplicated-cond +-Wduplicated-branches +-Wlogical-op +-Wnull-dereference +-Wformat=2 +-Wformat-overflow +-Wformat-truncation +-Wdouble-promotion +-Wundef +-DLOCAL +-std=c++23 +-std=c++23 diff --git a/codeforces/1037/d.cc b/codeforces/1037/d.cc new file mode 100644 index 0000000..60b90d2 --- /dev/null +++ b/codeforces/1037/d.cc @@ -0,0 +1,98 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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; + u64 k; + cin >> n >> k; + vec> c(n, vec(3)); + for (auto& e : c) { + for (u32 i = 0; i < 3; ++i) + cin >> e[i]; + } + + sort(all(c)); + + u32 position = k; + + for (u32 i = 0; i < n; ++i) { + // NOTE: forgot 3rd condition - always better to move forward + if (c[i][0] <= position && position <= c[i][1] && position <= c[i][2]) { + position = c[i][2]; + } + ans = max(ans, c[i][2]); + } + + println("{}", position); +} + +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; +} +// }}} diff --git a/codeforces/1037/debug_flags.txt b/codeforces/1037/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/1037/debug_flags.txt @@ -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++23 diff --git a/codeforces/1037/e.cc b/codeforces/1037/e.cc new file mode 100644 index 0000000..4c34afd --- /dev/null +++ b/codeforces/1037/e.cc @@ -0,0 +1,114 @@ +#include // {{{ + +// 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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} +#endif + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +template +using vec = std::vector; + +#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; + + vec p(n), s(n); + for (auto& e : p) + cin >> e; + for (auto& e : s) + cin >> e; + + for (u32 i = 0; i < n - 1; ++i) { + if (p[i] % p[i + 1]) { + NO(); + return; + } + } + + for (i32 i = n - 2; i >= 0; --i) { + if (s[i + 1] % s[i]) { + NO(); + return; + } + } + + if (p[n - 1] != s[0]) { + NO(); + return; + } + + u64 g = s[0]; + + for (i32 i = 0; i < n - 1; ++i) { + if (gcd(p[i], s[i + 1]) != g) { + NO(); + return; + } + } + + YES(); +} + +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; +} +// }}} diff --git a/codeforces/1037/io/a.in b/codeforces/1037/io/a.in new file mode 100644 index 0000000..5bd8040 --- /dev/null +++ b/codeforces/1037/io/a.in @@ -0,0 +1,6 @@ +5 +6 +96 +78 +122 +696 diff --git a/codeforces/1037/io/a.out b/codeforces/1037/io/a.out new file mode 100644 index 0000000..6f6ec06 --- /dev/null +++ b/codeforces/1037/io/a.out @@ -0,0 +1,9 @@ +6 +6 +7 +1 +6 + +[code]: 0 +[time]: 5.2259 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1037/io/b.in b/codeforces/1037/io/b.in new file mode 100644 index 0000000..279bd7c --- /dev/null +++ b/codeforces/1037/io/b.in @@ -0,0 +1,11 @@ +5 +5 1 +0 1 0 0 0 +7 3 +0 0 0 0 0 0 0 +3 1 +1 1 1 +4 2 +0 1 0 1 +6 2 +0 0 1 0 0 0 diff --git a/codeforces/1037/io/b.out b/codeforces/1037/io/b.out new file mode 100644 index 0000000..0305c3f --- /dev/null +++ b/codeforces/1037/io/b.out @@ -0,0 +1,9 @@ +3 +2 +0 +0 +2 + +[code]: 0 +[time]: 2.34175 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1037/io/c.in b/codeforces/1037/io/c.in new file mode 100644 index 0000000..5129cd2 --- /dev/null +++ b/codeforces/1037/io/c.in @@ -0,0 +1,11 @@ +5 +5 3 +3 2 1 4 5 +3 1 +1 3 4 +4 4 +4 4 4 2 +6 2 +2 3 6 9 1 2 +4 2 +1 2 5 6 diff --git a/codeforces/1037/io/c.out b/codeforces/1037/io/c.out new file mode 100644 index 0000000..649620e --- /dev/null +++ b/codeforces/1037/io/c.out @@ -0,0 +1,9 @@ +YES +NO +YES +YES +NO + +[code]: 0 +[time]: 2.50602 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1037/io/d.in b/codeforces/1037/io/d.in new file mode 100644 index 0000000..9692029 --- /dev/null +++ b/codeforces/1037/io/d.in @@ -0,0 +1,15 @@ +5 +3 1 +2 3 3 +1 2 2 +3 10 10 +1 0 +1 2 2 +1 2 +1 2 2 +2 2 +1 3 2 +2 4 4 +2 5 +1 10 5 +3 6 5 diff --git a/codeforces/1037/io/d.out b/codeforces/1037/io/d.out new file mode 100644 index 0000000..03aabeb --- /dev/null +++ b/codeforces/1037/io/d.out @@ -0,0 +1,9 @@ +2 +0 +2 +4 +5 + +[code]: 0 +[time]: 2.54178 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1037/io/e.in b/codeforces/1037/io/e.in new file mode 100644 index 0000000..f45da25 --- /dev/null +++ b/codeforces/1037/io/e.in @@ -0,0 +1,16 @@ +5 +6 +72 24 3 3 3 3 +3 3 3 6 12 144 +3 +1 2 3 +4 5 6 +5 +125 125 125 25 25 +25 25 25 25 75 +4 +123 421 282 251 +125 1981 239 223 +3 +124 521 125 +125 121 121 diff --git a/codeforces/1037/io/e.out b/codeforces/1037/io/e.out new file mode 100644 index 0000000..2aca53f --- /dev/null +++ b/codeforces/1037/io/e.out @@ -0,0 +1,9 @@ +YES +NO +YES +NO +NO + +[code]: 0 +[time]: 2.44951 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/1037/makefile b/codeforces/1037/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/1037/makefile @@ -0,0 +1,30 @@ +.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 .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 + +%: + @: diff --git a/codeforces/1037/scripts/debug.sh b/codeforces/1037/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/1037/scripts/debug.sh @@ -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" true +exit $? diff --git a/codeforces/1037/scripts/run.sh b/codeforces/1037/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/1037/scripts/run.sh @@ -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 $? diff --git a/codeforces/1037/scripts/utils.sh b/codeforces/1037/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/1037/scripts/utils.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +execute_binary() { + binary="$1" + input="$2" + output="$3" + is_debug="$4" + + start=$(date '+%s.%N') + if [ -n "$is_debug" ]; then + asan="$(ldconfig -p | grep libasan.so | head -n1 | awk '{print $4}')" + LD_PRELOAD="$asan" timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + else + timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + fi + 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 + test -n "$is_debug" && is_debug_string=true || is_debug_string=false + printf '\n[debug]: %s' "$is_debug_string" >>$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 +} diff --git a/codeforces/859/c.cc b/codeforces/859/c.cc index ce44084..37d674a 100644 --- a/codeforces/859/c.cc +++ b/codeforces/859/c.cc @@ -82,6 +82,9 @@ void solve() { string s; cin >> s; ve last(26, -1); + for (uint32_t j = 1; j > -1; ++j) { + + } for (int i = 0; i < n; ++i) { int x = s[i] - 'a'; if (last[x] != -1) {