feat(codeforces): 944
This commit is contained in:
parent
24744ab5c0
commit
c11932a0fb
20 changed files with 507 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
|||
*.debug
|
||||
*.run
|
||||
*.su
|
||||
build
|
||||
|
|
|
|||
9
codeforces/944/.clang-format
Normal file
9
codeforces/944/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: Google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
27
codeforces/944/.clangd
Normal file
27
codeforces/944/.clangd
Normal file
|
|
@ -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
|
||||
37
codeforces/944/a.cc
Normal file
37
codeforces/944/a.cc
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// 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;
|
||||
}
|
||||
// }}}
|
||||
11
codeforces/944/a.in
Normal file
11
codeforces/944/a.in
Normal file
|
|
@ -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
|
||||
12
codeforces/944/a.out
Normal file
12
codeforces/944/a.out
Normal file
|
|
@ -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
|
||||
44
codeforces/944/b.cc
Normal file
44
codeforces/944/b.cc
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// 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;
|
||||
}
|
||||
// }}}
|
||||
9
codeforces/944/b.in
Normal file
9
codeforces/944/b.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
8
|
||||
codeforces
|
||||
aaaaa
|
||||
xxxxy
|
||||
co
|
||||
d
|
||||
nutdealer
|
||||
mwistht
|
||||
hhhhhhhhhh
|
||||
15
codeforces/944/b.out
Normal file
15
codeforces/944/b.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
YES
|
||||
ocdeforces
|
||||
NO
|
||||
YES
|
||||
yxxxx
|
||||
YES
|
||||
oc
|
||||
NO
|
||||
YES
|
||||
untdealer
|
||||
YES
|
||||
wmistht
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
44
codeforces/944/c.cc
Normal file
44
codeforces/944/c.cc
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// 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;
|
||||
}
|
||||
// }}}
|
||||
16
codeforces/944/c.in
Normal file
16
codeforces/944/c.in
Normal file
|
|
@ -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
|
||||
17
codeforces/944/c.out
Normal file
17
codeforces/944/c.out
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
YES
|
||||
|
||||
[code]: 0
|
||||
24
codeforces/944/compile_flags.txt
Normal file
24
codeforces/944/compile_flags.txt
Normal file
|
|
@ -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
|
||||
43
codeforces/944/d.cc
Normal file
43
codeforces/944/d.cc
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// 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;
|
||||
}
|
||||
// }}}
|
||||
7
codeforces/944/d.in
Normal file
7
codeforces/944/d.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
6
|
||||
11010
|
||||
00000000
|
||||
1
|
||||
10
|
||||
0001111
|
||||
01010
|
||||
8
codeforces/944/d.out
Normal file
8
codeforces/944/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
3
|
||||
1
|
||||
1
|
||||
2
|
||||
1
|
||||
4
|
||||
|
||||
[code]: 0
|
||||
58
codeforces/944/e.cc
Normal file
58
codeforces/944/e.cc
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// 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<u64> 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;
|
||||
}
|
||||
// }}}
|
||||
|
||||
24
codeforces/944/e.in
Normal file
24
codeforces/944/e.in
Normal file
|
|
@ -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
|
||||
6
codeforces/944/e.out
Normal file
6
codeforces/944/e.out
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
0 6 7
|
||||
5 4 2 5
|
||||
99999999
|
||||
1 5 4
|
||||
|
||||
[code]: 0
|
||||
95
codeforces/944/makefile
Normal file
95
codeforces/944/makefile
Normal file
|
|
@ -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
|
||||
|
||||
%:
|
||||
@:
|
||||
Loading…
Add table
Add a link
Reference in a new issue