Skip to content

Instantly share code, notes, and snippets.

@kkralj
kkralj / abcdef.cpp
Last active August 29, 2015 14:12
SPOJ - 4580. ABCDEF - binary search. (n ^ 3 log(n) complexity AC > 7seconds)
#include <cstdio>
#include <algorithm>
#define MAXS 100
#define MAXARR 1000000
int leftElem[MAXARR + 1], rightElem[MAXARR + 1];
int il;
int binarysearch(int value, int arr[], int arrlen) {
@kkralj
kkralj / TRAVERSE.cpp
Created September 11, 2014 11:27
SPOJ - 8598. Traverse through the board
/*
easy "dp"
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
@kkralj
kkralj / NAJKRACI.cpp
Last active August 29, 2015 14:05
SPOJ - 3545. Najkraci
// hsin.hr/coci -> all credits
/*
Dijkstra, by using idea that
number of times path i->j will be reached is = (number of different paths to i) * (number of nodes that you can reach from j)
*/
#include <cstdio>
#include <set>
@kkralj
kkralj / SHPATH.cpp
Last active August 29, 2015 14:05
SPOJ - 15. The Shortest Path
/*
dijkstra + custom heap + binary search for city
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
@kkralj
kkralj / EASYPROB.cpp
Last active December 19, 2017 16:50
SPOJ - 1688. A Very Easy Problem!
/*
recursion
*/
#include <iostream>
#include <cstdio>
#include <fstream>
using namespace std;
string sol;
@kkralj
kkralj / SAMER08A.cpp
Last active August 29, 2015 14:04
SPOJ - 3405. Almost Shortest Path - Dijkstra
/*
Dijkstra
*/
#include <iostream>
#include <vector>
#include <cstdio>
#include <set>
using namespace std;
@kkralj
kkralj / TRSTAGE.cpp
Last active August 29, 2015 14:04
SPOJ - 1700. Traveling by Stagecoach
/*
shortest path (brute force, almost checks all possible combinations)
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
@kkralj
kkralj / MICEMAZE.cpp
Last active August 29, 2015 14:04
SPOJ - 1845. Mice and Maze
/*
easy dijkstra
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
@kkralj
kkralj / gist:dc085c9afcf587920888
Created July 21, 2014 22:13
3763. George - Dijkstra
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
using namespace std;
const int inf = (1 << 29);
@kkralj
kkralj / gist:52dfe3331f86d9ae85fa
Created July 19, 2014 11:27
4181. MELE3 - Dijkstra
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
const int inf = (1 << 29);
vector < vector < pair < int, int > > > graph;