diff --git a/alg2pdf b/alg2pdf new file mode 100755 index 0000000000000000000000000000000000000000..8548db0312b28750914cd8ab6cab67a6e45fbbc0 --- /dev/null +++ b/alg2pdf @@ -0,0 +1,91 @@ +#!/bin/bash + +# Random temp file name +tex_file=$(mktemp) + +# Print the tex file header +cat<<EOF >$tex_file +\documentclass{article} +\usepackage{listings} +\usepackage[usenames,dvipsnames]{color} %% Allow color names +\usepackage[letterpaper, portrait, margin=1in]{geometry} + +%\lstdefinestyle{customasm}{ +% belowcaptionskip=1\baselineskip, +% xleftmargin=\parindent, +% language=C++, %% Change this to whatever you write in +% breaklines=true, %% Wrap long lines +% basicstyle=\footnotesize\ttfamily, +% commentstyle=\itshape\color{Gray}, +% stringstyle=\color{Black}, +% numberstyle=\color{Orange}, +% keywordstyle=\bfseries\color{OliveGreen}, +% identifierstyle=\color{blue}, +%} + +\definecolor{darkgreen}{rgb}{0,0.6,0} +\definecolor{darkpink}{rgb}{0.75,0.25,0.5} + +\lstdefinestyle{customasm}{ + language=[ISO]C++, + breaklines=true, %% Wrap long lines + keywordstyle=\color{blue}\bfseries, + commentstyle=\color{darkgreen}\textit, + stringstyle=\color{darkpink}\ttfamily, + basicstyle=\footnotesize\ttfamily\color{red}, + identifierstyle={\color{black}}, +% + literate=* + {;}{{{\color{black};}}}{1} + {.7}{{{\color{red}.7}}}{2},% +% +morekeywords={int32_t} +} + +\usepackage[colorlinks=true,linkcolor=blue]{hyperref} +\begin{document} +\tableofcontents + +EOF +# xleftmargin=-8em, + +past_dir_name="00" + +find . -type f \( -iname \*.cpp -o -iname \*.cu \) | + +# Change ./foo/bar.src to foo/bar.src +sed 's/^\..//' | + +# Loop through each file +while read i; do + + dir_name=`echo $i | awk -F '/' '{print $1}' | sed 's/_/\\\_/g'` + file_name=`echo $i | awk -F '/' '{print $2}' | sed 's/_/\\\_/g'` + + if [ "$dir_name" != "$past_dir_name" ]; then + + # Start new section + echo "\newpage" >> $tex_file + echo "\section{$dir_name}" >> $tex_file + else + echo "\\" >> $tex_file + fi + + # Create a section for each file + echo "\subsection{$file_name}" >> $tex_file + + # This command will include the file in the PDF + echo "\lstinputlisting[style=customasm]{$i}" >>$tex_file + + past_dir_name="$dir_name" + +done && + +echo "\end{document}" >> $tex_file && + +# This needs to be run twice for the TOC to be generated +pdflatex $tex_file -output-directory . && +pdflatex $tex_file -output-directory . + +mv tmp.pdf caderno.pdf +rm tmp.* diff --git a/contests/GYM_101492/K.cpp b/contests/GYM_101492/K.cpp new file mode 100644 index 0000000000000000000000000000000000000000..86fbaf578754089d83bd44408d38c1cc4f4cafb2 --- /dev/null +++ b/contests/GYM_101492/K.cpp @@ -0,0 +1,38 @@ +#include <bits/stdc++.h> + +#define MAX 0 +#define MOD 1000000007 +#define EPS 1e-6 +#define inf 0x3f3f3f3f +#define llinf 0x3f3f3f3f3f3f3f3f + +#define fi first +#define se second +#define sz size() +#define pb push_back +#define ende '\n' + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() +#define mset(x, y) memset(&x, (y), sizeof(x)) + +using namespace std; + +typedef long long ll; +typedef pair<int,int> ii; + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + int n; cin >> n; + ll ans = 1; + for (int i = 0; i < n + 1; ++i) + ans *= 2; + + cout << ans - 1 << ende; + + + + return 0; +} diff --git a/contests/GYM_101492/a.out b/contests/GYM_101492/a.out deleted file mode 100755 index a4b473e8015bfd52a1fb16903b06de6b96e6d49d..0000000000000000000000000000000000000000 Binary files a/contests/GYM_101492/a.out and /dev/null differ diff --git a/graph/lca.cpp b/graph/lca.cpp index bd50708d94d59d3610f42e95a57fce2edde99be8..77b874c8a7a04701ad82bf75028e39ccef8fe3a0 100644 --- a/graph/lca.cpp +++ b/graph/lca.cpp @@ -11,21 +11,22 @@ * *** = used in both * and ** */ -vector<ii> graph[MAX]; +vector<int> graph[MAX]; //*** vector<ii> int h[MAX]; -int par[MAX][MAXLOG], cost[MAX][MAXLOG]; +int par[MAX][MAXLOG]; +//*** int cost[MAX][MAXLOG]; // Perform DFS while filling h, par, and cost void dfs(int v, int p = -1, int c = 0) { par[v][0] = p; //*** cost[v][0] = c; - if (p + 1) + if (p != -1) h[v] = h[p] + 1; for (int i = 1; i < MAXLOG; ++i) - if (par[v][i - 1] + 1) { + if (par[v][i - 1] != -1) { par[v][i] = par[par[v][i - 1]][i - 1]; //* cost[v][i] += cost[v][i - 1] + cost[par[v][i - 1]][i - 1]; //** cost[v][i] = max(cost[v][i], max(cost[par[v][i-1]][i-1], cost[v][i-1])); @@ -40,7 +41,7 @@ void dfs(int v, int p = -1, int c = 0) { // Preprocess tree rooted at v void preprocess(int v) { memset(par, -1, sizeof par); - memset(cost, 0, sizeof cost); + //*** memset(cost, 0, sizeof cost); dfs(v); } @@ -53,25 +54,24 @@ int query(int p, int q) { swap(p, q); for (int i = MAXLOG - 1; i >= 0; --i) - if (par[p][i] + 1 && h[par[p][i]] >= h[q]) { + if (par[p][i] != -1 && h[par[p][i]] >= h[q]) { //* ans += cost[p][i]; //** ans = max(ans, cost[p][i]); p = par[p][i]; } if (p == q) - return p; - //*** return ans; + return p; //*** return ans; for (int i = MAXLOG - 1; i >= 0; --i) - if (par[p][i] + 1 && par[p][i] != par[q][i]) { + if (par[p][i] != -1 && par[p][i] != par[q][i]) { //* ans += cost[p][i] + cost[q][i]; //** ans = max(ans, max(cost[p][i], cost[q][i])); p = par[p][i]; q = par[q][i]; } - return cost[p][0]; + return par[p][0]; //* if (p == q) return ans; //* else return ans + cost[p][0] + cost[q][0];