Aman Raj

~/home/

Competitive Programming C++ Cheat Sheet

After reading many codeforces blogs this is what I had learned and used as as my template for Competitive Programming.


Unlock speed

1#define fast_io  ios_base::sync_with_stdio(false);cin.tie(NULL);

Increase map speed

1mp.reserve(n)

Cheat with boost library on codechef

1#include <boost/multiprecision/cpp_int.hpp>
2using boost::multiprecision::cpp_int;

For Leetcode

1static int fast_io = []() {
2    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
3    return 0;
4}();

There are also things like use append_back instead of push_back but I dont think that makes much difference. I recommend reading these blogs

My template

1//      (╯°□°)╯︵ ┻━┻
2#include<bits/stdc++.h>
3// #include <boost/multiprecision/cpp_int.hpp>
4// using boost::multiprecision::cpp_int;
5using namespace std;
6#define ll                 long long int
7#define lld                long double
8#define vi                 vector<ll>
9#define pb                 push_back
10#define MOD                (ll)(1e9 + 7)
11#define rep(i,a,b)         for(ll i = a; i<b; ++i)
12#define f(a)               for(ll i = 0; i<a; ++i)
13#define all(a)             (a).begin(),(a).end()
14#define present(c,x)       ((c).find(x) != (c).end())
15#define cpresent(c,x)      (find(all(c),x) != (c).end())
16#define p(a)               cout << a << endl;
17#define p2(a,b)            cout << a << " " << b << endl;
18#define fast_io            ios_base::sync_with_stdio(false);cin.tie(NULL);
19//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
20// GCD + LCM function
21ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
22ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
23
24int32_t main() {
25    fast_io; cout.tie(NULL);
26    ll tc = 1;
27    cin >> tc;
28    while(tc--) {
29        //
30    }
31}

Thanks for reading. See you next time 😝