feat(cses); refactor structure

This commit is contained in:
Barrett Ruth 2025-04-18 21:59:45 -04:00
parent 446ad865d0
commit 3153490991
142 changed files with 1380 additions and 66 deletions

View file

@ -0,0 +1,9 @@
BasedOnStyle: Google
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false

34
codeforces/835/.clangd Normal file
View file

@ -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

40
codeforces/835/a.cc Normal file
View file

@ -0,0 +1,40 @@
#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 u4 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
// }}}
void solve() {
vector<i32> a(3);
for (u4 i = 0; i < 3; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
cout << a[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;
}
// }}}

43
codeforces/835/b.cc Normal file
View 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() {
u32 _;
cin >> _;
string s;
cin >> s;
i32 ans = 1;
for (auto c : s) {
ans = max(ans, c - 'a' + 1);
}
cout << ans << '\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;
}
// }}}

56
codeforces/835/c.cc Normal file
View file

@ -0,0 +1,56 @@
#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 u4 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
// }}}
void solve() {
u4 n;
cin >> n;
vector<i32> a(n);
for (auto& e : a)
cin >> e;
if (n == 1) {
cout << a[0] << '\n';
return;
}
vector<i32> ans(n);
auto copy = a;
sort(copy.begin(), copy.end());
auto big = copy.back(), big2 = copy[copy.size() - 2];
for (u4 i = 0; i < n; ++i) {
if (a[i] == big) {
ans[i] = a[i] - big2;
} else
ans[i] = a[i] - big;
}
for (auto e : ans)
cout << e << ' ';
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;
}
// }}}

View file

@ -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

51
codeforces/835/d.cc Normal file
View file

@ -0,0 +1,51 @@
#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 u4 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using f128 = long double;
// }}}
void solve() {
u4 n;
cin >> n;
vector<u4> a(n);
for (auto& e : a)
cin >> e;
u4 i = 0;
while (i < n - 1 && a[i] >= a[i + 1]) {
++i;
}
while (i < n - 1 && a[i] <= a[i + 1]) {
++i;
}
if (i == n - 1)
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;
for (int t = 0; t < tc; ++t) {
solve();
}
return 0;
}
// }}}

View file

@ -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

68
codeforces/835/e.cc Normal file
View file

@ -0,0 +1,68 @@
#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 n;
cin >> n;
vector<u32> a(n);
for (u32 i = 0; i < n; ++i) {
cin >> a[i];
}
vector<i64> prefix_one(n + 1, 0), postfix_zero(n + 2, 0);
for (u32 i = 0; i < n; ++i) {
prefix_one[i + 1] = (a[i] == 1) + prefix_one[i];
}
for (i32 i = n - 1; i >= 0; --i) {
postfix_zero[i + 1] = postfix_zero[i + 2] + (a[i] == 0);
}
postfix_zero[0] = postfix_zero[1];
i64 ans = 0;
for (u32 i = 0; i < n; ++i) {
if (a[i] == 1)
ans += postfix_zero[i + 2];
}
i64 init = ans;
for (u32 i = 0; i < n; ++i) {
if (a[i] == 0)
ans = max(ans, init + postfix_zero[i + 2] - prefix_one[i]);
else if (a[i] == 1)
ans = max(ans, init + prefix_one[i] - postfix_zero[i + 2]);
// } else { // NOTE: forgot 0->1 is possible
// }
}
cout << ans << '\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;
}
// }}}

67
codeforces/835/f.cc Normal file
View file

@ -0,0 +1,67 @@
#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() {
i64 n, c, d;
cin >> n >> c >> d;
vector<i64> a(n);
for (auto& e : a)
cin >> e;
sort(a.rbegin(), a.rend());
i64 low = 1, high = d + 2;
i64 ans = -1;
while (low <= high) {
i64 k = low + (high - low) / 2;
i64 total = 0;
for (i64 i = 0; i < d; ++i) {
total += a[i % k];
}
if (total >= c) {
ans = k;
low = k + 1;
} else {
high = k - 1;
}
}
if (low == 0) {
cout << "Impossible\n";
} else if (low == d + 1) {
cout << "Infinity\n";
} else {
cout << ans << '\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;
}
// }}}

94
codeforces/835/g.cc Normal file
View file

@ -0,0 +1,94 @@
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, a, b;
cin >> n >> a >> b;
vector<vector<pair<int, int>>> tree(n + 1);
for (int i = 0; i < n - 1; ++i) {
int u, v, w;
cin >> u >> v >> w;
tree[u].emplace_back(v, w);
tree[v].emplace_back(u, w);
}
unordered_set<int> xor_values;
vector<int> xor_a(n + 1, 0);
vector<bool> visited(n + 1, false);
bool found = false;
int target_xor = -1;
// First DFS to compute xor_a and check if direct a->b is 0
function<void(int, int)> dfs1 = [&](int u, int parent) {
visited[u] = true;
for (auto &[v, w] : tree[u]) {
if (v != parent && !visited[v]) {
xor_a[v] = xor_a[u] ^ w;
if (v == b) {
target_xor = xor_a[v];
if (target_xor == 0) {
found = true;
}
}
dfs1(v, u);
}
}
};
dfs1(a, -1);
if (found) {
cout << "YES\n";
return;
}
// Second DFS to collect xor values from a, excluding b
visited.assign(n + 1, false);
function<void(int, int)> dfs2 = [&](int u, int parent) {
visited[u] = true;
if (u != b) {
xor_values.insert(xor_a[u]);
}
for (auto &[v, w] : tree[u]) {
if (v != parent && !visited[v]) {
dfs2(v, u);
}
}
};
dfs2(a, -1);
// Third DFS to check if any node in b's subtree (or elsewhere) has xor_a[u]
// == target_xor
visited.assign(n + 1, false);
function<bool(int, int)> dfs3 = [&](int u, int parent) {
visited[u] = true;
if (u != a && u != b && xor_values.count(xor_a[u] ^ target_xor)) {
return true;
}
for (auto &[v, w] : tree[u]) {
if (v != parent && !visited[v]) {
if (dfs3(v, u)) {
return true;
}
}
}
return false;
};
if (dfs3(b, -1)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

35
codeforces/835/h.cc Normal file
View file

@ -0,0 +1,35 @@
#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() {
}
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;
}
// }}}

0
codeforces/835/io/.out Normal file
View file

10
codeforces/835/io/a.in Normal file
View file

@ -0,0 +1,10 @@
9
5 2 6
14 3 4
20 2 1
1 2 3
11 19 12
10 8 20
6 20 3
4 1 3
19 8 4

12
codeforces/835/io/a.out Normal file
View file

@ -0,0 +1,12 @@
5
4
2
2
12
10
6
3
8
[code]: 0
[time]: 4.3807 ms

11
codeforces/835/io/b.in Normal file
View file

@ -0,0 +1,11 @@
5
1
a
4
down
10
codeforces
3
bcf
5
zzzzz

8
codeforces/835/io/b.out Normal file
View file

@ -0,0 +1,8 @@
1
23
19
6
26
[code]: 0
[time]: 11.534 ms

11
codeforces/835/io/c.in Normal file
View file

@ -0,0 +1,11 @@
5
4
4 7 3 5
2
1 2
5
1 2 3 4 5
3
4 9 4
4
4 4 4 4

8
codeforces/835/io/c.out Normal file
View file

@ -0,0 +1,8 @@
-3 2 -4 -2
-1 1
-4 -3 -2 -1 1
-5 5 -5
0 0 0 0
[code]: 0
[time]: 4.1337 ms

13
codeforces/835/io/d.in Normal file
View file

@ -0,0 +1,13 @@
6
7
3 2 2 1 2 2 3
11
1 1 1 2 3 3 4 5 6 6 6
7
1 2 3 4 3 2 1
7
9 7 4 6 9 9 10
1
1000000000
8
9 4 4 5 9 4 9 10

9
codeforces/835/io/d.out Normal file
View file

@ -0,0 +1,9 @@
YES
YES
NO
YES
YES
NO
[code]: 0
[time]: 11.6994 ms

11
codeforces/835/io/e.in Normal file
View file

@ -0,0 +1,11 @@
5
4
1 0 1 0
6
0 1 0 0 1 0
2
0 0
8
1 0 1 1 0 0 0 1
3
1 1 1

8
codeforces/835/io/e.out Normal file
View file

@ -0,0 +1,8 @@
3
7
1
13
2
[code]: 0
[time]: 4.62437 ms

13
codeforces/835/io/f.in Normal file
View file

@ -0,0 +1,13 @@
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1

3
codeforces/835/io/f.out Normal file
View file

@ -0,0 +1,3 @@
[code]: 136 (SIGFPE)
[time]: 112.421 ms

14
codeforces/835/io/g.in Normal file
View file

@ -0,0 +1,14 @@
3
5 1 4
1 3 1
2 3 2
4 3 3
3 5 1
2 1 2
1 2 2
6 2 3
1 2 1
2 3 1
3 4 1
4 5 3
5 6 5

6
codeforces/835/io/g.out Normal file
View file

@ -0,0 +1,6 @@
YES
NO
YES
[code]: 0
[time]: 3.91221 ms

0
codeforces/835/io/h.in Normal file
View file

0
codeforces/835/io/h.out Normal file
View file

28
codeforces/835/makefile Normal file
View file

@ -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
%:
@:

View file

@ -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 $?

View file

@ -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 $?

View file

@ -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
}

View file

@ -43,8 +43,7 @@ void solve() {
to_take -= take; to_take -= take;
if (to_take != 0) { if (to_take != 0) {
cout << -1 << '\n'; break;
return;
} }
to_take = next_to_take; to_take = next_to_take;

View file

@ -20,4 +20,4 @@
..##..## ..##..##
[code]: 0 [code]: 0
[time]: 11.0681 ms [time]: 11.0681 ms

View file

@ -11,4 +11,4 @@
09:37 PM 09:37 PM
[code]: 0 [code]: 0
[time]: 4.08173 ms [time]: 4.08173 ms

View file

@ -11,4 +11,4 @@ NO
YES YES
[code]: 0 [code]: 0
[time]: 12.0294 ms [time]: 12.0294 ms

View file

@ -1,6 +1,31 @@
-O2
-Wall -Wall
-Wextra -Wextra
-Wpedantic -Wpedantic
-Wshadow -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 -DLOCAL
-std=c++20 -std=c++20

View file

@ -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

View file

@ -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
%:
@:

View file

@ -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 $?

View file

@ -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 $?

View file

@ -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
}

View file

@ -1,8 +1,34 @@
CompileFlags: CompileFlags:
Add: Add:
- -Wall -O2
- -Wextra -Wall
- -Wpedantic -Wextra
- -Wshadow -Wpedantic
- -DLOCAL -Wshadow
- -Wno-unknown-pragmas -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

View file

@ -1,6 +1,31 @@
-O2
-Wall -Wall
-Wextra -Wextra
-Wpedantic -Wpedantic
-Wshadow -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 -DLOCAL
-std=c++20 -std=c++20

View file

@ -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

Some files were not shown because too many files have changed in this diff Show more