Skip to content

Instantly share code, notes, and snippets.

View balamark's full-sized avatar
🎯
Focusing

Mark balamark

🎯
Focusing
View GitHub Profile
@balamark
balamark / Similars.cpp
Last active August 29, 2015 14:20
TCO 2015 round 1A
/* The similarity of two number is the number of common digits they have.
E.g. S(1123, 220181) = 2 as they all have 1 and 2*/
class Similars {
public:
vector<int> getDigits(int i){
vector<int> res;
while(i>0){
res.push_back(i%10);
i/=10;
}
@balamark
balamark / Similars.py
Created May 2, 2015 05:08
TCO 2015 round 1A
class Similars:
def maxsim(self, a, b):
return max(map(lambda (i,j):len(set(sorted(str(i))) & set(sorted(str(j)))), [(x,y) for x in range(a,b+1) for y in range(a,b+1) if y>x]))
@balamark
balamark / counter_culture_naive.cc
Last active August 29, 2015 14:20
2015 GCJ 1b
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
using namespace std;
typedef pair<int, int> pii;
int N, TC=1;
const int U=1000005;
@balamark
balamark / PowerOutage.cc
Created May 11, 2015 18:16
SRM 144 div2 1000
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <utility>
#include <cstring>
@balamark
balamark / DucksAlignment.cpp
Created May 12, 2015 16:58
SRM 526 DucksAlignment (div1 250)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
@balamark
balamark / wa.cc
Created May 12, 2015 17:25
retrospect
int ans=55;
for(int tryc=0;tryc<N;++tryc){
for(int cntr: vc){ // here I try to squeeze other ducks toward this center duck
int t=0; //tmp ans
printf("Try col @ %d, center @ %d\n", tryc, cntr);
for(int row: vc){
int up=cntr-1, down=cntr+1;
for(int c=0;c<N;++c) if(grid[row][c]=='o'){
t += abs(c - tryc);
//step toward center:
@balamark
balamark / DropCoins.cpp
Created June 4, 2015 08:10
SRM525 slow
typedef vector<bitset<30> > Grid;
template <>
struct hash<Grid>
{
std::size_t operator()(const Grid& k) const
{
size_t ret;
for(int i=0;i<k.size();++i)
for(int j=0;j<k[0].size();++j)
@balamark
balamark / getMinimum.java
Created June 4, 2015 08:13
SRM525 dropcoin editorial
public int getMinimum(String[] board, int K)
{
int w = board.length;
int h = board[0].length();
final int INF = 1000000000; //A large number
int res = INF;
// For each subrectangle of the board:
for (int x0 = 0; x0 < w; x0 ++) {
for (int x1 = x0+1; x1 <= w; x1++) {
@balamark
balamark / ex.cc
Created June 6, 2015 01:26
CF306 example
dfs(1,0);
dfs(x+1,tot+a[x]);
dfs(x+1,tot);
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>