diff --git a/codeforces/762/.clang-format b/codeforces/762/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/762/.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/762/.clangd b/codeforces/762/.clangd new file mode 100644 index 0000000..29010fb --- /dev/null +++ b/codeforces/762/.clangd @@ -0,0 +1,38 @@ +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 diff --git a/codeforces/762/a.cc b/codeforces/762/a.cc new file mode 100644 index 0000000..8aae1fe --- /dev/null +++ b/codeforces/762/a.cc @@ -0,0 +1,99 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + string s; + cin >> s; + + if (s.size() % 2 == 0 && + s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size())) { + YES(); + } else { + NO(); + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/762/b.cc b/codeforces/762/b.cc new file mode 100644 index 0000000..7dbb141 --- /dev/null +++ b/codeforces/762/b.cc @@ -0,0 +1,103 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + u64 n; + cin >> n; + + unordered_set ans; + + for (u64 x = 1; x * x <= n; ++x) { + ans.insert(x * x); + } + for (u64 x = 1; x * x * x <= n; ++x) { + ans.insert(x * x * x); + } + + println("{}", ans.size()); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/762/c.cc b/codeforces/762/c.cc new file mode 100644 index 0000000..effe76b --- /dev/null +++ b/codeforces/762/c.cc @@ -0,0 +1,122 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + u64 a, s; + cin >> a >> s; + + string ans; + + while (s) { + auto ad = a % 10, sd = s % 10; + if (ad <= sd) { + ans += to_string(sd - ad); + } else if (ad > sd && (10 + sd - ad) + ad == s % 100) { + ans += to_string(10 + sd - ad); + s /= 10; + } else { + println("-1"); + return; + } + s /= 10; + a /= 10; + } + + if (a) { + println("-1"); + return; + } + + reverse(all(ans)); + u32 i = 0; + while (ans[i] == '0') + ++i; + for (; i < ans.size(); ++i) + print("{}", ans[i]); + println(); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/762/compile_flags.txt b/codeforces/762/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/762/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/762/d.cc b/codeforces/762/d.cc new file mode 100644 index 0000000..2fbc154 --- /dev/null +++ b/codeforces/762/d.cc @@ -0,0 +1,168 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 +// }}} + +bitset<100000 + 1> friends; +void solve() { + /* + binary search on alpha + + how to know if i can choose at least n - 1 shops to give each guy a present + basically, choose, out of all m shops, n shops, one gives each guy a +present (in the worst) + + hm - must dynamically, per bsearch query, filter arrays + + consider each array: if someone unset can be set, + 1 to count, update max + if already set, take max of large value + +challenge: n - 1 shops, not all n + take a step back: + + we have m arrays, each which set values offriend individually + + consider each friend separately - have multiple values of joy set to; filter to +>= mid alphaq + + not nec. choose ones that set most -> greedy + + ok - one shop per friend - per friend, iterate - find shop that sets their joy +>= alpha + + now, either < n (bad) or n shops - consider each friend as the "substitute" +candidate + + in other words, consider each friend, and iter AGAIN thru the shit - can we +find ANOTHER diff array setting this guy, as well as setting another friend? + + if so, done! + */ + + u32 m, n; + cin >> m >> n; + + vec> p(m, vec(n)); + u64 maxp = 0; + for (auto& row : p) { + for (auto& e : row) { + cin >> e; + maxp = max(maxp, e); + } + } + + u64 l = 1, r = maxp; + + auto ok = [&](u64 alpha) { + friends.reset(); + bool both_covered = false; + + for (auto& shop : p) { + u32 shop_count = 0; + for (u32 i = 0; i < n; ++i) { + if (shop[i] >= alpha) { + ++shop_count; + friends.set(i); + } + } + both_covered |= shop_count > 1; + } + + return friends.count() == n && both_covered; + }; + + while (l <= r) { + u64 alpha = l + (r - l) / 2; + + if (ok(alpha)) { + l = alpha + 1; + } else { + r = alpha - 1; + } + } + + println("{}", r); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/762/debug_flags.txt b/codeforces/762/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/762/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/762/e.cc b/codeforces/762/e.cc new file mode 100644 index 0000000..fc6a16c --- /dev/null +++ b/codeforces/762/e.cc @@ -0,0 +1,187 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + /* + i=0->n, # opers (-1 if no) + + + when impossible? mex MEX, cannot form 0, 1, 2, ... MEX - 1 + + consider bf, needing to form mex MEX + need MEX - 1 - take if there + ow, need i; take from largest candidate x, i - x "pull" it up, b/c closest + + continue repeatedly - if not there, return -1 + + for all n, n^2 bf + + is there a recursive structure? + + say i pull up for mex MEX, does this help with MEX + 1 + what's the challenge - pulling up to MEX, may need to pull up to MEX - 1, +etc. then the gap eventually filled (if solution) + + idea, as go L->R, pull up minimal for answer -> making 0->MEX; also pull up + + observation - say missing for mex MEX, need to poull up - repeatedly +hoisting each, to push up is same as pulling up from closest gap index; keep +track of gap indices, and pull from closest one? + + but is puling from closets optimal? -> yes, it is + + narrow down in on this + + also, you have to push elements away - i.e., for each element equal to the +mex, + 1 is the "extra" count + + so, for mex M; push freq[m] first + then, pull for M - 1, and take max free unused #, M - it, + 1 to the prev +score (excluding the M count there) + +subtleties: the equal count - if matching MEX - 1 required pushing, we don't +need to (we can ignore count) really, we just care about pulled for each in our +dependent calculations + +let's be concrete + +mex MEX, solved 0->MEX - 1 + +- sort a increasingly, and for each mex +1. push off ==MEX values +2. define pull[mex] as total cost of pulling to make 0->mex-1 + - if no pull[MEX-1], -1 + - else, + pull from largest available value, adding MEX - 1 - value + - pop used value + push self + +great, now, impl + +we iter over array and mex from 0 to n - which order? +def iter over mex, then have freq map + available + +AFTER: so many mistakes + +only push f-1 elems, using 64-bit types, ease of implementation, breaking loop, using accumulator instead of deriving, etc. + */ + u64 n; + cin >> n; + vec a(n); + map f; + for (auto& e : a) { + cin >> e; + ++f[e]; + } + + vec available; + vec ans(n + 1, -1); + + ans[0] = f[0]; + for (i64 i = 0; i < max((i64)0, f[0] - 1); ++i) + available.push_back(0); + + for (i64 mex = 1; mex <= (i64)n; ++mex) { + ans[mex] = ans[mex - 1] - f[mex - 1] + f[mex]; + + if (f[mex - 1] == 0) { + if (available.empty()) { + ans[mex] = -1; + break; + } + ans[mex] += (mex - 1 - available.back()); + available.pop_back(); + } + + for (i64 i = 0; i < max((i64)0, f[mex] - 1); ++i) + available.push_back(mex); + } + + for (u64 i = 0; i <= n; ++i) + cout << ans[i] << " \n"[i == n]; +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/762/e2.cc b/codeforces/762/e2.cc new file mode 100644 index 0000000..ffe7252 --- /dev/null +++ b/codeforces/762/e2.cc @@ -0,0 +1,122 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 a(n); + for (auto& e : a) + cin >> e; + map f; + for (auto e : a) + ++f[e]; + + u64 pull = 0; + vec ans(n + 1, -1); + vec available; + + for (u32 mex = 0; mex <= n; ++mex) { + if (mex > 0 && f[mex - 1] == 0) { + if (available.empty()) { + break; + } + pull += mex - 1 - available.back(); + available.pop_back(); + } + ans[mex] = pull + f[mex]; + + for (u32 i = 0; i < (f[mex] > 0 ? f[mex] - 1 : 0); ++i) { + available.push_back(mex); + } + } + + for (u32 i = 0; i <= n; ++i) { + cout << ans[i] << " \n"[i == n]; + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/762/io/a.in b/codeforces/762/io/a.in new file mode 100644 index 0000000..db62061 --- /dev/null +++ b/codeforces/762/io/a.in @@ -0,0 +1,11 @@ +10 +a +aa +aaa +aaaa +abab +abcabc +abacaba +xxyy +xyyx +xyxy diff --git a/codeforces/762/io/a.out b/codeforces/762/io/a.out new file mode 100644 index 0000000..7d421ce --- /dev/null +++ b/codeforces/762/io/a.out @@ -0,0 +1,14 @@ +NO +YES +NO +YES +YES +YES +NO +NO +NO +YES + +[code]: 0 +[time]: 6.08635 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/762/io/b.in b/codeforces/762/io/b.in new file mode 100644 index 0000000..368c3cf --- /dev/null +++ b/codeforces/762/io/b.in @@ -0,0 +1,8 @@ +6 +10 +1 +25 +1000000000 +999999999 +500000000 + diff --git a/codeforces/762/io/b.out b/codeforces/762/io/b.out new file mode 100644 index 0000000..954ddcd --- /dev/null +++ b/codeforces/762/io/b.out @@ -0,0 +1,10 @@ +4 +1 +6 +32591 +32590 +23125 + +[code]: 0 +[time]: 11.6577 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/762/io/c.in b/codeforces/762/io/c.in new file mode 100644 index 0000000..02a2253 --- /dev/null +++ b/codeforces/762/io/c.in @@ -0,0 +1,8 @@ +7 +17236 1106911 +1 5 +108 112 +12345 1023412 +1 11 +1 20 +200 202 diff --git a/codeforces/762/io/c.out b/codeforces/762/io/c.out new file mode 100644 index 0000000..412d6f8 --- /dev/null +++ b/codeforces/762/io/c.out @@ -0,0 +1,11 @@ +3465 +4 +-1 +90007 +10 +-1 +2 + +[code]: 0 +[time]: 5.78475 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/762/io/d.in b/codeforces/762/io/d.in new file mode 100644 index 0000000..e3ef63e --- /dev/null +++ b/codeforces/762/io/d.in @@ -0,0 +1,25 @@ +5 + +2 2 +1 2 +3 4 + +4 3 +1 3 1 +3 1 1 +1 2 2 +1 1 3 + +2 3 +5 3 4 +2 5 1 + +4 2 +7 9 +8 1 +9 6 +10 8 + +2 4 +6 5 2 1 +7 9 7 2 diff --git a/codeforces/762/io/d.out b/codeforces/762/io/d.out new file mode 100644 index 0000000..f74a448 --- /dev/null +++ b/codeforces/762/io/d.out @@ -0,0 +1,9 @@ +3 +2 +4 +8 +2 + +[code]: 0 +[time]: 2.3489 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/762/io/e.in b/codeforces/762/io/e.in new file mode 100644 index 0000000..52d3c25 --- /dev/null +++ b/codeforces/762/io/e.in @@ -0,0 +1,12 @@ +5 +3 +0 1 3 +7 +0 1 2 3 4 3 2 +4 +3 0 0 0 +7 +4 6 2 3 5 0 5 +5 +4 0 1 0 4 + diff --git a/codeforces/762/io/e.out b/codeforces/762/io/e.out new file mode 100644 index 0000000..0b14e49 --- /dev/null +++ b/codeforces/762/io/e.out @@ -0,0 +1,9 @@ +1 1 0 -1 +1 1 2 2 1 0 2 6 +3 0 1 4 3 +1 0 -1 -1 -1 -1 -1 -1 +2 1 0 2 -1 -1 + +[code]: 0 +[time]: 2.57897 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/762/io/e2.in b/codeforces/762/io/e2.in new file mode 100644 index 0000000..7df6854 --- /dev/null +++ b/codeforces/762/io/e2.in @@ -0,0 +1,11 @@ +5 +3 +0 1 3 +7 +0 1 2 3 4 3 2 +4 +3 0 0 0 +7 +4 6 2 3 5 0 5 +5 +4 0 1 0 4 diff --git a/codeforces/762/io/e2.out b/codeforces/762/io/e2.out new file mode 100644 index 0000000..caacc48 --- /dev/null +++ b/codeforces/762/io/e2.out @@ -0,0 +1,9 @@ +1 1 0 -1 +1 1 2 2 1 0 2 6 +3 0 1 4 3 +1 0 -1 -1 -1 -1 -1 -1 +2 1 0 2 -1 -1 + +[code]: 0 +[time]: 2.49767 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/762/makefile b/codeforces/762/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/762/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/762/scripts/debug.sh b/codeforces/762/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/762/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/762/scripts/run.sh b/codeforces/762/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/762/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/762/scripts/utils.sh b/codeforces/762/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/762/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/920/.clang-format b/codeforces/920/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/920/.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/920/.clangd b/codeforces/920/.clangd new file mode 100644 index 0000000..bacf048 --- /dev/null +++ b/codeforces/920/.clangd @@ -0,0 +1,44 @@ +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 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/920/a.cc b/codeforces/920/a.cc new file mode 100644 index 0000000..b758f4d --- /dev/null +++ b/codeforces/920/a.cc @@ -0,0 +1,99 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + vec> coords(4); + for (auto& coord : coords) + cin >> coord.first >> coord.second; + + sort(all(coords)); + + auto side = coords[1].second - coords[0].second; + + println("{}", side * side); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/920/b.cc b/codeforces/920/b.cc new file mode 100644 index 0000000..e3fbe37 --- /dev/null +++ b/codeforces/920/b.cc @@ -0,0 +1,124 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + /* + if both set/unset -> done + + if final set, start unset - need + 1 + if orig set, final unset - must move + + must delete x, need y slots + + use min(x, y) slots for y + + remaining y must be added, remaining x must be deleted + */ + + u32 n; + cin >> n; + + string a, b; + cin >> a >> b; + + u32 A{}, B{}; + for (u32 i = 0; i < n; ++i) { + if (a[i] == b[i]) { + continue; + } + if (a[i] == '1') + ++A; + else + ++B; + } + + u32 ans = B; + A -= min(A, B); + ans += A; + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/920/c.cc b/codeforces/920/c.cc new file mode 100644 index 0000000..741a4a5 --- /dev/null +++ b/codeforces/920/c.cc @@ -0,0 +1,137 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + u64 n; + i64 f, b, a; + cin >> n >> f >> a >> b; + + vec m(n); + for (auto& e : m) { + cin >> e; + } + + i64 prev = 0; + for (u32 i = 0; i < n; ++i) { + auto delta = m[i] - prev; + f -= min(b, delta * a); + prev = m[i]; + } + + if (f <= 0) { + NO(); + } else { + YES(); + } + + /* + f charge + off costs b + on costs 1 + + if + + when to turn on/off the phone? + +NOTE: phone starts on + assume phone turns off, then, of course, you have to turn on at m[0] + + so, WLOG, the phone is on + + when to turn off? + if i have to wait > b to turn off, it will cost me > b; otherwise, it costs +me b + + wait, or turn off then on? + say delta seconds pass: min(delta * a, 2*b) + +details: message sending + +iter thru m, take time delta + */ +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/920/compile_flags.txt b/codeforces/920/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/920/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/920/d.cc b/codeforces/920/d.cc new file mode 100644 index 0000000..b7b85d0 --- /dev/null +++ b/codeforces/920/d.cc @@ -0,0 +1,147 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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, m; + cin >> n >> m; + vec a(n), b(m); + for (auto& e : a) + cin >> e; + for (auto& e : b) + cin >> e; + + /* +idea: maximize difference from a to b + +note: order doesn't matter in matching (but must print output) + +sort a? + +hm: consider a[0], w/ some remaining candidates + +min/max choice from b optimal - take better, alter ptrs + +3 6 7 9 10 +2 3 5 9 9 + +8 + +1 2 4 6 +1 2 3 3 5 7 + +6532 + + +tbh, idk why greedy even works here + */ + sort(all(a)); + sort(all(b)); + + u32 a_l = 0, a_r = n - 1; + u32 b_l = 0, b_r = m - 1; + u64 ans = 0; + while (a_l <= a_r) { + array diffs{abs(a[a_l] - b[b_l]), abs(a[a_l] - b[b_r]), + abs(a[a_r] - b[b_l]), abs(a[a_r] - b[b_r])}; + + auto best_diff = max_element(all(diffs)); + auto i = distance(diffs.begin(), best_diff); + + ans += *best_diff; + + if (i < 2) + ++a_l; + else + --a_r; + if (i % 2 == 0) + ++b_l; + else + --b_r; + } + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/920/debug_flags.txt b/codeforces/920/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/920/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/920/e.cc b/codeforces/920/e.cc new file mode 100644 index 0000000..ff0c6af --- /dev/null +++ b/codeforces/920/e.cc @@ -0,0 +1,181 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + i64 n, m; + cin >> n >> m; + + i64 ar, ac, br, bc; + cin >> ar >> ac >> br >> bc; + + // NOTE: forgot to adjust frontier + 1 (rly think thru!) + + string ans{"Draw"}; + if (ar < br) { + i64 frontier = (u64)ceill((ar + br) / 2.0); + + // NOTE: key is alice gets extra move + // TBH, still confused (see mistaken note above) - don't understand + // didn't think about "optimal" play - i.e. alice leading one way + // can bob just go the opposite? then, alice ought to lead straight + // i think if u dig into the logic alice can lead straight in which bob + // can't do antyhing, but anyway all of this logic circumvented my mind, smh + // NOTE: this is why - SIMPLIFY + // simply consider the two player's positions on the frontier row itself - + // both on the same alice goes first so she gets extra move if frontier + // distance odd also, optimal strategy principle (explore too) + i64 aleft = max((i64)1, ac - (frontier - ar)); + i64 aright = min(m, ac + frontier - ar); + + i64 bleft = max((i64)1, bc - (br - frontier)); + i64 bright = min(m, bc + (br - frontier)); + + bool alice_aggressor = (br - ar) & 1; + + if (alice_aggressor) { + if (aleft <= bleft && aright >= bright) { + ans = "Alice"; + } + } else { + if (bleft <= aleft && bright >= aright) { + ans = "Bob"; + } + } + } + + println("{}", ans); + /* + +--A------- +-A-A------ +BB-------- +B--------- +---------- +---------- +---------- +---------- +---------- +---------- + + Alice +Bob +Draw +Draw +Draw +Alice +Draw +Draw +Bob +Alice +Alice +Draw + +idea: consider frontier + +note: ar >= br -> DRAW +ow, alice below bob, and there is a frontier + +alice/bob have frontier pos - enumerate them +find aggressor - they cannot lose + +if aggressor can take all passive piece -> win, print aggressor +ow, draw + +chess moment :sunglasses: + +O(h) -> ok + +to flesh out: + +derive frontier row +derive a/b cols on row +derive aggressor + +note: only care about the coords + */ +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/920/io/a.in b/codeforces/920/io/a.in new file mode 100644 index 0000000..6138094 --- /dev/null +++ b/codeforces/920/io/a.in @@ -0,0 +1,13 @@ +3 +1 2 +4 5 +1 5 +4 2 +-1 1 +1 -1 +1 1 +-1 -1 +45 11 +45 39 +17 11 +17 39 diff --git a/codeforces/920/io/a.out b/codeforces/920/io/a.out new file mode 100644 index 0000000..eb35253 --- /dev/null +++ b/codeforces/920/io/a.out @@ -0,0 +1,7 @@ +9 +4 +784 + +[code]: 0 +[time]: 6.03485 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/920/io/b.in b/codeforces/920/io/b.in new file mode 100644 index 0000000..2989ae5 --- /dev/null +++ b/codeforces/920/io/b.in @@ -0,0 +1,19 @@ +6 +5 +10010 +00001 +1 +1 +1 +3 +000 +111 +4 +0101 +1010 +3 +100 +101 +8 +10011001 +11111110 diff --git a/codeforces/920/io/b.out b/codeforces/920/io/b.out new file mode 100644 index 0000000..7da9e93 --- /dev/null +++ b/codeforces/920/io/b.out @@ -0,0 +1,10 @@ +2 +0 +3 +2 +1 +4 + +[code]: 0 +[time]: 2.50673 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/920/io/c.in b/codeforces/920/io/c.in new file mode 100644 index 0000000..3d9020a --- /dev/null +++ b/codeforces/920/io/c.in @@ -0,0 +1,13 @@ +6 +1 3 1 5 +3 +7 21 1 3 +4 6 10 13 17 20 26 +5 10 1 2 +1 2 3 4 5 +1 1000000000 1000000000 1000000000 +1000000000 +3 11 9 6 +6 8 10 +12 621526648 2585904 3566299 +51789 61859 71998 73401 247675 298086 606959 663464 735972 806043 806459 919683 diff --git a/codeforces/920/io/c.out b/codeforces/920/io/c.out new file mode 100644 index 0000000..98e506c --- /dev/null +++ b/codeforces/920/io/c.out @@ -0,0 +1,10 @@ +NO +YES +YES +NO +NO +YES + +[code]: 0 +[time]: 5.87606 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/920/io/d.in b/codeforces/920/io/d.in new file mode 100644 index 0000000..1337bcf --- /dev/null +++ b/codeforces/920/io/d.in @@ -0,0 +1,28 @@ +9 +4 6 +6 1 2 4 +3 5 1 7 2 3 +3 4 +1 1 1 +1 1 1 1 +5 5 +1 2 3 4 5 +1 2 3 4 5 +2 6 +5 8 +8 7 5 8 2 10 +2 2 +4 1 +9 6 +4 6 +8 10 6 4 +3 10 6 1 8 9 +3 5 +6 5 2 +1 7 9 7 2 +5 5 +9 10 6 3 7 +5 9 2 3 9 +1 6 +3 +2 7 10 1 1 5 diff --git a/codeforces/920/io/d.out b/codeforces/920/io/d.out new file mode 100644 index 0000000..6048b08 --- /dev/null +++ b/codeforces/920/io/d.out @@ -0,0 +1,13 @@ +16 +0 +12 +11 +10 +23 +15 +25 +7 + +[code]: 0 +[time]: 2.69318 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/920/io/e.in b/codeforces/920/io/e.in new file mode 100644 index 0000000..aa82e59 --- /dev/null +++ b/codeforces/920/io/e.in @@ -0,0 +1,13 @@ +12 +6 5 2 2 5 3 +4 1 2 1 4 1 +1 4 1 3 1 1 +5 5 1 4 5 2 +4 4 1 1 4 4 +10 10 1 6 10 8 +10 10 2 6 10 7 +10 10 9 1 8 1 +10 10 8 1 10 2 +10 10 1 1 2 1 +10 10 1 3 4 1 +10 10 3 1 1 1 diff --git a/codeforces/920/io/e.out b/codeforces/920/io/e.out new file mode 100644 index 0000000..4d93970 --- /dev/null +++ b/codeforces/920/io/e.out @@ -0,0 +1,16 @@ +Alice +Bob +Draw +Draw +Draw +Alice +Draw +Draw +Bob +Alice +Alice +Draw + +[code]: 0 +[time]: 2.4941 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/920/makefile b/codeforces/920/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/920/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/920/scripts/debug.sh b/codeforces/920/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/920/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/920/scripts/run.sh b/codeforces/920/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/920/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/920/scripts/utils.sh b/codeforces/920/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/920/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/929/.clang-format b/codeforces/929/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/929/.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/929/.clangd b/codeforces/929/.clangd new file mode 100644 index 0000000..7ce1843 --- /dev/null +++ b/codeforces/929/.clangd @@ -0,0 +1,46 @@ +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 +-e -std=c++23 +-e -std=c++23 +-e -std=c++20 +-e -std=c++23 diff --git a/codeforces/929/a.cc b/codeforces/929/a.cc new file mode 100644 index 0000000..2efc205 --- /dev/null +++ b/codeforces/929/a.cc @@ -0,0 +1,129 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 +// }}} + +#include +#include +namespace pbds = __gnu_pbds; + +template +using hashset = pbds::gp_hash_table; + +template +using hashmap = pbds::gp_hash_table; + +template +using treemultimap = + pbds::tree, pbds::rb_tree_tag, + pbds::tree_order_statistics_node_update>; + +template +using treeset = + pbds::tree, pbds::rb_tree_tag, + pbds::tree_order_statistics_node_update>; + +template +using treemap = + pbds::tree, pbds::rb_tree_tag, + pbds::tree_order_statistics_node_update>; + +template +using treemultiset = + pbds::tree, pbds::rb_tree_tag, + pbds::tree_order_statistics_node_update>; + +void solve() { + u32 n; + cin >> n; + vec a(n); + for (auto& e : a) { + cin >> e; + e = abs(e); + } + + cout << accumulate(all(a), 0LL) << '\n'; +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/929/b.cc b/codeforces/929/b.cc new file mode 100644 index 0000000..38cf059 --- /dev/null +++ b/codeforces/929/b.cc @@ -0,0 +1,120 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 a(n); + u64 odd = 0; + for (auto& e : a) { + cin >> e; + if (e & 1) + odd = e; + } + + auto A = accumulate(all(a), 0LL); + u32 ans = 2; + + switch (A % 3) { + case 0: + cout << "0\n"; + return; + case 1: + for (auto e : a) { + if ((A - e) % 3 == 0) { + ans = 1; + break; + } + } + + cout << ans << '\n'; + return; + case 2: + cout << "1\n"; + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/929/c.cc b/codeforces/929/c.cc new file mode 100644 index 0000000..0da3e74 --- /dev/null +++ b/codeforces/929/c.cc @@ -0,0 +1,106 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + u64 a, b, l; + cin >> a >> b >> l; + + unordered_set seen; + + u64 ax = 1; + for (u32 x = 0; x <= 20 && ax <= l; ++x, ax *= a) { + u64 by = 1; + for (u32 y = 0; y <= 20 & ax * by <= l; ++y, by *= b) { + if (l % (ax * by) == 0) { + seen.insert(l / (ax * by)); + } + } + } + + println("{}", seen.size()); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/929/compile_flags.txt b/codeforces/929/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/929/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/929/d.cc b/codeforces/929/d.cc new file mode 100644 index 0000000..027953d --- /dev/null +++ b/codeforces/929/d.cc @@ -0,0 +1,111 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 a(n); + for (auto& e : a) + cin >> e; + + sort(all(a)); + + if (a[0] != a[1]) { + YES(); + return; + } + + for (u32 i = 2; i < n; ++i) { + if (a[i] % a[0] != 0) { + YES(); + return; + } + } + + NO(); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/929/debug_flags.txt b/codeforces/929/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/929/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/929/e.cc b/codeforces/929/e.cc new file mode 100644 index 0000000..0acde70 --- /dev/null +++ b/codeforces/929/e.cc @@ -0,0 +1,133 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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; + + vec pref(n + 1, 0); + for (i32 i = 1; i <= n; ++i) { + pref[i] = pref[i - 1] + a[i - 1]; + } + + u32 q; + cin >> q; + + i64 u; + i32 l; + + auto f = [&](i64 i) { + auto S = pref[i] - pref[l - 1]; + return (u + 1) * S - S * (S + 1) / 2; + }; + + auto delta = [&](i64 i) { + return f(i) - f(i - 1); + }; + + for (u32 i = 0; i < q; ++i) { + cin >> l >> u; + + i32 L = l + 1, R = n; + + while (L <= R) { + auto M = L + (R - L) / 2; + + if (delta(M) > 0) { + L = M + 1; + } else { + R = M - 1; + } + } + + print("{}{}", L - 1, " \n"[i == q - 1]); + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/929/f.cc b/codeforces/929/f.cc new file mode 100644 index 0000000..e196bad --- /dev/null +++ b/codeforces/929/f.cc @@ -0,0 +1,145 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 +// }}} + +bitset<1000000 + 1> seen; + +void solve() { + seen.reset(); + + i32 n, m; + cin >> n >> m; + vec> grid(n, vec(m)); + for (auto& row : grid) + for (auto& cell : row) + cin >> cell; + + queue> q{{{0, 0}}}; + auto index = [&](i32 r, i32 c) { + return r * m + c; + }; + + seen.set(index(0, 0)); + + auto valid = [&](i32 r, i32 c) { + return min(r, c) >= 0 && r < n && c < m; + }; + + i32 time = 0; + i32 ans = MAX; + while (!q.empty()) { + auto qsize{q.size()}; + + for (u32 i = 0; i < qsize; ++i) { + auto [r, c] = q.front(); + q.pop(); + + if (c == m - 1) { + ans = min(ans, time + min(n - 1 - r, (r + 1) % n)); + continue; + } + + i32 T = time % n; + + if (c < m - 1 && grid[(r + T + 1) % n][c + 1] == 0 && + !seen[index(r, c + 1)]) { + q.emplace(r, c + 1); + seen.set(index(r, c + 1)); + } + + if (grid[(r + T + 1) % n][c] == 0 && grid[(r + T + 2) % n][c] == 0 && + !seen[index((r + 1) % n, c)]) { + q.emplace((r + 1) % n, c); + seen.set(index((r + 1) % n, c)); + } + } + + ++time; + } + + println("{}", ans == MAX ? -1 : ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/929/io/a.in b/codeforces/929/io/a.in new file mode 100644 index 0000000..65b02a1 --- /dev/null +++ b/codeforces/929/io/a.in @@ -0,0 +1,17 @@ +8 +3 +-2 3 -3 +1 +0 +2 +0 1 +1 +-99 +4 +10 -2 -3 7 +5 +-1 -2 -3 -4 -5 +6 +-41 22 -69 73 -15 -50 +12 +1 2 3 4 5 6 7 8 9 10 11 12 diff --git a/codeforces/929/io/a.out b/codeforces/929/io/a.out new file mode 100644 index 0000000..0e711fc --- /dev/null +++ b/codeforces/929/io/a.out @@ -0,0 +1,12 @@ +8 +0 +1 +99 +22 +15 +270 +78 + +[code]: 0 +[time]: 2.30837 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/929/io/b.in b/codeforces/929/io/b.in new file mode 100644 index 0000000..d1181b1 --- /dev/null +++ b/codeforces/929/io/b.in @@ -0,0 +1,18 @@ +8 +4 +2 2 5 4 +3 +1 3 2 +4 +3 7 6 8 +1 +1 +4 +2 2 4 2 +2 +5 5 +7 +2 4 8 1 9 3 4 +2 +4 10 + diff --git a/codeforces/929/io/b.out b/codeforces/929/io/b.out new file mode 100644 index 0000000..7fb866d --- /dev/null +++ b/codeforces/929/io/b.out @@ -0,0 +1,12 @@ +1 +0 +0 +1 +1 +2 +1 +1 + +[code]: 0 +[time]: 2.33126 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/929/io/c.in b/codeforces/929/io/c.in new file mode 100644 index 0000000..ec77291 --- /dev/null +++ b/codeforces/929/io/c.in @@ -0,0 +1,12 @@ +11 +2 5 20 +2 5 21 +4 6 48 +2 3 72 +3 5 75 +2 2 1024 +3 7 83349 +100 100 1000000 +7 3 2 +2 6 6 +17 3 632043 diff --git a/codeforces/929/io/c.out b/codeforces/929/io/c.out new file mode 100644 index 0000000..1af8f2b --- /dev/null +++ b/codeforces/929/io/c.out @@ -0,0 +1,15 @@ +6 +1 +5 +12 +6 +11 +24 +4 +1 +3 +24 + +[code]: 0 +[time]: 5.31888 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/929/io/d.in b/codeforces/929/io/d.in new file mode 100644 index 0000000..1fb0d88 --- /dev/null +++ b/codeforces/929/io/d.in @@ -0,0 +1,17 @@ +8 +6 +1 2 3 4 5 6 +5 +3 3 3 3 3 +3 +2 2 3 +5 +1 1 2 3 7 +3 +1 2 2 +3 +1 1 2 +6 +5 2 10 10 10 2 +4 +3 6 9 3 diff --git a/codeforces/929/io/d.out b/codeforces/929/io/d.out new file mode 100644 index 0000000..aa72038 --- /dev/null +++ b/codeforces/929/io/d.out @@ -0,0 +1,12 @@ +YES +NO +YES +NO +YES +NO +YES +NO + +[code]: 0 +[time]: 2.24853 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/929/io/e.in b/codeforces/929/io/e.in new file mode 100644 index 0000000..c8887f7 --- /dev/null +++ b/codeforces/929/io/e.in @@ -0,0 +1,40 @@ +5 +6 +3 1 4 1 5 9 +3 +1 8 +2 7 +5 9 +1 +10 +1 +1 1 +9 +5 10 9 6 8 3 10 7 3 +5 +8 56 +1 12 +9 3 +1 27 +5 45 +5 +7 9 2 5 2 +10 +1 37 +2 9 +3 33 +4 32 +4 15 +2 2 +4 2 +2 19 +3 7 +2 7 +10 +9 1 6 7 6 3 10 7 3 10 +5 +10 43 +3 23 +9 3 +6 8 +5 14 diff --git a/codeforces/929/io/e.out b/codeforces/929/io/e.out new file mode 100644 index 0000000..245f83b --- /dev/null +++ b/codeforces/929/io/e.out @@ -0,0 +1,9 @@ +3 4 5 +1 +9 2 9 4 9 +5 2 5 5 5 2 4 5 4 2 +10 6 9 7 7 + +[code]: 0 +[time]: 2.41303 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/929/io/f.in b/codeforces/929/io/f.in new file mode 100644 index 0000000..c362ce1 --- /dev/null +++ b/codeforces/929/io/f.in @@ -0,0 +1,31 @@ +6 +4 5 +0 1 0 0 0 +0 0 1 0 0 +1 0 1 1 0 +0 0 0 0 0 +3 3 +0 0 0 +1 0 0 +0 0 0 +5 3 +0 0 0 +0 0 0 +1 0 0 +0 0 0 +1 0 0 +3 7 +0 0 1 0 0 1 0 +1 0 1 0 1 0 0 +0 1 0 0 0 0 0 +3 4 +0 1 0 0 +1 0 0 0 +0 1 1 0 +5 5 +0 0 0 0 0 +0 1 0 1 0 +0 1 0 1 0 +0 1 0 1 0 +0 0 0 1 0 + diff --git a/codeforces/929/io/f.out b/codeforces/929/io/f.out new file mode 100644 index 0000000..92bfe7a --- /dev/null +++ b/codeforces/929/io/f.out @@ -0,0 +1,10 @@ +7 +3 +3 +8 +-1 +12 + +[code]: 0 +[time]: 2.4085 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/929/makefile b/codeforces/929/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/929/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/929/scripts/debug.sh b/codeforces/929/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/929/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/929/scripts/run.sh b/codeforces/929/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/929/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/929/scripts/utils.sh b/codeforces/929/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/929/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/946/.clang-format b/codeforces/946/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/946/.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/946/.clangd b/codeforces/946/.clangd new file mode 100644 index 0000000..b77a15b --- /dev/null +++ b/codeforces/946/.clangd @@ -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 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 +-e -std=c++23 diff --git a/codeforces/946/a.cc b/codeforces/946/a.cc new file mode 100644 index 0000000..2157817 --- /dev/null +++ b/codeforces/946/a.cc @@ -0,0 +1,91 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/946/compile_flags.txt b/codeforces/946/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/946/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/946/debug_flags.txt b/codeforces/946/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/946/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/946/io/a.in b/codeforces/946/io/a.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/946/io/a.out b/codeforces/946/io/a.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/946/makefile b/codeforces/946/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/946/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/946/scripts/debug.sh b/codeforces/946/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/946/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/946/scripts/run.sh b/codeforces/946/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/946/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/946/scripts/utils.sh b/codeforces/946/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/946/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/962/.clang-format b/codeforces/962/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/962/.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/962/.clangd b/codeforces/962/.clangd new file mode 100644 index 0000000..316b539 --- /dev/null +++ b/codeforces/962/.clangd @@ -0,0 +1,41 @@ +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 diff --git a/codeforces/962/a.cc b/codeforces/962/a.cc new file mode 100644 index 0000000..f0d714f --- /dev/null +++ b/codeforces/962/a.cc @@ -0,0 +1,99 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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; + + u32 ans = n / 4; + n -= ans * 4; + + ans += n / 2; + + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/962/b.cc b/codeforces/962/b.cc new file mode 100644 index 0000000..bd55f86 --- /dev/null +++ b/codeforces/962/b.cc @@ -0,0 +1,103 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 grid(n); + for (auto& e : grid) + cin >> e; + + for (u32 i = 0; i < n; i += k) { + for (u32 j = 0; j < n; j += k) { + print("{}", grid[i][j]); + } + println(); + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/962/c.cc b/codeforces/962/c.cc new file mode 100644 index 0000000..d8aab3d --- /dev/null +++ b/codeforces/962/c.cc @@ -0,0 +1,120 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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, q; + cin >> n >> q; + + string a, b; + cin >> a >> b; + + vec> fa(n + 1, vec(26, 0)), fb(n + 1, vec(26, 0)); + + for (u32 i = 1; i <= n; ++i) { + fa[i] = fa[i - 1]; + ++fa[i][a[i - 1] - 'a']; + fb[i] = fb[i - 1]; + ++fb[i][b[i - 1] - 'a']; + } + + u32 l, r; + for (u32 i = 0; i < q; ++i) { + cin >> l >> r; + + u64 acc = 0; + for (u32 j = 0; j < 26; ++j) { + auto adiff = fa[r][j] - fa[l - 1][j]; + auto bdiff = fb[r][j] - fb[l - 1][j]; + + acc += max(adiff, bdiff) - min(adiff, bdiff); + } + + u64 ans = acc / 2; + println("{}", ans); + } +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/962/compile_flags.txt b/codeforces/962/compile_flags.txt new file mode 100644 index 0000000..17821f8 --- /dev/null +++ b/codeforces/962/compile_flags.txt @@ -0,0 +1,31 @@ +-pedantic-errors +-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 diff --git a/codeforces/962/d.cc b/codeforces/962/d.cc new file mode 100644 index 0000000..4ce29e6 --- /dev/null +++ b/codeforces/962/d.cc @@ -0,0 +1,102 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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() { + i64 n, x; + cin >> n >> x; + + u64 ans = 0; + for (i64 a = 1; a <= min(n, x); ++a) { + for (i64 b = 1; a * b <= n && a + b < x; ++b) { + i64 crange = min((n - a * b) / (a + b), x - a - b); + ans += crange; + } + } + + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/962/debug_flags.txt b/codeforces/962/debug_flags.txt new file mode 100644 index 0000000..62a0135 --- /dev/null +++ b/codeforces/962/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/962/e.cc b/codeforces/962/e.cc new file mode 100644 index 0000000..5ab4d3b --- /dev/null +++ b/codeforces/962/e.cc @@ -0,0 +1,111 @@ +#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +// 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 +// }}} + +static constexpr size_t MOD = 1e9 + 7; + +void solve() { + string s; + cin >> s; + + u32 n = s.size(); + vec pref10(n + 1, 0); + for (u32 i = 1; i <= n; ++i) { + pref10[i] = pref10[i - 1] + (s[i - 1] == '1' ? 1 : -1); + } + map cnt; + cnt[0] = 1; + + u64 ans = 0; + + for (u32 y = 1; y <= n; ++y) { + ans = (ans + cnt[pref10[y]] * (n - y + 1)) % MOD; + cnt[pref10[y]] = (cnt[pref10[y]] + y + 1) % MOD; + } + + println("{}", ans); +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); + +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif + + u32 tc = 1; + std::cin >> tc; + + for (u32 t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/962/io/a.in b/codeforces/962/io/a.in new file mode 100644 index 0000000..bed4423 --- /dev/null +++ b/codeforces/962/io/a.in @@ -0,0 +1,4 @@ +3 +2 +6 +8 diff --git a/codeforces/962/io/a.out b/codeforces/962/io/a.out new file mode 100644 index 0000000..ac2a553 --- /dev/null +++ b/codeforces/962/io/a.out @@ -0,0 +1,7 @@ +1 +2 +2 + +[code]: 0 +[time]: 2.64907 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/962/io/b.in b/codeforces/962/io/b.in new file mode 100644 index 0000000..14dd6c3 --- /dev/null +++ b/codeforces/962/io/b.in @@ -0,0 +1,29 @@ +4 +4 4 +0000 +0000 +0000 +0000 +6 3 +000111 +000111 +000111 +111000 +111000 +111000 +6 2 +001100 +001100 +111111 +111111 +110000 +110000 +8 1 +11111111 +11111111 +11111111 +11111111 +11111111 +11111111 +11111111 +11111111 diff --git a/codeforces/962/io/b.out b/codeforces/962/io/b.out new file mode 100644 index 0000000..4104784 --- /dev/null +++ b/codeforces/962/io/b.out @@ -0,0 +1,18 @@ +0 +01 +10 +010 +111 +100 +11111111 +11111111 +11111111 +11111111 +11111111 +11111111 +11111111 +11111111 + +[code]: 0 +[time]: 2.57421 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/962/io/c.in b/codeforces/962/io/c.in new file mode 100644 index 0000000..c33471a --- /dev/null +++ b/codeforces/962/io/c.in @@ -0,0 +1,18 @@ +3 +5 3 +abcde +edcba +1 5 +1 4 +3 3 +4 2 +zzde +azbe +1 3 +1 4 +6 3 +uwuwuw +wuwuwu +2 4 +1 3 +1 6 diff --git a/codeforces/962/io/c.out b/codeforces/962/io/c.out new file mode 100644 index 0000000..eaeb180 --- /dev/null +++ b/codeforces/962/io/c.out @@ -0,0 +1,12 @@ +0 +1 +0 +2 +2 +1 +1 +0 + +[code]: 0 +[time]: 2.44355 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/962/io/d.in b/codeforces/962/io/d.in new file mode 100644 index 0000000..188427b --- /dev/null +++ b/codeforces/962/io/d.in @@ -0,0 +1,5 @@ +4 +7 4 +10 5 +7 1000 +900000 400000 diff --git a/codeforces/962/io/d.out b/codeforces/962/io/d.out new file mode 100644 index 0000000..d7e0899 --- /dev/null +++ b/codeforces/962/io/d.out @@ -0,0 +1,8 @@ +4 +10 +7 +1768016938 + +[code]: 0 +[time]: 98.1693 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/962/io/e.in b/codeforces/962/io/e.in new file mode 100644 index 0000000..96449d5 --- /dev/null +++ b/codeforces/962/io/e.in @@ -0,0 +1,5 @@ +4 +0000 +01010101 +1100111001 +11000000111 diff --git a/codeforces/962/io/e.out b/codeforces/962/io/e.out new file mode 100644 index 0000000..6ea0d43 --- /dev/null +++ b/codeforces/962/io/e.out @@ -0,0 +1,8 @@ +0 +130 +147 +70 + +[code]: 0 +[time]: 8.88729 ms +[debug]: false \ No newline at end of file diff --git a/codeforces/962/makefile b/codeforces/962/makefile new file mode 100644 index 0000000..3c50267 --- /dev/null +++ b/codeforces/962/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/962/scripts/debug.sh b/codeforces/962/scripts/debug.sh new file mode 100644 index 0000000..1e63f37 --- /dev/null +++ b/codeforces/962/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/962/scripts/run.sh b/codeforces/962/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/962/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/962/scripts/utils.sh b/codeforces/962/scripts/utils.sh new file mode 100644 index 0000000..e4cf8f8 --- /dev/null +++ b/codeforces/962/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/io/e.in b/codeforces/io/e.in new file mode 100644 index 0000000..aa82e59 --- /dev/null +++ b/codeforces/io/e.in @@ -0,0 +1,13 @@ +12 +6 5 2 2 5 3 +4 1 2 1 4 1 +1 4 1 3 1 1 +5 5 1 4 5 2 +4 4 1 1 4 4 +10 10 1 6 10 8 +10 10 2 6 10 7 +10 10 9 1 8 1 +10 10 8 1 10 2 +10 10 1 1 2 1 +10 10 1 3 4 1 +10 10 3 1 1 1 diff --git a/codeforces/io/e.out b/codeforces/io/e.out new file mode 100644 index 0000000..e69de29 diff --git a/cses/graph-algorithms/.clangd b/cses/graph-algorithms/.clangd index 3bb51b3..ff31f80 100644 --- a/cses/graph-algorithms/.clangd +++ b/cses/graph-algorithms/.clangd @@ -47,3 +47,4 @@ CompileFlags: -e -std=c++20 -e -std=c++20 -e -std=c++20 +-e -std=c++20 diff --git a/cses/graph-algorithms/io/monsters.out b/cses/graph-algorithms/io/monsters.out index b8d07ed..0b64ab5 100644 --- a/cses/graph-algorithms/io/monsters.out +++ b/cses/graph-algorithms/io/monsters.out @@ -2,5 +2,5 @@ YES 7 URRRRDR [code]: 0 -[time]: 2.22921 ms +[time]: 3.60417 ms [debug]: false \ No newline at end of file