Skip to content

Instantly share code, notes, and snippets.

@KirillLykov
KirillLykov / codeforces_400_C.cpp
Created March 9, 2017 22:39
Solution for codeforces 400c
#include <bits/stdc++.h>
using namespace std;
// unordered_map leads to TLE on some tests
#define MAP map
int get(MAP<long long, int>& m, long long key) {
auto it = m.find(key);
if (it == m.end())
return 0;
// Just template to play with grundy theorem
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const vector<int> moves = {2, 3, 5}; // moves you can make
@KirillLykov
KirillLykov / jam2017_round1C_A.cpp
Created April 30, 2017 15:36
code jam 2017, round1C, problemA. The solution did not pass the tests
#include <bits/stdc++.h>
using namespace std;
double f(long double r, long double h) {
return r * r* M_PI + 2.0*M_PI*r*h;
}
struct Comparator {
const vector<long double>& data;
Comparator(const vector<long double>& indata) : data(indata) {}
@KirillLykov
KirillLykov / kruskal.cpp
Created May 29, 2017 22:00
kruscal implementation
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class disjoint_sets
{
vector<int> parent;
@KirillLykov
KirillLykov / prim.cpp
Last active June 7, 2019 19:27
prim impelementation
#include <bits/stdc++.h>
using namespace std;
// first is vtx, second is weight
typedef vector< list< pair<int, int> > > TGraph;
int prim(int root, const TGraph& graph)
{
// NOTE first is weight, second is vtx
set< pair<int, int> > q;
@KirillLykov
KirillLykov / closestPairOfPoints.cpp
Created June 30, 2017 15:56
Implementation of the algorithm which finds a pair of closest points on the plane using nlogn operations
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x,y,id;
};
struct ClosestPair {
int dist2, p1, p2;
vector<Point> bigBuffer;
@KirillLykov
KirillLykov / hourrank22_supermancunian.cpp
Created July 2, 2017 17:18
Solution for the hour rank 22 contest, Super mancunian Problem.
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class disjoint_sets
{
vector<int> parent;
@KirillLykov
KirillLykov / gridOfManyXor.cpp
Created July 3, 2017 07:48
Solution for the grid of many xor using prim algorithm
#include <bits/stdc++.h>
using namespace std;
struct Node {
int w;
pair<int, int> c;
Node(int wi, int xi, int yi)
: w(wi), c(xi, yi)
{}
bool operator< (const Node& another) const {
@KirillLykov
KirillLykov / topcoder_277_3.cpp
Created July 14, 2017 22:59
SRM277, div2 level3, UnionOfIntervals. Solution using sweepline
#include <bits/stdc++.h>
using namespace std;
class UnionOfIntervals {
public:
int nthElement(vector <int> lowerBound, vector <int> upperBound, int n) {
vector< pair<int, int> > events;
for (int i = 0; i < lowerBound.size(); ++i) {
events.push_back( make_pair(lowerBound[i], 1) );
events.push_back( make_pair(upperBound[i]+1, -1) );
}
/**
My bugs:
1) temp[i] += i*k; -> temp[i] += (i+1)*k;
2) lint r = c.size(); -> lint r = c.size() + 1;
3) used int at some places -> long long everywhere
My timing:
18m - had solution on paper
24m - wrote the first version
39m - accepted solution
*/