Skip to content

Instantly share code, notes, and snippets.

View magurofly's full-sized avatar
🐠
F

magurofly

🐠
F
View GitHub Profile
def ack(m, n):
stack = [(m, 1)]
while len(stack):
m, c = stack.pop()
if m == 0:
n += c
elif m == 1:
n += 2 * c
elif m == 2:
n = 2**c * (n + 3) - 3
@magurofly
magurofly / rustc-use-rlib.md
Created April 5, 2024 16:17
rustcでコンパイル時にライブラリをリンクする

rustc コマンドに --extern クレート名=rlibへのパス を渡すことでライブラリが use で使えるようになる。

rlib ファイルの作成

例: proconio-0.4.5 をコンパイルして rlib を作成する。

# proconio-0.4.5 を git clone する
git clone --depth 1 -b p-v0.4.5 https://github.com/statiolake/proconio-rs.git
# コンパイルする
cd proconio-rs/proconio
@magurofly
magurofly / .md
Last active March 9, 2024 06:20
UbuntuにRust競プロ環境を構築する
# Rust をインストール
sudo snap install rustup --classic
rustup toolchain install 1.70.0

# いろいろ依存パッケージをインストール
sudo apt update
sudo apt install build-essential pkg-config libssl-dev zlib1g-dev

# cargo-compete, cargo-equip, sccache をインストール
@magurofly
magurofly / compete.toml
Last active March 29, 2024 01:55
cargo-compete (AtCoder) compete.toml
# Path to the test file (Liquid template)
#
# Variables:
#
# - `manifest_dir`: Package directory
# - `contest`: Contest ID (e.g. "abc100")
# - `bin_name`: Name of a `bin` target (e.g. "abc100-a")
# - `bin_alias`: "Alias" for a `bin` target defined in `pacakge.metadata.cargo-compete` (e.g. "a")
# - `problem`: Alias for `bin_alias` (deprecated)
#
@magurofly
magurofly / .md
Last active October 21, 2023 11:56
せんべい問題を見た感想

積の符号

ジャブみたいな問題だ

$0$ の個数と負の数の個数をそれぞれ数えて

  • $0$ がある→ 0
  • 負の数が奇数個→ -
  • それ以外→+
@magurofly
magurofly / kairo.md
Last active July 23, 2023 07:03
フェーザ表示を使った解法

電源 e, 抵抗 R, コイル L, キャパシタ C が直列接続された回路があり、ここに電流 $i(t) = \sqrt{2} I \sin(ωt+θ)$ が流れている。 抵抗、コイル、キャパシタの電圧降下および電源電圧を求めよ。

定常状態なので、フェーザ表示を使って求めることができる。ここで虚数単位を $j$ とおく。

瞬時値が $x(t) = A \sin(ωt + θ)$ のときを複素数 $\dot{X} = A e^{jθ}$ で表すこととする。また、 $\frac{d}{dt} x(t)$$jω \dot{X}$$\int x(t) dt$$\frac{1}{jω} \dot{X}$ で表す。

  • $i(t) = \sqrt{2} I \sin(ωt+θ)$ より、 $\dot{I} = \sqrt{2} I e^{jθ}$
  • 抵抗の複素インピーダンス $\dot{Z}_R = R$
  • コイルの複素インピーダンス $\dot{Z}_L = jωL$
main = -> {
bm = BrainMem.new(false)
bm.exec do
a = alloc
a.getchar
a.sub ?0.ord
alloc_tmp { |_| _.getchar }
b = alloc
@magurofly
magurofly / kansou.md
Last active May 5, 2023 13:15
ザ・スーパーマリオブラザーズ・ムービーの感想

前置き

Twitter で全人類(人以外も含む)が良かったと言っていたので行ってみた。

ネタバレがあるので、見てない人は見てから読んでください。

逆に、見てないと何を言ってるかわからないかも。


@magurofly
magurofly / linear-median.rb
Created April 19, 2023 19:27
unique な配列の中央値を O(N) で計算する
# 中央値以下の最大の要素を取得する
def linear_median(array)
n = array.size
return array.sort[(n - 1) / 2] if n <= 3
case n % 3
when 0
pivot = linear_median((0 ... n / 3).map { |i| array[i * 3, 3].sort[1] })
remain = []
(n / 3).times do |i|
l, c, r = array[i * 3, 3].sort
@magurofly
magurofly / killer-a.txt
Created April 14, 2023 12:38
mod 2^128 のロリハを殺すやつ
0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100101101001100101101001011001101001100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010011001011001101001011010011001011010010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110