Skip to content

Instantly share code, notes, and snippets.

@cocodrips
cocodrips / PairGame.cpp
Last active August 29, 2015 14:04
SRM620 Div1 Easy in C++ PairGame
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <tuple>
@cocodrips
cocodrips / PairGame.py
Created July 21, 2014 15:37
SRM620 Div1 Easy なんかアリーナだとエラー出る。謎。
class PairGame:
def maxSum(self, a, b, c, d):
partA = self.parts(a, b)
partC = self.parts(c, d)
group = sorted(list(partA.items()), reverse=True)
for g in group:
if partC.has_key(g[0]):
if partC[g[0]] == g[1]:
return g[0]
return -1
@cocodrips
cocodrips / wa.py
Created July 20, 2014 11:46
二次元累積和を使う
# board[n][n] があるとする
table = [[0 for _ in xrange(N)] for _ in xrange(N)]
for c in xrange(N):
for r in xrange(N):
total = 0
if c != 0:
total += table[c - 1][r]
if r != 0:
total += table[c][r - 1]
@cocodrips
cocodrips / UniformBoard.py
Created July 20, 2014 11:41
SRM623 Div1 Easy
# -*- coding: utf-8 -*-
import math, string, itertools, fractions, heapq, collections, re, array, bisect
# .が1つもないのはk = 0と扱うと良い
class UniformBoard:
def getBoard(self, board, K):
N = len(board)
dots, apples, pears = self.count(board)
# print dots, apples, pears
if dots == 0:
@cocodrips
cocodrips / BuildingHeights.cpp
Created July 18, 2014 13:13
SRM624 Div1 Easy in C++
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
@cocodrips
cocodrips / BuildingHeights.py
Created July 18, 2014 13:01
SRM624 Div1 Easy in python
class BuildingHeights:
""" 4000 ** 2 -> T L E"""
def minimum(self, heights):
N = len(heights)
heights = list(heights)
heights.sort()
sums = [0 for _ in xrange(N+1)]
for i in xrange(N):
sums[i+1] = sums[i] + heights[i]
@cocodrips
cocodrips / D.cpp
Last active August 29, 2015 14:03
ICPC予選2014 D問題
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
@cocodrips
cocodrips / HappyLetterDiv1.py
Created July 11, 2014 05:06
SRM627 Div1 Easy
import math,string,itertools,fractions,heapq,collections,re,array,bisect, copy
class HappyLetterDiv1:
def getHappyLetters(self, letters):
letters = list(letters)
letters.sort()
cnt = collections.Counter()
for letter in letters:
cnt[letter] += 1
@cocodrips
cocodrips / A.cpp
Last active August 29, 2015 14:03
ICPC 模擬予選 A
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int gcd(int a, int b){
while(b){
int bb = b;
b = a % b;
a = bb;
}
return a;
}