Skip to content

Instantly share code, notes, and snippets.

View joonas-yoon's full-sized avatar
🎃
Focusing

Joona Yoon joonas-yoon

🎃
Focusing
View GitHub Profile
@joonas-yoon
joonas-yoon / eulerian-path.cpp
Created May 13, 2020 10:13
using Eulerian path
#define MAX_V 100001
int id = 0;
int L[MAX_V], R[MAX_V]; // [L, R]
vector<int> adj[MAX_V];
int dfs(int cur) {
int i = ++id, cnt = 0;
L[cur] = i;
for (auto& nxt : adj[cur]) {
@joonas-yoon
joonas-yoon / boj-9034.cpp
Created May 1, 2020 08:18
BOJ 9034 - 순위
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
struct seg {
int n;
vector<int> t;
void build(int sz) {
@joonas-yoon
joonas-yoon / 1539.cpp
Created April 17, 2020 10:15
BOJ 1539 - 이진 검색 트리
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<(n); ++i)
typedef long long lld;
map<int, int> h1, h2;
int main() {
@joonas-yoon
joonas-yoon / boj-18109-automata.cpp
Created April 2, 2020 09:24
BOJ 18109 - 도깨비불 (오토마타 풀이)
#include <bits/stdc++.h>
using namespace std;
#define CONSO 0
#define VOWEL 1
#define COMBINE_C 2
#define COMBINE_V 3
bool isVowel[255];
set<string> cVowel, cConso;
@joonas-yoon
joonas-yoon / binary_search.cpp
Created March 28, 2020 02:08
Binary search - why it can be checked by lower bound
bool binary_search(int arr[], int len, const int& key) {
int l = 0, r = len - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (arr[mid] < key)
l = mid + 1;
else
r = mid - 1;
}
return a[l] == key;
@joonas-yoon
joonas-yoon / test_main.cpp
Created March 19, 2020 08:12
alternative for STL - test/main
#include <cstdio>
// if you want to use STL, uncomment following includes:
// #include <vector>
// #include <algorithm>
// using namespace std;
// count "key" from array sized n
// if no key, print "NO"
int main() {
int n;
@joonas-yoon
joonas-yoon / binary_search(short).cpp
Last active April 6, 2020 04:22
alternative for STL - lower_bound, upper_bound, binary_search
template<typename T>
bool binary_search(T *arr, T *end, const T& x) {
return *lower_bound(arr, end, x) == x;
}
@joonas-yoon
joonas-yoon / sort.cpp
Created March 19, 2020 08:07
alternative for STL - sort(quick)
// based on quick sort
template<typename T>
void sort(T *arr, T *end) {
int l = 0, r = (end - arr) - 1;
if (l >= r) return;
T mid = arr[(l + r) / 2];
while (l <= r) {
while (arr[l] < mid) ++l;
while (mid < arr[r]) --r;
if (l <= r) {
@joonas-yoon
joonas-yoon / vector.cpp
Created March 19, 2020 08:07
alternative for STL (vector)
template<typename T>
class vector {
public:
vector(int capacity = 4) {
_a = new T[capacity]();
_cap = _size = capacity;
}
vector(int capacity, const T value) {
_a = new T[capacity]();
_cap = _size = capacity;
@joonas-yoon
joonas-yoon / hotbrains-s2-13.py
Last active March 6, 2020 05:43
문제적 남자 : 브레인 유랑단 13회, 신비로운 문제
# https://www.youtube.com/watch?v=Hx58twR_VY0
NUMBERS = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "twentyone", "twentytwo", "twentythree", "twentyfour", "twentyfive", "twentysix", "twentyseven", "twentyeight", "twentynine", "thirty", "thirtyone", "thirtytwo", "thirtythree", "thirtyfour", "thirtyfive", "thirtysix", "thirtyseven", "thirtyeight", "thirtynine", "forty", "fortyone", "fortytwo", "fortythree", "fortyfour", "fortyfive", "fortysix", "fortyseven", "fortyeight", "fortynine", "fifty", "fiftyone", "fiftytwo", "fiftythree", "fiftyfour", "fiftyfive", "fiftysix", "fiftyseven", "fiftyeight", "fiftynine", "sixty", "sixtyone", "sixtytwo", "sixtythree", "sixtyfour", "sixtyfive", "sixtysix", "sixtyseven", "sixtyeight", "sixtynine", "seventy", "seventyone", "seventytwo", "seventythree", "seventyfour", "seventyfive", "seventysix", "seventyseven", "seventyeig