diff --git a/codeforces/431/.clang-format b/codeforces/431/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/431/.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/431/.null-ls_210584_c.cc b/codeforces/431/.null-ls_210584_c.cc new file mode 100644 index 0000000..2462f22 --- /dev/null +++ b/codeforces/431/.null-ls_210584_c.cc @@ -0,0 +1 @@ +#include diff --git a/codeforces/431/.null-ls_213694_c.cc b/codeforces/431/.null-ls_213694_c.cc new file mode 100644 index 0000000..35605d1 --- /dev/null +++ b/codeforces/431/.null-ls_213694_c.cc @@ -0,0 +1,139 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +template void print(string const &str, Args &&...args) { + cout << vformat(str, make_format_args(forward(args)...)); +} + +template void print(T const &t) { cout << t; } + +template void print(T const &t) { + if constexpr (is_same_v || is_convertible_v) { + cout << t << '\n'; + } else { + for (const auto &e : t) { + cout << e << ' '; + } + cout << '\n'; + } +} + +template void println(string const &str, Args &&...args) { + print(str, fo diff --git a/codeforces/431/.null-ls_271044_c.cc b/codeforces/431/.null-ls_271044_c.cc new file mode 100644 index 0000000..aa8bdaa --- /dev/null +++ b/codeforces/431/.null-ls_271044_c.cc @@ -0,0 +1,193 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +template void print(string const &str, Args &&...args) { + cout << vformat(str, make_format_args(forward(args)...)); +} + +template void print(T const &t) { cout << t; } + +template void print(T const &t) { + if constexpr (is_same_v || is_convertible_v) { + cout << t << '\n'; + } else { + for (const auto &e : t) { + cout << e << ' '; + } + cout << '\n'; + } +} + +template void println(string const &str, Args &&...args) { + print(str, forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { + print(t); + cout << '\n'; +} + +void println() { cout << '\n'; } + +template T max() { return numeric_limits::max(); } + +template T min() { return numeric_limits::min(); } + +constexpr static int MOD = 1e9 + 7; + +void solve() { + int n, k, d; + cin >> n >> k >> d; + hashmap, int> memo; + + auto dp = [&](auto &self, int n, int d) -> int { + if (memo.find({n, d}) != memo.end()) + return memo[{n, d}]; + + if (n == 0) + return d == 0 ? 1 : 0; + + ll total = 0; + + FOR(i, 1, min(n + 1, k + 1)) { + total = (total + self(self, n - i, i < d ? d : 0)) % MOD; + } + + return memo[{n, d}] = total; + }; + + print(dp(dp, n, d)); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/431/.null-ls_427011_c.cc b/codeforces/431/.null-ls_427011_c.cc new file mode 100644 index 0000000..aa8bdaa --- /dev/null +++ b/codeforces/431/.null-ls_427011_c.cc @@ -0,0 +1,193 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +template void print(string const &str, Args &&...args) { + cout << vformat(str, make_format_args(forward(args)...)); +} + +template void print(T const &t) { cout << t; } + +template void print(T const &t) { + if constexpr (is_same_v || is_convertible_v) { + cout << t << '\n'; + } else { + for (const auto &e : t) { + cout << e << ' '; + } + cout << '\n'; + } +} + +template void println(string const &str, Args &&...args) { + print(str, forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { + print(t); + cout << '\n'; +} + +void println() { cout << '\n'; } + +template T max() { return numeric_limits::max(); } + +template T min() { return numeric_limits::min(); } + +constexpr static int MOD = 1e9 + 7; + +void solve() { + int n, k, d; + cin >> n >> k >> d; + hashmap, int> memo; + + auto dp = [&](auto &self, int n, int d) -> int { + if (memo.find({n, d}) != memo.end()) + return memo[{n, d}]; + + if (n == 0) + return d == 0 ? 1 : 0; + + ll total = 0; + + FOR(i, 1, min(n + 1, k + 1)) { + total = (total + self(self, n - i, i < d ? d : 0)) % MOD; + } + + return memo[{n, d}] = total; + }; + + print(dp(dp, n, d)); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/431/.null-ls_433724_c.cc b/codeforces/431/.null-ls_433724_c.cc new file mode 100644 index 0000000..35605d1 --- /dev/null +++ b/codeforces/431/.null-ls_433724_c.cc @@ -0,0 +1,139 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +template void print(string const &str, Args &&...args) { + cout << vformat(str, make_format_args(forward(args)...)); +} + +template void print(T const &t) { cout << t; } + +template void print(T const &t) { + if constexpr (is_same_v || is_convertible_v) { + cout << t << '\n'; + } else { + for (const auto &e : t) { + cout << e << ' '; + } + cout << '\n'; + } +} + +template void println(string const &str, Args &&...args) { + print(str, fo diff --git a/codeforces/431/.null-ls_441630_c.cc b/codeforces/431/.null-ls_441630_c.cc new file mode 100644 index 0000000..2462f22 --- /dev/null +++ b/codeforces/431/.null-ls_441630_c.cc @@ -0,0 +1 @@ +#include diff --git a/codeforces/431/.null-ls_544573_c.cc b/codeforces/431/.null-ls_544573_c.cc new file mode 100644 index 0000000..aa8bdaa --- /dev/null +++ b/codeforces/431/.null-ls_544573_c.cc @@ -0,0 +1,193 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +template void print(string const &str, Args &&...args) { + cout << vformat(str, make_format_args(forward(args)...)); +} + +template void print(T const &t) { cout << t; } + +template void print(T const &t) { + if constexpr (is_same_v || is_convertible_v) { + cout << t << '\n'; + } else { + for (const auto &e : t) { + cout << e << ' '; + } + cout << '\n'; + } +} + +template void println(string const &str, Args &&...args) { + print(str, forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { + print(t); + cout << '\n'; +} + +void println() { cout << '\n'; } + +template T max() { return numeric_limits::max(); } + +template T min() { return numeric_limits::min(); } + +constexpr static int MOD = 1e9 + 7; + +void solve() { + int n, k, d; + cin >> n >> k >> d; + hashmap, int> memo; + + auto dp = [&](auto &self, int n, int d) -> int { + if (memo.find({n, d}) != memo.end()) + return memo[{n, d}]; + + if (n == 0) + return d == 0 ? 1 : 0; + + ll total = 0; + + FOR(i, 1, min(n + 1, k + 1)) { + total = (total + self(self, n - i, i < d ? d : 0)) % MOD; + } + + return memo[{n, d}] = total; + }; + + print(dp(dp, n, d)); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/431/c.cc b/codeforces/431/c.cc new file mode 100644 index 0000000..c4c1066 --- /dev/null +++ b/codeforces/431/c.cc @@ -0,0 +1,193 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +template void print(string const &str, Args &&...args) { + cout << vformat(str, make_format_args(forward(args)...)); +} + +template void print(T const &t) { cout << t; } + +template void print(T const &t) { + if constexpr (is_same_v || is_convertible_v) { + cout << t << '\n'; + } else { + for (const auto &e : t) { + cout << e << ' '; + } + cout << '\n'; + } +} + +template void println(string const &str, Args &&...args) { + print(str, forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { + print(t); + cout << '\n'; +} + +void println() { cout << '\n'; } + +template T max() { return numeric_limits::max(); } + +template T min() { return numeric_limits::min(); } + +constexpr static int MOD = 1e9 + 7; + +void solve() { + int n, k, d; + cin >> n >> k >> d; + hashmap, int> memo; + + auto dp = [&](auto self, int n, int d) -> int { + if (memo.find({n, d}) != memo.end()) + return memo[{n, d}]; + + if (n == 0) + return d == 0 ? 1 : 0; + + ll total = 0; + + FOR(i, 1, min(n + 1, k + 1)) { + total = (total + self(self, n - i, i < d ? d : 0)) % MOD; + } + + return memo[{n, d}] = total; + }; + + print(dp(dp, n, d)); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/431/c.debug b/codeforces/431/c.debug new file mode 100755 index 0000000..2d0767c Binary files /dev/null and b/codeforces/431/c.debug differ diff --git a/codeforces/431/c.in b/codeforces/431/c.in new file mode 100644 index 0000000..ce4b2ec --- /dev/null +++ b/codeforces/431/c.in @@ -0,0 +1 @@ +4 5 2 diff --git a/codeforces/431/c.out b/codeforces/431/c.out new file mode 100644 index 0000000..c793025 --- /dev/null +++ b/codeforces/431/c.out @@ -0,0 +1 @@ +7 \ No newline at end of file diff --git a/codeforces/431/compile_flags.txt b/codeforces/431/compile_flags.txt new file mode 100644 index 0000000..ebd5be8 --- /dev/null +++ b/codeforces/431/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wshadow +-DLOCAL diff --git a/codeforces/431/d.cc b/codeforces/431/d.cc new file mode 100644 index 0000000..46c7e68 --- /dev/null +++ b/codeforces/431/d.cc @@ -0,0 +1,109 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/431/d.debug b/codeforces/431/d.debug new file mode 100755 index 0000000..50f9758 Binary files /dev/null and b/codeforces/431/d.debug differ diff --git a/codeforces/431/d.in b/codeforces/431/d.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/431/d.out b/codeforces/431/d.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/431/e.cc b/codeforces/431/e.cc new file mode 100644 index 0000000..46c7e68 --- /dev/null +++ b/codeforces/431/e.cc @@ -0,0 +1,109 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/431/e.debug b/codeforces/431/e.debug new file mode 100755 index 0000000..a16567f Binary files /dev/null and b/codeforces/431/e.debug differ diff --git a/codeforces/431/e.in b/codeforces/431/e.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/431/e.out b/codeforces/431/e.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/640/.clang-format b/codeforces/640/.clang-format new file mode 100644 index 0000000..5625628 --- /dev/null +++ b/codeforces/640/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: Empty diff --git a/codeforces/640/a.cc b/codeforces/640/a.cc new file mode 100644 index 0000000..db5f976 --- /dev/null +++ b/codeforces/640/a.cc @@ -0,0 +1,126 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n; + cin >> n; + + int k = 0; + vec summands; + int power = 0; + while (n) { + int digit = n % 10; + if (digit) { + ++k; + summands.push_back(static_cast(pow(10, power)) * digit); + } + ++power; + n /= 10; + } + cout << k << '\n'; + for (auto summand : summands) cout << summand << ' '; + cout << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/a.in b/codeforces/640/a.in new file mode 100644 index 0000000..3f448ef --- /dev/null +++ b/codeforces/640/a.in @@ -0,0 +1,6 @@ +5 +5009 +7 +9876 +10000 +10 diff --git a/codeforces/640/a.out b/codeforces/640/a.out new file mode 100644 index 0000000..d260f1f --- /dev/null +++ b/codeforces/640/a.out @@ -0,0 +1,10 @@ +2 +9 5000 +1 +7 +4 +6 70 800 9000 +1 +10000 +1 +10 diff --git a/codeforces/640/b.cc b/codeforces/640/b.cc new file mode 100644 index 0000000..1cb42af --- /dev/null +++ b/codeforces/640/b.cc @@ -0,0 +1,134 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + /* + n, k; SUM ai = n, same parity + + n odd: k even -> NO; k odd -> YES + n even: k even: odd #s -> NO, only even + */ + int n, k; + cin >> n >> k; + + if (k > n) { + NO(); + return; + } + + if ((n - 2 * (k - 1)) % 2 == 0 && (n - 2 * (k - 1)) > 0) { + YES(); + FOR(i, 1, k) + cout << 2 << ' '; + cout << n - 2 * (k - 1) << '\n'; + } else if ((n - k + 1) & 1) { + YES(); + FOR(i, 1, k) + cout << 1 << ' '; + cout << n - k + 1 << '\n'; + } else + NO(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/b.in b/codeforces/640/b.in new file mode 100644 index 0000000..b87a5e7 --- /dev/null +++ b/codeforces/640/b.in @@ -0,0 +1,9 @@ +8 +10 3 +100 4 +8 7 +97 2 +8 8 +3 10 +5 3 +1000000000 9 diff --git a/codeforces/640/b.out b/codeforces/640/b.out new file mode 100644 index 0000000..4495de0 --- /dev/null +++ b/codeforces/640/b.out @@ -0,0 +1,13 @@ +YES +2 2 6 +YES +2 2 2 94 +NO +NO +YES +1 1 1 1 1 1 1 1 +NO +YES +1 1 3 +YES +2 2 2 2 2 2 2 2 999999984 diff --git a/codeforces/640/c.cc b/codeforces/640/c.cc new file mode 100644 index 0000000..b0d8cd3 --- /dev/null +++ b/codeforces/640/c.cc @@ -0,0 +1,124 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n, k; + + cin >> n >> k; + + /* + take n; + n divides n, 2n, 3n, 4n, ... + kth positive integer not divisible by n; + just count ^ : n - 1, n - 1 between each + + binary search on the right #; + */ + + ll x = k + k / (n - 1); + if (x % n == 0) --x; + println(x); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/c.in b/codeforces/640/c.in new file mode 100644 index 0000000..c1d0911 --- /dev/null +++ b/codeforces/640/c.in @@ -0,0 +1,7 @@ +6 +3 7 +4 12 +2 1000000000 +7 97 +1000000000 1000000000 +2 1 diff --git a/codeforces/640/c.out b/codeforces/640/c.out new file mode 100644 index 0000000..100793b --- /dev/null +++ b/codeforces/640/c.out @@ -0,0 +1,6 @@ +10 +15 +1999999999 +113 +1000000001 +1 diff --git a/codeforces/640/compile_flags.txt b/codeforces/640/compile_flags.txt new file mode 100644 index 0000000..ebd5be8 --- /dev/null +++ b/codeforces/640/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wshadow +-DLOCAL diff --git a/codeforces/640/d.cc b/codeforces/640/d.cc new file mode 100644 index 0000000..2ab9035 --- /dev/null +++ b/codeforces/640/d.cc @@ -0,0 +1,139 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n; + cin >> n; + vec A(n); + for (auto &e : A) cin >> e; + + int moves = 1, i = 1, j = sz(A) - 1; + int a = A[0], b = 0; + int prev = a; + + while (i <= j) { + int cur = 0; + // bob + if (moves & 1) { + while (i <= j && cur <= prev) { + cur += A[j]; + --j; + } + b += cur; + prev = cur; + } else { // alice + while (i <= j && cur <= prev) { + cur += A[i]; + ++i; + } + a += cur; + prev = cur; + } + ++moves; + } + + println("{} {} {}", moves, a, b); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/d.in b/codeforces/640/d.in new file mode 100644 index 0000000..e5a3fa3 --- /dev/null +++ b/codeforces/640/d.in @@ -0,0 +1,15 @@ +7 +11 +3 1 4 1 5 9 2 6 5 3 5 +1 +1000 +3 +1 1 1 +13 +1 2 3 4 5 6 7 8 9 10 11 12 13 +2 +2 1 +6 +1 1 1 1 1 1 +7 +1 1 1 1 1 1 1 diff --git a/codeforces/640/d.out b/codeforces/640/d.out new file mode 100644 index 0000000..1a3d92b --- /dev/null +++ b/codeforces/640/d.out @@ -0,0 +1,7 @@ +6 23 21 +1 1000 0 +2 1 2 +6 45 46 +2 2 1 +3 4 2 +4 4 3 diff --git a/codeforces/640/e.cc b/codeforces/640/e.cc new file mode 100644 index 0000000..b06dcc8 --- /dev/null +++ b/codeforces/640/e.cc @@ -0,0 +1,231 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +#include +#include + +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template +struct custom_hash {}; + +template +inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) hash_combine(value, x); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +void solve() { + int n; + cin >> n; + vec a(n); + + vec freq(n + 1, 0); + for (auto &e : a) { + cin >> e; + ++freq[e]; + } + + int ans = 0; + FOR(i, 0, n) { + int total = 0; + FOR(j, i, n) { + total += a[j]; + if (i != j && total <= n) { + ans += freq[total]; + freq[total] = 0; + } + } + } + println(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/e.in b/codeforces/640/e.in new file mode 100644 index 0000000..7fe04ef --- /dev/null +++ b/codeforces/640/e.in @@ -0,0 +1,11 @@ +5 +9 +3 1 4 1 5 9 2 6 5 +3 +1 1 2 +5 +1 1 1 1 1 +8 +8 7 6 5 4 3 2 1 +1 +1 diff --git a/codeforces/640/e.out b/codeforces/640/e.out new file mode 100644 index 0000000..9c0b33c --- /dev/null +++ b/codeforces/640/e.out @@ -0,0 +1,5 @@ +5 +1 +0 +4 +0 diff --git a/codeforces/640/f.cc b/codeforces/640/f.cc new file mode 100644 index 0000000..749f927 --- /dev/null +++ b/codeforces/640/f.cc @@ -0,0 +1,124 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n0, n1, n2; + cin >> n0 >> n1 >> n2; + + if (n1 == 0) { + char s = n0 ? '0' : '1'; + cout << string(max(n0, n2) + 1, s) << '\n'; + return; + } + + string ans; + FOR(i, 0, n1 + 1) + ans += i & 1 ? '0' : '1'; + ans.insert(1, string(n0, '0')); + ans = string(n2, '1') + ans; + + println(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/f.in b/codeforces/640/f.in new file mode 100644 index 0000000..14c9585 --- /dev/null +++ b/codeforces/640/f.in @@ -0,0 +1,9 @@ +8 +0 3 4 +1 3 5 +1 1 1 +3 9 3 +0 1 0 +3 1 2 +0 0 3 +2 0 0 diff --git a/codeforces/640/f.out b/codeforces/640/f.out new file mode 100644 index 0000000..f48ec1b --- /dev/null +++ b/codeforces/640/f.out @@ -0,0 +1,8 @@ +11111010 +1111110010 +1100 +1111000010101010 +10 +1110000 +1111 +000 diff --git a/codeforces/640/g.cc b/codeforces/640/g.cc new file mode 100644 index 0000000..0ec3b23 --- /dev/null +++ b/codeforces/640/g.cc @@ -0,0 +1,174 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n; + cin >> n; + + /* + + 1, 4, 2, 5, 3, 6, 9, 7, 10, 8 + +1: 5, 7, 3, 6 -> pop -> 2, -4, 3 +2: 5, 7, 3, 6, 8 +3: 3, 7, 9, 6, 8 -> +4, +2, -3, +2 +4: 3, -2, 3, -2 + + 1, 4, 2, 5, 3, 7, 9, 6, 8 + + n = 4 -> 2 4 1 3 + + + +1, +3, -2, +3, -2, +3, +3, -2, +3, -2 + + */ + + if (n < 4) { + println(-1); + return; + } + + if (n == 4) { + println("2 4 1 3"); + return; + } + + vec ans{1}; + int prev = 1; + --n; + while (n >= 5) { + for (auto diff : {3, -2, 3, -2, 3}) { + prev += diff; + ans.push_back(prev); + } + n -= 5; + } + + vec diff; + switch (n) { + case 1: + ans.pop_back(); + ans.pop_back(); + diff = {2, -4, 3}; + break; + case 2: + ans.pop_back(); + ans.pop_back(); + diff = {2, -4, 3, 2}; + break; + case 3: + ans.pop_back(); + diff = {4, 2, -3, 2}; + break; + case 4: + diff = {3, -2, 3, -2}; + break; + } + for (auto d : diff) ans.push_back(ans[sz(ans) - 1] + d); + + for (auto e : ans) cout << e << ' '; + println(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/640/g.in b/codeforces/640/g.in new file mode 100644 index 0000000..56f6744 --- /dev/null +++ b/codeforces/640/g.in @@ -0,0 +1,8 @@ +7 +10 +2 +4 +6 +7 +9 +13 diff --git a/codeforces/640/g.out b/codeforces/640/g.out new file mode 100644 index 0000000..404a102 --- /dev/null +++ b/codeforces/640/g.out @@ -0,0 +1,7 @@ +1 4 2 5 3 6 9 7 10 8 +-1 +2 4 1 3 +1 4 2 5 3 6 +1 4 2 5 7 3 6 +1 4 2 5 3 7 9 6 8 +1 4 2 5 3 6 9 7 10 12 8 11 13 diff --git a/codeforces/923/.clang-format b/codeforces/923/.clang-format new file mode 100644 index 0000000..5625628 --- /dev/null +++ b/codeforces/923/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: Empty diff --git a/codeforces/923/a.cc b/codeforces/923/a.cc new file mode 100644 index 0000000..14e09b1 --- /dev/null +++ b/codeforces/923/a.cc @@ -0,0 +1,120 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n; + cin >> n; + int l = -1, r = -1; + + FOR(i, 0, n) { + char c; + cin >> c; + if (l == -1 && c == 'B') l = i; + if (c == 'B') r = i; + } + + println(r - l + 1); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/923/a.in b/codeforces/923/a.in new file mode 100644 index 0000000..31d5fa9 --- /dev/null +++ b/codeforces/923/a.in @@ -0,0 +1,17 @@ +8 +6 +WBBWBW +1 +B +2 +WB +3 +BBW +4 +BWWB +6 +BWBWWB +6 +WWBBWB +9 +WBWBWWWBW diff --git a/codeforces/923/a.out b/codeforces/923/a.out new file mode 100644 index 0000000..e44b01a --- /dev/null +++ b/codeforces/923/a.out @@ -0,0 +1,24 @@ +hi + +4 +hi + +1 +hi + +1 +hi + +2 +hi + +4 +hi + +6 +hi + +4 +hi + +7 diff --git a/codeforces/923/b.cc b/codeforces/923/b.cc new file mode 100644 index 0000000..22d1fff --- /dev/null +++ b/codeforces/923/b.cc @@ -0,0 +1,231 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +#include +#include + +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template +struct custom_hash {}; + +template +inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) hash_combine(value, x); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +void solve() { + int n; + cin >> n; + + string ans; + vec> rev(n + 1); + int last_used = -1; + + FOR(i, 0, n) { + int a; + cin >> a; + if (a == 0) { + ++last_used; + cout << (char(last_used + 'a')); + rev[1].push_back(last_used); + } else { + cout << char(rev[a].front() + 'a'); + rev[a + 1].push_back(rev[a].front()); + rev[a].pop_front(); + } + } + + println(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/923/b.in b/codeforces/923/b.in new file mode 100644 index 0000000..1c42608 --- /dev/null +++ b/codeforces/923/b.in @@ -0,0 +1,11 @@ +5 +11 +0 0 0 1 0 2 0 3 1 1 4 +10 +0 0 0 0 0 1 0 1 1 0 +1 +0 +8 +0 1 2 3 4 5 6 7 +8 +0 0 0 0 0 0 0 0 diff --git a/codeforces/923/b.out b/codeforces/923/b.out new file mode 100644 index 0000000..62e29d4 --- /dev/null +++ b/codeforces/923/b.out @@ -0,0 +1,5 @@ +abcadaeabca +abcdeafbcg +a +aaaaaaaa +abcdefgh diff --git a/codeforces/923/c.cc b/codeforces/923/c.cc new file mode 100644 index 0000000..af73b24 --- /dev/null +++ b/codeforces/923/c.cc @@ -0,0 +1,150 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +bitset<2 * 2 * 100000 + 1> a, b; + +void solve() { + int n, m, k; + cin >> n >> m >> k; + + // ensure: + // a) all found + // b) <= k / 2 elements in [1,k] from just one arry + + int x; + + while (n--) { + cin >> x; + if (x > k) continue; + a.set(x); + } + + while (m--) { + cin >> x; + if (x > k) continue; + b.set(x); + } + + bool all_found = true; + + int unique_to_a = 0, unique_to_b = 0; + for (int i = 1; i <= k; ++i) { + if (!a[i] && !b[i]) { + all_found = false; + break; + } + if (a[i] && !b[i]) ++unique_to_a; + if (!a[i] && b[i]) ++unique_to_b; + } + + if (all_found && unique_to_a <= k / 2 && unique_to_b <= k / 2) + YES(); + else + NO(); + + a.reset(); + b.reset(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/923/c.in b/codeforces/923/c.in new file mode 100644 index 0000000..27c1ad3 --- /dev/null +++ b/codeforces/923/c.in @@ -0,0 +1,19 @@ +6 +6 5 6 +2 3 8 5 6 5 +1 3 4 10 5 +6 5 6 +2 3 4 5 6 5 +1 3 8 10 3 +3 3 4 +1 3 5 +2 4 6 +2 5 4 +1 4 +7 3 4 4 2 +1 4 2 +2 +6 4 4 2 +1 5 2 +3 +2 2 1 4 3 diff --git a/codeforces/923/c.out b/codeforces/923/c.out new file mode 100644 index 0000000..faa6105 --- /dev/null +++ b/codeforces/923/c.out @@ -0,0 +1,6 @@ +YES +NO +YES +YES +NO +NO diff --git a/codeforces/923/compile_flags.txt b/codeforces/923/compile_flags.txt new file mode 100644 index 0000000..ebd5be8 --- /dev/null +++ b/codeforces/923/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wshadow +-DLOCAL diff --git a/codeforces/923/d.cc b/codeforces/923/d.cc new file mode 100644 index 0000000..2e06910 --- /dev/null +++ b/codeforces/923/d.cc @@ -0,0 +1,136 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n; + cin >> n; + vec a(n); + vec p(n, -1); + cin >> a[0]; + + FOR(i, 1, n) { + cin >> a[i]; + p[i] = p[i - 1]; + if (a[i] != a[i - 1]) p[i] = i - 1; + } + + int q; + cin >> q; + while (q--) { + int l, r; + cin >> l >> r; + + --l; + --r; + + int i = r; + int j = p[r]; + + if (j < l) i = -2, j = -2; + + println("{} {}", i + 1, j + 1); + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/923/d.in b/codeforces/923/d.in new file mode 100644 index 0000000..e0a89b3 --- /dev/null +++ b/codeforces/923/d.in @@ -0,0 +1,40 @@ +5 +5 +1 1 2 1 1 +3 +1 5 +1 2 +1 3 +6 +30 20 20 10 10 20 +5 +1 2 +2 3 +2 4 +2 6 +3 5 +4 +5 2 3 4 +4 +1 2 +1 4 +2 3 +2 4 +5 +1 4 3 2 4 +5 +1 5 +2 4 +3 4 +3 5 +4 5 +5 +2 3 1 4 2 +7 +1 2 +1 4 +1 5 +2 4 +2 5 +3 5 +4 5 diff --git a/codeforces/923/d.out b/codeforces/923/d.out new file mode 100644 index 0000000..cf249ed --- /dev/null +++ b/codeforces/923/d.out @@ -0,0 +1,24 @@ +5 3 +-1 -1 +3 2 +2 1 +-1 -1 +4 3 +6 5 +5 3 +2 1 +4 3 +3 2 +4 3 +5 4 +4 3 +4 3 +5 4 +5 4 +2 1 +4 3 +5 4 +4 3 +5 4 +5 4 +5 4 diff --git a/codeforces/923/exe b/codeforces/923/exe new file mode 100755 index 0000000..756ff62 Binary files /dev/null and b/codeforces/923/exe differ diff --git a/codeforces/923/j.cc b/codeforces/923/j.cc new file mode 100644 index 0000000..22f079d --- /dev/null +++ b/codeforces/923/j.cc @@ -0,0 +1,110 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + aknf; + kdsafkjadsfjadsfj +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/923/j.in b/codeforces/923/j.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/923/j.out b/codeforces/923/j.out new file mode 100644 index 0000000..c7aa030 --- /dev/null +++ b/codeforces/923/j.out @@ -0,0 +1,8 @@ +j.cc: In function ‘void solve()’: +j.cc:72:3: error: ‘aknf’ was not declared in this scope + 72 | aknf;kdsafkjadsfjadsfj + | ^~~~ +j.cc:72:8: error: ‘kdsafkjadsfjadsfj’ was not declared in this scope + 72 | aknf;kdsafkjadsfjadsfj + | ^~~~~~~~~~~~~~~~~ +zsh:1: permission denied: /tmp/tmp.yMxI36SPlf diff --git a/codeforces/923/k.cc b/codeforces/923/k.cc new file mode 100644 index 0000000..a1f8773 --- /dev/null +++ b/codeforces/923/k.cc @@ -0,0 +1,86 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template void print(T const &t) { std::cout << t; } + +template void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { cout << t << '\n'; } + +void println() { std::cout << '\n'; } + +template T MAX() { return std::numeric_limits::max(); } + +template T MIN() { return std::numeric_limits::min(); } + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { cout << "YES\n"; } +void NO() { cout << "NO\n"; } + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/923/k.in b/codeforces/923/k.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/923/k.out b/codeforces/923/k.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/974/.clang-format b/codeforces/974/.clang-format new file mode 100644 index 0000000..5625628 --- /dev/null +++ b/codeforces/974/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: Empty diff --git a/codeforces/974/a.cc b/codeforces/974/a.cc new file mode 100644 index 0000000..bb4c0b6 --- /dev/null +++ b/codeforces/974/a.cc @@ -0,0 +1,67 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n, k; + cin >> n >> k; + vec people(n); + for (auto &e : people) cin >> e; + int ans = 0, robin = 0; + for (auto amount : people) { + if (amount >= k) + robin += amount; + else if (robin > 0 && amount == 0) { + --robin; + ++ans; + } + } + cout << ans << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/974/a.debug b/codeforces/974/a.debug new file mode 100755 index 0000000..3f565de Binary files /dev/null and b/codeforces/974/a.debug differ diff --git a/codeforces/974/a.in b/codeforces/974/a.in new file mode 100644 index 0000000..d3afac1 --- /dev/null +++ b/codeforces/974/a.in @@ -0,0 +1,9 @@ +4 +2 2 +2 0 +3 2 +3 0 0 +6 2 +0 3 0 0 0 0 +2 5 +5 4 diff --git a/codeforces/974/a.out b/codeforces/974/a.out new file mode 100644 index 0000000..82b6055 --- /dev/null +++ b/codeforces/974/a.out @@ -0,0 +1,4 @@ +1 +2 +3 +0 diff --git a/codeforces/974/b.cc b/codeforces/974/b.cc new file mode 100644 index 0000000..94ade19 --- /dev/null +++ b/codeforces/974/b.cc @@ -0,0 +1,112 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat( + str, + // make_format_args binds arguments to const + str, std::make_format_args(static_cast(args)...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + int n, k; + cin >> n >> k; + + int overlaps = k - 1; + + if (n & 1) { + // need odd # odds in overlaps + int odd_count = floor(overlaps / 2); + + cout << (odd_count & 1 ? "YES" : "NO"); + } else { + int odd_count = ceil(overlaps / 2); + cout << (odd_count & 1 ? "NO" : "YES"); + } + + cout << '\n'; +} + +int main() { + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/974/b.debug b/codeforces/974/b.debug new file mode 100755 index 0000000..09c0356 Binary files /dev/null and b/codeforces/974/b.debug differ diff --git a/codeforces/974/b.in b/codeforces/974/b.in new file mode 100644 index 0000000..8910375 --- /dev/null +++ b/codeforces/974/b.in @@ -0,0 +1,6 @@ +5 +1 1 +2 1 +2 2 +3 2 +4 4 diff --git a/codeforces/974/b.out b/codeforces/974/b.out new file mode 100644 index 0000000..0d0a576 --- /dev/null +++ b/codeforces/974/b.out @@ -0,0 +1,5 @@ +NO +YES +YES +NO +NO diff --git a/codeforces/974/c.cc b/codeforces/974/c.cc new file mode 100644 index 0000000..75799d2 --- /dev/null +++ b/codeforces/974/c.cc @@ -0,0 +1,114 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat( + str, + // make_format_args binds arguments to const + str, std::make_format_args(static_cast(args)...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + ll n; + cin >> n; + vec people(n); + ll total = 0; + for (auto &e : people) { + cin >> e; + total += e; + }; + + sort(all(people)); + + if (n >= 3) { + cout << max(static_cast(0), 1 + people[n / 2] * 2 * n - total); + } else + cout << -1; + cout << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/974/c.in b/codeforces/974/c.in new file mode 100644 index 0000000..b45c2c4 --- /dev/null +++ b/codeforces/974/c.in @@ -0,0 +1,13 @@ +6 +1 +2 +2 +2 19 +3 +1 3 20 +4 +1 2 3 4 +5 +1 2 3 4 5 +6 +1 2 1 1 1 25 diff --git a/codeforces/974/c.out b/codeforces/974/c.out new file mode 100644 index 0000000..4d752d6 --- /dev/null +++ b/codeforces/974/c.out @@ -0,0 +1,6 @@ +-1 +-1 +0 +15 +16 +0 diff --git a/codeforces/974/compile_flags.txt b/codeforces/974/compile_flags.txt new file mode 100644 index 0000000..ebd5be8 --- /dev/null +++ b/codeforces/974/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wshadow +-DLOCAL diff --git a/codeforces/974/d.cc b/codeforces/974/d.cc new file mode 100644 index 0000000..801dd0d --- /dev/null +++ b/codeforces/974/d.cc @@ -0,0 +1,130 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat( + str, + // make_format_args binds arguments to const + str, std::make_format_args(static_cast(args)...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +void solve() { + int n, d, k; + cin >> n >> d >> k; + vec start(n + 1); + vec end(n + 1); + while (k--) { + int l, r; + cin >> l >> r; + ++start[l]; + ++end[r]; + } + + // prefix + FOR(i, 1, n + 1) { + start[i] += start[i - 1]; + end[i] += end[i - 1]; + } + + int brother = MIN(), mother = MAX(); + int brother_day = 0, mother_day = 0; + FOR(i, 0, n - d + 1) { + if (start[i + d] - end[i] > brother) { + brother = start[i + d] - end[i]; + brother_day = i; + } + if (start[i + d] - end[i] < mother) { + mother = start[i + d] - end[i]; + mother_day = i; + } + } + cout << (brother_day + 1) << ' ' << (mother_day + 1) << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/974/d.in b/codeforces/974/d.in new file mode 100644 index 0000000..f8717c0 --- /dev/null +++ b/codeforces/974/d.in @@ -0,0 +1,20 @@ +6 +2 1 1 +1 2 +4 1 2 +1 2 +2 4 +7 2 3 +1 2 +1 3 +6 7 +5 1 2 +1 2 +3 5 +9 2 1 +2 8 +9 2 4 +7 9 +4 8 +1 3 +2 3 diff --git a/codeforces/974/d.out b/codeforces/974/d.out new file mode 100644 index 0000000..4e830a2 --- /dev/null +++ b/codeforces/974/d.out @@ -0,0 +1,6 @@ +1 1 +2 1 +1 4 +1 1 +1 1 +3 4 diff --git a/codeforces/974/h.cc b/codeforces/974/h.cc new file mode 100644 index 0000000..070106a --- /dev/null +++ b/codeforces/974/h.cc @@ -0,0 +1,229 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat( + str, + // make_format_args binds arguments to const + str, std::make_format_args(static_cast(args)...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +static constexpr int MOD = 1e9 + 7; + +#include +#include + +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template +struct custom_hash {}; + +template +inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) hash_combine(value, x); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +std::random_device rd; +std::mt19937 gen(rd()); +std::uniform_int_distribution<> distrib(0, MAX()); + +void solve() { + int n, q; + cin >> n >> q; + + vector prefix_hash_xor(n); + // map index in a -> hash + hashmap hm; + + FOR(i, 0, n) { + cin >> prefix_hash_xor[i]; + prefix_hash_xor[i] ^= (i ? prefix_hash_xor[i - 1] : 0); + } + + while (q--) { + int l, r; + cin >> l >> r; + + --l; + --r; + + bool even_each = + (prefix_hash_xor[r] ^ (l ? prefix_hash_xor[l - 1] : 0)) == 0; + + cout << (even_each ? "YES" : "NO") << '\n'; + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/974/h.in b/codeforces/974/h.in new file mode 100644 index 0000000..5742f58 --- /dev/null +++ b/codeforces/974/h.in @@ -0,0 +1,11 @@ +2 +3 3 +1 2 2 +1 2 +1 3 +2 3 +5 3 +2 1 2 1 1 +1 2 +1 3 +4 5 diff --git a/codeforces/974/h.out b/codeforces/974/h.out new file mode 100644 index 0000000..187ad8a --- /dev/null +++ b/codeforces/974/h.out @@ -0,0 +1,6 @@ +NO +NO +YES +NO +NO +YES diff --git a/codeforces/984/a.cc b/codeforces/984/a.cc new file mode 100644 index 0000000..ccacab5 --- /dev/null +++ b/codeforces/984/a.cc @@ -0,0 +1,45 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(x) for (int i = 0; i < (x).size(); ++i) + +#ifdef LOCAL +#define dbg(x) cerr << #x << " = " << (x) << '\n' +#else +#define dbg(x) +#endif + +void solve() { + int n; + cin >> n; + vector notes(n, 0); + for (auto &x : notes) + cin >> x; + + for (int i = 1; i < notes.size(); ++i) { + auto diff = abs(notes[i] - notes[i - 1]); + + if (!(diff == 5 || diff == 7)) { + cout << "NO\n"; + return; + } + } + + cout << "YES\n"; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/984/a.in b/codeforces/984/a.in new file mode 100644 index 0000000..b1e6ff9 --- /dev/null +++ b/codeforces/984/a.in @@ -0,0 +1,17 @@ +8 +2 +114 109 +2 +17 10 +3 +76 83 88 +8 +38 45 38 80 85 92 99 106 +5 +63 58 65 58 65 +8 +117 124 48 53 48 43 54 49 +5 +95 102 107 114 121 +10 +72 77 82 75 70 75 68 75 68 75 diff --git a/codeforces/984/b.cc b/codeforces/984/b.cc new file mode 100644 index 0000000..c6987e3 --- /dev/null +++ b/codeforces/984/b.cc @@ -0,0 +1,54 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(x) for (int i = 0; i < (x).size(); ++i) + +#ifdef LOCAL +#define dbg(x) cerr << #x << " = " << (x) << '\n' +#else +#define dbg(x) +#endif + +#define MAX_K 2 * 100000 + +// clearing/resetting vector +// clean way for x^n; exppow +// sorting in orders +// totally misread: test case time * +// how does time work???? per-test case... or + +void solve() { + int n, k; + cin >> n >> k; + + vector brand_to_cost(k + 1, 0); + + for (int i = 0; i < k; ++i) { + int b, c; + cin >> b >> c; + brand_to_cost[b] += c; + } + + sort(all(brand_to_cost), std::greater{}); + + std::cout << accumulate(brand_to_cost.begin(), + brand_to_cost.begin() + min(n, sz(brand_to_cost)), + 0LL) + << '\n'; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/984/b.in b/codeforces/984/b.in new file mode 100644 index 0000000..f235cf6 --- /dev/null +++ b/codeforces/984/b.in @@ -0,0 +1,14 @@ +4 +3 3 +2 6 +2 7 +1 15 +1 3 +2 6 +2 7 +1 15 +6 2 +1 7 +2 5 +190000 1 +1 1000 diff --git a/codeforces/984/b.out b/codeforces/984/b.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/984/c.cc b/codeforces/984/c.cc new file mode 100644 index 0000000..d3343d0 --- /dev/null +++ b/codeforces/984/c.cc @@ -0,0 +1,76 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(x) for (int i = 0; i < (x).size(); ++i) + +// variable iterator macro needed +// NOTE: can prob optimize by sorting queries +// fix matchparen highlight +// NOTE: didn't realize queries are independent (bruh) + +void solve() { + string s; + cin >> s; + + auto valid = [&](int i) -> bool { + return i >= 0 && i < sz(s) - 3 && s[i] == '1' && s[i + 1] == '1' && + s[i + 2] == '0' && s[i + 3] == '0'; + }; + + int count = 0; + + for (int i = 0; i < sz(s); ++i) { + if (valid(i)) { + ++count; + } + } + + int q; + cin >> q; + + for (int _ = 0; _ < q; _++) { + int i; + char v; + cin >> i >> v; + --i; + + if (s[i] != v) { + bool left = false; + for (int j = i - 3; j <= i; ++j) { + if (valid(j)) { + left = true; + break; + } + } + + s[i] = v; + + bool right = false; + for (int j = i - 3; j <= i; ++j) { + if (valid(j)) { + right = true; + break; + } + } + + count += (right - left); + } + cout << (count > 0 ? "YES" : "NO") << '\n'; + } +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/984/c.in b/codeforces/984/c.in new file mode 100644 index 0000000..eea2dea --- /dev/null +++ b/codeforces/984/c.in @@ -0,0 +1,24 @@ +4 +100 +4 +1 1 +2 0 +2 0 +3 1 +1100000 +3 +6 1 +7 1 +4 1 +111010 +4 +1 1 +5 0 +4 1 +5 0 +0100 +4 +3 1 +1 1 +2 0 +2 1 diff --git a/codeforces/984/c.out b/codeforces/984/c.out new file mode 100644 index 0000000..202b0b7 --- /dev/null +++ b/codeforces/984/c.out @@ -0,0 +1,15 @@ +NO +NO +NO +NO +YES +YES +NO +NO +YES +YES +YES +NO +NO +NO +NO diff --git a/codeforces/984/d.cc b/codeforces/984/d.cc new file mode 100644 index 0000000..8cc00b2 --- /dev/null +++ b/codeforces/984/d.cc @@ -0,0 +1,93 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(x) for (int i = 0; i < (x).size(); ++i) + +#ifdef LOCAL +#define dbg(x) cerr << #x << " = " << (x) << '\n' +#else +#define dbg(x) +#endif + +constexpr auto _1543 = "1543"; + +int find_1543(const string &layer) { + if (sz(layer) < 4) { + return 0; + } + string extended = layer + layer.substr(0, 3); + + int count = 0; + for (int i = 0; i < sz(layer); ++i) { + bool found = true; + for (int j = 0; j < 4; j++) { + if (extended[i + j] != _1543[j]) { + found = false; + break; + } + } + + count += found; + } + return count; +} + +string layer(const vector &carpet, int n, int m, int i) { + int top = i, bot = n - 1 - i, l = i, r = m - 1 - i; + + string pattern; + for (int c = l; c <= r; c++) { + pattern.push_back(carpet[top][c]); + } + for (int row = top + 1; row < bot; row++) { + pattern.push_back(carpet[row][r]); + } + if (bot > top) { + for (int c = r; c >= l; c--) { + pattern.push_back(carpet[bot][c]); + } + } + if (l < r) { + for (int r = bot - 1; r > top; r--) { + pattern.push_back(carpet[r][l]); + } + } + + return pattern; +} + +void solve() { + int n, m; + cin >> n >> m; + + vector carpet(n); + for (auto &x : carpet) { + cin >> x; + } + + long long ans = 0; + const int LAYER_COUNT = min(n, m) / 2; + + for (int i = 0; i < LAYER_COUNT; ++i) { + string ring = layer(carpet, n, m, i); + ans += find_1543(ring); + } + + cout << ans << '\n'; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/984/d.in b/codeforces/984/d.in new file mode 100644 index 0000000..5e89c0b --- /dev/null +++ b/codeforces/984/d.in @@ -0,0 +1,31 @@ +8 +2 4 +1543 +7777 +2 4 +7154 +8903 +2 4 +3451 +8888 +2 2 +54 +13 +2 2 +51 +43 +2 6 +432015 +512034 +4 4 +5431 +1435 +5518 +7634 +6 4 +5432 +1152 +4542 +2432 +2302 +5942 diff --git a/codeforces/984/d.out b/codeforces/984/d.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/984/e.cc b/codeforces/984/e.cc new file mode 100644 index 0000000..230c4f3 --- /dev/null +++ b/codeforces/984/e.cc @@ -0,0 +1,64 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(x) for (int i = 0; i < (x).size(); ++i) + +void solve() { + int n, k, q; + cin >> n >> k >> q; + + vector> b(k + 1, vector(n + 1, 0)); + + int v; + for (int i = 1; i <= n; ++i) { + for (int j = 1; j <= k; ++j) { + cin >> v; + b[j][i] = b[j][i - 1] | v; + } + } + + while (q--) { + int m; + cin >> m; + + int l = 0, r = n - 1; + + while (m--) { + int R, v; + char c; + cin >> R; + cin >> c; + cin >> v; + + if (c == '<') { + int i = distance(b[R].begin() + 1, lower_bound(all(b[R]), v)) - 1; + r = min(r, i); + } else { + int i = distance(b[R].begin() + 1, upper_bound(all(b[R]), v)); + l = max(l, i); + } + } + + if (l <= r) { + cout << l + 1 << '\n'; + } else { + cout << -1 << '\n'; + } + } +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + // int t; + // cin >> t; + + // while (t--) { + solve(); + // } + + return 0; +} diff --git a/codeforces/984/e.in b/codeforces/984/e.in new file mode 100644 index 0000000..a83311b --- /dev/null +++ b/codeforces/984/e.in @@ -0,0 +1,16 @@ +3 4 4 +1 3 5 9 +4 6 5 3 +2 1 2 7 +3 +1 > 4 +2 < 8 +1 < 6 +2 +1 < 8 +2 > 8 +1 +3 > 5 +2 +4 > 8 +1 < 8 diff --git a/codeforces/984/e.out b/codeforces/984/e.out new file mode 100644 index 0000000..512d5c5 --- /dev/null +++ b/codeforces/984/e.out @@ -0,0 +1,4 @@ +2 +-1 +3 +1 diff --git a/codeforces/991/.null-ls_940867_d.cc b/codeforces/991/.null-ls_940867_d.cc new file mode 100644 index 0000000..058dea0 --- /dev/null +++ b/codeforces/991/.null-ls_940867_d.cc @@ -0,0 +1,188 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +template void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + std::make_format_args(std::forward(args)...)); +} + +template void print(T const &t) { std::cout << t; } + +template void print(T const &t) { + if constexpr (std::is_same_v || + std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { cout << t << '\n'; } + +void println() { std::cout << '\n'; } + +template T MAX() { return std::numeric_limits::max(); } + +template T MIN() { return std::numeric_limits::min(); } + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +constexpr static int MOD = 1e9 + 7; + +void solve() { + string s; + cin >> s; + + for (int i = 1; i < s.size(); ++i) { + if (s[i] == '0') + continue; + + int j = i; + while (j >= 1 && s[j] - 1 > s[j - 1]) { + --s[j]; + swap(s[j], s[-1]); + --j; + } + } + + println(s); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/991/buf b/codeforces/991/buf new file mode 100644 index 0000000..4fd015e --- /dev/null +++ b/codeforces/991/buf @@ -0,0 +1,29 @@ +void solve() { + stGCD.clear(); + int n, q; cin >> n >> q; + vector a(n); + for (int &x : a) cin >> x; + + vector b; + for (int i = 1; i < n; i++) + b.push_back(abs(a[i - 1] - a[i])); + + stGCD.resize(LOGN, vector(b.size(), 1)); + for (int i = 0; i < b.size(); i++) + stGCD[0][i] = b[i]; + for (int i = 1; i < LOGN; i++) + for (int j = 0; j + (1 << (i - 1)) < b.size(); j++) + stGCD[i][j] = __gcd(stGCD[i - 1][j], stGCD[i - 1][j + (1 << (i - 1))]); + + while (q--) { + int l, r; cin >> l >> r; + if (l == r) { + cout << 0 << " "; + continue; + } + l--; r -= 2; + int gcd = get_gcd(l, r); + cout << gcd << " "; + } +} + diff --git a/codeforces/991/compile_flags.txt b/codeforces/991/compile_flags.txt new file mode 100644 index 0000000..e23b2ae --- /dev/null +++ b/codeforces/991/compile_flags.txt @@ -0,0 +1 @@ +-std=c++20 diff --git a/codeforces/991/d.cc b/codeforces/991/d.cc new file mode 100644 index 0000000..bb2a3bd --- /dev/null +++ b/codeforces/991/d.cc @@ -0,0 +1,188 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +template void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + std::make_format_args(std::forward(args)...)); +} + +template void print(T const &t) { std::cout << t; } + +template void print(T const &t) { + if constexpr (std::is_same_v || + std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { cout << t << '\n'; } + +void println() { std::cout << '\n'; } + +template T MAX() { return std::numeric_limits::max(); } + +template T MIN() { return std::numeric_limits::min(); } + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +constexpr static int MOD = 1e9 + 7; + +void solve() { + string s; + cin >> s; + + for (int i = 1; i < s.size(); ++i) { + if (s[i] == '0') + continue; + + int j = i; + while (j >= 1 && s[j] - 1 > s[j - 1]) { + --s[j]; + swap(s[j], s[j - 1]); + --j; + } + } + + println(s); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/991/d.in b/codeforces/991/d.in new file mode 100644 index 0000000..44707b6 --- /dev/null +++ b/codeforces/991/d.in @@ -0,0 +1,7 @@ +6 +19 +1709 +11555 +51476 +9876543210 +5891917899 diff --git a/codeforces/991/d.out b/codeforces/991/d.out new file mode 100644 index 0000000..6f17443 --- /dev/null +++ b/codeforces/991/d.out @@ -0,0 +1,6 @@ +81 +6710 +33311 +55431 +9876543210 +7875567711 diff --git a/codeforces/991/e.cc b/codeforces/991/e.cc new file mode 100644 index 0000000..43a44b6 --- /dev/null +++ b/codeforces/991/e.cc @@ -0,0 +1,50 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(i, x) for (int i = 0; i < (x).size(); ++i) + +#ifdef LOCAL +#define dbg(x) cerr << #x << " = " << (x) << '\n' +#else +#define dbg(x) +#endif + +void solve() { + string a, b, c; + cin >> a >> b >> c; + + if (a.size() < b.size()) { + swap(a, b); + } + + vector dp(b.size() + 1, 0); + + for (int j = 1; j <= b.size(); ++j) { + dp[j] = dp[j - 1] + (b[j - 1] != c[j - 1]); + } + + for (int i = 1; i <= a.size(); ++i) { + dp[0] += (a[i - 1] != c[i - 1]); + for (int j = 1; j <= b.size(); ++j) { + int k = i + j - 1; + dp[j] = min(dp[j] + (a[i - 1] != c[k]), dp[j - 1] + (b[j - 1] != c[k])); + } + } + + cout << dp[b.size()] << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/991/e.in b/codeforces/991/e.in new file mode 100644 index 0000000..a785c94 --- /dev/null +++ b/codeforces/991/e.in @@ -0,0 +1,22 @@ +7 +a +b +cb +ab +cd +acbd +ab +ba +aabb +xxx +yyy +xyxyxy +a +bcd +decf +codes +horse +codeforces +egg +annie +egaegaeg diff --git a/codeforces/991/e.out b/codeforces/991/e.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/991/f.cc b/codeforces/991/f.cc new file mode 100644 index 0000000..2040e28 --- /dev/null +++ b/codeforces/991/f.cc @@ -0,0 +1,219 @@ +#include +#include +#include + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template struct custom_hash {}; + +template inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +template void print(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + std::make_format_args(std::forward(args)...)); +} + +template void print(T const &t) { std::cout << t; } + +template void print(T const &t) { + if constexpr (std::is_same_v || + std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template void println(T const &t) { print("{}\n", t); } + +template void println(T const &t) { cout << t << '\n'; } + +void println() { std::cout << '\n'; } + +template T MAX() { return std::numeric_limits::max(); } + +template T MIN() { return std::numeric_limits::min(); } + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +constexpr static int MOD = 1e9 + 7; + +template struct sparse_table { + sparse_table(std::vector const &ts, F const &f) + : f(f), st(floor(__lg(max(1, static_cast(ts.size())))) + 1, + std::vector>(ts.size())) { + for (size_t i = 0; i < ts.size(); ++i) { + st[0][i] = ts[i]; + } + + for (size_t j = 1; j < st.size(); ++j) { + for (size_t i = 0; i + (1 << (j - 1)) < ts.size(); ++i) { + st[j][i] = f(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]); + } + } + } + + [[nodiscard]] T query(int const l, int const r) const noexcept { + int k = floor(__lg(r - l + 1)); + return f(st[k][l], st[k][r - (1 << k) + 1]); + } + + F f; + std::vector>> st; +}; + +void solve() { + int n, q; + cin >> n >> q; + vector a(n); + for (auto &e : a) + cin >> e; + vector diffs(a.size() - 1, 0); + for (int i = 0; i < diffs.size(); i++) + diffs[i] = abs(a[i] - a[i + 1]); + auto gcd = [](int a, int b) { return __gcd(a, b); }; + sparse_table st(diffs, gcd); + + while (q--) { + int l, r; + cin >> l >> r; + if (l == r) { + cout << 0 << ' '; + } else { + --l; + r -= 2; + cout << st.query(l, r) << ' '; + } + } + cout << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/991/f.in b/codeforces/991/f.in new file mode 100644 index 0000000..36db677 --- /dev/null +++ b/codeforces/991/f.in @@ -0,0 +1,18 @@ +4 +1 1 +1 +1 1 +5 5 +5 14 2 6 3 +4 5 +1 4 +2 4 +3 5 +1 1 +1 1 +7 +1 1 +3 2 +1 7 8 +2 3 +1 2 diff --git a/codeforces/991/f.out b/codeforces/991/f.out new file mode 100644 index 0000000..1aa6cc5 --- /dev/null +++ b/codeforces/991/f.out @@ -0,0 +1,4 @@ +0 +3 1 4 1 0 +0 +1 6 diff --git a/codeforces/991/g.cc b/codeforces/991/g.cc new file mode 100644 index 0000000..8833614 --- /dev/null +++ b/codeforces/991/g.cc @@ -0,0 +1,82 @@ +#include +using namespace std; + +#define all(x) (x).begin(), (x).end() +#define sz(x) static_cast((x).size()) +#define FOR(i, x) for (int i = 0; i < (x).size(); ++i) + +template T max() { return numeric_limits::max(); } +template T min() { return numeric_limits::min(); } + +#ifdef LOCAL +#define dbg(x) cerr << #x << " = " << (x) << '\n' +#else +#define dbg(x) +#endif + +void solve() { + int n; + cin >> n; + + unordered_map> graph; + + while (--n) { + int u, v; + cin >> u >> v; + + graph[u].push_back(v); + graph[v].push_back(u); + } + + auto ans = min(); + + auto is_leaf = [&graph](int u) { + return (u != 1 && graph[u].size() == 1) || (u == 1) && graph[u].empty(); + }; + + auto dfs = [&](auto &dfs, int u, int parent) -> int { + if (u == parent || is_leaf(u)) { + return 0; + } + + int first = 0, second = 0; + + for (auto v : graph[u]) { + if (v == parent) + continue; + + auto through = dfs(dfs, v, u); + + if (through > first) { + second = through; + swap(first, second); + } else if (through > second) { + second = through; + } + } + + int remove_u_and_one_child = sz(graph[u]) - (u != 1) - (first != 0) + first; + int remove_through_u = + sz(graph[u]) - (u != 1) - (first != 0) - (second != 0) + first + second; + int no_remove_u = 1 + first; + + ans = max(ans, max(remove_through_u, no_remove_u)); + + return remove_u_and_one_child; + }; + + std::cout << max(ans, dfs(dfs, 1, -1)) << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/991/g.in b/codeforces/991/g.in new file mode 100644 index 0000000..c90f099 --- /dev/null +++ b/codeforces/991/g.in @@ -0,0 +1,29 @@ +6 +2 +1 2 +5 +1 2 +2 3 +3 4 +3 5 +4 +1 2 +2 3 +3 4 +5 +2 1 +3 1 +4 1 +5 4 +6 +2 1 +3 1 +4 1 +5 3 +6 3 +6 +2 1 +3 2 +4 2 +5 3 +6 4 diff --git a/codeforces/991/g.out b/codeforces/991/g.out new file mode 100644 index 0000000..0146f5f --- /dev/null +++ b/codeforces/991/g.out @@ -0,0 +1,6 @@ +1 +3 +2 +3 +4 +3 diff --git a/codeforces/991/x.out b/codeforces/991/x.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/993/.clang-format b/codeforces/993/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/993/.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/993/a.cc b/codeforces/993/a.cc new file mode 100644 index 0000000..146b464 --- /dev/null +++ b/codeforces/993/a.cc @@ -0,0 +1,95 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +void solve() { + int n; + cin >> n; + cout << n - 1 << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/a.in b/codeforces/993/a.in new file mode 100644 index 0000000..449693b --- /dev/null +++ b/codeforces/993/a.in @@ -0,0 +1,4 @@ +3 +2 +4 +6 diff --git a/codeforces/993/b.cc b/codeforces/993/b.cc new file mode 100644 index 0000000..26e1f02 --- /dev/null +++ b/codeforces/993/b.cc @@ -0,0 +1,104 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +void solve() { + string s; + cin >> s; + + for (int i = sz(s) - 1; i >= 0; --i) { + if (s[i] == 'w') + cout << 'w'; + else if (s[i] == 'p') + cout << 'q'; + else + cout << 'p'; + } + cout << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/b.in b/codeforces/993/b.in new file mode 100644 index 0000000..f04f0e5 --- /dev/null +++ b/codeforces/993/b.in @@ -0,0 +1,6 @@ +5 +qwq +ppppp +pppwwwqqq +wqpqwpqwwqp +pqpqpqpq diff --git a/codeforces/993/b.out b/codeforces/993/b.out new file mode 100644 index 0000000..8708425 --- /dev/null +++ b/codeforces/993/b.out @@ -0,0 +1,5 @@ +pwp +qqqqq +pppwwwqqq +qpwwpqwpqpw +pqpqpqpq diff --git a/codeforces/993/c.cc b/codeforces/993/c.cc new file mode 100644 index 0000000..0e84e5e --- /dev/null +++ b/codeforces/993/c.cc @@ -0,0 +1,98 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +void solve() { + int m, a, b, c; + cin >> m >> a >> b >> c; + int used = min(a, m) + min(b, m); + int rest = min(2 * m - used, c); + + cout << used + rest << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/c.in b/codeforces/993/c.in new file mode 100644 index 0000000..0b2b5e0 --- /dev/null +++ b/codeforces/993/c.in @@ -0,0 +1,6 @@ +5 +10 5 5 10 +3 6 1 1 +15 14 12 4 +1 1 1 1 +420 6 9 69 diff --git a/codeforces/993/c.out b/codeforces/993/c.out new file mode 100644 index 0000000..cf694eb --- /dev/null +++ b/codeforces/993/c.out @@ -0,0 +1,5 @@ +20 +5 +30 +2 +84 diff --git a/codeforces/993/compile_flags.txt b/codeforces/993/compile_flags.txt new file mode 100644 index 0000000..b5d4b68 --- /dev/null +++ b/codeforces/993/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/993/d.cc b/codeforces/993/d.cc new file mode 100644 index 0000000..9651d7c --- /dev/null +++ b/codeforces/993/d.cc @@ -0,0 +1,121 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} +void solve() { + int n; + cin >> n; + + int maxf = 0; + + vector a(n + 1), ans(n); + FOR(i, 0, n) { + int x; + cin >> x; + if (!a[x]) { + a[x] = 1; + ans[i] = x; + } + } + + queue q; + FOR(i, 1, n + 1) + if (!a[i]) + q.push(i); + FOR(i, 0, n) { + if (!ans[i]) { + ans[i] = q.front(); + q.pop(); + } + } + + FOR(i, 0, n) + cout << ans[i] << ' '; + + cout << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/d.in b/codeforces/993/d.in new file mode 100644 index 0000000..6d3543f --- /dev/null +++ b/codeforces/993/d.in @@ -0,0 +1,9 @@ +4 +2 +1 2 +4 +1 1 1 2 +8 +4 5 5 5 1 1 2 1 +10 +1 1 2 2 1 1 3 3 1 1 diff --git a/codeforces/993/d.out b/codeforces/993/d.out new file mode 100644 index 0000000..d5111d7 --- /dev/null +++ b/codeforces/993/d.out @@ -0,0 +1,4 @@ +1 2 +1 3 4 2 +4 5 3 6 1 7 2 8 +1 4 2 5 6 7 3 8 9 10 diff --git a/codeforces/993/e.cc b/codeforces/993/e.cc new file mode 100644 index 0000000..0f928b7 --- /dev/null +++ b/codeforces/993/e.cc @@ -0,0 +1,125 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +void solve() { + ll k, l1, r1, l2, r2; + cin >> k >> l1 >> r1 >> l2 >> r2; + /* + y = k ^ n * x + + x in [l1, r1]; y in [l2, r2] + + y/x=k^n -> n bounded by r2/l1=k^n<-> n=log_k(r2/l1) + + knowing n, let A=k^n + y=Ax + + left bound = max{l1, ceil(l2/A)} + right bound = min{r1, floor r2/A} + + ans += right - left + */ + + ll max_n = ceill(log((ld)r2 / l1) / log(k)); + ll A = 1; + ll ans = 0; + + FOR(_, 0, max_n + 1) { + ll left = max(l1, (ll)ceill((ld)l2 / A)); + ll right = min(r1, (ll)floorl((ld)r2 / A)); + + if (left <= right) + ans += right - left + 1; + + A *= k; + } + + cout << ans << '\n'; +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/e.in b/codeforces/993/e.in new file mode 100644 index 0000000..0f3558f --- /dev/null +++ b/codeforces/993/e.in @@ -0,0 +1,6 @@ +5 +2 2 6 2 12 +2 1 1000000000 1 1000000000 +3 5 7 15 63 +1000000000 1 5 6 1000000000 +15 17 78 2596 20914861 diff --git a/codeforces/993/e.out b/codeforces/993/e.out new file mode 100644 index 0000000..a833dff --- /dev/null +++ b/codeforces/993/e.out @@ -0,0 +1,5 @@ +12 +1999999987 +6 +1 +197 diff --git a/codeforces/993/e.run b/codeforces/993/e.run new file mode 100755 index 0000000..e89f32d Binary files /dev/null and b/codeforces/993/e.run differ diff --git a/codeforces/993/exe b/codeforces/993/exe new file mode 100755 index 0000000..69b89b4 Binary files /dev/null and b/codeforces/993/exe differ diff --git a/codeforces/993/f.cc b/codeforces/993/f.cc new file mode 100644 index 0000000..3ae6e75 --- /dev/null +++ b/codeforces/993/f.cc @@ -0,0 +1,220 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +#include +#include + +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template +struct custom_hash {}; + +template +inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) + hash_combine(value, x); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply( + [&value](T const &...args) { + (hash_combine(value, args), ...); + }, + a); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +void solve() { + int n, m, q; + cin >> n >> m >> q; + dbgln("{} {} {}", n, m, q); + vec a(n), b(m); + for (auto &e : a) + cin >> e; + for (auto &e : b) + cin >> e; + + ll bprod = accumulate(all(b), 1, multiplies()); + ll total = n * bprod + accumulate(all(a), 0LL); + + hashset hm; + + FOR(i, 0, n) { + FOR(j, 0, m) { + hm.insert(total - n * b[j] - m * a[i] + a[i] * b[j]); + } + } + + while (q--) { + int x; + cin >> x; + if (hm.find(x) != hm.end()) + YES(); + else + NO(); + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} diff --git a/codeforces/993/f.in b/codeforces/993/f.in new file mode 100644 index 0000000..7f40ee1 --- /dev/null +++ b/codeforces/993/f.in @@ -0,0 +1,9 @@ +3 3 6 +-2 3 -3 +-2 2 -1 +-1 +1 +-2 +2 +-3 +3 diff --git a/codeforces/993/g1.cc b/codeforces/993/g1.cc new file mode 100644 index 0000000..5e3c029 --- /dev/null +++ b/codeforces/993/g1.cc @@ -0,0 +1,94 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int (a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int (a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +void solve() { + +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/g1.in b/codeforces/993/g1.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/993/g1.out b/codeforces/993/g1.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/993/h.cc b/codeforces/993/h.cc new file mode 100644 index 0000000..59b83c0 --- /dev/null +++ b/codeforces/993/h.cc @@ -0,0 +1,137 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, + // make_format_args binds arguments to const + std::make_format_args(args...)); +} + +template +void dbg(T const &t) { + std::cout << t; +} + +template +void dbgln(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void dbgln(std::string const &str, Args &&...args) { + dbg(str, std::forward(args)...); + cout << '\n'; +} + +template +void dbgln(T const &t) { + dbg("{}\n", t); +} + +void println() { + std::cout << '\n'; +} + +template +constexpr auto MIN = std::numeric_limits::min(); + +template +constexpr auto MAX = std::numeric_limits::min(); + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +std::random_device rd; +std::mt19937 gen(rd()); + +void YES() { + cout << "YES\n"; +} + +void NO() { + cout << "NO\n"; +} + +void solve() { + int n, q; + cin >> n; + vec> grid(n, vec(n)); + FOR(i, 0, n) { + FOR(j, 0, n) { + cin >> grid[i][j]; + } + } + + vec> dp(n + 1, vec(n + 1, 1)); + + while (q--) { + int x1, x2, y1, y2; + cin >> x1 >> x2 >> y1 >> y2; + } + + /* + + 00 01 02 03 04 05 ... + 10 11 12 13 14 15 ... + + 1 * 00 * 2 * 01 + 3 * 02 + 4 * 01 + 5 * + + 1 * M[i][j] + 2 * M[i][j + 1] + 3 * M[i][j + 2] + + 4 * M[i + 1][j] + 5 * M[i + 1][j + 2] + + = sum r0 * n + c0 -> r1 * n + c1 + + 1 2 + 3 4 + 5 6 + + 1 2 0 0 + 1 2 + 2 2 + 1 2 + 4 4 + + 3+4^2+8^3+9^4+13^5+14^6 + + 8+9^2+13^3+14^4 - ( 8^2+9^2+13^2 ) + */ + // FIX: cout + + dbgln("hi"); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/993/h.in b/codeforces/993/h.in new file mode 100644 index 0000000..f4f17a1 --- /dev/null +++ b/codeforces/993/h.in @@ -0,0 +1,16 @@ +2 +4 3 +1 5 2 4 +4 9 5 3 +4 5 2 3 +1 5 5 2 +1 1 4 4 +2 2 3 3 +1 2 4 3 +3 3 +1 2 3 +4 5 6 +7 8 9 +1 1 1 3 +1 3 3 3 +2 2 2 2 diff --git a/codeforces/993/h.out b/codeforces/993/h.out new file mode 100644 index 0000000..7452ee8 --- /dev/null +++ b/codeforces/993/h.out @@ -0,0 +1,2 @@ +hi +hi diff --git a/codeforces/993/h.run b/codeforces/993/h.run new file mode 100755 index 0000000..7caaba5 Binary files /dev/null and b/codeforces/993/h.run differ diff --git a/leetcode/.clang-format b/leetcode/.clang-format new file mode 100644 index 0000000..5625628 --- /dev/null +++ b/leetcode/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Google +AllowShortFunctionsOnASingleLine: Empty diff --git a/leetcode/a.cc b/leetcode/a.cc new file mode 100644 index 0000000..b1ed3ac --- /dev/null +++ b/leetcode/a.cc @@ -0,0 +1,268 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat( + str, + // make_format_args binds arguments to const + std::make_format_args(static_cast(args)...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +void println(T const &t) { + print(t); + println(); +} + +template +void println(T const &t) { + print(t); + println(); +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +#include +#include + +using namespace __gnu_pbds; + +// https://mirror.codeforces.com/blog/entry/124683 + +namespace hashing { +using i64 = std::int64_t; +using u64 = std::uint64_t; +static const u64 FIXED_RANDOM = + std::chrono::steady_clock::now().time_since_epoch().count(); + +#if USE_AES +std::mt19937 rd(FIXED_RANDOM); +const __m128i KEY1{(i64)rd(), (i64)rd()}; +const __m128i KEY2{(i64)rd(), (i64)rd()}; +#endif + +template +struct custom_hash {}; + +template +inline void hash_combine(u64 &seed, T const &v) { + custom_hash hasher; + seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4); +}; + +template +struct custom_hash::value>::type> { + u64 operator()(T _x) const { + u64 x = _x; +#if USE_AES + __m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM}; + __m128i y = _mm_aesenc_si128(m, KEY1); + __m128i z = _mm_aesenc_si128(y, KEY2); + return z[0]; +#else + x += 0x9e3779b97f4a7c15 + FIXED_RANDOM; + x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; + x = (x ^ (x >> 27)) * 0x94d049bb133111eb; + return x ^ (x >> 31); +#endif + } +}; + +template +struct custom_hash()))>> { + u64 operator()(T const &a) const { + u64 value = FIXED_RANDOM; + for (auto &x : a) hash_combine(value, x); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(const std::tuple &a) const { + u64 value = FIXED_RANDOM; + std::apply([&value](T const &...args) { (hash_combine(value, args), ...); }, + a); + return value; + } +}; + +template +struct custom_hash> { + u64 operator()(std::pair const &a) const { + u64 value = FIXED_RANDOM; + hash_combine(value, a.first); + hash_combine(value, a.second); + return value; + } +}; +}; // namespace hashing + +#ifdef PB_DS_ASSOC_CNTNR_HPP +template +using hashmap = gp_hash_table< + Key, Value, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; +template +using hashset = gp_hash_table< + Key, null_type, hashing::custom_hash, std::equal_to, + direct_mask_range_hashing<>, linear_probe_fn<>, + hash_standard_resize_policy, + hash_load_check_resize_trigger<>, true>>; + +#endif +#ifdef PB_DS_TREE_POLICY_HPP +template +using multiset = tree, rb_tree_tag, + tree_order_statistics_node_update>; +template +using rbtree = tree, rb_tree_tag, + tree_order_statistics_node_update>; +#endif + +const vec> dirs = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; + +constexpr int RIGHT = 1, LEFT = 2, DOWN = 3, UP = 4; + +void solve() { + int m, n; + cin >> m >> n; + + vec> grid(m, vec(n, 0)); + + for (auto &row : grid) { + for (auto &cell : row) { + cin >> cell; + } + } + + deque> q{{0, 0, 0}}; + + hashset> seen; + + while (!q.empty()) { + auto [r, c, w] = q.front(); + q.pop_front(); + + println("at r={}, c={}, w={}", r, c, w); + + if (min(r, c) < 0 || r == m || c == n) continue; + + if (r == m - 1 && c == n - 1) { + println(w); + return; + } + + if (seen.find({r, c}) != seen.end()) continue; + + seen.insert({r, c}); + + switch (grid[r][c]) { + case UP: + q.emplace_front(r - 1, c, w); + break; + case LEFT: + q.emplace_front(r, c - 1, w); + break; + case DOWN: + q.emplace_front(r + 1, c, w); + break; + case RIGHT: + q.emplace_front(r, c + 1, w); + break; + } + + for (auto &[dr, dc] : dirs) { + int nr = r + dr, nc = c + dc; + + q.emplace_back(nr, nc, w + 1); + } + } +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/leetcode/a.in b/leetcode/a.in new file mode 100644 index 0000000..aca90a1 --- /dev/null +++ b/leetcode/a.in @@ -0,0 +1,7 @@ +3 +4 4 +1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 +3 3 +1 1 3 3 2 2 1 1 4 +2 2 +1 2 4 3 diff --git a/leetcode/a.out b/leetcode/a.out new file mode 100644 index 0000000..eb297f5 --- /dev/null +++ b/leetcode/a.out @@ -0,0 +1,81 @@ +at r=0, c=0, w=0 +at r=0, c=1, w=0 +at r=0, c=2, w=0 +at r=0, c=3, w=0 +at r=0, c=4, w=0 +at r=-1, c=1, w=1 +at r=0, c=0, w=1 +at r=1, c=1, w=1 +at r=1, c=0, w=1 +at r=1, c=-1, w=1 +at r=0, c=2, w=1 +at r=-1, c=2, w=1 +at r=0, c=1, w=1 +at r=1, c=2, w=1 +at r=1, c=1, w=1 +at r=0, c=3, w=1 +at r=-1, c=3, w=1 +at r=0, c=2, w=1 +at r=1, c=3, w=1 +at r=1, c=2, w=1 +at r=0, c=4, w=1 +at r=-1, c=4, w=1 +at r=0, c=3, w=1 +at r=1, c=4, w=1 +at r=0, c=5, w=1 +at r=0, c=0, w=2 +at r=1, c=-1, w=2 +at r=2, c=0, w=2 +at r=2, c=1, w=2 +at r=2, c=2, w=2 +at r=2, c=3, w=2 +at r=2, c=4, w=2 +at r=1, c=1, w=2 +at r=0, c=-1, w=2 +at r=1, c=-2, w=2 +at r=2, c=-1, w=2 +at r=1, c=0, w=2 +at r=0, c=1, w=2 +at r=1, c=0, w=2 +at r=2, c=1, w=2 +at r=1, c=2, w=2 +at r=0, c=2, w=2 +at r=1, c=1, w=2 +at r=2, c=2, w=2 +at r=1, c=3, w=2 +at r=-1, c=5, w=2 +at r=0, c=4, w=2 +at r=1, c=5, w=2 +at r=0, c=6, w=2 +at r=1, c=1, w=3 +at r=2, c=0, w=3 +at r=3, c=1, w=3 +at r=3, c=0, w=3 +at r=3, c=-1, w=3 +at r=2, c=2, w=3 +at r=1, c=2, w=3 +at r=2, c=1, w=3 +at r=3, c=2, w=3 +at r=3, c=1, w=3 +at r=2, c=3, w=3 +at r=1, c=3, w=3 +at r=2, c=2, w=3 +at r=3, c=3, w=3 +3 +at r=0, c=0, w=0 +at r=0, c=1, w=0 +at r=0, c=2, w=0 +at r=1, c=2, w=0 +at r=1, c=1, w=0 +at r=1, c=0, w=0 +at r=2, c=0, w=0 +at r=2, c=1, w=0 +at r=2, c=2, w=0 +0 +at r=0, c=0, w=0 +at r=0, c=1, w=0 +at r=0, c=0, w=0 +at r=-1, c=1, w=1 +at r=0, c=0, w=1 +at r=1, c=1, w=1 +1 diff --git a/leetcode/b.cc b/leetcode/b.cc new file mode 100644 index 0000000..7aa6310 --- /dev/null +++ b/leetcode/b.cc @@ -0,0 +1,110 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void print(std::string const &str, Args &&...args) { + std::cout << std::vformat( + str, + // make_format_args binds arguments to const + str, std::make_format_args(static_cast(args)...)); +} + +template +void print(T const &t) { + std::cout << t; +} + +template +void print(T const &t) { + if constexpr (std::is_convertible_v) { + std::cout << t << '\n'; + } else { + for (auto const &e : t) { + std::cout << e << ' '; + } + std::cout << '\n'; + } +} + +template +void println(std::string const &str, Args &&...args) { + print(str, std::forward(args)...); + cout << '\n'; +} + +template +void println(T const &t) { + print("{}\n", t); +} + +template +void println(T const &t) { + cout << t << '\n'; +} + +void println() { + std::cout << '\n'; +} + +template +T MAX() { + return std::numeric_limits::max(); +} + +template +T MIN() { + return std::numeric_limits::min(); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector + +#define all(x) (x).begin(), (x).end() +#define rall(x) (r).rbegin(), (x).rend() +#define sz(x) static_cast((x).size()) +#define FOR(a, b, c) for (int a = b; a < c; ++a) + +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); +#define randint(a, b) uniform_int_distribution(a, b)(rng) + +void YES() { + cout << "YES\n"; +} +void NO() { + cout << "NO\n"; +} + +#ifdef LOCAL +#define dbg(x) cout << __LINE__ << ": " << #x << "=<" << (x) << ">\n"; +#else +#define dbg(x) +#endif + +static constexpr int MOD = 1e9 + 7; + +void solve() { + +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/leetcode/b.in b/leetcode/b.in new file mode 100644 index 0000000..e69de29 diff --git a/leetcode/b.out b/leetcode/b.out new file mode 100644 index 0000000..e69de29 diff --git a/leetcode/compile_flags.txt b/leetcode/compile_flags.txt new file mode 100644 index 0000000..ebd5be8 --- /dev/null +++ b/leetcode/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wshadow +-DLOCAL