Skip to content

Instantly share code, notes, and snippets.

import sys
from math import sqrt
def rec(state, v):
if state == (1 << N) - 1:
return cakes[v]
if dp[state][v] != -1:
return dp[state][v]
@knuu
knuu / Treestrat.cpp
Last active October 14, 2015 06:55
SRM670 div.1 450/div.2 1050 Treestrat.cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
@knuu
knuu / TreeCutting.cpp
Last active October 17, 2015 10:19
SRM644 div.2 1000 TreeCutting
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
@knuu
knuu / Procrastination.py
Created October 21, 2015 11:46
SRM672 div.1 250 Procrastination
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
class Procrastination:
def findFinalAssignee(self, n):
def miller_rabin(n):
""" primality Test
if n < 3,825,123,056,546,413,051, it is enough to test
a = 2, 3, 5, 7, 11, 13, 17, 19, and 23.
Complexity: O(log^3 n)
@knuu
knuu / aoj0530.cpp
Created October 23, 2015 09:24
AOJ0530 Pyon-Pyon River Crossing
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(x);i++)
#define REP(i,x) FOR(i,0,x)
@knuu
knuu / BearCries.cpp
Created October 28, 2015 10:17
SRM671 div.1 300 BearCries
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
@knuu
knuu / kupc2015_g.cpp
Created October 31, 2015 09:20
KUPC2015 G ケンドー
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
/*
@knuu
knuu / cdf204_1a.cpp
Last active November 3, 2015 09:44
Codeforces Round #204(Div. 1) - A. Jeff and Rounding
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
int main() {
// use scanf in CodeForces!
cin.tie(0);
ios_base::sync_with_stdio(false);
@knuu
knuu / TheKingsFactorization.py
Created November 7, 2015 07:31
SRM 643 div.2 500 / div.1 250 TheKingsFactorization
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
class TheKingsFactorization:
def getVector(self, N, primes):
ans = list(primes)
n = N
for p in primes:
n /= p
@knuu
knuu / aoj2332.cpp
Last active January 6, 2016 00:56
AOJ2332 Space-Time Sugoroku Road
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define INF 1<<25
#define MAX_V 100010