Skip to content

Instantly share code, notes, and snippets.

View ctylim's full-sized avatar
💥
Meow. 🐱

Kotaro Shikata ctylim

💥
Meow. 🐱
View GitHub Profile
@ctylim
ctylim / cf16-asapro_d.cpp
Created February 3, 2020 18:06
cf16-asapro_d (DP & fixed-range-maximum)
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
@ctylim
ctylim / BIT.cpp
Last active October 8, 2019 19:19
Competitive Programming Snippets
struct bit {
vector<ll> v; // 部分和をbitで管理 仮想配列はa[1...n]
bit(int n){ // bit(int n) : v(n + 1) {}
v.resize(n + 1);
}
ll sum(int i){ // 仮想配列a[1]~a[i]の和を求める
ll ret = 0;
for(; i > 0; i -= i & -i){ // i & -i: iの1が立っている最高位bitをの2^を返す
ret += v[i];
@ctylim
ctylim / fin.rs
Created November 22, 2018 03:54
file input
extern crate rayon;
use std::fs::{File};
use std::io::prelude::*;
use std::io::{BufReader};
use std::env;
fn main() {
let filename = match env::args().nth(1) {
Some(filename) => filename,
@ctylim
ctylim / hogwild.rs
Last active November 21, 2018 11:36
concurrent access to shared memory
extern crate rayon;
use std::cell::UnsafeCell;
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
use rayon::prelude::*;
#[derive(Clone)]
pub struct Hogwild<T>(Arc<UnsafeCell<T>>);
@ctylim
ctylim / into.rs
Created November 21, 2018 08:34
From, Default
use std::fmt;
#[derive(Debug)]
pub struct MyFloat {
pub val: f64
}
impl From<f64> for MyFloat {
fn from(a: f64) -> Self {
MyFloat { val: a }
@ctylim
ctylim / concurrency.rs
Created November 19, 2018 18:21
concurrency.rs
use std::thread;
use std::sync::{Arc, Mutex};
use std::time::Duration;
fn main() {
let mut data = Arc::new(Mutex::new(vec![1, 2, 3]));
for i in 0..6 {
let data = data.clone();
thread::spawn(move || {
let mut data = data.lock().unwrap();
@ctylim
ctylim / parallel.cpp
Created November 15, 2018 11:15
parallel.cpp
#include <iostream>
#include <vector>
#include <queue>
#include <thread>
#include <chrono>
typedef long long ll;
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
@ctylim
ctylim / docker-delete-images.sh
Created August 3, 2018 04:10
Delete all built docker images
docker ps -aq | xargs docker rm;
docker images -aq | xargs docker rmi;
@ctylim
ctylim / A.lisp
Created January 23, 2018 16:33
clisp
; Y Combinator
(defun Y (f)
((lambda (x)
(funcall f (lambda (y) (funcall (funcall x x) y))))
(function
(lambda (x)
(funcall f (lambda (y) (funcall (funcall x x) y)))))))
(defun fact (f)
@ctylim
ctylim / G.cpp
Created December 17, 2017 12:07
Code Festival 2017 Final G Mancala
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>