From d1b961e1c4adcbabcff896c531c4a6407a6bcee6 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 9 Feb 2025 15:59:43 -0500 Subject: [PATCH] codeforces: 1003 --- codeforces/1003/.clang-format | 9 ++ codeforces/1003/.clangd | 8 ++ codeforces/1003/a.cc | 79 +++++++++++ codeforces/1003/a.in | 10 ++ codeforces/1003/a.out | 12 ++ codeforces/1003/b.cc | 102 +++++++++++++++ codeforces/1003/b.in | 5 + codeforces/1003/b.out | 7 + codeforces/1003/c.cc | 106 +++++++++++++++ codeforces/1003/c.in | 16 +++ codeforces/1003/c.out | 8 ++ codeforces/1003/compile_flags.txt | 5 + codeforces/1003/d.cc | 109 ++++++++++++++++ codeforces/1003/d.in | 11 ++ codeforces/1003/d.out | 6 + codeforces/1003/e.cc | 86 ++++++++++++ codeforces/1003/e.in | 0 codeforces/1003/e.out | 0 codeforces/1003/f.cc | 134 +++++++++++++++++++ codeforces/1003/f.in | 29 +++++ codeforces/1003/f.out | 7 + codeforces/957/.clang-format | 9 ++ codeforces/957/.clangd | 8 ++ codeforces/957/a.cc | 87 +++++++++++++ codeforces/957/a.in | 3 + codeforces/957/a.out | 5 + codeforces/957/b.cc | 93 +++++++++++++ codeforces/957/b.in | 9 ++ codeforces/957/b.out | 7 + codeforces/957/c.cc | 87 +++++++++++++ codeforces/957/c.in | 4 + codeforces/957/c.out | 6 + codeforces/957/compile_flags.txt | 5 + codeforces/957/d.cc | 119 +++++++++++++++++ codeforces/957/d.in | 13 ++ codeforces/957/d.out | 9 ++ codeforces/957/f.cc | 81 ++++++++++++ codeforces/957/f.in | 17 +++ codeforces/957/f.out | 11 ++ codeforces/996/.clang-format | 9 ++ codeforces/996/.clangd | 8 ++ codeforces/996/a.cc | 84 ++++++++++++ codeforces/996/a.in | 8 ++ codeforces/996/a.out | 10 ++ codeforces/996/b.cc | 96 ++++++++++++++ codeforces/996/b.in | 9 ++ codeforces/996/b.out | 11 ++ codeforces/996/c.cc | 210 ++++++++++++++++++++++++++++++ codeforces/996/c.in | 19 +++ codeforces/996/c.out | 12 ++ codeforces/996/compile_flags.txt | 5 + codeforces/996/d.cc | 103 +++++++++++++++ codeforces/996/d.in | 16 +++ codeforces/996/d.out | 8 ++ codeforces/996/e.cc | 145 +++++++++++++++++++++ codeforces/996/e.in | 16 +++ codeforces/996/e.out | 8 ++ codeforces/996/f.cc | 106 +++++++++++++++ codeforces/996/f.in | 27 ++++ codeforces/996/f.out | 3 + 60 files changed, 2235 insertions(+) create mode 100644 codeforces/1003/.clang-format create mode 100644 codeforces/1003/.clangd create mode 100644 codeforces/1003/a.cc create mode 100644 codeforces/1003/a.in create mode 100644 codeforces/1003/a.out create mode 100644 codeforces/1003/b.cc create mode 100644 codeforces/1003/b.in create mode 100644 codeforces/1003/b.out create mode 100644 codeforces/1003/c.cc create mode 100644 codeforces/1003/c.in create mode 100644 codeforces/1003/c.out create mode 100644 codeforces/1003/compile_flags.txt create mode 100644 codeforces/1003/d.cc create mode 100644 codeforces/1003/d.in create mode 100644 codeforces/1003/d.out create mode 100644 codeforces/1003/e.cc create mode 100644 codeforces/1003/e.in create mode 100644 codeforces/1003/e.out create mode 100644 codeforces/1003/f.cc create mode 100644 codeforces/1003/f.in create mode 100644 codeforces/1003/f.out create mode 100644 codeforces/957/.clang-format create mode 100644 codeforces/957/.clangd create mode 100644 codeforces/957/a.cc create mode 100644 codeforces/957/a.in create mode 100644 codeforces/957/a.out create mode 100644 codeforces/957/b.cc create mode 100644 codeforces/957/b.in create mode 100644 codeforces/957/b.out create mode 100644 codeforces/957/c.cc create mode 100644 codeforces/957/c.in create mode 100644 codeforces/957/c.out create mode 100644 codeforces/957/compile_flags.txt create mode 100644 codeforces/957/d.cc create mode 100644 codeforces/957/d.in create mode 100644 codeforces/957/d.out create mode 100644 codeforces/957/f.cc create mode 100644 codeforces/957/f.in create mode 100644 codeforces/957/f.out create mode 100644 codeforces/996/.clang-format create mode 100644 codeforces/996/.clangd create mode 100644 codeforces/996/a.cc create mode 100644 codeforces/996/a.in create mode 100644 codeforces/996/a.out create mode 100644 codeforces/996/b.cc create mode 100644 codeforces/996/b.in create mode 100644 codeforces/996/b.out create mode 100644 codeforces/996/c.cc create mode 100644 codeforces/996/c.in create mode 100644 codeforces/996/c.out create mode 100644 codeforces/996/compile_flags.txt create mode 100644 codeforces/996/d.cc create mode 100644 codeforces/996/d.in create mode 100644 codeforces/996/d.out create mode 100644 codeforces/996/e.cc create mode 100644 codeforces/996/e.in create mode 100644 codeforces/996/e.out create mode 100644 codeforces/996/f.cc create mode 100644 codeforces/996/f.in create mode 100644 codeforces/996/f.out diff --git a/codeforces/1003/.clang-format b/codeforces/1003/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1003/.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/1003/.clangd b/codeforces/1003/.clangd new file mode 100644 index 0000000..4fab872 --- /dev/null +++ b/codeforces/1003/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++23 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/1003/a.cc b/codeforces/1003/a.cc new file mode 100644 index 0000000..dc070a3 --- /dev/null +++ b/codeforces/1003/a.cc @@ -0,0 +1,79 @@ +// {{{ +#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 constexpr T MIN = std::numeric_limits::min(); + +template constexpr T MAX = std::numeric_limits::max(); + +template [[nodiscard]] static T sc(auto &&x) { + return static_cast(x); +} + +template [[nodiscard]] static T sz(auto &&x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args &&...args) { + std::print(fmt, std::forward(args)...); +} + +template void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args &&...args) { + std::println(fmt, std::forward(args)...); +} + +template void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { std::println(); } + +void prln(auto const &t) { std::println("{}", t); } + +using ll = long long; +using ld = long double; +template using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +// }}} + +void solve() { + string s; + cin >> s; + for (int i = 0; i < s.size() - 2; ++i) { + cout << s[i]; + } + cout << "i\n"; +} + +// {{{ +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1003/a.in b/codeforces/1003/a.in new file mode 100644 index 0000000..daba651 --- /dev/null +++ b/codeforces/1003/a.in @@ -0,0 +1,10 @@ +9 +us +sus +fungus +cactus +sussus +amogus +chungus +ntarsus +skibidus diff --git a/codeforces/1003/a.out b/codeforces/1003/a.out new file mode 100644 index 0000000..0a18258 --- /dev/null +++ b/codeforces/1003/a.out @@ -0,0 +1,12 @@ +i +si +fungi +cacti +sussi +amogi +chungi +ntarsi +skibidi + +[code]: 0 +[time]: 4.63152 ms \ No newline at end of file diff --git a/codeforces/1003/b.cc b/codeforces/1003/b.cc new file mode 100644 index 0000000..9ba93b7 --- /dev/null +++ b/codeforces/1003/b.cc @@ -0,0 +1,102 @@ +// {{{ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { + std::println(); +} + +void prln(auto const& t) { + std::println("{}", t); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +// }}} + +void solve() { + string s; + cin >> s; + vec S; + for (auto e : s) { + if (!S.empty() && S.back() == e) { + S.pop_back(); + S.push_back('*'); + } else + S.push_back(e); + } + + while (sz(S) >= 2) { + if (S.back() == '*' || S[sz(S) - 1] == '*') + S.pop_back(); + else + break; + } + prln("{}", sz(S)); +} + +// {{{ +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1003/b.in b/codeforces/1003/b.in new file mode 100644 index 0000000..c076cd2 --- /dev/null +++ b/codeforces/1003/b.in @@ -0,0 +1,5 @@ +4 +baa +skibidus +cc +ohio diff --git a/codeforces/1003/b.out b/codeforces/1003/b.out new file mode 100644 index 0000000..9cb7dc7 --- /dev/null +++ b/codeforces/1003/b.out @@ -0,0 +1,7 @@ +1 +8 +1 +4 + +[code]: 0 +[time]: 11.9956 ms \ No newline at end of file diff --git a/codeforces/1003/c.cc b/codeforces/1003/c.cc new file mode 100644 index 0000000..04eaf46 --- /dev/null +++ b/codeforces/1003/c.cc @@ -0,0 +1,106 @@ +// {{{ +#include + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { + std::println(); +} + +void prln(auto const& t) { + std::println("{}", t); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +// }}} + +void solve() { + int n, m; + cin >> n >> m; + vec a(n); + for (auto& e : a) + cin >> e; + int x; + cin >> x; + + a[0] = min(a[0], x - a[0]); + for (int i = 1; i < n; ++i) { + if (a[i] >= a[i - 1] && x - a[i] >= a[i - 1]) { + a[i] = min(a[i], x - a[i]); + } else if (a[i] >= a[i - 1]) { + ; + } else if (x - a[i] >= a[i - 1]) { + a[i] = x - a[i]; + } else { + prln("NO"); + return; + } + } + prln("YES"); +} + +// {{{ +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1003/c.in b/codeforces/1003/c.in new file mode 100644 index 0000000..01b5f29 --- /dev/null +++ b/codeforces/1003/c.in @@ -0,0 +1,16 @@ +5 +1 1 +5 +9 +3 1 +1 4 3 +3 +4 1 +1 4 2 5 +6 +4 1 +5 4 10 5 +4 +3 1 +9 8 7 +8 diff --git a/codeforces/1003/c.out b/codeforces/1003/c.out new file mode 100644 index 0000000..7f8db64 --- /dev/null +++ b/codeforces/1003/c.out @@ -0,0 +1,8 @@ +YES +NO +YES +NO +YES + +[code]: 0 +[time]: 11.0981 ms \ No newline at end of file diff --git a/codeforces/1003/compile_flags.txt b/codeforces/1003/compile_flags.txt new file mode 100644 index 0000000..0adea68 --- /dev/null +++ b/codeforces/1003/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++23 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/1003/d.cc b/codeforces/1003/d.cc new file mode 100644 index 0000000..4acdb5d --- /dev/null +++ b/codeforces/1003/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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { + std::println(); +} + +void prln(auto const& t) { + std::println("{}", t); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +// }}} + +void solve() { + ll n, m; + cin >> n >> m; + vec> arrays(n, vec(m)); + vec> scores; + for (int i = 0; i < n; ++i) { + ll score = 0; + for (auto& e : arrays[i]) { + cin >> e; + score += e; + } + scores.eb(score, i); + } + + sort(rall(scores)); + + ll ans = 0; + ll x = n * m; + for (int i = 0; i < sz(scores); ++i) { + int index = scores[i].ss; + for (auto e : arrays[index]) { + ans += e * x--; + } + } + + prln("{}", ans); +} + +// {{{ +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1003/d.in b/codeforces/1003/d.in new file mode 100644 index 0000000..ecf1703 --- /dev/null +++ b/codeforces/1003/d.in @@ -0,0 +1,11 @@ +3 +2 2 +4 4 +6 1 +3 4 +2 2 2 2 +3 2 1 2 +4 1 2 1 +2 3 +3 4 5 +1 1 9 diff --git a/codeforces/1003/d.out b/codeforces/1003/d.out new file mode 100644 index 0000000..d7c997a --- /dev/null +++ b/codeforces/1003/d.out @@ -0,0 +1,6 @@ +41 +162 +72 + +[code]: 0 +[time]: 11.8089 ms \ No newline at end of file diff --git a/codeforces/1003/e.cc b/codeforces/1003/e.cc new file mode 100644 index 0000000..3d00d89 --- /dev/null +++ b/codeforces/1003/e.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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { + std::println(); +} + +void prln(auto const& t) { + std::println("{}", t); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +// }}} + +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/1003/e.in b/codeforces/1003/e.in new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/1003/e.out b/codeforces/1003/e.out new file mode 100644 index 0000000..e69de29 diff --git a/codeforces/1003/f.cc b/codeforces/1003/f.cc new file mode 100644 index 0000000..b7e3ede --- /dev/null +++ b/codeforces/1003/f.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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto &&x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto &&x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args &&...args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args &&...args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { + std::println(); +} + +void prln(auto const &t) { + std::println("{}", t); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +// }}} + +void solve() { + int n; + cin >> n; + vec a(n + 1); + for (int i = 1; i < sz(a); ++i) { + cin >> a[i]; + } + + vec> tree(n + 1, vec()); + string ans(n, '0'); + + int root; + for (int i = 0; i < n - 1; ++i) { + int u, v; + cin >> u >> v; + root = u; + tree[u].pb(v); + tree[v].pb(u); + } + + unordered_map> children; + vec par(n + 1, -1); + par[root] = root; + + queue q{{root}}; + + while (!q.empty()) { + int size = sz(q); + while (size--) { + auto u = q.front(); + q.pop(); + for (auto v : tree[u]) { + if (par[v] != -1) + continue; + par[v] = u; + q.push(v); + if (++children[u][a[v]] == 2) + ans[a[v] - 1] = '1'; + } + } + } + + q.push(root); + + for (int u = 1; u <= n; ++u) { + if (par[u] != u && a[u] == a[par[u]] || + par[u] != root && a[u] == a[par[par[u]]]) + ans[a[u] - 1] = '1'; + } + + prln("{}", ans); +} + +// {{{ +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1003/f.in b/codeforces/1003/f.in new file mode 100644 index 0000000..2806230 --- /dev/null +++ b/codeforces/1003/f.in @@ -0,0 +1,29 @@ +4 +3 +1 2 3 +1 3 +2 3 +4 +3 1 1 3 +1 2 +2 3 +4 2 +4 +2 4 4 2 +1 2 +2 3 +3 4 +13 +1 4 4 7 4 7 1 1 7 11 11 11 11 +1 2 +2 3 +3 4 +4 5 +4 6 +2 7 +7 8 +2 9 +6 10 +5 11 +11 12 +10 13 diff --git a/codeforces/1003/f.out b/codeforces/1003/f.out new file mode 100644 index 0000000..4daedd7 --- /dev/null +++ b/codeforces/1003/f.out @@ -0,0 +1,7 @@ +000 +1010 +0001 +1001001000100 + +[code]: 0 +[time]: 3.66259 ms \ No newline at end of file diff --git a/codeforces/957/.clang-format b/codeforces/957/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/957/.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/957/.clangd b/codeforces/957/.clangd new file mode 100644 index 0000000..4fab872 --- /dev/null +++ b/codeforces/957/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++23 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/957/a.cc b/codeforces/957/a.cc new file mode 100644 index 0000000..27fb537 --- /dev/null +++ b/codeforces/957/a.cc @@ -0,0 +1,87 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto &&x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto &&x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args &&...args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args &&...args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + ll a, b, c; + cin >> a >> b >> c; + + ll ans = 0; + FORI(i, 0, 5 + 1) { + FORI(j, 0, 5 - i + 1) { + ans = max(ans, (a + i) * (b + j) * (c + (5 - i - j))); + } + } + prln("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/957/a.in b/codeforces/957/a.in new file mode 100644 index 0000000..0f9ad3f --- /dev/null +++ b/codeforces/957/a.in @@ -0,0 +1,3 @@ +2 +2 3 4 +10 1 10 diff --git a/codeforces/957/a.out b/codeforces/957/a.out new file mode 100644 index 0000000..668c429 --- /dev/null +++ b/codeforces/957/a.out @@ -0,0 +1,5 @@ +100 +600 + +[code]: 0 +[time]: 10.5841 ms \ No newline at end of file diff --git a/codeforces/957/b.cc b/codeforces/957/b.cc new file mode 100644 index 0000000..229349d --- /dev/null +++ b/codeforces/957/b.cc @@ -0,0 +1,93 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + int n, k; + cin >> n >> k; + vec a(k); + for (auto& e : a) + cin >> e; + + sort(all(a)); + + ll ans = 0; + FORI(i, 0, sz(a) - 1) { + if (a[i] > 1) { + ans += (a[i] << 1) - 1; + } else + ++ans; + } + prln("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/957/b.in b/codeforces/957/b.in new file mode 100644 index 0000000..288e0ac --- /dev/null +++ b/codeforces/957/b.in @@ -0,0 +1,9 @@ +4 +5 3 +3 1 1 +5 2 +3 2 +11 4 +2 3 1 5 +16 6 +1 6 1 1 1 6 diff --git a/codeforces/957/b.out b/codeforces/957/b.out new file mode 100644 index 0000000..0a42214 --- /dev/null +++ b/codeforces/957/b.out @@ -0,0 +1,7 @@ +2 +3 +9 +15 + +[code]: 0 +[time]: 12.924 ms \ No newline at end of file diff --git a/codeforces/957/c.cc b/codeforces/957/c.cc new file mode 100644 index 0000000..e4dd46f --- /dev/null +++ b/codeforces/957/c.cc @@ -0,0 +1,87 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + int n, m, k; + cin >> n >> m >> k; + + ROFI(x, n, m) { + pr("{} ", x); + } + FORI(x, 1, m + 1) { + pr("{} ", x); + } + println(); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/957/c.in b/codeforces/957/c.in new file mode 100644 index 0000000..6ef8622 --- /dev/null +++ b/codeforces/957/c.in @@ -0,0 +1,4 @@ +3 +5 2 5 +3 1 3 +10 3 8 diff --git a/codeforces/957/c.out b/codeforces/957/c.out new file mode 100644 index 0000000..e25a3ab --- /dev/null +++ b/codeforces/957/c.out @@ -0,0 +1,6 @@ +5 4 3 1 2 +3 2 1 +10 9 8 7 6 5 4 1 2 3 + +[code]: 0 +[time]: 4.05407 ms \ No newline at end of file diff --git a/codeforces/957/compile_flags.txt b/codeforces/957/compile_flags.txt new file mode 100644 index 0000000..0adea68 --- /dev/null +++ b/codeforces/957/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++23 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/957/d.cc b/codeforces/957/d.cc new file mode 100644 index 0000000..c0473cb --- /dev/null +++ b/codeforces/957/d.cc @@ -0,0 +1,119 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + int _, jump, swim; + cin >> _ >> jump >> swim; + string s; + cin >> s; + + int get_to = 0; + vec logs; + FORI(i, 0, sz(s)) { + if (s[i] == 'L') + logs.pb(i); + } + + logs.pb(sz(s) + 1); + + int pos = -1; + bool done = true; + while (pos < sz(s)) { + auto diff = logs[get_to] - pos; + if (jump < diff) { + if ((pos += jump) < sz(s)) { + while (pos < sz(s) && pos < logs[get_to]) { + if (s[pos] == 'C' || swim == 0) { + done = false; + break; + } + ++pos; + --swim; + } + if (!done) + break; + } else + break; + } else { + pos = logs[get_to]; + } + ++get_to; + } + + if (done) + prln("YES"); + else + prln("NO"); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/957/d.in b/codeforces/957/d.in new file mode 100644 index 0000000..1dccc7e --- /dev/null +++ b/codeforces/957/d.in @@ -0,0 +1,13 @@ +6 +6 2 0 +LWLLLW +6 1 1 +LWLLLL +6 1 1 +LWLLWL +6 2 15 +LWLLCC +6 10 0 +CCCCCC +6 6 1 +WCCCCW diff --git a/codeforces/957/d.out b/codeforces/957/d.out new file mode 100644 index 0000000..72434ba --- /dev/null +++ b/codeforces/957/d.out @@ -0,0 +1,9 @@ +YES +YES +NO +NO +YES +YES + +[code]: 0 +[time]: 18.3692 ms \ No newline at end of file diff --git a/codeforces/957/f.cc b/codeforces/957/f.cc new file mode 100644 index 0000000..71c499b --- /dev/null +++ b/codeforces/957/f.cc @@ -0,0 +1,81 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +void prln() { + std::println(); +} + +void prln(auto const& t) { + std::println("{}", t); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +void solve() { + prln(5); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/957/f.in b/codeforces/957/f.in new file mode 100644 index 0000000..f2e8be5 --- /dev/null +++ b/codeforces/957/f.in @@ -0,0 +1,17 @@ +8 +6 4 +2 3 6 2 1 2 +9 100000 +50000 25000 12500 6250 3125 2 4 8 16 +5 2 +1 1 1 1 1 +8 6 +4 3 4 3 4 3 4 3 +7 12 +6 11 1 3 11 10 2 +10 5 +2 4 4 2 4 4 4 3 1 1 +7 8 +4 6 5 1 2 4 1 +8 27 +3 9 17 26 2 20 9 3 diff --git a/codeforces/957/f.out b/codeforces/957/f.out new file mode 100644 index 0000000..84ed3d3 --- /dev/null +++ b/codeforces/957/f.out @@ -0,0 +1,11 @@ +5 +5 +5 +5 +5 +5 +5 +5 + +[code]: 0 +[time]: 12.038 ms \ No newline at end of file diff --git a/codeforces/996/.clang-format b/codeforces/996/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/996/.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/996/.clangd b/codeforces/996/.clangd new file mode 100644 index 0000000..4fab872 --- /dev/null +++ b/codeforces/996/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -std=c++23 + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/996/a.cc b/codeforces/996/a.cc new file mode 100644 index 0000000..8f71861 --- /dev/null +++ b/codeforces/996/a.cc @@ -0,0 +1,84 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto &&x) { + return static_cast(x); +} + +[[nodiscard]] static int sz(auto &&x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args &&...args) { + std::print(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt, Args &&...args) { + std::println(fmt, std::forward(args)...); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() // }}} + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) + +void solve() { + string a; + cin >> a; + if (!(a.size() > 2)) { + std::println("NO"); + return; + } + if (!(a[0] == '1' && a[1] == '0')) { + std::println("NO"); + return; + } + + int x = sz(a); + + if (stoi(a.substr(2, a.size())) < 2 || a[2] == '0') { + std::println("NO"); + } else { + std::println("YES"); + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/996/a.in b/codeforces/996/a.in new file mode 100644 index 0000000..0ad5858 --- /dev/null +++ b/codeforces/996/a.in @@ -0,0 +1,8 @@ +7 +100 +1010 +101 +105 +2033 +1019 +1002 diff --git a/codeforces/996/a.out b/codeforces/996/a.out new file mode 100644 index 0000000..a777185 --- /dev/null +++ b/codeforces/996/a.out @@ -0,0 +1,10 @@ +NO +YES +NO +YES +NO +YES +NO + +[code]: 0 +[time]: 12.1806 ms \ No newline at end of file diff --git a/codeforces/996/b.cc b/codeforces/996/b.cc new file mode 100644 index 0000000..5874cab --- /dev/null +++ b/codeforces/996/b.cc @@ -0,0 +1,96 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + int n; + cin >> n; + int a; + cin >> a; + int l = a, r = a; + bool done = false; + while (--n) { + cin >> a; + if (!(a == l - 1 || a == r + 1)) { + done = true; + } + l = min(l, a); + r = max(r, a); + } + + if (done) + prln("NO"); + else + prln("YES"); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/996/b.in b/codeforces/996/b.in new file mode 100644 index 0000000..bdacbc2 --- /dev/null +++ b/codeforces/996/b.in @@ -0,0 +1,9 @@ +4 +5 +5 4 2 1 3 +3 +2 3 1 +4 +2 3 1 4 +5 +1 2 3 5 4 diff --git a/codeforces/996/b.out b/codeforces/996/b.out new file mode 100644 index 0000000..4258b17 --- /dev/null +++ b/codeforces/996/b.out @@ -0,0 +1,11 @@ +n=5 +NO +n=3 +YES +n=4 +YES +n=5 +NO + +[code]: 0 +[time]: 11.2283 ms \ No newline at end of file diff --git a/codeforces/996/c.cc b/codeforces/996/c.cc new file mode 100644 index 0000000..4b535bc --- /dev/null +++ b/codeforces/996/c.cc @@ -0,0 +1,210 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto &&x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto &&x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args &&...args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args &&...args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll 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 hashtable = 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>>; + +#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); + for (auto &e : a) + cin >> e; + int m; + cin >> m; + + hashtable a2s, s2a; + + while (m--) { + string s; + cin >> s; + if (s.size() != a.size()) { + prln("NO"); + continue; + } + bool done = false; + FORI(i, 0, sz(a)) { + if (a2s.find(a[i]) == a2s.end() && s2a.find(s[i]) == s2a.end()) { + a2s[a[i]] = s[i]; + s2a[s[i]] = a[i]; + } else if (a2s[a[i]] != s[i] || s2a[s[i]] != a[i]) { + done = true; + break; + } + } + if (done) + prln("NO"); + else + prln("YES"); + a2s.clear(); + s2a.clear(); + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/996/c.in b/codeforces/996/c.in new file mode 100644 index 0000000..5fe125c --- /dev/null +++ b/codeforces/996/c.in @@ -0,0 +1,19 @@ +3 +5 +3 5 2 1 3 +2 +abfda +afbfa +2 +1 2 +3 +ab +abc +aa +4 +5 -3 5 -3 +4 +aaaa +bcbc +aba +cbcb diff --git a/codeforces/996/c.out b/codeforces/996/c.out new file mode 100644 index 0000000..c493259 --- /dev/null +++ b/codeforces/996/c.out @@ -0,0 +1,12 @@ +YES +NO +YES +NO +NO +NO +YES +NO +YES + +[code]: 0 +[time]: 4.55689 ms \ No newline at end of file diff --git a/codeforces/996/compile_flags.txt b/codeforces/996/compile_flags.txt new file mode 100644 index 0000000..0adea68 --- /dev/null +++ b/codeforces/996/compile_flags.txt @@ -0,0 +1,5 @@ +-std=c++23 +-Wall +-Wextra +-Wpedantic +-Wshadow diff --git a/codeforces/996/d.cc b/codeforces/996/d.cc new file mode 100644 index 0000000..904769f --- /dev/null +++ b/codeforces/996/d.cc @@ -0,0 +1,103 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + int n; + cin >> n; + vec a(n); + vec prefix(n + 1, 0); + FORI(i, 0, n) { + cin >> a[i]; + prefix[i + 1] = prefix[i] + a[i]; + } + string s; + cin >> s; + + int l = 0, r = n - 1; + ll ans = 0; + + while (l < r) { + if (s[l] == 'L' && s[r] == 'R') { + ans += prefix[r + 1] - prefix[l]; + ++l; + --r; + } else if (s[r] == 'L') { + --r; + } else { + ++l; + } + } + prln("{}", ans); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/996/d.in b/codeforces/996/d.in new file mode 100644 index 0000000..7d554b3 --- /dev/null +++ b/codeforces/996/d.in @@ -0,0 +1,16 @@ +5 +3 +-1 -1 -1 +LLR +6 +3 5 1 4 3 2 +LRLLLR +2 +2 8 +LR +2 +3 9 +RL +5 +1 2 3 4 5 +LRLRR diff --git a/codeforces/996/d.out b/codeforces/996/d.out new file mode 100644 index 0000000..2e84862 --- /dev/null +++ b/codeforces/996/d.out @@ -0,0 +1,8 @@ +0 +18 +10 +0 +22 + +[code]: 0 +[time]: 10.4334 ms \ No newline at end of file diff --git a/codeforces/996/e.cc b/codeforces/996/e.cc new file mode 100644 index 0000000..eebe049 --- /dev/null +++ b/codeforces/996/e.cc @@ -0,0 +1,145 @@ +#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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void fill(vec>& matrix, vec& a, int k) { + int n = matrix.size(); + int m = matrix[0].size(); + + vec> extra(n, vec(m)); + + FORI(i, 0, n) { + FORI(j, 0, m) { + int top = max(0, i - (k - 1)); + int left = max(0, j - (k - 1)); + int bottom = min(n - k, i); + int right = min(m - k, j); + extra[i][j] = (bottom - top + 1) * (right - left + 1); + } + } + + vec>> cells; + FORI(i, 0, n) { + FORI(j, 0, m) { + cells.push_back({extra[i][j], {i, j}}); + } + } + + sort(rall(cells)); + + FORI(i, 0, min(n * m, sz(a))) { + auto [x, y] = cells[i].ss; + matrix[x][y] = a[i]; + } +} + +long long sums(vector>& matrix, int k) { + int n = matrix.size(), m = matrix[0].size(); + + vec> prefix(n + 1, vec(m + 1, 0)); + FORI(i, 1, n + 1) { + FORI(j, 1, m + 1) { + prefix[i][j] = matrix[i - 1][j - 1] + prefix[i - 1][j] + + prefix[i][j - 1] - prefix[i - 1][j - 1]; + } + } + auto get = [&](int r1, int c1, int r2, int c2) -> ll { + return prefix[r2 + 1][c2 + 1] - prefix[r2 + 1][c1] - prefix[r1][c2 + 1] + + prefix[r1][c1]; + }; + ll ans = 0; + FORI(i, 0, n - k + 1) { + FORI(j, 0, m - k + 1) { + ans += get(i, j, i + k - 1, j + k - 1); + } + } + return ans; +} + +void solve() { + int n, m, k; + cin >> n >> m >> k; + int w; + cin >> w; + vec a(w); + for (auto& e : a) + cin >> e; + sort(rall(a)); + + vector> matrix(n, vector(m, 0)); + + fill(matrix, a, k); + + prln("{}", sums(matrix, k)); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/996/e.in b/codeforces/996/e.in new file mode 100644 index 0000000..3c82751 --- /dev/null +++ b/codeforces/996/e.in @@ -0,0 +1,16 @@ +5 +3 4 2 +9 +1 1 1 1 1 1 1 1 1 +2 1 1 +2 +5 7 +20 15 7 +9 +4 1 4 5 6 1 1000000000 898 777 +1984 1 1 +4 +5 4 1499 2004 +9 5 5 +6 +6 7 14 16 16 6 diff --git a/codeforces/996/e.out b/codeforces/996/e.out new file mode 100644 index 0000000..81d114d --- /dev/null +++ b/codeforces/996/e.out @@ -0,0 +1,8 @@ +21 +12 +49000083104 +3512 +319 + +[code]: 0 +[time]: 13.2093 ms \ No newline at end of file diff --git a/codeforces/996/f.cc b/codeforces/996/f.cc new file mode 100644 index 0000000..e690d86 --- /dev/null +++ b/codeforces/996/f.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 +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +template +void pr(std::format_string fmt, Args&&... args) { + std::print(fmt, std::forward(args)...); +} + +template +void pr(std::format_string fmt) { + std::print(fmt); +} + +template +void prln(std::format_string fmt, Args&&... args) { + std::println(fmt, std::forward(args)...); +} + +template +void prln(std::format_string fmt) { + std::println(fmt); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; + +#define ff first +#define ss second +#define eb emplace_back +#define pb push_back +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#define FORI(a, b, c) for (int a = (b); a < (c); ++a) +#define ROFI(a, b, c) for (int a = (b); a > (c); --a) +#define FORLL(a, b, c) for (ll a = (b); a < (c); ++a) +#define ROFLL(a, b, c) for (ll a = (b); a > (c); --a) // }}} + +void solve() { + int n, k; + cin >> n >> k; + + vec> recs; + FORI(i, 0, n) { + cin >> recs[i].ff >> recs[i].ss; + } + + vec> dp(n + 1, vec(k + 1, MAX)); + FORI(i, 0, n + 1) { + dp[i][0] = 0; + } + + FORLL(i, 1, n + 1) { + FORLL(j, 1, k + 1) { + int x = recs[i - 1].ff, y = recs[i - 1].ss; + int cost = 0; + FORLL(take, 0, min(j, recs[i - 1].ff + recs[i - 1].ss) + 1) { + if (dp[i - 1][j - take] != MAX) + dp[i][j] = min(dp[i][j], dp[i - 1][j - take] + cost); + if (x > y) + swap(x, y); + cost += x; + y--; + } + } + } + + cout << (dp[n][k] == MAX ? -1 : dp[n][k]) << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} //}}} diff --git a/codeforces/996/f.in b/codeforces/996/f.in new file mode 100644 index 0000000..018190d --- /dev/null +++ b/codeforces/996/f.in @@ -0,0 +1,27 @@ +7 +1 4 +6 3 +1 5 +4 4 +5 10 +1 1 +1 1 +1 1 +1 1 +1 1 +2 100 +1 2 +5 6 +3 11 +2 2 +3 3 +4 4 +3 25 +9 2 +4 3 +8 10 +4 18 +5 4 +8 5 +8 3 +6 2 diff --git a/codeforces/996/f.out b/codeforces/996/f.out new file mode 100644 index 0000000..6cdba7c --- /dev/null +++ b/codeforces/996/f.out @@ -0,0 +1,3 @@ + +[code]: 15 (SIGTERM) +[time]: 98.3179 ms \ No newline at end of file