diff --git a/codeforces/937/.clang-format b/codeforces/937/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/937/.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/937/.clangd b/codeforces/937/.clangd new file mode 100644 index 0000000..5b59a31 --- /dev/null +++ b/codeforces/937/.clangd @@ -0,0 +1,34 @@ +CompileFlags: + Add: + -O2 + -Wall + -Wextra + -Wpedantic + -Wshadow + -Wformat=2 + -Wfloat-equal + -Wlogical-op + -Wshift-overflow=2 + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-qual + -Wuseless-cast + -Wno-sign-promotion + -Wcast-align + -Wunused + -Woverloaded-virtual + -Wconversion + -Wsign-conversion + -Wmisleading-indentation + -Wduplicated-cond + -Wduplicated-branches + -Wlogical-op + -Wnull-dereference + -Wformat=2 + -Wformat-overflow + -Wformat-truncation + -Wdouble-promotion + -Wundef + -DLOCAL + -std=c++20 + -Wno-unknown-pragmas diff --git a/codeforces/937/a.cc b/codeforces/937/a.cc new file mode 100644 index 0000000..1999f16 --- /dev/null +++ b/codeforces/937/a.cc @@ -0,0 +1,44 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; +// }}} + +void solve() { + u32 a, b, c; + cin >> a >> b >> c; + if (a < b && b < c) { + cout << "STAIR"; + } else if (a < b && b > c) { + cout << "PEAK"; + } else { + cout << "NONE"; + } + cout << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/937/b.cc b/codeforces/937/b.cc new file mode 100644 index 0000000..5523ddc --- /dev/null +++ b/codeforces/937/b.cc @@ -0,0 +1,54 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; +// }}} + +void solve() { + u32 n; + cin >> n; + + vector> board(2 * n, vector(2 * n, '.')); + for (u32 i = 0; i < n; ++i) { + for (u32 j = 0; j < n; ++j) { + if ((i & 1) == (j & 1)) { + board[2 * i][2 * j] = '#'; + board[2 * i + 1][2 * j] = '#'; + board[2 * i + 1][2 * j + 1] = '#'; + board[2 * i][2 * j + 1] = '#'; + } + } + } + for (auto& r : board) { + for (auto& c : r) { + cout << c; + } + cout << '\n'; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/937/c.cc b/codeforces/937/c.cc new file mode 100644 index 0000000..f0a339d --- /dev/null +++ b/codeforces/937/c.cc @@ -0,0 +1,55 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; +// }}} + +void solve() { + string time; + cin >> time; + u32 hour = stoi(time.substr(0, 2)); + u32 minute = stoi(time.substr(3, 2)); + + bool pm = hour >= 12; + if (hour > 12) { + hour %= 12; + } + if (hour == 0) { + hour = 12; + } + + if (hour < 10) { + cout << '0'; + } + cout << hour << ':'; + if (minute < 10) { + cout << '0'; + } + cout << minute << ' ' << (pm ? "PM" : "AM") << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/937/compile_flags.txt b/codeforces/937/compile_flags.txt new file mode 100644 index 0000000..af7fb72 --- /dev/null +++ b/codeforces/937/compile_flags.txt @@ -0,0 +1,31 @@ +-O2 +-Wall +-Wextra +-Wpedantic +-Wshadow +-Wformat=2 +-Wfloat-equal +-Wlogical-op +-Wshift-overflow=2 +-Wnon-virtual-dtor +-Wold-style-cast +-Wcast-qual +-Wuseless-cast +-Wno-sign-promotion +-Wcast-align +-Wunused +-Woverloaded-virtual +-Wconversion +-Wsign-conversion +-Wmisleading-indentation +-Wduplicated-cond +-Wduplicated-branches +-Wlogical-op +-Wnull-dereference +-Wformat=2 +-Wformat-overflow +-Wformat-truncation +-Wdouble-promotion +-Wundef +-DLOCAL +-std=c++20 diff --git a/codeforces/937/d.cc b/codeforces/937/d.cc new file mode 100644 index 0000000..495a178 --- /dev/null +++ b/codeforces/937/d.cc @@ -0,0 +1,171 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; +// }}} + +#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 + +hashtable seen; +bitset<100000 + 1> dp; + +void solve() { + u64 n; + cin >> n; + + if (seen.find(n) != seen.end()) { + cout << "YES\n"; + } else + cout << "NO\n"; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + dp[1] = true; + seen.insert(1); + + vector binaries; + for (u64 i = 1; i <= 100000; ++i) { + u64 I = i; + bool good = true; + while (I) { + if (I % 10 > 1) { + good = false; + break; + } + I /= 10; + } + + if (good) + binaries.push_back(i); + } + + for (u64 bin : binaries) { + for (u64 j = 1; j * bin <= 100000; ++j) { + if (dp[j]) { + dp[j * bin] = true; + seen.insert(j * bin); + } + } + } + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/937/debug_flags.txt b/codeforces/937/debug_flags.txt new file mode 100644 index 0000000..03cba1b --- /dev/null +++ b/codeforces/937/debug_flags.txt @@ -0,0 +1,12 @@ +-g3 +-fsanitize=address,undefined +-fsanitize=float-divide-by-zero +-fsanitize=float-cast-overflow +-fno-sanitize-recover=all +-fstack-protector-all +-fstack-usage +-fno-omit-frame-pointer +-fno-inline +-ffunction-sections +-D_GLIBCXX_DEBUG +-D_GLIBCXX_DEBUG_PEDANTIC diff --git a/codeforces/937/e.cc b/codeforces/937/e.cc new file mode 100644 index 0000000..fd81a12 --- /dev/null +++ b/codeforces/937/e.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; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; +// }}} + +void solve() { + u32 n; + cin >> n; + string s; + cin >> s; + u64 ans = n; + for (u32 i = 1; i < n; ++i) { + if (n % i) { + continue; + } + unordered_map seen; + bool bad = false; + for (u32 j = 0; j < n; j += i) { + ++seen[s.substr(j, i)]; + if (seen.size() > 2) { + bad = true; + break; + } + } + if (bad) + continue; + if (seen.size() == 1) { + ans = i; + break; + } else if (seen.size() == 2) { + int first = seen.begin()->second, second = next(seen.begin())->second; + int diff = 0; + for (u32 j = 0; j < seen.begin()->first.size(); ++j) { + diff += seen.begin()->first[j] != next(seen.begin())->first[j]; + } + if ((first == 1 || second == 1) && diff <= 1) { + ans = i; + break; + } + } + } + cout << ans << endl; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/937/f.cc b/codeforces/937/f.cc new file mode 100644 index 0000000..8b77fb3 --- /dev/null +++ b/codeforces/937/f.cc @@ -0,0 +1,73 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; +// }}} + +void solve() { + u64 a, b, c; + cin >> a >> b >> c; + + u64 depth = 0; + u64 to_take = 1; + + // NOTE :look at prev wrong submissions; full tree assumptions, when u can + // have b on last layer this should be oe of ur first observatoins + while (to_take && (a > 0 || b > 0 || c > 0)) { + ++depth; + u64 next_to_take = 0; + + auto take = min(a, to_take); + a -= take; + next_to_take = 2 * take; + to_take -= take; + + take = min(b, to_take); + b -= take; + to_take -= take; + next_to_take += take; + + take = min(c, to_take); + c -= take; + to_take -= take; + + if (to_take != 0) { + cout << -1 << '\n'; + return; + } + + to_take = next_to_take; + } + + if (to_take > 0 || a > 0 || b > 0 || c > 0) { + cout << -1 << '\n'; + } else { + cout << depth - 1 << '\n'; + } +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/937/io/a.in b/codeforces/937/io/a.in new file mode 100644 index 0000000..2a59631 --- /dev/null +++ b/codeforces/937/io/a.in @@ -0,0 +1,8 @@ +7 +1 2 3 +3 2 1 +1 5 3 +3 4 1 +0 0 0 +4 1 7 +4 5 7 diff --git a/codeforces/937/io/a.out b/codeforces/937/io/a.out new file mode 100644 index 0000000..03bf546 --- /dev/null +++ b/codeforces/937/io/a.out @@ -0,0 +1,10 @@ +STAIR +NONE +PEAK +PEAK +NONE +NONE +STAIR + +[code]: 0 +[time]: 10.5526 ms diff --git a/codeforces/937/io/b.in b/codeforces/937/io/b.in new file mode 100644 index 0000000..4934959 --- /dev/null +++ b/codeforces/937/io/b.in @@ -0,0 +1,5 @@ +4 +1 +2 +3 +4 diff --git a/codeforces/937/io/b.out b/codeforces/937/io/b.out new file mode 100644 index 0000000..230211e --- /dev/null +++ b/codeforces/937/io/b.out @@ -0,0 +1,23 @@ +## +## +##.. +##.. +..## +..## +##..## +##..## +..##.. +..##.. +##..## +##..## +##..##.. +##..##.. +..##..## +..##..## +##..##.. +##..##.. +..##..## +..##..## + +[code]: 0 +[time]: 11.0681 ms \ No newline at end of file diff --git a/codeforces/937/io/c.in b/codeforces/937/io/c.in new file mode 100644 index 0000000..f1df236 --- /dev/null +++ b/codeforces/937/io/c.in @@ -0,0 +1,12 @@ +11 +09:41 +18:06 +12:14 +00:59 +00:00 +14:34 +01:01 +19:07 +11:59 +12:00 +21:37 diff --git a/codeforces/937/io/c.out b/codeforces/937/io/c.out new file mode 100644 index 0000000..57f20e7 --- /dev/null +++ b/codeforces/937/io/c.out @@ -0,0 +1,14 @@ +09:41 AM +06:06 PM +12:14 PM +12:59 AM +12:00 AM +02:34 PM +01:01 AM +07:07 PM +11:59 AM +12:00 PM +09:37 PM + +[code]: 0 +[time]: 4.08173 ms \ No newline at end of file diff --git a/codeforces/937/io/d.in b/codeforces/937/io/d.in new file mode 100644 index 0000000..f402b95 --- /dev/null +++ b/codeforces/937/io/d.in @@ -0,0 +1,12 @@ +11 +121 +1 +14641 +12221 +10110 +100000 +99 +112 +2024 +12421 +1001 diff --git a/codeforces/937/io/d.out b/codeforces/937/io/d.out new file mode 100644 index 0000000..e24ad61 --- /dev/null +++ b/codeforces/937/io/d.out @@ -0,0 +1,14 @@ +YES +YES +YES +YES +YES +YES +NO +NO +NO +NO +YES + +[code]: 0 +[time]: 12.0294 ms \ No newline at end of file diff --git a/codeforces/937/io/e.in b/codeforces/937/io/e.in new file mode 100644 index 0000000..fd643db --- /dev/null +++ b/codeforces/937/io/e.in @@ -0,0 +1,11 @@ +5 +4 +abaa +4 +abba +13 +slavicgslavic +8 +hshahaha +20 +stormflamestornflame diff --git a/codeforces/937/io/e.out b/codeforces/937/io/e.out new file mode 100644 index 0000000..a295413 --- /dev/null +++ b/codeforces/937/io/e.out @@ -0,0 +1,8 @@ +1 +4 +13 +2 +10 + +[code]: 0 +[time]: 12.5105 ms \ No newline at end of file diff --git a/codeforces/937/io/f.in b/codeforces/937/io/f.in new file mode 100644 index 0000000..f18b680 --- /dev/null +++ b/codeforces/937/io/f.in @@ -0,0 +1,2 @@ +1 +2 1 3 diff --git a/codeforces/937/io/f.out b/codeforces/937/io/f.out new file mode 100644 index 0000000..cc9e753 --- /dev/null +++ b/codeforces/937/io/f.out @@ -0,0 +1,4 @@ +2 + +[code]: 0 +[time]: 11.7621 ms \ No newline at end of file diff --git a/codeforces/937/makefile b/codeforces/937/makefile new file mode 100644 index 0000000..9c5450b --- /dev/null +++ b/codeforces/937/makefile @@ -0,0 +1,28 @@ +.PHONY: run debug clean setup init + +SRC = $(word 2,$(MAKECMDGOALS)) + +.SILENT: + +run: + sh scripts/run.sh $(SRC) + +debug: + sh scripts/debug.sh $(SRC) + +clean: + rm -rf build/* + +setup: + test -d build || mkdir -p build + test -d io || mkdir -p io + test -d scripts || mkdir -p scripts + test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . + test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . + test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format . + +init: + make setup + +%: + @: diff --git a/codeforces/937/scripts/debug.sh b/codeforces/937/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/937/scripts/debug.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. ./scripts/utils.sh + +SRC="$1" +BASE=$(basename "$SRC" .cc) +INPUT="${BASE}.in" +OUTPUT="${BASE}.out" +DBG_BIN="${BASE}.debug" + +test -d build || mkdir -p build +test -d io || mkdir -p io + +test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/" +test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/" + +test -f "io/$INPUT" || touch "io/$INPUT" +test -f "io/$OUTPUT" || touch "io/$OUTPUT" + +INPUT="io/$INPUT" +OUTPUT="io/$OUTPUT" +DBG_BIN="build/$DBG_BIN" + +compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt +CODE=$? +test $CODE -gt 0 && exit $CODE + +execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT" +exit $? diff --git a/codeforces/937/scripts/run.sh b/codeforces/937/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/937/scripts/run.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. ./scripts/utils.sh + +SRC="$1" +BASE=$(basename "$SRC" .cc) +INPUT="${BASE}.in" +OUTPUT="${BASE}.out" +RUN_BIN="${BASE}.run" + +test -d build || mkdir -p build +test -d io || mkdir -p io + +test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/" +test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/" + +test -f "io/$INPUT" || touch "io/$INPUT" +test -f "io/$OUTPUT" || touch "io/$OUTPUT" + +INPUT="io/$INPUT" +OUTPUT="io/$OUTPUT" +RUN_BIN="build/$RUN_BIN" + +compile_source "$SRC" "$RUN_BIN" "$OUTPUT" "" +CODE=$? +test $CODE -gt 0 && exit $CODE + +execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT" +exit $? diff --git a/codeforces/937/scripts/utils.sh b/codeforces/937/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/937/scripts/utils.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +execute_binary() { + binary="$1" + input="$2" + output="$3" + + start=$(date '+%s.%N') + timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + CODE=$? + end=$(date '+%s.%N') + truncate -s "$(head -n 1000 "$output" | wc -c)" "$output" + + if [ $CODE -ge 124 ]; then + MSG='' + case $CODE in + 124) MSG='TIMEOUT' ;; + 128) MSG='SIGILL' ;; + 130) MSG='SIGABRT' ;; + 131) MSG='SIGBUS' ;; + 136) MSG='SIGFPE' ;; + 135) MSG='SIGSEGV' ;; + 137) MSG='SIGPIPE' ;; + 139) MSG='SIGTERM' ;; + esac + [ $CODE -ne 124 ] && sed -i '$d' "$output" + test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output" + else + printf '\n[code]: %s' "$CODE" >>"$output" + fi + + printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output + return $CODE +} + +compile_source() { + src="$1" + bin="$2" + output="$3" + flags="$4" + + test -f "$bin" && rm "$bin" || true + g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output" + CODE=$? + + if [ $CODE -gt 0 ]; then + printf '\n[code]: %s' "$CODE" >>"$output" + return $CODE + else + echo '' >"$output" + return 0 + fi +}