Skip to content

Instantly share code, notes, and snippets.

@knuu
knuu / codethanksfes2015_g.cpp
Last active January 6, 2016 00:54
CODE THANKS FESTIVAL 2015 G - カメレオン
#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 MAX_V 40010
// graph by adjacency list
@knuu
knuu / cdf336_1b.cpp
Last active December 23, 2015 21:39
Codeforces Round #336 Div.2 D / Div.1 B - Zuma
#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 dp[512][512], c[512];
const int INF = 500;
int main() {
@knuu
knuu / ABBADiv1.py
Created December 24, 2015 17:18
SRM663 div.1 300 ABBADiv1
class ABBADiv1:
def canObtain(self, initial, target):
def dfs(s):
if len(s) == len(target):
return s == target
if s not in target and s not in rev_target:
return False
return dfs(s + 'A') or dfs((s + 'B')[::-1])
rev_target = target[::-1]
return "Possible" if dfs(initial) else "Impossible"
@knuu
knuu / cdf210_1b.cpp
Last active December 29, 2015 20:21
Codeforces Round #210 Div.2 D / Div.1 B - Levko and Array
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
int N, K; cin >> N >> K;
vector<int> a(N);
for (int i = 0; i < N; i++) cin >> a[i];
@knuu
knuu / ApplesAndOrangesEasy.cpp
Last active January 4, 2016 13:35
SRM659 div.1 250 ApplesAndOrangesEasy
#include <bits/stdc++.h>
using namespace std;
struct ApplesAndOrangesEasy {
int maximumApples(int N, int K, vector<int> _info) {
vector<int> info(N, 0);
for (int i : _info) info[i-1] = 1;
for (int i = 0; i < N; i++) {
int cnt = 0, left = max(0, i-K+1);
@knuu
knuu / SPartition.cpp
Last active January 11, 2016 14:04
SRM528 div.1 500 SPartition
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[21][21];
int s[40], L, N;
ll rec(int x, int y, int bit) {
if (x + y == L) return 1;
@knuu
knuu / aoj2067.cpp
Created February 17, 2016 12:55
AOJ2067 Flame of Nucleus
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x) FOR(i,0,x)
#define INF 1<<29
template <typename T>
struct MaxFlow {
struct Edge {
@knuu
knuu / cdf345_1c.cpp
Created March 9, 2016 11:50
Codeforces Round #345 Div.2 E / Div.1 C - Table Compression
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
struct StronglyConnectedComponents {
int V;
@knuu
knuu / brewfile.sh
Created April 5, 2016 04:15
brew install
#/bin/sh
# emacs
brew install emacs --with-cocoa --with-ctags --with-d-bus --with-gnutls --with-imagemagick --with-librsvg --with-mailutils
brew applinks
# brewcask
brew install caskroom/cask/brew-cask
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
@knuu
knuu / gist:e569268e3915feab0c77bc618d13f7ee
Last active April 8, 2016 16:38
SRM687 div1 250の証明
(命題) 任意の正の整数iについて、2以上A[i+1]未満の全ての数は、A[1], A[2], ..., A[i]の異なる要素の和で表すことができる。
(証明)
数学的帰納法で示す。
(1) i=1,2のとき
2はA[1]、3はA[2]なので、示せた。
(2) i=k, k+1のときに、命題が成立すると仮定する。
このとき、i=k+2について、命題(2以上A[k+3]未満の全ての数は、A[1], ..., A[k+2]の異なる要素の和で表すことができる)が成立することを示す。
(2-i) 2 <= x < A[k+2]のとき
仮定より、A[1], ..., A[k+1]で表すことができる。