diff --git a/.gitignore b/.gitignore index 1bbf0d0..a89a5ff 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.debug *.run *.su +build diff --git a/codeforces/944/.clang-format b/codeforces/944/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/944/.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/944/.clangd b/codeforces/944/.clangd new file mode 100644 index 0000000..4c67c32 --- /dev/null +++ b/codeforces/944/.clangd @@ -0,0 +1,27 @@ +CompileFlags: + Add: + - -std=c++20 + - -Wall + - -Wextra + - -Wshadow + - -Wnon-virtual-dtor + - -Wold-style-cast + - -Wcast-align + - -Wunused + - -Woverloaded-virtual + - -Wpedantic + - -Wconversion + - -Wsign-conversion + - -Wmisleading-indentation + - -Wduplicated-cond + - -Wduplicated-branches + - -Wlogical-op + - -Wnull-dereference + - -Wuseless-cast + - -Wformat=2 + - -Wformat-overflow + - -Wformat-truncation + - -Wdouble-promotion + - -Wundef + - -DLOCAL + - -Wno-unknown-pragmas \ No newline at end of file diff --git a/codeforces/944/a.cc b/codeforces/944/a.cc new file mode 100644 index 0000000..1bc3fde --- /dev/null +++ b/codeforces/944/a.cc @@ -0,0 +1,37 @@ +#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() { + i32 x, y; + cin >> x >> y; + cout << min(x, y) << ' ' << max(x, y) << '\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/944/a.in b/codeforces/944/a.in new file mode 100644 index 0000000..51d54a8 --- /dev/null +++ b/codeforces/944/a.in @@ -0,0 +1,11 @@ +10 +1 9 +8 4 +1 4 +3 4 +2 0 +2 4 +6 9 +3 3 +0 0 +9 9 diff --git a/codeforces/944/a.out b/codeforces/944/a.out new file mode 100644 index 0000000..23a96c7 --- /dev/null +++ b/codeforces/944/a.out @@ -0,0 +1,12 @@ +1 9 +4 8 +1 4 +3 4 +0 2 +2 4 +6 9 +3 3 +0 0 +9 9 + +[code]: 0 \ No newline at end of file diff --git a/codeforces/944/b.cc b/codeforces/944/b.cc new file mode 100644 index 0000000..7e0d9e6 --- /dev/null +++ b/codeforces/944/b.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() { + string s; + cin >> s; + for (u32 i = 1; i < s.size(); ++i) { + if (s[i] != s[0]) { + swap(s[i], s[0]); + cout << "YES\n" << s << '\n'; + return; + } + } + cout << "NO\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/944/b.in b/codeforces/944/b.in new file mode 100644 index 0000000..8f6e0fa --- /dev/null +++ b/codeforces/944/b.in @@ -0,0 +1,9 @@ +8 +codeforces +aaaaa +xxxxy +co +d +nutdealer +mwistht +hhhhhhhhhh diff --git a/codeforces/944/b.out b/codeforces/944/b.out new file mode 100644 index 0000000..db6f11f --- /dev/null +++ b/codeforces/944/b.out @@ -0,0 +1,15 @@ +YES +ocdeforces +NO +YES +yxxxx +YES +oc +NO +YES +untdealer +YES +wmistht +NO + +[code]: 0 \ No newline at end of file diff --git a/codeforces/944/c.cc b/codeforces/944/c.cc new file mode 100644 index 0000000..209604b --- /dev/null +++ b/codeforces/944/c.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, d; + cin >> a >> b >> c >> d; + i32 acc = 0; + for (u32 i = 1; i <= 12; ++i) { + if (i == a || i == b) + acc = (acc << 1) | 1; + else if (i == c || i == d) + acc <<= 1; + } + cout << ((acc == 0b1010 || acc == 0b0101) ? "YES" : "NO") << '\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/944/c.in b/codeforces/944/c.in new file mode 100644 index 0000000..aa7e165 --- /dev/null +++ b/codeforces/944/c.in @@ -0,0 +1,16 @@ +15 +2 9 10 6 +3 8 9 1 +1 2 3 4 +5 3 4 12 +1 8 2 10 +3 12 11 8 +9 10 12 1 +12 1 10 2 +3 12 6 9 +1 9 8 4 +6 7 9 12 +7 12 9 6 +10 12 11 1 +3 9 6 12 +1 4 3 5 diff --git a/codeforces/944/c.out b/codeforces/944/c.out new file mode 100644 index 0000000..11cfba0 --- /dev/null +++ b/codeforces/944/c.out @@ -0,0 +1,17 @@ +YES +NO +NO +YES +YES +NO +NO +NO +NO +NO +NO +YES +YES +YES +YES + +[code]: 0 \ No newline at end of file diff --git a/codeforces/944/compile_flags.txt b/codeforces/944/compile_flags.txt new file mode 100644 index 0000000..6d76ca1 --- /dev/null +++ b/codeforces/944/compile_flags.txt @@ -0,0 +1,24 @@ +-std=c++20 +-Wall +-Wextra +-Wshadow +-Wnon-virtual-dtor +-Wold-style-cast +-Wcast-align +-Wunused +-Woverloaded-virtual +-Wpedantic +-Wconversion +-Wsign-conversion +-Wmisleading-indentation +-Wduplicated-cond +-Wduplicated-branches +-Wlogical-op +-Wnull-dereference +-Wuseless-cast +-Wformat=2 +-Wformat-overflow +-Wformat-truncation +-Wdouble-promotion +-Wundef +-DLOCAL diff --git a/codeforces/944/d.cc b/codeforces/944/d.cc new file mode 100644 index 0000000..b4677f8 --- /dev/null +++ b/codeforces/944/d.cc @@ -0,0 +1,43 @@ +#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 s; + cin >> s; + u32 ans = 0; + bool found = false; + for (u32 i = 0; i < s.size() - 1; ++i) { + ans += s[i] != s[i + 1]; + found |= s[i] == '0' && s[i + 1] == '1'; + } + cout << ans + 1 - found << '\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/944/d.in b/codeforces/944/d.in new file mode 100644 index 0000000..6836ffb --- /dev/null +++ b/codeforces/944/d.in @@ -0,0 +1,7 @@ +6 +11010 +00000000 +1 +10 +0001111 +01010 diff --git a/codeforces/944/d.out b/codeforces/944/d.out new file mode 100644 index 0000000..aad8f83 --- /dev/null +++ b/codeforces/944/d.out @@ -0,0 +1,8 @@ +3 +1 +1 +2 +1 +4 + +[code]: 0 diff --git a/codeforces/944/e.cc b/codeforces/944/e.cc new file mode 100644 index 0000000..30728f9 --- /dev/null +++ b/codeforces/944/e.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; + +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 n; + u32 k, q; + cin >> n >> k >> q; + vector a(k + 1, 0), b(k + 1, 0); + for (u32 i = 0; i < k; ++i) { + cin >> a[i + 1]; + } + for (u32 i = 0; i < k; ++i) { + cin >> b[i + 1]; + } + u64 d; + while (q--) { + cin >> d; + auto it = lower_bound(a.begin(), a.end(), d); + u64 dist = distance(a.begin(), it); + u64 ans = b[dist]; + if (d < *it) { + ans = b[dist - 1] + + (d - a[dist - 1]) * (b[dist] - b[dist - 1]) / (*it - *prev(it)); + } + cout << ans << ' '; + } + 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/944/e.in b/codeforces/944/e.in new file mode 100644 index 0000000..3e91c5c --- /dev/null +++ b/codeforces/944/e.in @@ -0,0 +1,24 @@ +4 +10 1 3 +10 +10 +0 +6 +7 +10 2 4 +4 10 +4 7 +6 +4 +2 +7 +1000000000 1 1 +1000000000 +1000000000 +99999999 +6 1 3 +6 +5 +2 +6 +5 diff --git a/codeforces/944/e.out b/codeforces/944/e.out new file mode 100644 index 0000000..634f462 --- /dev/null +++ b/codeforces/944/e.out @@ -0,0 +1,6 @@ +0 6 7 +5 4 2 5 +99999999 +1 5 4 + +[code]: 0 \ No newline at end of file diff --git a/codeforces/944/makefile b/codeforces/944/makefile new file mode 100644 index 0000000..e454976 --- /dev/null +++ b/codeforces/944/makefile @@ -0,0 +1,95 @@ +.PHONY: run debug clean setup init + +CXX = g++ +# lefticus.gitbooks.io/cpp-best-practice +CXXFLAGS := -O2 -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 \ + -Wfloat-equal -Wlogical-op -Wshift-overflow=2 -Wnon-virtual-dtor \ + -Wold-style-cast -Wcast-equal -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 + +# https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags +DEBUG_CXX_FLAGS := -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 + +DEBUG_CXXFLAGS += -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC + +SRC = $(word 2,$(MAKECMDGOALS)) +BASE = $(basename $(SRC)) +INPUT = $(BASE).in +OUTPUT = $(BASE).out +RUN_BIN = $(BASE).run +DBG_BIN = $(BASE).debug + +TEMPLATE_DIR = ~/.config/cp-template + +.SILENT: + +run: $(RUN_BIN) + $(call execute_binary,$(RUN_BIN)) + +debug: $(DBG_BIN) + $(call execute_binary,$(DBG_BIN)) + +$(RUN_BIN): $(SRC) + test -f $@ && rm $@ || true + $(CXX) @compile_flags.txt $(SRC) -o $@ 2>$(OUTPUT); \ + CODE=$$?; \ + if [ $${CODE} -gt 0 ]; then \ + printf '\n[code]: %s' $${CODE} >>$(OUTPUT); \ + exit $${CODE}; \ + else \ + echo '' >$(OUTPUT); \ + fi + +$(DBG_BIN): $(SRC) + test -f $@ && rm $@ || true + $(CXX) @compile_flags.txt $(DEBUG_CXX_FLAGS) $(SRC) -o $@ 2>$(OUTPUT); \ + CODE=$$?; \ + if [ $${CODE} -gt 0 ]; then \ + printf '\n[code]: %s' $${CODE} >>$(OUTPUT); \ + exit $${CODE}; \ + else \ + echo '' >$(OUTPUT); \ + fi + +define execute_binary + timeout 2s ./$1 < $(INPUT) >$(OUTPUT) 2>&1; \ + CODE=$$?; \ + 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; \ + [ -n "$${MSG}" ] && printf '\n[code]: %s (%s)' "$${CODE}" "$${MSG}" >>$(OUTPUT); \ + else \ + printf '\n[code]: %s' $${CODE} >>$(OUTPUT); \ + fi +endef + +clean: + find . -type f -name "*.run" -o -name "*.debug" -o -name "*.su" | xargs rm -f + +setup: + test -f compile_flags.txt || cp $(TEMPLATE_DIR)/compile_flags.txt . + test -f .clangd || cp $(TEMPLATE_DIR)/.clangd . + test -f .clang-format || cp $(TEMPLATE_DIR)/.clang-format . + +init: + make setup + +%: + @: