Skip to content

Commit

Permalink
add cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Jul 23, 2023
1 parent d8771ce commit a67f0b6
Show file tree
Hide file tree
Showing 12 changed files with 759 additions and 3 deletions.
1 change: 1 addition & 0 deletions cpp/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
4 changes: 4 additions & 0 deletions cpp/.markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"no-duplicate-header": false,
"line-length": false
}
39 changes: 39 additions & 0 deletions cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# VSCodium generic

This flake provides a devshell with `VSCodium` a `hello` executable on `PATH` and with a couple of extensions.

## Prerequisites

See these for additional info:

- [codium-generic](https://github.com/deemp/flakes/tree/main/templates/codium/generic#readme) - info just about `VSCodium` and extensions.
- [nix-vscode-extensions](https://github.com/nix-community/nix-vscode-extensions) (pinned [here](https://github.com/deemp/flakes/blob/main/source-flake/vscode-extensions/flake.nix)).
- [Prerequisites](https://github.com/deemp/flakes#prerequisites).
- [Troubleshooting](https://github.com/deemp/flakes/blob/main/README/Troubleshooting.md)

## Example

1. Install Nix - see [how](https://github.com/deemp/flakes/blob/main/README/InstallNix.md).

1. In a new terminal, start a devshell:

```console
nix flake new my-project -t github:deemp/flakes#codium-generic
cd my-project
git init && git add
nix develop
hello
```

1. (Optionally) Write `settings.json` and start `VSCodium`:

```console
nix run .#writeSettings
nix run .#codium .
```

## Configs

- [.markdownlint.jsonc](./.markdownlint.jsonc) - for `markdownlint` from the extension `davidanson.vscode-markdownlint`
- [.envrc](./.envrc) - for [direnv](https://github.com/direnv/direnv)
- [ci.yaml](.github/workflows/ci.yaml) - a generated `GitHub Actions` workflow. See [workflows](https://github.com/deemp/flakes/tree/main/workflows).
43 changes: 43 additions & 0 deletions cpp/algorithms/ZFunction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<bits/stdc++.h>
using namespace std;

#define fou(i,a,b) for(int i = a, _i = b; i <= _i; ++i)
#define fod(i,a,b) for(int i = a, _i = b; i >= _i; --i)

template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); }
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);

#define ll long long
#define eb emplace_back

const ll N = 1e5+3, M = 998244353;

template<typename T>
vector<int> ZF(T &t){
int n = t.size();
vector<int> z(n,0);

for(int i = 1, l = 0, r = 0; i < n; ++i){
if(i <= r){
z[i] = min(z[i-l], r - i + 1);
}
while(i+z[i] < n and t[i+z[i]] == t[z[i]]) {
z[i]++;
}
if(r < i + z[i]-1){
l = i;
r = i + z[i]-1;
}
}
return z;
}

int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

string s = "ksumksumkso";
dbg(ZF(s));
}
Loading

0 comments on commit a67f0b6

Please sign in to comment.