PathToMaster's blog

By PathToMaster, history, 3 years ago, In English

Hi! I'd like to share with the community the template I use for competing in Codeforces rounds. It's very simple, so is easier to learn to use it.

I hope it helps someone :-)

#include <bits/stdc++.h>
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for(int i=a;i<b;++i)
#define all(x) x.begin(), x.end()
#define sz(v) (int)(v.size())
#define feq(a, b) (fabs(a - b) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll INF = 1e18, MOD = 1e9+7;
const int int_max = 1e9;
const ld eps = 1e-9;

void solve() {
	
}
int main() {
	cin.tie(0) -> sync_with_stdio(0);
	int T = 1;
	cin>>T;//You can comment this if you don't need it
	while(T--) {
		solve();
	}
}
  • Vote: I like it
  • -19
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

A couple things I would like to point out as improvements or just changes you could make. note these are just my ideas, not yours so you don't have to use them.

cin.tie(0) -> sync_with_stdio(0);

The above code works the same as what you have written but in one line. how it works is dark magic and I won't bother explaining it.

const ll mod = 1e9 +7; //use 1e9 instead of 9 0's, its easier to read/understand
const ll INF = 1e18; //same reasoning
const int int_max = 0x3f3f3f3f; //the reasoning on this is more complex, but this is one viable value for INF < 2^(32). int_max = 1e9 is fine too
const int MX = 1e5 +10; //if you use global arrays, a practice which is being less common these days :<, this is a must have

The above code are just some ways to approach constants

#define lb long double //using/typedef is fine too
#define feq(a, b) (fabs(a - b) < eps)
const lb eps = 1e-9; //this is much better for comparing doubles/floats

The above code is just something for doubles.

#define sz(vec) (int)(vec.size()) //using siz is also fine

there is a danger of things going wrong with vec.size() since its an unsigned integer so this is a nice way to wrap it up.

you can also add macros/lines of code for better random and uid. a few other things I personally have, 2 macros for memsetting an entire array and memsetting to a certain size (good for multitest). i also have 2 macros LC(k) to (k*2 +1) and RC(k) to (k*2 + 2) for my segtree. this can be put into snippets if you want. i also just have a thing for putting return 0 at the end :).

so there are my thoughts, you are welcome to do as you wish with them

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PathToMaster (previous revision, new revision, compare).

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by PathToMaster (previous revision, new revision, compare).