From ceda5687f26e9aa08feb6ff1c48c51465e9c3f64 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Wed, 5 Feb 2025 19:54:11 -0500 Subject: [PATCH] feat(cf): 952 --- codeforces/952/.clang-format | 9 ++ codeforces/952/.clangd | 8 ++ codeforces/952/a.cc | 99 +++++++++++++++ codeforces/952/a.in | 7 ++ codeforces/952/a.out | 9 ++ codeforces/952/b.cc | 106 ++++++++++++++++ codeforces/952/b.in | 3 + codeforces/952/b.out | 5 + codeforces/952/c.cc | 209 +++++++++++++++++++++++++++++++ codeforces/952/c.in | 15 +++ codeforces/952/c.out | 10 ++ codeforces/952/compile_flags.txt | 5 + codeforces/952/d.cc | 107 ++++++++++++++++ codeforces/952/d.in | 30 +++++ codeforces/952/d.out | 9 ++ codeforces/952/e.cc | 111 ++++++++++++++++ codeforces/952/e.in | 8 ++ codeforces/952/e.out | 10 ++ codeforces/952/f.cc | 120 ++++++++++++++++++ codeforces/952/f.in | 25 ++++ codeforces/952/f.out | 11 ++ codeforces/952/g.cc | 107 ++++++++++++++++ codeforces/952/g.in | 7 ++ codeforces/952/g.out | 9 ++ codeforces/952/h.cc | 208 ++++++++++++++++++++++++++++++ codeforces/952/h.in | 33 +++++ codeforces/952/h.out | 9 ++ codeforces/964/.clangd | 8 ++ codeforces/964/a.out | 8 -- codeforces/964/e.out | 9 +- 30 files changed, 1302 insertions(+), 12 deletions(-) create mode 100644 codeforces/952/.clang-format create mode 100644 codeforces/952/.clangd create mode 100644 codeforces/952/a.cc create mode 100644 codeforces/952/a.in create mode 100644 codeforces/952/a.out create mode 100644 codeforces/952/b.cc create mode 100644 codeforces/952/b.in create mode 100644 codeforces/952/b.out create mode 100644 codeforces/952/c.cc create mode 100644 codeforces/952/c.in create mode 100644 codeforces/952/c.out create mode 100644 codeforces/952/compile_flags.txt create mode 100644 codeforces/952/d.cc create mode 100644 codeforces/952/d.in create mode 100644 codeforces/952/d.out create mode 100644 codeforces/952/e.cc create mode 100644 codeforces/952/e.in create mode 100644 codeforces/952/e.out create mode 100644 codeforces/952/f.cc create mode 100644 codeforces/952/f.in create mode 100644 codeforces/952/f.out create mode 100644 codeforces/952/g.cc create mode 100644 codeforces/952/g.in create mode 100644 codeforces/952/g.out create mode 100644 codeforces/952/h.cc create mode 100644 codeforces/952/h.in create mode 100644 codeforces/952/h.out create mode 100644 codeforces/964/.clangd delete mode 100644 codeforces/964/a.out diff --git a/codeforces/952/.clang-format b/codeforces/952/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/952/.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/952/.clangd b/codeforces/952/.clangd new file mode 100644 index 0000000..61f8494 --- /dev/null +++ b/codeforces/952/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++20 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/952/a.cc b/codeforces/952/a.cc new file mode 100644 index 0000000..03cd088 --- /dev/null +++ b/codeforces/952/a.cc @@ -0,0 +1,99 @@ +#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, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +void solve() { + string a, b; + cin >> a >> b; + dbg(b[0]); + FOR(i, 1, sz(a)) { + dbg(a[i]); + } + dbg(' '); + dbg(a[0]); + FOR(i, 1, sz(b)) { + dbg(b[i]); + } + dbgln(); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/a.in b/codeforces/952/a.in new file mode 100644 index 0000000..5840479 --- /dev/null +++ b/codeforces/952/a.in @@ -0,0 +1,7 @@ +6 +bit set +cat dog +hot dog +uwu owo +cat cat +zzz zzz diff --git a/codeforces/952/a.out b/codeforces/952/a.out new file mode 100644 index 0000000..55910fd --- /dev/null +++ b/codeforces/952/a.out @@ -0,0 +1,9 @@ +sit bet +dat cog +dot hog +owu uwo +cat cat +zzz zzz + +[code]: 0 +[time]: 4.55022 ms \ No newline at end of file diff --git a/codeforces/952/b.cc b/codeforces/952/b.cc new file mode 100644 index 0000000..078d7b0 --- /dev/null +++ b/codeforces/952/b.cc @@ -0,0 +1,106 @@ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +void dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +void solve() { + int n; + cin >> n; + + int ans = 0, big = 0; + + FOR(x, 2, n + 1) { + int total = 0; + int k = 1; + while (k * x <= n) { + total += k * x; + ++k; + } + if (total > big) { + big = total; + ans = x; + } + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/b.in b/codeforces/952/b.in new file mode 100644 index 0000000..1889041 --- /dev/null +++ b/codeforces/952/b.in @@ -0,0 +1,3 @@ +2 +3 +15 diff --git a/codeforces/952/b.out b/codeforces/952/b.out new file mode 100644 index 0000000..36d93cc --- /dev/null +++ b/codeforces/952/b.out @@ -0,0 +1,5 @@ +3 +2 + +[code]: 0 +[time]: 4.70328 ms \ No newline at end of file diff --git a/codeforces/952/c.cc b/codeforces/952/c.cc new file mode 100644 index 0000000..9f05a0b --- /dev/null +++ b/codeforces/952/c.cc @@ -0,0 +1,209 @@ +#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, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +#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; + + ll ans = 0; + + ll prefix = 0; + hashset seen; + + FOR(i, 0, n) { + ll x; + cin >> x; + prefix += x; + seen.insert(x); + ans += (prefix % 2 == 0) && seen.find(prefix / 2) != seen.end(); + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/c.in b/codeforces/952/c.in new file mode 100644 index 0000000..9f1652f --- /dev/null +++ b/codeforces/952/c.in @@ -0,0 +1,15 @@ +7 +1 +0 +1 +1 +4 +1 1 2 0 +5 +0 1 2 1 4 +7 +1 1 0 3 5 2 12 +7 +1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 294967296 +10 +0 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 589934592 diff --git a/codeforces/952/c.out b/codeforces/952/c.out new file mode 100644 index 0000000..09a3f67 --- /dev/null +++ b/codeforces/952/c.out @@ -0,0 +1,10 @@ +1 +0 +3 +3 +4 +1 +2 + +[code]: 0 +[time]: 4.12488 ms \ No newline at end of file diff --git a/codeforces/952/compile_flags.txt b/codeforces/952/compile_flags.txt new file mode 100644 index 0000000..b5d4b68 --- /dev/null +++ b/codeforces/952/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++20 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/952/d.cc b/codeforces/952/d.cc new file mode 100644 index 0000000..7752a2a --- /dev/null +++ b/codeforces/952/d.cc @@ -0,0 +1,107 @@ +#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, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +void solve() { + int n, m; + cin >> n >> m; + int bot = -1, top; + int left = -1, right; + FOR(r, 0, n) { + string s; + cin >> s; + FOR(c, 0, m) { + if (s[c] == '#') { + if (bot == -1) + bot = r; + top = r; + if (left == -1) + left = c; + right = c; + } + } + } + + dbgln("{} {}", bot + (top - bot) / 2 + 1, left + (right - left) / 2 + 1); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/d.in b/codeforces/952/d.in new file mode 100644 index 0000000..7aea098 --- /dev/null +++ b/codeforces/952/d.in @@ -0,0 +1,30 @@ +6 +5 5 +..... +..... +..#.. +..... +..... +5 5 +..#.. +.###. +##### +.###. +..#.. +5 6 +...... +...... +.#.... +###... +.#.... +1 1 +# +5 6 +...#.. +..###. +.##### +..###. +...#.. +2 10 +.......... +...#...... diff --git a/codeforces/952/d.out b/codeforces/952/d.out new file mode 100644 index 0000000..435fb5e --- /dev/null +++ b/codeforces/952/d.out @@ -0,0 +1,9 @@ +3 3 +3 3 +4 2 +1 1 +3 4 +2 4 + +[code]: 0 +[time]: 4.17209 ms \ No newline at end of file diff --git a/codeforces/952/e.cc b/codeforces/952/e.cc new file mode 100644 index 0000000..0a5c879 --- /dev/null +++ b/codeforces/952/e.cc @@ -0,0 +1,111 @@ +#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, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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 (ll(a) = (b); (a) < (c); ++(a)) +#define ROF(a, b, c) for (int(a) = (b); (a) > (c); --(a)) + +void solve() { + ll x, y, z, k; + cin >> x >> y >> z >> k; + /* + vol = k <= x * y * z + + explore all valid box volumes at 0, 0, 0 + + a * b * c = k + a * b = k / c <-> c = k / (a * b) + a=1 -> b * c <= k - bsearch? + */ + + ll ans = 0; + + FOR(a, 1, x + 1) { + FOR(b, 1, y + 1) { + ll total = a * b; + if (k % total == 0 && k / total <= z) { + ans = max(ans, (x - a + 1) * (y - b + 1) * (z - k / total + 1)); + } + } + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/e.in b/codeforces/952/e.in new file mode 100644 index 0000000..836a850 --- /dev/null +++ b/codeforces/952/e.in @@ -0,0 +1,8 @@ +7 +3 3 3 8 +3 3 3 18 +5 1 1 1 +2 2 2 7 +3 4 2 12 +4 3 1 6 +1800 1800 1800 4913000000 diff --git a/codeforces/952/e.out b/codeforces/952/e.out new file mode 100644 index 0000000..72aede5 --- /dev/null +++ b/codeforces/952/e.out @@ -0,0 +1,10 @@ +8 +2 +5 +0 +4 +4 +1030301 + +[code]: 0 +[time]: 10.1058 ms \ No newline at end of file diff --git a/codeforces/952/f.cc b/codeforces/952/f.cc new file mode 100644 index 0000000..a4d65cc --- /dev/null +++ b/codeforces/952/f.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 dbg(std::string const &str, Args &&...args) { + std::cout << std::vformat(str, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +void solve() { + ll h, n; + cin >> h >> n; + + vec> a(n); + + ll agg = 0; + ll maxcooldown = MIN; + + FOR(i, 0, n) { + cin >> a[i].ss; + } + FOR(i, 0, n) { + cin >> a[i].ff; + agg += a[i].ss; + maxcooldown = max(maxcooldown, a[i].ff); + } + + ll l = 0, r = maxcooldown * (ld)h / agg; + + while (l <= r) { + ll t = l + (r - l) / 2; + ll total = 0; + for (auto [C, A] : a) { + total += A * (1 + t / C); + } + if (total >= h) { + r = t - 1; + } else { + l = t + 1; + } + } + + dbgln(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/952/f.in b/codeforces/952/f.in new file mode 100644 index 0000000..eb430d8 --- /dev/null +++ b/codeforces/952/f.in @@ -0,0 +1,25 @@ +8 +3 2 +2 1 +2 1 +5 2 +2 1 +2 1 +50 3 +5 6 7 +5 6 7 +50 3 +2 2 2 +3 3 3 +90000 2 +200000 200000 +1 1 +100000 1 +1 +200000 +6 7 +3 2 3 2 3 1 2 +6 5 9 5 10 7 7 +21 6 +1 1 1 1 1 1 +5 5 8 10 7 6 diff --git a/codeforces/952/f.out b/codeforces/952/f.out new file mode 100644 index 0000000..31bf947 --- /dev/null +++ b/codeforces/952/f.out @@ -0,0 +1,11 @@ +1 +3 +15 +25 +1 +19999800001 +1 +21 + +[code]: 0 +[time]: 4.58527 ms \ No newline at end of file diff --git a/codeforces/952/g.cc b/codeforces/952/g.cc new file mode 100644 index 0000000..0e40ab3 --- /dev/null +++ b/codeforces/952/g.cc @@ -0,0 +1,107 @@ +#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, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +constexpr int MOD = 1000000007; + +long long power(long long a, long long b) { + long long ans = 1; + while (b > 0) { + if (b & 1) + ans = (ans % MOD * a % MOD) % MOD; + a = (a % MOD * a % MOD) % MOD; + b >>= 1; + } + return ans; +} + +void solve() { + // D(n) = sum digits of n + // D(k*n) = k*D(n) + + ll l, r, k; + cin >> l >> r >> k; + + dbgln((power(1 + 9 / k, r) - power(1 + 9 / k, l) + MOD) % MOD); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/g.in b/codeforces/952/g.in new file mode 100644 index 0000000..c2126ba --- /dev/null +++ b/codeforces/952/g.in @@ -0,0 +1,7 @@ +6 +0 1 4 +0 2 7 +1 2 1 +1 2 3 +582 74663 3 +0 3 1 diff --git a/codeforces/952/g.out b/codeforces/952/g.out new file mode 100644 index 0000000..83d6eef --- /dev/null +++ b/codeforces/952/g.out @@ -0,0 +1,9 @@ +2 +3 +90 +12 +974995667 +999 + +[code]: 0 +[time]: 12.0807 ms \ No newline at end of file diff --git a/codeforces/952/h.cc b/codeforces/952/h.cc new file mode 100644 index 0000000..c314fa8 --- /dev/null +++ b/codeforces/952/h.cc @@ -0,0 +1,208 @@ +#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, 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'; + } +} + +void dbgln() { + 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(t); + cout << '\n'; +} + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::min(); + +template +static T sc(auto &&x) { + return static_cast(x); +} + +#define ff first +#define ss second +#define eb emplace_back +#define ll long long +#define ld long double +#define vec vector +#define endl '\n' + +#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)) + +struct union_find { + public: + union_find(size_t n) : par(n + 1), rank(n + 1, 0), size(n + 1, 0) { + std::iota(par.begin(), par.end(), 0); + }; + + void join(int u, int v) { + u = find(u), v = find(v); + + if (size[u] == 0) + size[u] = 1; + if (size[v] == 0) + size[v] = 1; + + if (u == v) + return; + + if (rank[u] < rank[v]) + std::swap(u, v); + + if (rank[u] == rank[v]) { + ++rank[u]; + } + size[u] += size[v]; + + par[v] = u; + } + + int find(int u) { + if (u != par[u]) + par[u] = find(par[u]); + return par[u]; + } + + size_t capacity; + std::vector par; + std::vector rank; + std::vector size; +}; + +vector> dirs; + +vec grid; + +void solve() { + int n, m; + cin >> n >> m; + vec seen(n * m + 1, false); + + grid.resize(n); + + union_find uf(m * n); + + auto index = [&m](int r, int c) { + return r * m + c; + }; + + auto valid = [&](int r, int c) { + return min(r, c) >= 0 && r < n && c < m; + }; + + FOR(r, 0, n) { + cin >> grid[r]; + } + + FOR(r, 0, n) { + FOR(c, 0, m) { + if (grid[r][c] == '#') { + uf.join(index(r, c), index(r, c)); + for (auto [dr, dc] : dirs) { + int nr = r + dr, nc = c + dc; + if (valid(nr, nc) && grid[nr][nc] == '#') { + uf.join(index(r, c), index(nr, nc)); + } + } + } + } + } + + ll ans = 0; + + FOR(r, 0, n) { + ll cur = 0; + seen.assign(sz(seen), false); + FOR(c, 0, m) { + cur += grid[r][c] == '.'; + if (grid[r][c] == '.') { + FOR(dr, -1, 2) { + int nr = r + dr; + int i; + if (valid(nr, c) && !seen[i = uf.find(index(nr, c))]) { + cur += uf.size[i]; + seen[i] = true; + } + } + } + ans = max(ans, cur); + } + + FOR(c, 0, m) { + ll cur = 0; + seen.assign(sz(seen), false); + FOR(r, 0, n) { + cur += grid[r][c] == '.'; + FOR(dc, -1, 2) { + int nc = c + dc; + int i; + if (valid(r, nc) && !seen[i = uf.find(index(r, nc))]) { + cur += uf.size[i]; + seen[i] = true; + } + } + } + ans = max(ans, cur); + } + + dbgln(ans); +} + +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + dirs.emplace_back(1, 0); + dirs.emplace_back(-1, 0); + dirs.emplace_back(0, 1); + dirs.emplace_back(0, -1); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} diff --git a/codeforces/952/h.in b/codeforces/952/h.in new file mode 100644 index 0000000..045b780 --- /dev/null +++ b/codeforces/952/h.in @@ -0,0 +1,33 @@ +6 +1 1 +. +4 2 +.. +#. +#. +.# +3 5 +.#.#. +..#.. +.#.#. +5 5 +#...# +....# +#...# +..... +...## +6 6 +.#..#. +#..#.. +.#...# +#.#.#. +.#.##. +###..# +6 8 +..#....# +.####.#. +###.#..# +.##.#.## +.#.##.## +#..##.#. + diff --git a/codeforces/952/h.out b/codeforces/952/h.out new file mode 100644 index 0000000..a181e32 --- /dev/null +++ b/codeforces/952/h.out @@ -0,0 +1,9 @@ +1 +6 +9 +11 +15 +30 + +[code]: 0 +[time]: 3.87812 ms \ No newline at end of file diff --git a/codeforces/964/.clangd b/codeforces/964/.clangd new file mode 100644 index 0000000..61f8494 --- /dev/null +++ b/codeforces/964/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++20 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/964/a.out b/codeforces/964/a.out deleted file mode 100644 index 109c7ca..0000000 --- a/codeforces/964/a.out +++ /dev/null @@ -1,8 +0,0 @@ -14 -3 -4 -7 -10 -12 -1 -18 diff --git a/codeforces/964/e.out b/codeforces/964/e.out index 5c41d91..c2410ac 100644 --- a/codeforces/964/e.out +++ b/codeforces/964/e.out @@ -1,7 +1,8 @@ -5 +6 6 36 -263 -1635429922 +324 +1678476632 -24:10 03/02/25 \ No newline at end of file +[code]: 0 +[time]: 11.8585 ms \ No newline at end of file