text stringlengths 1 24.5M |
|---|
#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<utility>
#include<map>
#include<algorithm>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(0)
#define mp make_pair
#define minp(v) *min_element(v.begin(), v.end())
#define maxp(v) *max_element(v.begin(), v.end())
#d... |
#include <iostream>
using namespace std;
struct Node {
int data;
struct Node* next;
Node(int data)
{
this->data = data;
next = NULL;
}
};
struct LinkedList {
Node* head;
LinkedList() { head = NULL; }
void reverse()
{
Node* current = head;
Node *p... |
#include <iostream>
#define R 4
#define C 5
using namespace std;
class value_list{
public:
int col_index;
int value;
value_list *next;
};
class row_list{
public:
int row_number;
row_list *link_down;
value_list *link_right;
};
void create_value_node(int data, int j, row_list **z)
{
... |
/*
Title - Demonstration of Priority Queue data structure using STL library in C++.
std::priority_queue can lookup the largest OR smallest element in constant time i.e. O(1).
Priority Queues work on the concepts of max-heap and min-heap.
Implementation of priority queue with both these concepts is demonstrated here.
... |
/* A queue can be implemented using two stacks in two ways.
1. By making enqueue operation costly
2. By making dequeue operation costly
Here we discuss the second method however the first could be implemented
in the same way interchanging enqueue and dequeue methods. */
/* Time complexity for enqueue... |
/* Queue is a data structure with FIFO (first in first out) arrangement */
/* The elements in the queue are inserted at the back and deleted from the front */
#include <bits/stdc++.h>
using namespace std;
void printQueue(queue<int> q) // for printing the elements
{
while (!q.empty()) // While the queue is not emp... |
// CPP program to evaluate value of a postfix
// expression having multiple digit operands
#include <bits/stdc++.h>
using namespace std;
// Stack type
class Stack
{
public:
int top;
unsigned capacity;
int* array;
};
// Stack Operations
Stack* createStack( unsigned capacity )
{
Stack* stack = new S... |
// CPP program to demonstrate working of STL stack
#include <bits/stdc++.h>
using namespace std;
void showstack(stack <int> s)
{
while (!s.empty())
{
cout << '\t' << s.top();
s.pop();
}
}
int main ()
{
// push element in stack
stack <int> s;
s.push(10);
s.push(30);
s.push(20);
s.push(5)... |
// stack implementation using linkedlist from scratch
#include<bits/stdc++.h>
using namespace std;
// linkedList class for stack
class stackNode{
// data and pointer part of node
int data;
stackNode *next;
public:
// constructor to create new node
stackNode *newNode(int data){
... |
//C++ Program to implement Stack Data Structure
#include <bits/stdc++.h>
//Setting a Max SIZE for Stack
#define SIZE 100
using namespace std;
class Stack
{
int item[SIZE];
int top;
public:
Stack() //default constructor
{
top = -1;
}
bool isEmpty() //check if stack is Empty
{
... |
//Problem-Implement two stacks in a single array such that
// push1(int x) –> pushes x to first stack
// push2(int x) –> pushes x to second stack
// pop1() –> pops an element from first stack
// pop2() –> pops an element from second stack
//All operations should take O(1) time complexity
#include<bits/stdc+... |
/* Binary Search Tree implementation
In Binary Search tree left subtree is having smaller values than root
right subtree has values larger than root
Time Complexity for search = insertion = deletion = O(heightOfTre)= O(N)
*/
#include<bits/stdc++.h>
using namespace std;
class BinarySearchTree{
private:
// this ... |
/*
* The Fenwick Tree, also known as a Binary Indexed Tree is a very useful data
* structure that can be used for answering range type queries and single
* point updates. There are multiple adaptations of it and it can be made to
* support more complex operations, however this is the simplest one.
*
*
* Time Co... |
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
// Every node of the binary tree is represented by a 'node' data type
struct node
{
int key_value; // Value the node holds
node *left; // Address of its left child
node *right; // Address of its right child
};
class binaryTr... |
/*
Level order traversal of a binary search Tree
This is an algorithm to traverse through a binary search tree level by level
Time complexity for level order traversal: O(N) where N is the number of nodes in the tree
*/
#include<bits/stdc++.h>
using namespace std;
//implementation of binary Tree - very minima... |
/*
## Lowest Common Anscestor for a Tree in C++
## what will change
create a trees folder in DS and add lca code to it.
## Problem
Given tree and n-1 edges.
Given two nodes a and b.
To find the lowest common ancestor of a and b in linear time.
input :
first line contains a single integer n - number of nodes
next n-... |
/* Tree Node
struct Node {
int data;
Node* left;
Node* right;
};*/
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> inOrder(Node* root)
{
Node*cur=root;
vector<int>v;
//code here
while(cur){
if(!cur->left) {v.push_back(cur-... |
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
// Every node of the binary tree is represented by a 'node' data type
struct node
{
int key_value; // Value the node holds
node *left; // Address of its left child
node *right; // Address of its right child
};
class binaryTre... |
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
// every node of the binary tree is represented by a 'node' data type
struct node{
int key_value; // value the node holds
node* left; // address of its left child
node* right; // address of its right child
};
class binaryT... |
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), l... |
#include <iostream>
using namespace std;
struct node
{
node *arr[26];
bool end;
node()
{
end = false;
for(int i=0;i<26;i++)
arr[i] = nullptr;
}
bool contains(char c)
{
return arr[c - 'a'] != nullptr;
}
};
class Trie
{
private : node *root;
pu... |
#include <iostream>
#include <vector>
using namespace std;
struct node
{
node *arr[26];
bool end;
node()
{
end = false;
for(int i=0;i<26;i++)
{
arr[i] = nullptr;
}
}
bool contains(char c)
{
return arr[c - 'a'] != nullptr;
}
};
class T... |
#include <iostream>
using namespace std;
// ************ THIS IS THE COMPLETE IMPLEMENTATION OF TRIE ************
// *********************************************************************
// Trie is very useful in solving dictionary related problems, like :
// 1. search the given word in list of words
// 2. Print all... |
#include <iostream>
using namespace std;
// *********** THIS IS ANOTHER KIND OF IMPLEMENTATION OF TRIE DATA STRUCTURE **********
// THIS IS A CODE TO FIND COUNT OF WORDS :
// 1. WHICH MATCH WITH GIVEN WORDS
// 2. WHICH SATRT WITH GIVEN PREFIXES
// 3. TO ERASE THE GIVEN WORDS FROM OUR DICTIONARY
// *******************... |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/*Vectors are same as dynamic arrays with the ability to resize itself
automatically when an element is inserted or deleted*/
void iterate_over_vector(auto start,auto end)
{
for(auto i=start;i!=end;i++)
{
cout<<*i<<" ";
}
cout<<endl;... |
#include <iostream>
#include <vector>
using namespace std;
int N, M;
vector<int> vec;
void f() {
if(vec.size() == M) {
for(int i : vec) cout << i << " ";
cout << "\n";
return;
}
for(int i = 0; i < N; i++) {
bool isOK = true;
for(int j : vec) {
if(j == i) {
isOK = false;
break;
}
}
if(i... |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N;
struct Person {
int age;
string name;
};
bool compare(const Person &x, const Person &y) {
return x.age < y.age;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> N;
vector<Person> vec... |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N;
vector<int> vec;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> N;
int tmp;
for(int i = 0; i < N; i++) {
cin >> tmp;
vec.push_back(tmp);
}
sort(vec.begin(), vec.end());
for(int ... |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M;
vector<string> vec;
bool binaraySearch(string target) {
int left = 0, right = vec.size() - 1;
while(left < right) {
int mid = (left + right) / 2;
if(vec[mid] < target) left = mid + 1;
else right = mid;
}
return (vec[... |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, M;
vector<int> vec;
bool binaraySearch(int num) {
int left = 0, right = vec.size() - 1;
while(left < right) {
int mid = (left + right) / 2;
if(vec[mid] < num) left = mid + 1;
else right = mid;
}
return (vec[(left + righ... |
#include <bits/stdc++.h>
using namespace std;
long long solution(string expression) {
long long answer = 0;
vector<long long> num;
vector<char> exp, location;
string n = "";
for(int i = 0; i < expression.size(); i++)
{
if(expression[i] == '+' || expression[i] == '-' || expression[i... |
/**
* ë¬¸ì œ: ì œë¡œ (http://boj.kr/10773)
* Tier: Silver 4 (2021.01.14 기준)
* Comment: 0ì´ ë‚˜ì˜¬ë•Œ 가장 ìµœê·¼ì˜ ê°’ì„ ëºë‹ˆë‹¤.
* 즉, FIFO 구조를 ë„ê³ ìžˆê³ , ìžì—°ìŠ¤ëŸ½ê²Œ 스íƒì„ 사용하시면 ë©ë‹ˆë‹¤.
*/
#include <iostream>
#include <stack>
using namespace std;
int N;
stack<int> st;
int ma... |
/**
* ë¬¸ì œ: 요세푸스 ë¬¸ì œ 0 (http://boj.kr/1158)
* Tier: Silver 5 (2021.01.12 기준)
* Comment: í를 í™œìš©í• ìˆ˜ 있는 대표ì ì¸ ë¬¸ì œìž…ë‹ˆë‹¤.
* ì¶œë ¥ì´ ì¡°ê¸ˆ 특ì´í•˜ê¸° ë•Œë¬¸ì— ì¶œë ¥ë§Œ ìœ ì˜í•´ì„œ 풀어주세요.
*/
#include <iostream>
#include <queue>
#include <vector>
using namespace st... |
/**
* ë¬¸ì œ: ê³¼ì œëŠ” ë나지 않아! (http://boj.kr/17952)
* Tier: Silver 3 (2021.01.14 기준)
* Comment: 하다가 새로운 ê²ƒì´ ë“¤ì–´ì˜¤ë©´ ì´ì–´ì„œ 하는 ê²ƒì´ ì•„ë‹ˆë¼
* 새로 ë°›ì€ ê²ƒ 부터 í•œë‹¤ê³ í•©ë‹ˆë‹¤.
* 당연히 스íƒì´ê² ì£ ?
*/
#include <iostream>
#include <stack>
using namespace st... |
/**
* ë¬¸ì œ: 카드 2 (http://boj.kr/2164)
* Tier: Silver 4 (2021.01.12 기준)
* Comment: í를 ë°°ì› ìœ¼ë‹ˆ í를 통해서 í’€ì´ í•˜ì˜€ìŠµë‹ˆë‹¤.
* í•œë²ˆì€ ê·¸ëƒ¥ ë¹¼ê³ , í•œë²ˆì€ ëº€ 걸 다시 넣는ë°, ê²°êµ ë‘ ì—°ì‚°ì„ í•œ 번씩 하면 í¬ê¸°ê°€ 1씩 ê°ì†Œí•©ë‹ˆë‹¤.
* 즉 í¬ê¸°ê°€ 1ì´ ë 때 까지 ë¹¼ê³ ... |
/**
* ë¬¸ì œ: 괄호 (http://boj.kr/9012)
* Tier: Silver 4 (2021.01.14 기준)
* Comment: ìŠ¤íƒ í•˜ë©´ ë– ì˜¬ë¦´ 수 있는 가장 ìœ ëª…í•œ ë¬¸ì œìž…ë‹ˆë‹¤.
* 그런ë°, 어차피 괄호 종류는 하나ì¸ë° êµ³ì´ ìŠ¤íƒì„ ì¨ì•¼ í• ê¹Œìš”?
*/
#include <iostream>
using namespace std;
int main() {
ios_base::sy... |
/**
* ë¬¸ì œ: 주ì‹ê°€ê²© (https://programmers.co.kr/learn/courses/30/lessons/42584)
* Difficulty: Level 2
* Comment: 스íƒì„ 활용한 ë¬¸ì œìž…ë‹ˆë‹¤.
* 새로 들어오는 ê°’ì´ ìŠ¤íƒì˜ top 보다 작으면 스íƒì˜ ê°’ì„ ë¹¼ë²„ë¦¬ê³ , 얼마나 오래 있었는지 리턴하면 ë©ë‹ˆë‹¤.
* ë”°ë¼ì„œ 들어오는... |
/**
* ë¬¸ì œ: 기능개발 (https://programmers.co.kr/learn/courses/30/lessons/42586)
* Difficulty: Level 2
* Comment: "ë’¤ì— ìžˆëŠ” ê¸°ëŠ¥ì€ ì•žì— ìžˆëŠ” ê¸°ëŠ¥ì´ ë°°í¬ë 때 함께 ë°°í¬ëœë‹¤." ë¼ëŠ” ë§ì— 주목하세요.
* 즉, ëª¨ë“ ê¸°ëŠ¥ì´ ìˆœì°¨ì 으로 ë°°í¬ë˜ì–´ì•¼ 합니다.
* 순차ì ì´ë©´ ì–´ë–¤ ìžë£... |
#include <iostream>
int main() { std::cout << "test" << std::endl; } |
/*************************************************************************************
Cartesian tree. Can be used as a balanced binary search tree.
O(logN) on operation.
Based on problem 2782 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=2782
************... |
/*************************************************************************************
Cartesian tree using implicit keys. Implementation below contains
array segment reverse and finding range minimum. O(logN) on operation.
Based on problem 111240 from informatics.mccme.ru:
http://informatics.mccme.r... |
/*************************************************************************************
Fenwick tree for sum on the interval and update of an element.
O(logN) on operation.
Based on problem 3317 from informatics.mccme.ru:
http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=3317#1
*... |
/*************************************************************************************
Fenwick tree for sum on the rectangle and update of an element.
O(logN ^ 2) on query.
Based on problem 3013 from informatics.mccme.ru:
http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=3013#1
*... |
/*************************************************************************************
Implicit segment tree with addition on the interval
and getting the value of some element.
Works on the intervals like [1..10^9].
O(logN) on query, O(NlogN) of memory.
Author: Bekzhan Kassenov.
Based on ... |
/*************************************************************************************
Modification of queue, which allows finding the minimum element in it.
Time complexity: O(1) on operation.
Based on problem 756 from informatics.mccme.ru:
http://informatics.mccme.ru//mod/statements/view.php?chap... |
/******************************************************************************
Segment Tree with addition and min/max on the interval
Based on problem 1263E from https://codeforces.com/contest/1263/problem/E
******************************************************************************/
#include <iostream>... |
/**********************************************************************
Segment Tree with assignment and sum on the interval
Based on problem C from http://codeforces.ru/gym/100093
**********************************************************************/
#include <iostream>
#include <fstream>
#include <cmath>... |
/*************************************************************************************
Segment tree. Solves RMQ problem (maximum on a segment and value update)
O(N) on precalculation, O(logN) on query.
Based on problem 3309 from informatics.mccme.ru:
http://informatics.mccme.ru/moodle/mod/statements/... |
/*************************************************************************************
Sparse table. Solves static RMQ problem (without element changes).
O(NlogN) on precalculation, O(1) on query.
Based on problem 3309 from informatics.mccme.ru:
http://informatics.mccme.ru/moodle/mod/statements/view.... |
/********************************************************************************
Convex Hull trick. About it: http://wcipeg.com/wiki/Convex_hull_trick
Based on CFR #189, task C: http://codeforces.ru/contest/319/problem/C
********************************************************************************/
#incl... |
/****************************************************************************************************
Finding Longest Increasing Sequence in O(NlogN)
About it: http://e-maxx.ru/algo/longest_increasing_subseq_log
Based on problem http://informatics.mccme.ru/mod/statements/view3.php?id=766&chapterid=1794
**... |
/**********************************************************************************
Finding the closest pair of points. O(NlogN), divide-and-conquer.
Based on http://www.spoj.com/problems/CLOPPAIR/
**********************************************************************************/
#include <iostream>
#includ... |
/***********
Solution to Closest Pair of Points Problem. O(nlogn) Divide-and-Conquer.
Tested on http://www.spoj.com/problems/CLOPPAIR/
***********/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
#define sqr(a) ((a)*(a))
const double inf =... |
/**********************************************************************************
Convex Hull [ Graham-Andrew method, O(NlogN) ]
Based on problem 638 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=638
Tested on problem 290 from informatics.mccme.ru:
h... |
/*
Method convex_hull() returns convex hull of arbitrary points.
Graham scan. O(sort) + O(n);
Tested: informatics.mccme.ru #290, #638
*/
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define sqr(x) ((x) * (x))
const double inf = 1e100,... |
/**************************************************************************************
Bellman-Ford algorithm finding shortest distances from a single vertex
in graph. Works in O(N*M)
Based on problem 178 from informatics.mccme.ru
http://informatics.mccme.ru/mod/statements/view3.php?id=260&chapterid=... |
/**************************************************************************************
Kuhn algorithm for maximum matching in bipartite graph. Works in O(N * M)
More about it: http://e-maxx.ru/algo/kuhn_matching
Based on problem 1683 from informatics.mccme.ru:
http://informat... |
/**************************************************************************************
Algorithm for finding all bridges in the graph (edges, after removal of
which graph divides into several components). O(M)
Based on problem C from here: http://codeforces.ru/gym/100083
********************************... |
/*******************************************************************************************************
Centroid decomposition in O(NlogN), and LCA in O(logN).
More about centroid decomposition:
- http://acm.math.spbu.ru/~sk1/mm/lections/zksh2016-centroid/conspect.pdf (in Russian)
- https://medium.... |
/**************************************************************************************
Algorithm for finding all cutpoints in the graph (vertices, after removal of
which graph divides into several components). O(M)
Based on problem D from here: http://codeforces.ru/gym/100083
***************************... |
/**************************************************************************************
Dijkstra on heap for sparse graphs - O(MlogM)
Based on problem 20C from codeforces: http://codeforces.ru/contest/20/problem/C
**************************************************************************************/
#includ... |
/**************************************************************************************
Dijkstra on set for sparse graphs - O(MlogM). Slower than heap version
Based on problem 20C from codeforces: http://codeforces.ru/contest/20/problem/C
*****************************************************************... |
/********************************************************************************
MaxFlow Dinic algorithm with scaling.
O(N * M * log(MC)), where MC is maximum edge capacity.
Based on problem 2784 from informatics.mccme.ru
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=2784#1
**... |
/************************************************************************************
Algorithm for finding Eulerian path/cycle (path that visits every edge
exactly once). O(M).
Based on problem 1704 from informatics.mccme.ru
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=1704
******... |
/**************************************************************************************
Floyd-Warshall algorithm finding shortest distance between all
pairs of vertices in graph. Works in O(N^3)
Based on problem 95 from informatics.mccme.ru
http://informatics.mccme.ru/mod/statements/view.php?id=218#1
... |
/********************************************************************************
MaxFlow Ford-Fulkerson algorithm. O(M|f|), |f| - maxflow value
Based on problem 2783 from informatics.mccme.ru
http://informatics.mccme.ru/mod/statements/view3.php?chapterid=2783#1
******************************************... |
/************************************************************************************
Heavy-light decomposition with segment trees in paths.
Used for finding maximum on the path between two vertices.
O(N) on building, O(logN ^ 2) on query.
Based on problem 1553 from acm.timus.ru
http://acm.timus... |
/***************************************************************************************************
Hungarian matching algorithm - O(N ^ 3)
Based on problem http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=394#1
Algorithm realization based on http://e-maxx.ru/algo/assignment_hunga... |
/************************************************************************************
Finding LCA (Least common ancestor) of two vertices in the tree.
Uses dp calculated on powers of 2.
O(NlogN) for preprocessing, O(logN) on query.
Based on problem 111796 from informatics.mccme.ru
http://informa... |
/************************************************************************************
Finding LCA (Least common ancestor) of two vertices in the tree.
Uses heavy-light decomposition.
O(N) for preprocessing, O(logN) on query.
Based on problem 111796 from informatics.mccme.ru
http://informatics.mc... |
/************************************************************************************
Min Cost Flow (or Min Cost Max Flow) algorithm with
Dijkstra algorithm (with potentials) as shortest path search method.
(Dijkstra for dense graphs running in O(N^2))
Works O(N ^ 5). Less on practice.
Runs in O... |
/************************************************************************************
Min Cost Flow (or Min Cost Max Flow) algorithm with
Dijkstra algorithm (with potentials) as shortest path search method.
(Dijkstra on heap for sparse graphs)
Works (N * M ^ 2 * logN). Less on practice.
Runs in ... |
/************************************************************************************
Min Cost Flow (or Min Cost Max Flow) algorithm with
Ford-Bellman algorithm as shortest path search method.
Works O(N ^ 6). Less on practice.
Runs in O(N ^ 4) for bipartite matching case.
Based on problem 394 fr... |
/**************************************************************************************
Minimum spanning tree using Kruskal algorithm with DSU. O(MlogM)
Based on problem 1377 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=261&chapterid=1377
****************************... |
/**************************************************************************************
Minimum spanning tree using Prim algorithm. O(N ^ 2)
Based on problem 185 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=261&chapterid=185
******************************************... |
/********************************************************************************
Structure implementing long arithmetic in C++
Analogue to BigInteger in Java.
Tested on many problems.
TODO: list some problems
********************************************************************************/
struct B... |
/*******************************************************************************
Finding Nth Catalan number modulo some mod
(N <= 500000, mod is not necessary prime)
Uses Eratosthenes sieve for fast factorization
Works in O(N * loglogN)
Based on problem 140 from acm.mipt.ru
http://acm.mi... |
/************************************************************************************
Solving Diophantine equations in form of a * x + b * y = c
Uses extended Euclid algorithm
(which finds such x, y that a * x + b * y = gcd(a, b))
Based on problem 4188 from informatics.mccme.ru
http://informatic... |
/********************************************************************************
Fast Fourier transformation used to multiply long numbers.
Fast non-recursive version. O(NlogN).
Based on problem 317 from E-Olimp: http://www.e-olimp.com.ua/problems/317
*****************************************************... |
/*******************************************************************************
Gauss method of solving system of linear algebraic equation.
Works in O(n ^ 3) (more precisely - O(min(n, m) * n * m))
Based on problem 198 from acmp.ru:
http://acmp.ru/index.asp?main=task&id_task=198
*******************... |
/*******************************************************************************
Matrix multiplication and fast binary power.
Works in O(n ^ 3).
Based on problem Walk from AtCoder:
https://atcoder.jp/contests/dp/tasks/dp_r
******************************************************************************... |
/*******************************************************************************
Finding number of permutation in lexicographical order
Works in O(n^2)
Based on problem 2388 from e-olimp.com
http://www.e-olimp.com/problems/2388
*************************************************************************... |
/*******************************************************************************
Finding permutation by its length and number in lexicographical order
Works in O(n^2)
Based on problem 190 from informatics.mccme.ru
http://informatics.mccme.ru/moodle/mod/statements/view.php?chapterid=190#1
************... |
/*****************************************************************
Calculation of the value of the expression.
Uses recursive descent parser. Supports doubles.
Available operations:
+ - / * Usual meaning
- Unary minus
# Root (3 # 8 = 2)
^ Power (2 ^ 3 = ... |
/************************************************************************************
Merge sort. O(NlogN).
Based on problem 766 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=1129&chapterid=766
**************************************************************************... |
/************************************************************************************
Quick sort with random pivot element. O(NlogN).
Based on problem 766 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=1129&chapterid=766
************************************************... |
/************************************************************************************
Radix sort. O(N * len), where len - maximum length of numbers.
Based on problem 766 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=1129&chapterid=766
*********************************... |
/******************************************************************************
Aho-Corasick algorithm.
This code finds all words in the text that contain any of the
initially given words. O(len of queries + sum len of initial strings)
Based on problem K from here: http://codeforces.ru/gym/10013... |
/******************************************************************************
Hashing in strings based problems.
This code compares substrings using two hashes (one
uses 2^64 as a modulo, another 10^9 + 7)
Based on problem C from here: http://codeforces.ru/gym/100133
***************************... |
/****************************************************************************
Manacher's algorithm for finding all subpalindromes in the string.
Based on problem L from here: http://codeforces.ru/gym/100133
****************************************************************************/
#include <iostream>
#in... |
/**************************************************************************************
Palindrome tree. Useful structure to deal with palindromes in strings. O(N)
This code counts number of palindrome substrings of the string.
Based on problem 1750 from informatics.mccme.ru:
http://informatics.mccme.... |
/*************************************************************************************
Prefix function. O(N)
About it: http://e-maxx.ru/algo/prefix_function
Based on problem 1323 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=241&chapterid=1323
********************... |
/************************************************************************
Suffix Array. Builing works in O(NlogN).
Also LCP array is calculated in O(NlogN).
This code counts number of different substrings in the string.
Based on problem I from here: http://codeforces.ru/gym/100133
*******************... |
/****************************************************************************
Trie. Builds tree from the set of strings. O(total length of strings)
This code counts number of different substrings in the string.
Based on problem B from here: http://codeforces.ru/gym/100133
*********************... |
/************************************************************************
Suffix Tree. Ukkonen's algorithm using sibling lists — O(N).
This code counts number of different substrings in the string.
Based on problem I from here: http://codeforces.ru/gym/100133
*********************************************... |
/*************************************************************************************
Z function. O(N)
About it: http://e-maxx.ru/algo/z_function
Based on problem 1324 from informatics.mccme.ru:
http://informatics.mccme.ru/mod/statements/view3.php?id=241&chapterid=1324
******************************... |
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
#include "cache.h"
#include "util/crc.h"
#include "util/version.h"
#include <cassert>
#include <hiredis/hiredis.h>
#include <iostream>
#include <string>
using namespace std;
static const char... |
#pragma once
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
#include <string>
struct redisContext;
class Cache {
redisContext *ctx = nullptr;
public:
Cache(unsigned port, bool allow_version_mismatch);
#ifndef NO_REDIS_SUPPORT
~Cac... |
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
#include "ir/attrs.h"
#include "ir/function.h"
#include "ir/globals.h"
#include "ir/instr.h"
#include "ir/memory.h"
#include "ir/state.h"
#include "ir/state_value.h"
#include "ir/type.h"
#inclu... |
#pragma once
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
#include "ir/functions.h"
#include "smt/exprs.h"
#include <optional>
#include <ostream>
#include <string>
#include <vector>
namespace IR {
class Instr;
class ParamAttrs;
class S... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.