Skip to content
Merged

Golf #207

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 44 additions & 23 deletions .github/workflows/programming_team_code_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,35 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up LLVM repository
- name: Install LLVM
run: |
sudo apt update
sudo apt install -y wget software-properties-common
wget -O - https://apt.llvm.org/llvm.sh | sudo bash
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
- name: Install dependencies
run: sudo apt update && sudo apt install -y clang-format-19 cppcheck
run: sudo apt install -y clang-format-22 cppcheck
- name: Verify
run: |
clang-22 --version
clang-format-22 --version
- name: grep, clang-format, cppcheck
run: make --directory=tests/ grep_clangformat_cppcheck

clangtidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up LLVM repository
- name: Install LLVM
run: |
sudo apt update
sudo apt install -y wget software-properties-common
wget -O - https://apt.llvm.org/llvm.sh | sudo bash
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
- name: Install dependencies
run: sudo apt update && sudo apt install -y clang-tidy-19
run: sudo apt install -y clang-tidy-22
- name: Verify
run: |
clang-22 --version
clang-tidy-22 --version
- name: clang-tidy
run: make --directory=tests/ clangtidy

Expand All @@ -70,10 +78,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up LLVM repository
run: wget -qO- https://apt.llvm.org/llvm.sh | sudo bash -s -- 19
- name: Install dependencies
run: sudo apt update && sudo apt install -y clang-19
- name: Install LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
- name: Verify
run: |
clang-22 --version
- name: g++ with clang
run: make --directory=tests/ compile_clang

Expand All @@ -88,12 +100,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install texlive, rename, nodejs, npm, clang
- name: Install texlive, rename, nodejs, npm
run: |
sudo apt update
sudo apt install texlive texlive-latex-extra rename nodejs npm
wget -qO- https://apt.llvm.org/llvm.sh | sudo bash -s -- 19
sudo apt update && sudo apt install -y clang-19
- name: Install LLVM
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
- name: Verify
run: |
clang-22 --version
- name: build pdf
run: make --directory=tests/ build_pdf
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -125,13 +142,17 @@ jobs:
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Set up LLVM repository
- name: Install LLVM
run: |
sudo apt update
sudo apt install -y wget software-properties-common
wget -O - https://apt.llvm.org/llvm.sh | sudo bash
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
- name: Install dependencies
run: sudo apt update && sudo apt install -y clang-format-19
run: sudo apt install -y clang-format-22 cppcheck
- name: Verify
run: |
clang-22 --version
clang-format-22 --version
- name: Combine includes and force push to main branch
run: |
git config --local user.name github-actions
Expand Down
2 changes: 1 addition & 1 deletion library/loops/chooses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
//! @time O(n choose k)
//! @space O(1)
for (int mask = (1 << k) - 1; mask < (1 << n);
mask = next_subset(mask))
mask = next_subset(mask))
2 changes: 1 addition & 1 deletion library/loops/submasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
//! of every mask of size n
//! @space O(1)
for (int submask = mask; submask;
submask = (submask - 1) & mask)
submask = (submask - 1) & mask)
2 changes: 1 addition & 1 deletion library/loops/supermasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
//! of every mask of size n
//! @space O(1)
for (int supermask = mask; supermask < (1 << n);
supermask = (supermask + 1) | mask)
supermask = (supermask + 1) | mask)
3 changes: 1 addition & 2 deletions library/math/matrix_related/solve_linear_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ struct solve_linear_mod {
rep(i, 0, n) mat[i].push_back(rhs[i]);
tie(rank, det) = row_reduce(mat, m);
if (any_of(rank + all(mat),
[](vi& v) { return v.back(); })) {
[](vi& v) { return v.back(); }))
return;
}
sol.resize(m);
int j = 0;
for_each(begin(mat), begin(mat) + rank, [&](vi& v) {
Expand Down
6 changes: 1 addition & 5 deletions library/trees/centroid_decomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ void centroid(auto& g, auto f) {
w = u, u = *big_ch;
}
f(u, p);
for (int v : g[u]) {
iter_swap(ranges::find(g[v], u), rbegin(g[v]));
g[v].pop_back();
dfs(dfs, v, u);
}
for (int v : g[u]) erase(g[v], u), dfs(dfs, v, u);
};
dfs(dfs, 0, -1);
}
9 changes: 4 additions & 5 deletions library/trees/edge_cd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ template<class G> void edge_cd(vector<G>& g, auto f) {
if (c != -1) return c;
siz[u] += siz[v];
}
return 2 * siz[u] > m
? p >= 0 && (siz[p] = m + 1 - siz[u]),
u : -1;
return 2 * siz[u] > m ? siz[p] = m + 1 - siz[u],
u : -1;
};
auto dfs = [&](auto&& dfs, int u, int m) -> void {
if (m < 2) return;
u = cent(cent, u, -1, m);
u = cent(cent, u, u, m);
int sum = 0;
auto it = partition(all(g[u]), [&](int v) {
ll x = sum + siz[v];
return x * x < m * (m - x) ? sum += siz[v], 1 : 0;
return x * x < m * (m - x) ? sum = x : 0;
});
f(u, it - begin(g[u]));
G oth(it, end(g[u]));
Expand Down
4 changes: 1 addition & 3 deletions library/trees/hld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ template<bool VALS_EDGES> struct HLD {
HLD(auto& g): n(sz(g)), p(n), siz(n, 1), rt(n), tin(n) {
auto dfs1 = [&](auto&& dfs1, int u) -> void {
for (int& v : g[u]) {
iter_swap(ranges::find(g[v], u), rbegin(g[v]));
g[v].pop_back();
p[v] = u;
erase(g[v], p[v] = u);
dfs1(dfs1, v);
siz[u] += siz[v];
if (siz[v] > siz[g[u][0]]) swap(v, g[u][0]);
Expand Down
4 changes: 1 addition & 3 deletions library/trees/shallowest_decomp_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ void shallowest(auto& g, auto f) {
for (const vi& vec : order | views::reverse)
for (int u : vec) {
f(u);
for (int v : g[u])
iter_swap(ranges::find(g[v], u), rbegin(g[v])),
g[v].pop_back();
for (int v : g[u]) erase(g[v], u);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,12 @@ int main() {
dfs(dfs, adj[cent][i], cent, {b[e_id], c[e_id]},
{b[e_id], c[e_id]}, i < split);
}
for (int side = 0; side < 2; side++) {
for (
auto [u, curr_b, curr_c] : all_backwards[side]) {
for (int side = 0; side < 2; side++)
for (auto [u, curr_b, curr_c] : all_backwards[side])
res[u] =
(res[u] + 1LL * curr_b * sum_forward[!side] +
1LL * curr_c * cnt_nodes[!side]) %
mod;
}
}
});
swap(base_adj, adj);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ int main() {
for (int i = 0; i < ssize(adj[v]); i++) {
int u = adj[v][i];
line curr_line = weight[v][i];
if (u != p) {
if (u != p)
self(self, u, v, compose(downwards, curr_line),
compose(curr_line, upwards), forwards);
}
}
};
for (int i = 0; i < ssize(adj[cent]); i++) {
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/clangtidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ git submodule init
git submodule update

find library_checker_aizu_tests/ -type f -name "*.test.cpp" |
parallel clang-tidy-19 --config-file=.config/.clang-tidy {} -- -std=c++20 ||
parallel clang-tidy-22 --config-file=.config/.clang-tidy {} -- -std=c++20 ||
exit 1
2 changes: 1 addition & 1 deletion tests/scripts/compile_clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ git submodule init
git submodule update

find library_checker_aizu_tests/ -type f -name "*.test.cpp" |
parallel clang++-19 {} "$(tr '\n' ' ' <.config/.clang_compile_flags)" -std=c++20
parallel clang++-22 {} "$(tr '\n' ' ' <.config/.clang_compile_flags)" -std=c++20
2 changes: 1 addition & 1 deletion tests/scripts/compile_commented_snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ echo "compiling code in @code ... @endcode comments with g++"
g++ -std=c++20 entire_library.cpp || exit 1

echo "compiling code in @code ... @endcode comments with clang++"
clang++-19 -std=c++20 entire_library.cpp || exit 1
clang++-22 -std=c++20 entire_library.cpp || exit 1
2 changes: 1 addition & 1 deletion tests/scripts/grep_clangformat_cppcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ find ../library/ library_checker_aizu_tests/ -name "*[A-Z]*" -or -name "*-*" |
grep --invert-match "README" &&
exit 1

clang-format-19 --dry-run --Werror --style=file:.config/dev.clang-format library_checker_aizu_tests/**/*.hpp library_checker_aizu_tests/**/*.test.cpp ../library/**/*.hpp ../library/**/*.cpp || exit 1
clang-format-22 --dry-run --Werror --style=file:.config/dev.clang-format library_checker_aizu_tests/**/*.hpp library_checker_aizu_tests/**/*.test.cpp ../library/**/*.hpp ../library/**/*.cpp || exit 1

git submodule init
git submodule update
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/update_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ done
sed --in-place '/^[[:space:]]*$/d' ../**/*.hpp

# cpp command messes up formatting
clang-format-19 -i --style=file:.config/main.clang-format ../**/*.hpp ../**/*.cpp
clang-format-22 -i --style=file:.config/main.clang-format ../**/*.hpp ../**/*.cpp
Loading