diff --git a/codeforces/1006/.clang-format b/codeforces/1006/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/1006/.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/1006/.clangd b/codeforces/1006/.clangd new file mode 100644 index 0000000..4f8ead9 --- /dev/null +++ b/codeforces/1006/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -DLOCAL + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/1006/a.cc b/codeforces/1006/a.cc new file mode 100644 index 0000000..0f3250b --- /dev/null +++ b/codeforces/1006/a.cc @@ -0,0 +1,101 @@ +#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); +} + +#ifdef LOCAL +#define dbgln(...) prln(...) +#define dbg(...) pr(...) +#endif + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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, k, p; + cin >> n >> k >> p; + + k = abs(k); + + int ans = k / p; + k -= p * ans; + if (k) { + ++ans; + } + + cout << (ans > n ? -1 : ans) << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1006/a.in b/codeforces/1006/a.in new file mode 100644 index 0000000..886ed2b --- /dev/null +++ b/codeforces/1006/a.in @@ -0,0 +1,9 @@ +8 +21 100 10 +9 -420 42 +5 -7 2 +13 37 7 +10 0 49 +1 10 9 +7 -7 7 +20 31 1 diff --git a/codeforces/1006/a.out b/codeforces/1006/a.out new file mode 100644 index 0000000..7f83f99 --- /dev/null +++ b/codeforces/1006/a.out @@ -0,0 +1,11 @@ +10 +-1 +4 +6 +0 +-1 +1 +-1 + +[code]: 0 +[time]: 11.3668 ms \ No newline at end of file diff --git a/codeforces/1006/b.cc b/codeforces/1006/b.cc new file mode 100644 index 0000000..20901af --- /dev/null +++ b/codeforces/1006/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); +} + +#ifdef LOCAL +#define dbgln(...) prln(...) +#define dbg(...) pr(...) +#endif + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + string s; + cin >> s; + ll hyphen = 0, underscore = 0; + for (auto c : s) { + hyphen += c == '-'; + underscore += c != '-'; + } + + ll left = hyphen / 2, right = hyphen / 2 + (hyphen & 1); + + cout << left * right * underscore << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1006/b.in b/codeforces/1006/b.in new file mode 100644 index 0000000..e882264 --- /dev/null +++ b/codeforces/1006/b.in @@ -0,0 +1,17 @@ +8 +3 +--_ +5 +__-__ +9 +--__-_--- +4 +_--_ +10 +_-_-_-_-_- +7 +_------ +1 +- +2 +_- diff --git a/codeforces/1006/b.out b/codeforces/1006/b.out new file mode 100644 index 0000000..a59f65d --- /dev/null +++ b/codeforces/1006/b.out @@ -0,0 +1,11 @@ +1 +0 +27 +2 +30 +9 +0 +0 + +[code]: 0 +[time]: 12.301 ms \ No newline at end of file diff --git a/codeforces/1006/c.cc b/codeforces/1006/c.cc new file mode 100644 index 0000000..44e951b --- /dev/null +++ b/codeforces/1006/c.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 +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); +} + +#ifdef LOCAL +#define dbgln(...) prln(...) +#define dbg(...) pr(...) +#endif + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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, x; + cin >> n >> x; + + ll cur = 0; + + bool broken = false; + if (n > 1) { + cout << 0 << ' '; + } else { + cout << x << endl; + return; + } + int a = 0; + for (int i = 0; i < n - 2; ++i) { + ++cur; + + if (broken || (cur | x) > x) { + broken = true; + } + + if (broken) { + cout << x; + a |= x; + } else { + cout << cur; + a |= cur; + } + cout << ' '; + } + + ++cur; + + if (broken) { + cout << x; + } else { + if ((cur | x) <= x && (a | cur) == x) { + cout << cur; + } else + cout << x; + } + cout << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1006/c.in b/codeforces/1006/c.in new file mode 100644 index 0000000..d9ee7a3 --- /dev/null +++ b/codeforces/1006/c.in @@ -0,0 +1,10 @@ +9 +1 69 +7 7 +5 7 +7 3 +8 7 +3 52 +9 11 +6 15 +2 3 diff --git a/codeforces/1006/c.out b/codeforces/1006/c.out new file mode 100644 index 0000000..2a3d404 --- /dev/null +++ b/codeforces/1006/c.out @@ -0,0 +1,12 @@ +69 +0 1 2 3 4 5 6 +0 1 2 3 4 +0 1 2 3 3 3 3 +0 1 2 3 4 5 6 7 +0 52 52 +0 1 2 3 11 11 11 11 11 +0 1 2 3 4 15 +0 3 + +[code]: 0 +[time]: 11.3029 ms \ No newline at end of file diff --git a/codeforces/1006/compile_flags.txt b/codeforces/1006/compile_flags.txt new file mode 100644 index 0000000..504aea8 --- /dev/null +++ b/codeforces/1006/compile_flags.txt @@ -0,0 +1,6 @@ +-Wall +-Wextra +-Wpedantic +-Wshadow +-DLOCAL +-std=c++23 diff --git a/codeforces/1006/d.cc b/codeforces/1006/d.cc new file mode 100644 index 0000000..c5ed21a --- /dev/null +++ b/codeforces/1006/d.cc @@ -0,0 +1,108 @@ +#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); +} + +#ifdef LOCAL +#define dbgln(...) prln(...) +#define dbg(...) pr(...) +#endif + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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); + for (auto &e : a) { + cin >> e; + } + + arr ans{0, 0, 0}; + + for (int l = 0; l < sz(a); ++l) { + ll delta = 0; + for (int r = l + 1; r < sz(a); ++r) { + delta += a[l] < a[r]; + delta -= a[l] > a[r]; + ans = min(ans, {delta, l, r}); + } + } + + prln("{} {}", ans[1] + 1, ans[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/1006/d.in b/codeforces/1006/d.in new file mode 100644 index 0000000..ccf0804 --- /dev/null +++ b/codeforces/1006/d.in @@ -0,0 +1,19 @@ +9 +7 +1 4 3 2 5 3 3 +6 +1 4 3 2 5 3 +8 +7 6 5 8 4 3 2 1 +10 +1 1 1 5 1 1 5 6 7 8 +2 +1337 69 +4 +2 1 2 1 +3 +998 244 353 +3 +1 2 1 +9 +1 1 2 3 5 8 13 21 34 diff --git a/codeforces/1006/d.out b/codeforces/1006/d.out new file mode 100644 index 0000000..017d3f1 --- /dev/null +++ b/codeforces/1006/d.out @@ -0,0 +1,12 @@ +2 7 +2 6 +1 8 +4 7 +1 2 +1 4 +1 3 +2 3 +1 2 + +[code]: 0 +[time]: 3.81064 ms \ No newline at end of file diff --git a/codeforces/1006/e.cc b/codeforces/1006/e.cc new file mode 100644 index 0000000..af2aa1a --- /dev/null +++ b/codeforces/1006/e.cc @@ -0,0 +1,115 @@ +#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); +} + +#ifdef LOCAL +#define dbgln(...) prln(...) +#define dbg(...) pr(...) +#endif + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 k; + cin >> k; + ll y = 0, x = 0; + vec> ans; + + while (k) { + ll count = 0; + + while (count * (count - 1) / 2 <= k) { + ++count; + } + + --count; + + k -= count * (count - 1) / 2; + + for (int i = 0; i < count; ++i) { + ans.eb(x, y++); + } + ++x; + } + + cout << ans.size() << endl; + for (auto [a, b] : ans) { + cout << a << ' ' << b << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/1006/e.in b/codeforces/1006/e.in new file mode 100644 index 0000000..9873ee0 --- /dev/null +++ b/codeforces/1006/e.in @@ -0,0 +1,4 @@ +3 +1 +2 +3 diff --git a/codeforces/1006/e.out b/codeforces/1006/e.out new file mode 100644 index 0000000..9a93072 --- /dev/null +++ b/codeforces/1006/e.out @@ -0,0 +1,15 @@ +2 +0 0 +0 1 +4 +0 0 +0 1 +1 2 +1 3 +3 +0 0 +0 1 +0 2 + +[code]: 0 +[time]: 11.3349 ms \ No newline at end of file diff --git a/cses/introductory-problems/.clang-format b/cses/introductory-problems/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/cses/introductory-problems/.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/cses/introductory-problems/.clangd b/cses/introductory-problems/.clangd new file mode 100644 index 0000000..4f8ead9 --- /dev/null +++ b/cses/introductory-problems/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -DLOCAL + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/cses/introductory-problems/apple-division.cc b/cses/introductory-problems/apple-division.cc new file mode 100644 index 0000000..dda14ae --- /dev/null +++ b/cses/introductory-problems/apple-division.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 +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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); + for (auto& e : a) { + cin >> e; + } + + auto rec = [&](auto&& self, int i, ll l, ll r) { + if (i == n) { + return abs(r - l); + } + + return min(self(self, i + 1, l + a[i], r), self(self, i + 1, l, r + a[i])); + }; + + cout << rec(rec, 0, 0, 0); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/apple-division.in b/cses/introductory-problems/apple-division.in new file mode 100644 index 0000000..4f8bb59 --- /dev/null +++ b/cses/introductory-problems/apple-division.in @@ -0,0 +1,2 @@ +3 +7 7 100 diff --git a/cses/introductory-problems/apple-division.out b/cses/introductory-problems/apple-division.out new file mode 100644 index 0000000..c503bcc --- /dev/null +++ b/cses/introductory-problems/apple-division.out @@ -0,0 +1,3 @@ +86 +[code]: 0 +[time]: 3.65114 ms \ No newline at end of file diff --git a/cses/introductory-problems/chessboard-and-queens.cc b/cses/introductory-problems/chessboard-and-queens.cc new file mode 100644 index 0000000..ab53e3c --- /dev/null +++ b/cses/introductory-problems/chessboard-and-queens.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 +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +constexpr static int N = 8; + +vec board(N); + +// SC: O(n) for recursive space + queens +// TC: O(n*n*n) - every row every col check all queens + +// NOTE: pruning +ll backtrack(vec &queens) { + if (queens.size() == N) { + return 1; + } + + ll r = queens.size(); + ll ans = 0; + for (int C = 0; C < N; ++C) { + if (board[r][C] == '*') + continue; + bool bad = false; + for (int qr = 0; qr < sz(queens); ++qr) { + int qc = queens[qr]; + // Q: does it fall on the DIAGONAL? + // for each line, is there an integer sol'n? + // y - qr = x - qc -> x - qc + qr <- n queens + // or y - qr = -x + qc -> y = -x + qc + qr + if (qc == C || abs(r - qr) == abs(C - qc)) { + bad = true; + break; + } + } + if (bad) + continue; + queens.eb(C); + ans += backtrack(queens); + queens.pop_back(); + } + return ans; +} + +void solve() { + for (int i = 0; i < N; ++i) { + cin >> board[i]; + } + + vec queens; + ll ans = backtrack(queens); + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/chessboard-and-queens.in b/cses/introductory-problems/chessboard-and-queens.in new file mode 100644 index 0000000..994f68d --- /dev/null +++ b/cses/introductory-problems/chessboard-and-queens.in @@ -0,0 +1,8 @@ +........ +........ +..*..... +........ +........ +.....**. +...*.... +........ diff --git a/cses/introductory-problems/chessboard-and-queens.out b/cses/introductory-problems/chessboard-and-queens.out new file mode 100644 index 0000000..deab8c3 --- /dev/null +++ b/cses/introductory-problems/chessboard-and-queens.out @@ -0,0 +1,4 @@ +65 + +[code]: 0 +[time]: 12.8713 ms \ No newline at end of file diff --git a/cses/introductory-problems/coin-piles.cc b/cses/introductory-problems/coin-piles.cc new file mode 100644 index 0000000..1cf4b06 --- /dev/null +++ b/cses/introductory-problems/coin-piles.cc @@ -0,0 +1,58 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 a, b; + cin >> a >> b; + + cout << (((a + b) % 3 == 0) && 2 * min(a, b) >= max(a, b) ? "YES\n" : "NO\n"); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t; + cin >> t; + while (t--) + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/coin-piles.in b/cses/introductory-problems/coin-piles.in new file mode 100644 index 0000000..8b27344 --- /dev/null +++ b/cses/introductory-problems/coin-piles.in @@ -0,0 +1,5 @@ +4 +2 1 +2 2 +3 3 +11 4 diff --git a/cses/introductory-problems/coin-piles.out b/cses/introductory-problems/coin-piles.out new file mode 100644 index 0000000..7530cea --- /dev/null +++ b/cses/introductory-problems/coin-piles.out @@ -0,0 +1,7 @@ +YES +NO +YES +NO + +[code]: 0 +[time]: 11.4977 ms \ No newline at end of file diff --git a/cses/introductory-problems/compile_flags.txt b/cses/introductory-problems/compile_flags.txt new file mode 100644 index 0000000..573a6b6 --- /dev/null +++ b/cses/introductory-problems/compile_flags.txt @@ -0,0 +1,6 @@ +-Wall +-Wextra +-Wpedantic +-Wshadow +-DLOCAL +-std=c++20 diff --git a/cses/introductory-problems/creating-strings.cc b/cses/introductory-problems/creating-strings.cc new file mode 100644 index 0000000..20845ee --- /dev/null +++ b/cses/introductory-problems/creating-strings.cc @@ -0,0 +1,85 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 backtrack(vec& freq, string& cur, vector& ans, int len) { + if (sz(cur) == len) { + ans.eb(cur); + return; + } + for (int i = 0; i < sz(freq); ++i) { + if (freq[i] == 0) + continue; + + --freq[i]; + + cur.push_back(i + 'a'); + backtrack(freq, cur, ans, len); + cur.pop_back(); + + ++freq[i]; + } +} + +void solve() { + string s; + cin >> s; + + vec m(26, 0); + int len = s.size(); + for (auto c : s) + ++m[c - 'a']; + + string cur = ""; + vec ans; + backtrack(m, cur, ans, len); + cout << ans.size() << endl; + for (auto& S : ans) { + cout << S << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/creating-strings.in b/cses/introductory-problems/creating-strings.in new file mode 100644 index 0000000..8baef1b --- /dev/null +++ b/cses/introductory-problems/creating-strings.in @@ -0,0 +1 @@ +abc diff --git a/cses/introductory-problems/creating-strings.out b/cses/introductory-problems/creating-strings.out new file mode 100644 index 0000000..ddb5c82 --- /dev/null +++ b/cses/introductory-problems/creating-strings.out @@ -0,0 +1,10 @@ +6 +abc +acb +bac +bca +cab +cba + +[code]: 0 +[time]: 11.6973 ms \ No newline at end of file diff --git a/cses/introductory-problems/digit-queries.cc b/cses/introductory-problems/digit-queries.cc new file mode 100644 index 0000000..3e7bf50 --- /dev/null +++ b/cses/introductory-problems/digit-queries.cc @@ -0,0 +1,85 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 q; + cin >> q; + while (q--) { + ll k; + cin >> k; + if (k <= 9) { + cout << k << endl; + continue; + } + + ll exp = 1; + while (true) { + ll numbers_in_band = 9 * powl(10, exp - 1); + ll per = numbers_in_band * exp; + + if (k <= per) + break; + + k -= per; + exp++; + } + + ll i = (k - 1) / exp; + ll index = k % exp; + if (index == 0) + index = exp; + ll ans = powl(10, exp - 1) + i; + ll offset = exp - index; + while (offset--) { + ans /= 10; + } + + cout << ans % 10 << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/digit-queries.in b/cses/introductory-problems/digit-queries.in new file mode 100644 index 0000000..c708451 --- /dev/null +++ b/cses/introductory-problems/digit-queries.in @@ -0,0 +1,8 @@ +7 +5 +10 +11 +12 +13 +14 +15 diff --git a/cses/introductory-problems/digit-queries.out b/cses/introductory-problems/digit-queries.out new file mode 100644 index 0000000..deca5bb --- /dev/null +++ b/cses/introductory-problems/digit-queries.out @@ -0,0 +1,10 @@ +5 +1 +0 +1 +1 +1 +2 + +[code]: 0 +[time]: 10.8669 ms \ No newline at end of file diff --git a/cses/introductory-problems/gray-code.cc b/cses/introductory-problems/gray-code.cc new file mode 100644 index 0000000..81c0c59 --- /dev/null +++ b/cses/introductory-problems/gray-code.cc @@ -0,0 +1,71 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +vec f(int n) { + vec gray{"0", "1"}; + + while (--n) { + vec copy(gray); + reverse(all(copy)); + gray.insert(gray.end(), all(copy)); + for (int i = 0; i < sz(gray); ++i) + gray[i].push_back('0' + (i >= sz(gray) >> 1)); + } + return gray; +} + +void solve() { + int n; + cin >> n; + + vec gray = f(n); + for (auto s : gray) { + cout << s << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/gray-code.in b/cses/introductory-problems/gray-code.in new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/cses/introductory-problems/gray-code.in @@ -0,0 +1 @@ +2 diff --git a/cses/introductory-problems/gray-code.out b/cses/introductory-problems/gray-code.out new file mode 100644 index 0000000..0b59be0 --- /dev/null +++ b/cses/introductory-problems/gray-code.out @@ -0,0 +1,8 @@ +4 +00 +10 +11 +01 + +[code]: 0 +[time]: 11.6062 ms \ No newline at end of file diff --git a/cses/introductory-problems/grid-paths.cc b/cses/introductory-problems/grid-paths.cc new file mode 100644 index 0000000..a015f64 --- /dev/null +++ b/cses/introductory-problems/grid-paths.cc @@ -0,0 +1,108 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +bitset<7 * 7 + 1> seen; + +vec> dirs; +unordered_map> dir_map{ + {'U', {-1, 0}}, {'D', {1, 0}}, {'L', {0, -1}}, {'R', {0, 1}}}; + +ll ans = 0; + +string s; + +void dfs(int r, int c, int i) { + if (min(r, c) < 0 || max(r, c) > 6 || seen[r * 7 + c]) { + return; + } + if (r == 6 && c == 0) { + ans += i == 48; + return; + } + seen[r * 7 + c] = true; + bool up = (r > 0 && !seen[(r - 1) * 7 + c]); + bool down = (r < 6 && !seen[(r + 1) * 7 + c]); + bool left = (c > 0 && !seen[r * 7 + (c - 1)]); + bool right = (c < 6 && !seen[r * 7 + (c + 1)]); + + if ((up && down && !left && !right) || (!up && !down && left && right)) { + seen[r * 7 + c] = false; + return; + } + int open_count = up + down + left + right; + if (open_count == 1) { + if (up) dfs(r - 1, c, i + 1); + else if (down) dfs(r + 1, c, i + 1); + else if (left) dfs(r, c - 1, i + 1); + else if (right) dfs(r, c + 1, i + 1); + + seen[r * 7 + c] = false; + return; + } + if (s[i] == '?') { + for (auto& [dr, dc] : dirs) { + dfs(r + dr, c + dc, i + 1); + } + } else { + dfs(r + dir_map[s[i]].ff, c + dir_map[s[i]].ss, i + 1); + } + seen[r * 7 + c] = false; +} + +void solve() { + dirs.eb(1, 0); + dirs.eb(0, 1); + dirs.eb(-1, 0); + dirs.eb(0, -1); + cin >> s; + + dfs(0, 0, 0); + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/grid-paths.in b/cses/introductory-problems/grid-paths.in new file mode 100644 index 0000000..f954ea7 --- /dev/null +++ b/cses/introductory-problems/grid-paths.in @@ -0,0 +1 @@ +??????R??????U??????????????????????????LD????D? diff --git a/cses/introductory-problems/grid-paths.out b/cses/introductory-problems/grid-paths.out new file mode 100644 index 0000000..15cd666 --- /dev/null +++ b/cses/introductory-problems/grid-paths.out @@ -0,0 +1,4 @@ +5986 + +[code]: 0 +[time]: 557.243 ms \ No newline at end of file diff --git a/cses/introductory-problems/increasing-array.cc b/cses/introductory-problems/increasing-array.cc new file mode 100644 index 0000000..9976961 --- /dev/null +++ b/cses/introductory-problems/increasing-array.cc @@ -0,0 +1,65 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 ans = 0; + int n; + cin >> n; + ll last = 0; + while (n--) { + ll x; + cin >> x; + if (last != 0 && last > x) { + ans += last - x; + x += last - x; + } + last = x; + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/increasing-array.in b/cses/introductory-problems/increasing-array.in new file mode 100644 index 0000000..84428d7 --- /dev/null +++ b/cses/introductory-problems/increasing-array.in @@ -0,0 +1,2 @@ +10 +1000000000 1 1 1 1 1 1 1 1 1 diff --git a/cses/introductory-problems/increasing-array.out b/cses/introductory-problems/increasing-array.out new file mode 100644 index 0000000..7de34c9 --- /dev/null +++ b/cses/introductory-problems/increasing-array.out @@ -0,0 +1,4 @@ +8999999991 + +[code]: 0 +[time]: 4.4868 ms \ No newline at end of file diff --git a/cses/introductory-problems/missing-number.cc b/cses/introductory-problems/missing-number.cc new file mode 100644 index 0000000..2867d0e --- /dev/null +++ b/cses/introductory-problems/missing-number.cc @@ -0,0 +1,65 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 seen(n + 1, false); + while (--n) { + int x; + cin >> x; + seen[x] = true; + } + for (int i = 1; i < sz(seen); ++i) { + if (!seen[i]) { + cout << i << endl; + break; + } + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/missing-number.in b/cses/introductory-problems/missing-number.in new file mode 100644 index 0000000..58c8e41 --- /dev/null +++ b/cses/introductory-problems/missing-number.in @@ -0,0 +1,2 @@ +5 +2 3 1 5 diff --git a/cses/introductory-problems/missing-number.out b/cses/introductory-problems/missing-number.out new file mode 100644 index 0000000..8b5d8e1 --- /dev/null +++ b/cses/introductory-problems/missing-number.out @@ -0,0 +1,4 @@ +4 + +[code]: 0 +[time]: 3.88908 ms \ No newline at end of file diff --git a/cses/introductory-problems/number-spiral.cc b/cses/introductory-problems/number-spiral.cc new file mode 100644 index 0000000..607777f --- /dev/null +++ b/cses/introductory-problems/number-spiral.cc @@ -0,0 +1,62 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 x, y; + cin >> y >> x; + ll base = max(x, y); + ll ans = base * base; + if (ans & 1) + swap(x, y); + ans -= x - 1 + base - y; + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t; + cin >> t; + while (t--) + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/number-spiral.in b/cses/introductory-problems/number-spiral.in new file mode 100644 index 0000000..edaf77c --- /dev/null +++ b/cses/introductory-problems/number-spiral.in @@ -0,0 +1,5 @@ +4 +2 3 +1 1 +4 2 +2 4 diff --git a/cses/introductory-problems/number-spiral.out b/cses/introductory-problems/number-spiral.out new file mode 100644 index 0000000..8b42200 --- /dev/null +++ b/cses/introductory-problems/number-spiral.out @@ -0,0 +1,7 @@ +8 +1 +15 +11 + +[code]: 0 +[time]: 4.26793 ms \ No newline at end of file diff --git a/cses/introductory-problems/palindrome-reorder.cc b/cses/introductory-problems/palindrome-reorder.cc new file mode 100644 index 0000000..ee8370b --- /dev/null +++ b/cses/introductory-problems/palindrome-reorder.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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + + unordered_map m; + for (auto c : s) + ++m[c]; + + int odd = 0; + + string ans(s.size(), 'A'); + + int l = 0; + + for (auto& [k, v] : m) { + if (v & 1) { + if (++odd == 2) { + cout << "NO SOLUTION"; + return; + } + ans[ans.size() / 2] = k; + --v; + } + while (v) { + ans[l++] = k; + ans[ans.size() - l] = k; + v -= 2; + } + } + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/palindrome-reorder.in b/cses/introductory-problems/palindrome-reorder.in new file mode 100644 index 0000000..6dacbd4 --- /dev/null +++ b/cses/introductory-problems/palindrome-reorder.in @@ -0,0 +1 @@ +AAABBB diff --git a/cses/introductory-problems/palindrome-reorder.out b/cses/introductory-problems/palindrome-reorder.out new file mode 100644 index 0000000..5630a4b --- /dev/null +++ b/cses/introductory-problems/palindrome-reorder.out @@ -0,0 +1,3 @@ +NO SOLUTION +[code]: 0 +[time]: 12.1081 ms \ No newline at end of file diff --git a/cses/introductory-problems/permutations.cc b/cses/introductory-problems/permutations.cc new file mode 100644 index 0000000..32f707b --- /dev/null +++ b/cses/introductory-problems/permutations.cc @@ -0,0 +1,76 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + /* + n= 5; + 1 4 2 5 3 + 1 4 2 5 3 6 + 1 7 2 6 3 5 4 + + + 41325 + */ + + if (n == 1) { + cout << 1 << endl; + } else if (n <= 3) { + cout << "NO SOLUTION\n"; + } else { + for (int cur = n & 1 ? n - 1 : n; cur > 4; cur -= 2) { + cout << cur << ' '; + } + cout << "2 4"; + for (int cur = 1; cur <= n; cur += 2) { + cout << ' ' << cur; + } + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/permutations.in b/cses/introductory-problems/permutations.in new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/cses/introductory-problems/permutations.in @@ -0,0 +1 @@ +1 diff --git a/cses/introductory-problems/permutations.out b/cses/introductory-problems/permutations.out new file mode 100644 index 0000000..25af5b9 --- /dev/null +++ b/cses/introductory-problems/permutations.out @@ -0,0 +1,4 @@ +1 + +[code]: 0 +[time]: 4.06551 ms \ No newline at end of file diff --git a/cses/introductory-problems/repetitions.cc b/cses/introductory-problems/repetitions.cc new file mode 100644 index 0000000..759f3b2 --- /dev/null +++ b/cses/introductory-problems/repetitions.cc @@ -0,0 +1,60 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template using vec = std::vector; +template using arr = std::array; + +#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; + + ll streak = 0, ans = 0; + char last = ' '; + for (auto c : s) { + if (last == ' ' || last == c) { + ++streak; + ans = max(ans, streak); + } else { + streak = 1; + } + last = c; + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/repetitions.in b/cses/introductory-problems/repetitions.in new file mode 100644 index 0000000..855590a --- /dev/null +++ b/cses/introductory-problems/repetitions.in @@ -0,0 +1 @@ +ABCDEF diff --git a/cses/introductory-problems/repetitions.out b/cses/introductory-problems/repetitions.out new file mode 100644 index 0000000..cfce1bd --- /dev/null +++ b/cses/introductory-problems/repetitions.out @@ -0,0 +1,4 @@ +1 + +[code]: 0 +[time]: 4.20523 ms \ No newline at end of file diff --git a/cses/introductory-problems/tower-of-hanoi.cc b/cses/introductory-problems/tower-of-hanoi.cc new file mode 100644 index 0000000..550528e --- /dev/null +++ b/cses/introductory-problems/tower-of-hanoi.cc @@ -0,0 +1,68 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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> ans; + auto hanoi = [&](auto&& self, int src, int dest, int aux, int x) { + if (x == 1) { + ans.eb(src, dest); + return; + } + self(self, src, aux, dest, x - 1); + ans.eb(src, dest); + self(self, aux, dest, src, x - 1); + }; + hanoi(hanoi, 1, 3, 2, n); + cout << ans.size() << endl; + for (auto& [a, b] : ans) { + cout << a << ' ' << b << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/tower-of-hanoi.in b/cses/introductory-problems/tower-of-hanoi.in new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/cses/introductory-problems/tower-of-hanoi.in @@ -0,0 +1 @@ +2 diff --git a/cses/introductory-problems/tower-of-hanoi.out b/cses/introductory-problems/tower-of-hanoi.out new file mode 100644 index 0000000..9889ccd --- /dev/null +++ b/cses/introductory-problems/tower-of-hanoi.out @@ -0,0 +1,7 @@ +3 +1 2 +1 3 +2 3 + +[code]: 0 +[time]: 11.8749 ms \ No newline at end of file diff --git a/cses/introductory-problems/trailing-zeroes.cc b/cses/introductory-problems/trailing-zeroes.cc new file mode 100644 index 0000000..04c57ed --- /dev/null +++ b/cses/introductory-problems/trailing-zeroes.cc @@ -0,0 +1,72 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + + /* + every time 10 goes into it, + 1 + + 1 * 2 * 3 * 4 * 5 <- 1 + + 6 * 7 * 8 * 9 * 10 + + 11 12 13 14 15 + 16 17 18 19 20 +*/ + + int ans = 0; + int b = 5; + while (n / b) { + ans += n / b; + b *= 5; + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/trailing-zeroes.in b/cses/introductory-problems/trailing-zeroes.in new file mode 100644 index 0000000..b4249c4 --- /dev/null +++ b/cses/introductory-problems/trailing-zeroes.in @@ -0,0 +1 @@ +239 diff --git a/cses/introductory-problems/trailing-zeroes.out b/cses/introductory-problems/trailing-zeroes.out new file mode 100644 index 0000000..81dbf7b --- /dev/null +++ b/cses/introductory-problems/trailing-zeroes.out @@ -0,0 +1,4 @@ +57 + +[code]: 0 +[time]: 11.5106 ms \ No newline at end of file diff --git a/cses/introductory-problems/weird-algorithm.cc b/cses/introductory-problems/weird-algorithm.cc new file mode 100644 index 0000000..c811ee2 --- /dev/null +++ b/cses/introductory-problems/weird-algorithm.cc @@ -0,0 +1,64 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + cin >> n; + + while (n != 1) { + cout << n << ' '; + if (n & 1) { + n = n * 3 + 1; + } else { + n /= 2; + } + } + cout << 1 << endl; +} + +// {{{ +int main() { + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/introductory-problems/weird-algorithm.in b/cses/introductory-problems/weird-algorithm.in new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/cses/introductory-problems/weird-algorithm.in @@ -0,0 +1 @@ +3 diff --git a/cses/introductory-problems/weird-algorithm.out b/cses/introductory-problems/weird-algorithm.out new file mode 100644 index 0000000..4d566c8 --- /dev/null +++ b/cses/introductory-problems/weird-algorithm.out @@ -0,0 +1,4 @@ +3 10 5 16 8 4 2 1 + +[code]: 0 +[time]: 11.0214 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/.clang-format b/cses/sorting-and-searching/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/cses/sorting-and-searching/.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/cses/sorting-and-searching/.clangd b/cses/sorting-and-searching/.clangd new file mode 100644 index 0000000..4f8ead9 --- /dev/null +++ b/cses/sorting-and-searching/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -DLOCAL + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/cses/sorting-and-searching/apartments.cc b/cses/sorting-and-searching/apartments.cc new file mode 100644 index 0000000..cb6fa04 --- /dev/null +++ b/cses/sorting-and-searching/apartments.cc @@ -0,0 +1,75 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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, k; + cin >> n >> m >> k; + vec requests(n); + for (auto& e : requests) + cin >> e; + vec sizes(m); + for (auto& e : sizes) + cin >> e; + sort(all(requests)); + sort(all(sizes)); + + ll ans = 0; + int size = 0; + for (int request = 0; request < n && size < m; ++request) { + while (size < m && sizes[size] + k < requests[request]) { + ++size; + } + if (sizes[size] - k <= requests[request] && + requests[request] <= sizes[size] + k) { + ++ans; + ++size; + } + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/apartments.in b/cses/sorting-and-searching/apartments.in new file mode 100644 index 0000000..7a36e5b --- /dev/null +++ b/cses/sorting-and-searching/apartments.in @@ -0,0 +1,3 @@ +10 10 10 +90 41 20 39 49 21 35 31 74 86 +14 24 24 7 82 85 82 4 60 95 diff --git a/cses/sorting-and-searching/apartments.out b/cses/sorting-and-searching/apartments.out new file mode 100644 index 0000000..a0ea022 --- /dev/null +++ b/cses/sorting-and-searching/apartments.out @@ -0,0 +1,4 @@ +6 + +[code]: 0 +[time]: 12.7234 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/collecting-numbers.cc b/cses/sorting-and-searching/collecting-numbers.cc new file mode 100644 index 0000000..949ea62 --- /dev/null +++ b/cses/sorting-and-searching/collecting-numbers.cc @@ -0,0 +1,72 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +int n; +void solve() { + cin >> n; + vec> a(n); + for (int i = 0; i < n; ++i) { + cin >> a[i].ff; + a[i].ss = i; + } + sort(all(a), [](auto& l, auto& r) { + return l.ff < r.ff; + }); + ll ans = 1; + int last_i = a[0].ss; + + for (int i = 1; i < sz(a); ++i) { + if (a[i].ss < last_i) { + ++ans; + } + last_i = a[i].ss; + } + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/collecting-numbers.in b/cses/sorting-and-searching/collecting-numbers.in new file mode 100644 index 0000000..3da6d09 --- /dev/null +++ b/cses/sorting-and-searching/collecting-numbers.in @@ -0,0 +1,2 @@ +5 +4 2 1 5 3 diff --git a/cses/sorting-and-searching/collecting-numbers.out b/cses/sorting-and-searching/collecting-numbers.out new file mode 100644 index 0000000..740e5cb --- /dev/null +++ b/cses/sorting-and-searching/collecting-numbers.out @@ -0,0 +1,4 @@ +3 + +[code]: 0 +[time]: 11.512 ms diff --git a/cses/sorting-and-searching/compile_flags.txt b/cses/sorting-and-searching/compile_flags.txt new file mode 100644 index 0000000..573a6b6 --- /dev/null +++ b/cses/sorting-and-searching/compile_flags.txt @@ -0,0 +1,6 @@ +-Wall +-Wextra +-Wpedantic +-Wshadow +-DLOCAL +-std=c++20 diff --git a/cses/sorting-and-searching/concert-tickets.cc b/cses/sorting-and-searching/concert-tickets.cc new file mode 100644 index 0000000..06ab7a3 --- /dev/null +++ b/cses/sorting-and-searching/concert-tickets.cc @@ -0,0 +1,172 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +#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 multitree = 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; + cin >> n >> m; + + vec a(n); + for (auto &e : a) + cin >> e; + + multitree mm(all(a)); + + while (m--) { + ll x; + cin >> x; + + auto i = mm.order_of_key(x + 1); + if (i == 0) + cout << -1 << endl; + else { + auto it = mm.find_by_order(i - 1); + cout << *it << endl; + mm.erase(it); + } + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/concert-tickets.in b/cses/sorting-and-searching/concert-tickets.in new file mode 100644 index 0000000..575b768 --- /dev/null +++ b/cses/sorting-and-searching/concert-tickets.in @@ -0,0 +1,3 @@ +5 3 +5 3 7 8 5 +4 8 3 diff --git a/cses/sorting-and-searching/concert-tickets.out b/cses/sorting-and-searching/concert-tickets.out new file mode 100644 index 0000000..039ae0f --- /dev/null +++ b/cses/sorting-and-searching/concert-tickets.out @@ -0,0 +1,6 @@ +3 +8 +-1 + +[code]: 0 +[time]: 4.20356 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/distinct-numbers.cc b/cses/sorting-and-searching/distinct-numbers.cc new file mode 100644 index 0000000..aa80810 --- /dev/null +++ b/cses/sorting-and-searching/distinct-numbers.cc @@ -0,0 +1,162 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +#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; + ll x; + ll ans = 0; + set seen; + while (n--) { + cin >> x; + if (seen.find(x) == seen.end()) + ++ans; + seen.insert(x); + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/distinct-numbers.in b/cses/sorting-and-searching/distinct-numbers.in new file mode 100644 index 0000000..2f697a1 --- /dev/null +++ b/cses/sorting-and-searching/distinct-numbers.in @@ -0,0 +1,2 @@ +5 +2 3 2 2 3 diff --git a/cses/sorting-and-searching/distinct-numbers.out b/cses/sorting-and-searching/distinct-numbers.out new file mode 100644 index 0000000..bb9171a --- /dev/null +++ b/cses/sorting-and-searching/distinct-numbers.out @@ -0,0 +1,4 @@ +2 + +[code]: 0 +[time]: 11.4255 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/ferris-wheel.cc b/cses/sorting-and-searching/ferris-wheel.cc new file mode 100644 index 0000000..7a4e8b0 --- /dev/null +++ b/cses/sorting-and-searching/ferris-wheel.cc @@ -0,0 +1,68 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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, x; + cin >> n >> x; + vec a(n); + for (auto &e : a) + cin >> e; + sort(all(a)); + int l = 0, r = sz(a) - 1; + + ll ans = n; + while (l < r) { + if (a[l] + a[r] <= x) { + --ans; + ++l; + } + --r; + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/ferris-wheel.in b/cses/sorting-and-searching/ferris-wheel.in new file mode 100644 index 0000000..8d443f6 --- /dev/null +++ b/cses/sorting-and-searching/ferris-wheel.in @@ -0,0 +1,2 @@ +4 10 +7 2 3 9 diff --git a/cses/sorting-and-searching/ferris-wheel.out b/cses/sorting-and-searching/ferris-wheel.out new file mode 100644 index 0000000..3c9ade1 --- /dev/null +++ b/cses/sorting-and-searching/ferris-wheel.out @@ -0,0 +1,4 @@ +3 + +[code]: 0 +[time]: 11.009 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/maximum-subarray-sum.cc b/cses/sorting-and-searching/maximum-subarray-sum.cc new file mode 100644 index 0000000..9f7f49f --- /dev/null +++ b/cses/sorting-and-searching/maximum-subarray-sum.cc @@ -0,0 +1,66 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +ll n; +void solve() { + cin >> n; + vec a(n); + for (auto& e : a) + cin >> e; + + ll ans = a[0]; + ll cur = a[0]; + + for (int i = 1; i < n; ++i) { + cur = max(cur + a[i], a[i]); + ans = max(ans, cur); + } + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/maximum-subarray-sum.in b/cses/sorting-and-searching/maximum-subarray-sum.in new file mode 100644 index 0000000..d1963e8 --- /dev/null +++ b/cses/sorting-and-searching/maximum-subarray-sum.in @@ -0,0 +1,2 @@ +8 +-1 3 -2 5 3 -5 2 2 diff --git a/cses/sorting-and-searching/maximum-subarray-sum.out b/cses/sorting-and-searching/maximum-subarray-sum.out new file mode 100644 index 0000000..5191ae6 --- /dev/null +++ b/cses/sorting-and-searching/maximum-subarray-sum.out @@ -0,0 +1,4 @@ +9 + +[code]: 0 +[time]: 11.0552 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/missing-coin-sum.cc b/cses/sorting-and-searching/missing-coin-sum.cc new file mode 100644 index 0000000..f2b9c06 --- /dev/null +++ b/cses/sorting-and-searching/missing-coin-sum.cc @@ -0,0 +1,66 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +int n; +void solve() { + cin >> n; + vec a(n); + for (auto& e : a) + cin >> e; + sort(all(a)); + ll ans = 1; + + for (auto x : a) { + if (x > ans) { + break; + } + ans += x; + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/missing-coin-sum.in b/cses/sorting-and-searching/missing-coin-sum.in new file mode 100644 index 0000000..dd42c74 --- /dev/null +++ b/cses/sorting-and-searching/missing-coin-sum.in @@ -0,0 +1,2 @@ +5 +2 9 1 2 7 diff --git a/cses/sorting-and-searching/missing-coin-sum.out b/cses/sorting-and-searching/missing-coin-sum.out new file mode 100644 index 0000000..faba003 --- /dev/null +++ b/cses/sorting-and-searching/missing-coin-sum.out @@ -0,0 +1,4 @@ +6 + +[code]: 0 +[time]: 12.3503 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/movie-festival.cc b/cses/sorting-and-searching/movie-festival.cc new file mode 100644 index 0000000..3d58027 --- /dev/null +++ b/cses/sorting-and-searching/movie-festival.cc @@ -0,0 +1,70 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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); + for (auto& [A, b] : a) + cin >> A >> b; + sort(all(a), [](auto& l, auto& r) { + return l.ss < r.ss; + }); + + ll t = a[0].ss; + ll ans = 1; + for (auto& [l, r] : a) { + if (l < t) { + continue; + } + t = r; + ++ans; + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/movie-festival.in b/cses/sorting-and-searching/movie-festival.in new file mode 100644 index 0000000..908574e --- /dev/null +++ b/cses/sorting-and-searching/movie-festival.in @@ -0,0 +1,4 @@ +3 +3 5 +4 9 +5 8 diff --git a/cses/sorting-and-searching/movie-festival.out b/cses/sorting-and-searching/movie-festival.out new file mode 100644 index 0000000..4d38795 --- /dev/null +++ b/cses/sorting-and-searching/movie-festival.out @@ -0,0 +1,4 @@ +2 + +[code]: 0 +[time]: 11.569 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/restaurant-customers.cc b/cses/sorting-and-searching/restaurant-customers.cc new file mode 100644 index 0000000..5299d46 --- /dev/null +++ b/cses/sorting-and-searching/restaurant-customers.cc @@ -0,0 +1,74 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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> events(2 * n); + + for (int i = 0; i < 2 * n; i += 2) { + int x; + cin >> x; + events[i] = {x, 1}; + cin >> x; + events[i + 1] = {x, -1}; + } + + sort(all(events)); + + ll ans = 0, cum = 0; + + for (auto& [i, e] : events) { + cum += e; + ans = max(ans, cum); + } + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/restaurant-customers.in b/cses/sorting-and-searching/restaurant-customers.in new file mode 100644 index 0000000..494d1cd --- /dev/null +++ b/cses/sorting-and-searching/restaurant-customers.in @@ -0,0 +1,4 @@ +3 +5 8 +2 4 +3 9 diff --git a/cses/sorting-and-searching/restaurant-customers.out b/cses/sorting-and-searching/restaurant-customers.out new file mode 100644 index 0000000..56aa5d7 --- /dev/null +++ b/cses/sorting-and-searching/restaurant-customers.out @@ -0,0 +1,4 @@ +2 + +[code]: 0 +[time]: 11.1048 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/stick-lengths.cc b/cses/sorting-and-searching/stick-lengths.cc new file mode 100644 index 0000000..0ab83a7 --- /dev/null +++ b/cses/sorting-and-searching/stick-lengths.cc @@ -0,0 +1,64 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +int n; +void solve() { + cin >> n; + vec sticks(n); + for (auto& stick : sticks) + cin >> stick; + + sort(all(sticks)); + + ll median = sticks[sticks.size() / 2]; + + cout << accumulate(all(sticks), 0LL, [&](ll acc, ll i) { + return acc + abs(median - i); + }); +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/stick-lengths.in b/cses/sorting-and-searching/stick-lengths.in new file mode 100644 index 0000000..072b94d --- /dev/null +++ b/cses/sorting-and-searching/stick-lengths.in @@ -0,0 +1,2 @@ +5 +2 3 1 5 2 diff --git a/cses/sorting-and-searching/stick-lengths.out b/cses/sorting-and-searching/stick-lengths.out new file mode 100644 index 0000000..f1d9cef --- /dev/null +++ b/cses/sorting-and-searching/stick-lengths.out @@ -0,0 +1,3 @@ +5 +[code]: 0 +[time]: 11.8039 ms \ No newline at end of file diff --git a/cses/sorting-and-searching/sum-of-two-values.cc b/cses/sorting-and-searching/sum-of-two-values.cc new file mode 100644 index 0000000..ecb7be3 --- /dev/null +++ b/cses/sorting-and-searching/sum-of-two-values.cc @@ -0,0 +1,165 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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() +// }}} + +#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 + +int n; +ll target; +void solve() { + cin >> n >> target; + hashtable seen; + ll x; + for (int i = 0; i < n; ++i) { + cin >> x; + if (seen.find(target - x) != seen.end()) { + cout << i + 1 << ' ' << seen[target - x] + 1; + return; + } + seen[x] = i; + } + + cout << "IMPOSSIBLE\n"; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + solve(); + + return 0; +} +// }}} diff --git a/cses/sorting-and-searching/sum-of-two-values.in b/cses/sorting-and-searching/sum-of-two-values.in new file mode 100644 index 0000000..a5153fc --- /dev/null +++ b/cses/sorting-and-searching/sum-of-two-values.in @@ -0,0 +1,2 @@ +4 8 +2 7 5 1 diff --git a/cses/sorting-and-searching/sum-of-two-values.out b/cses/sorting-and-searching/sum-of-two-values.out new file mode 100644 index 0000000..e6cf939 --- /dev/null +++ b/cses/sorting-and-searching/sum-of-two-values.out @@ -0,0 +1,3 @@ +4 2 +[code]: 0 +[time]: 12.1336 ms \ No newline at end of file diff --git a/kattis/25-2-2025/.clang-format b/kattis/25-2-2025/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/kattis/25-2-2025/.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/kattis/25-2-2025/.clangd b/kattis/25-2-2025/.clangd new file mode 100644 index 0000000..4f8ead9 --- /dev/null +++ b/kattis/25-2-2025/.clangd @@ -0,0 +1,8 @@ +CompileFlags: + Add: + - -Wall + - -Wextra + - -Wpedantic + - -Wshadow + - -DLOCAL + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/kattis/25-2-2025/choosing-numbers.cc b/kattis/25-2-2025/choosing-numbers.cc new file mode 100644 index 0000000..6ac3f11 --- /dev/null +++ b/kattis/25-2-2025/choosing-numbers.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 +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); +} + +#ifdef LOCAL +#define dbgln(...) prln(...) +#define dbg(...) pr(...) +#endif + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + while (cin >> n) { + vec a(n); + for (auto& e : a) cin >> e; + + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/kattis/25-2-2025/choosing-numbers.in b/kattis/25-2-2025/choosing-numbers.in new file mode 100644 index 0000000..e69de29 diff --git a/kattis/25-2-2025/choosing-numbers.out b/kattis/25-2-2025/choosing-numbers.out new file mode 100644 index 0000000..e69de29 diff --git a/kattis/25-2-2025/compile_flags.txt b/kattis/25-2-2025/compile_flags.txt new file mode 100644 index 0000000..504aea8 --- /dev/null +++ b/kattis/25-2-2025/compile_flags.txt @@ -0,0 +1,6 @@ +-Wall +-Wextra +-Wpedantic +-Wshadow +-DLOCAL +-std=c++23 diff --git a/kattis/25-2-2025/hitting-targets.cc b/kattis/25-2-2025/hitting-targets.cc new file mode 100644 index 0000000..f4e525c --- /dev/null +++ b/kattis/25-2-2025/hitting-targets.cc @@ -0,0 +1,88 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 m; + cin >> m; + string s; + vec> recs, circs; + while (m--) { + cin >> s; + ld x1, y1, x2, y2, h, k, r; + if (s[0] == 'r') { + cin >> x1 >> y1 >> x2 >> y2; + recs.pb({x1, y1, x2, y2}); + } else { + cin >> h >> k >> r; + circs.pb({h, k, r}); + } + } + int shots; + cin >> shots; + ld x, y; + while (shots--) { + cin >> x >> y; + ll ans = 0; + for (auto &r : recs) { + if (y >= r[1] && y <= r[3] && x >= r[0] && x <= r[2]) + ++ans; + } + for (auto &c : circs) { + if (sqrtl(powl(x - c[0], 2) + powl(y - c[1], 2)) <= c[2]) { + ++ans; + } + } + cout << ans << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/kattis/25-2-2025/hitting-targets.in b/kattis/25-2-2025/hitting-targets.in new file mode 100644 index 0000000..d54306a --- /dev/null +++ b/kattis/25-2-2025/hitting-targets.in @@ -0,0 +1,10 @@ +3 +rectangle 1 1 10 5 +circle 5 0 8 +rectangle -5 3 5 8 +5 +1 1 +4 5 +10 10 +-10 -1 +4 -3 diff --git a/kattis/25-2-2025/hitting-targets.out b/kattis/25-2-2025/hitting-targets.out new file mode 100644 index 0000000..419e8c9 --- /dev/null +++ b/kattis/25-2-2025/hitting-targets.out @@ -0,0 +1,8 @@ +2 +3 +0 +0 +1 + +[code]: 0 +[time]: 12.0492 ms \ No newline at end of file diff --git a/kattis/25-2-2025/quite-a-problem.cc b/kattis/25-2-2025/quite-a-problem.cc new file mode 100644 index 0000000..2936e22 --- /dev/null +++ b/kattis/25-2-2025/quite-a-problem.cc @@ -0,0 +1,65 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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; + string problem = "problem"; + while (getline(cin, s)) { + transform(all(s), s.begin(), [](char c) { + return std::tolower(c); + }); + + cout << (s.find(problem) != string::npos ? "yes" : "no") << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/kattis/25-2-2025/quite-a-problem.in b/kattis/25-2-2025/quite-a-problem.in new file mode 100644 index 0000000..c43e12c --- /dev/null +++ b/kattis/25-2-2025/quite-a-problem.in @@ -0,0 +1,17 @@ +Problematic pair programming +"There's a joke that pairs, like fish and house guests, go +rotten after three days," said Zach Brock, an engineering +manager. Working out problems with a pairing partner can be +a lot like working out problems with a significant other. +During one recent rough patch, Jamie Kite, a developer, sat +her partner down for a talk. "Hey, it feels like we're +driving in different directions," she recalls saying. "It's +like any relationship," Ms. Kite said. "If you don't talk +about the problems, it's not going to work." When those +timeouts don't solve the problem, partners can turn to +on-staff coaches who can help with counseling. "People who +have been pairing a while, they'll start acting like old +married couples," said Marc Phillips, one of the coaches. +People can be as much of a challenge as writing software. +(Excerpted from "Computer Programmers Learn Tough Lesson in +Sharing"; Wall Street Journal, August 27, 2012) diff --git a/kattis/25-2-2025/quite-a-problem.out b/kattis/25-2-2025/quite-a-problem.out new file mode 100644 index 0000000..1565807 --- /dev/null +++ b/kattis/25-2-2025/quite-a-problem.out @@ -0,0 +1,20 @@ +yes +no +no +yes +yes +no +no +no +no +yes +yes +no +no +no +no +no +no + +[code]: 0 +[time]: 11.6799 ms \ No newline at end of file diff --git a/kattis/25-2-2025/ragged-right.cc b/kattis/25-2-2025/ragged-right.cc new file mode 100644 index 0000000..46b80d6 --- /dev/null +++ b/kattis/25-2-2025/ragged-right.cc @@ -0,0 +1,70 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 line; + vec lengths; + while (getline(cin, line)) { + lengths.eb(sz(line)); + } + + ll ans = 0; + ll large = *max_element(all(lengths)); + lengths.pop_back(); + for (auto l : lengths) { + ans += (large - l) * (large - l); + } + + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/kattis/25-2-2025/ragged-right.in b/kattis/25-2-2025/ragged-right.in new file mode 100644 index 0000000..04b291c --- /dev/null +++ b/kattis/25-2-2025/ragged-right.in @@ -0,0 +1,5 @@ +some blocks +of text line up +well on the right, +but +some don't. diff --git a/kattis/25-2-2025/ragged-right.out b/kattis/25-2-2025/ragged-right.out new file mode 100644 index 0000000..bdc6681 --- /dev/null +++ b/kattis/25-2-2025/ragged-right.out @@ -0,0 +1,4 @@ +283 + +[code]: 0 +[time]: 11.2939 ms \ No newline at end of file diff --git a/kattis/25-2-2025/unicycle-counting.cc b/kattis/25-2-2025/unicycle-counting.cc new file mode 100644 index 0000000..7672fd9 --- /dev/null +++ b/kattis/25-2-2025/unicycle-counting.cc @@ -0,0 +1,135 @@ +#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()); +} + +using ll = long long; +using ld = long double; +template +using vec = std::vector; +template +using arr = std::array; + +#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 line; + + while (getline(cin, line)) { + istringstream iss(line); + ll m, n; + iss >> m >> n; + ll x; + vector tires; + vector has(m + 1, false); + + while (n--) { + iss >> x; + tires.push_back(x); + has[x] = true; + } + + ll ans = 0; + ll i = 0; + + while (i < tires.size()) { + while (i < tires.size() && !has[tires[i]]) { + i++; + } + + if (i >= tires.size()) { + break; + } + + if (i == tires.size() - 1) { + ++ans; + break; + } + + ll best_count = 0; + ll best_delta = 0; + + for (int advance = i + 1; advance < tires.size(); ++advance) { + ll count = 0; + ll delta = tires[advance] - tires[i]; + ll cur = tires[i]; + bool bad = false; + + while (cur <= m - 1) { + if (has[cur]) { + ++count; + } else { + bad = true; + break; + } + cur += delta; + } + + if (bad) { + continue; + } + + if (count > best_count) { + best_count = count; + best_delta = delta; + } + } + + if (best_delta == 0) { + has[tires[i]] = false; + ++ans; + continue; + } + + ll cur = tires[i]; + while (cur <= m - 1) { + has[cur] = false; + cur += best_delta; + } + + ++ans; + } + + cout << ans << endl; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + + int t = 1; + // cin >> t; + + while (t--) { + solve(); + } + + return 0; +} +// }}} diff --git a/kattis/25-2-2025/unicycle-counting.in b/kattis/25-2-2025/unicycle-counting.in new file mode 100644 index 0000000..6f38400 --- /dev/null +++ b/kattis/25-2-2025/unicycle-counting.in @@ -0,0 +1 @@ +6 5 1 2 3 4 5 diff --git a/kattis/25-2-2025/unicycle-counting.out b/kattis/25-2-2025/unicycle-counting.out new file mode 100644 index 0000000..3f07fa5 --- /dev/null +++ b/kattis/25-2-2025/unicycle-counting.out @@ -0,0 +1,5 @@ +removing: 1 w/ delta 1 +1 + +[code]: 0 +[time]: 4.21095 ms \ No newline at end of file