Skip to content

Commit 53e7b54

Browse files
committed
Initial commit
0 parents  commit 53e7b54

File tree

10 files changed

+291
-0
lines changed

10 files changed

+291
-0
lines changed

check.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//The below contains the brute force code for any solution
2+
//It helps me to check the answers or find a pattern in question
3+
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
typedef long long LL;
8+
typedef long double LD;
9+
typedef pair<int,int> pii;
10+
typedef pair<int,pii> piii;
11+
12+
const int MAX = 100005;
13+
const int INF = 1000000001;
14+
const LL INFL = 1000000000000000001LL;
15+
const LL MOD = 1000000007LL;
16+
const LD EPS = 1e-10;
17+
const double PI = acos(-1.0);
18+
19+
#define pb push_back
20+
#define mp make_pair
21+
#define fi first
22+
#define sec second
23+
#define all(c) (c).begin(),(c).end()
24+
#define allr(c) (c).rbegin(),(c).rend()
25+
#define loop(c,i) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
26+
#define loopr(c,i) for(typeof(c.end()) i = c.end(); i != c.begin(); )
27+
#define uni(a) sort(all(a)), (a).erase(unique(all(a)),(a).end())
28+
#define present(c,x) ((c).find(x) != (c).end())
29+
#define cpresent(c,x) (find(all(c),x) != (c).end())
30+
31+
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
32+
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
33+
template<typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
34+
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
35+
template<typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
36+
template<typename T> T InverseEuler(T a, T m){return (a==1?1:power(a,m-2,m));}
37+
template<typename T> T gcd(T a, T b){return (b==0?a:__gcd(a,b));}
38+
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
39+
40+
int main() {
41+
#ifndef ONLINE_JUDGE
42+
freopen("inp.txt", "r", stdin);
43+
freopen("res.txt", "w", stdout);
44+
#endif
45+
46+
// Brute force code goes below
47+
48+
// cerr<<tick();
49+
return 0;
50+
}

code_template.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//Below is the template in C++ which I used for Programming Competitions
2+
3+
/******************************************
4+
* AUTHOR: BHUVNESH JAIN *
5+
* INSTITUITION: BITS PILANI, PILANI *
6+
******************************************/
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
typedef long long LL;
11+
typedef unsigned long long ULL;
12+
typedef long double LD;
13+
typedef pair<int,int> pii;
14+
typedef pair<int,pii> piii;
15+
16+
const int MAX = 100005;
17+
const int LIM = 263005;
18+
const int INF = 1000000001;
19+
const LL INFL = 1000000000000000001LL;
20+
const LL MOD = 1000000007LL;
21+
const LD EPS = 1e-10;
22+
const double PI = acos(-1.0);
23+
24+
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
25+
#define inchar getchar//_unlocked
26+
#define outchar(x) putchar(x)//_unlocked(x)
27+
#define pb push_back
28+
#define mp make_pair
29+
#define fi first
30+
#define sec second
31+
#define all(c) (c).begin(),(c).end()
32+
#define allr(c) (c).rbegin(),(c).rend()
33+
#define loop(c,i) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
34+
#define loopr(c,i) for(typeof(c.end()) i = c.end(); i != c.begin(); )
35+
#define uni(a) sort(all(a)), (a).erase(unique(all(a)),(a).end())
36+
#define present(c,x) ((c).find(x) != (c).end())
37+
#define cpresent(c,x) (find(all(c),x) != (c).end())
38+
39+
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
40+
template<typename T> void inPos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
41+
template<typename T> void outPos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}
42+
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
43+
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
44+
template<typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
45+
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
46+
template<typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
47+
template<typename T> T InverseEuler(T a, T m){return (a==1?1:power(a,m-2,m));}
48+
template<typename T> T gcd(T a, T b){return (b==0?a:__gcd(a,b));}
49+
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
50+
51+
int main() {
52+
#ifndef ONLINE_JUDGE
53+
freopen("inp.txt", "r", stdin);
54+
#endif
55+
56+
// cerr<<tick();
57+
return 0;
58+
}

inp.txt

Whitespace-only changes.

inp_generator.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Below code is used to generate some random test cases
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long LL;
7+
8+
const int mod = 1e9;
9+
const LL modl = 1e17;
10+
11+
int main() {
12+
#ifndef ONLINE_JUDGE
13+
freopen("inp.txt", "w", stdout);
14+
#endif
15+
srand(unsigned(time(0)));
16+
int t;
17+
t = 10;
18+
printf("%d\n", t);
19+
while (t--) {
20+
LL n;
21+
n = (LL)rand() * (LL)rand() % modl + 1;
22+
// n = rand() % mod + 1;
23+
printf("%lld\n", n);
24+
}
25+
return 0;
26+
}

out.txt

Whitespace-only changes.

output_checker.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//Below is used to compare the output of two files
2+
//The "out.txt" file is generated from the "work.cpp" file
3+
//The "res.txt" file is generated from the "check.cpp" file
4+
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
8+
int main() {
9+
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
10+
11+
ifstream output1;
12+
ifstream output2;
13+
output1.open("out.txt", ios::in);
14+
output2.open("res.txt", ios::in);
15+
16+
if (!output1) {
17+
cout<<"Can't open output file 1\n";
18+
return 0;
19+
}
20+
if (!output2) {
21+
cout<<"Can't open output file 2\n";
22+
return 0;
23+
}
24+
25+
int lines = 1;
26+
string str1, str2;
27+
while (getline(output1, str1)) {
28+
getline(output2, str2);
29+
if (str1 != str2) {
30+
cout<<"Output differs at line number : "<<lines<<"\n";
31+
return 0;
32+
}
33+
lines += 1;
34+
}
35+
cout<<"Scanned a total of "<<lines<<" lines from both files\n";
36+
cout<<"Both output files are same\n";
37+
output1.close();
38+
output2.close();
39+
return 0;
40+
}

res.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
4256178549306104/5252000529515471
2+
17029570951453186/20688372816560163
3+
41779179275628391/50319537767180790
4+
503317526778745237/606549087413172010
5+
25524879556576135/30805950249264526
6+
71903613157526343/88531384307240410
7+
26216413989010084/32314916107736685
8+
43460932620688859/53622306208060170
9+
73906955891627819/88950921050264065
10+
2277151887607348/2823994303399151

stack_limit.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Below code is included to check the stack limit size on the Online Judge
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main() {
7+
const rlim_t kStackSize = 8 * 1024 * 1024; // min stack size = 8 MB
8+
struct rlimit rl;
9+
int result;
10+
11+
result = getrlimit(RLIMIT_STACK, &rl);
12+
if (result == 0)
13+
{
14+
if (rl.rlim_cur < kStackSize)
15+
{
16+
rl.rlim_cur = kStackSize;
17+
result = setrlimit(RLIMIT_STACK, &rl);
18+
if (result != 0)
19+
{
20+
fprintf(stderr, "setrlimit returned result = %d\n", result);
21+
}
22+
}
23+
}
24+
25+
return 0;
26+
}

timer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Below code is used to calculate the time for execution of your program
2+
//The time, in seconds, is written on the error screen
3+
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
double tick() {
8+
static clock_t oldticks;
9+
clock_t newticks = clock();
10+
double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC;
11+
oldticks = newticks;
12+
return diff;
13+
}
14+
15+
int main() {
16+
17+
//write your code below
18+
19+
//include this at the end of your code to get the time
20+
cerr<<tick();
21+
return 0;
22+
}

work.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//Below contains the workspace for my coding
2+
//This is the file which I upload on Online Judges
3+
4+
/******************************************
5+
* AUTHOR: BHUVNESH JAIN *
6+
* INSTITUITION: BITS PILANI, PILANI *
7+
******************************************/
8+
#include <bits/stdc++.h>
9+
using namespace std;
10+
11+
typedef long long LL;
12+
typedef unsigned long long ULL;
13+
typedef long double LD;
14+
typedef pair<int,int> pii;
15+
typedef pair<int,pii> piii;
16+
17+
const int MAX = 100005;
18+
const int LIM = 263005;
19+
const int INF = 1000000001;
20+
const LL INFL = 1000000000000000001LL;
21+
const LL MOD = 1000000007LL;
22+
const LD EPS = 1e-10;
23+
const double PI = acos(-1.0);
24+
25+
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
26+
#define inchar getchar//_unlocked
27+
#define outchar(x) putchar(x)//_unlocked(x)
28+
#define pb push_back
29+
#define mp make_pair
30+
#define fi first
31+
#define sec second
32+
#define all(c) (c).begin(),(c).end()
33+
#define allr(c) (c).rbegin(),(c).rend()
34+
#define loop(c,i) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
35+
#define loopr(c,i) for(typeof(c.end()) i = c.end(); i != c.begin(); )
36+
#define uni(a) sort(all(a)), (a).erase(unique(all(a)),(a).end())
37+
#define present(c,x) ((c).find(x) != (c).end())
38+
#define cpresent(c,x) (find(all(c),x) != (c).end())
39+
40+
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
41+
template<typename T> void inPos(T &x){x=0;register T c=inchar();while(((c<48)||(c>57))&&(c!='-'))c=inchar();bool neg=false;if(c=='-')neg=true;for(;c<48||c>57;c=inchar());for(;c>47&&c<58;c=inchar())x=(x<<3)+(x<<1)+(c&15);if(neg)x=-x;}
42+
template<typename T> void outPos(T n){if(n<0){outchar('-');n*=-1;}char snum[65];int i=0;do {snum[i++]=n%10+'0';n/=10;}while(n);i=i-1;while(i>=0)outchar(snum[i--]);outchar('\n');}
43+
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
44+
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((LD)a*(LD)b)/(LD)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}
45+
template<typename T, typename S>T expo(T e, S n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
46+
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p,m);p=mod(p*p,m);n>>=1;}return x;}
47+
template<typename T>T powerL(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
48+
template<typename T> T InverseEuler(T a, T m){return (a==1?1:power(a,m-2,m));}
49+
template<typename T> T gcd(T a, T b){return (b==0?a:__gcd(a,b));}
50+
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
51+
52+
int main() {
53+
#ifndef ONLINE_JUDGE
54+
freopen("inp.txt", "r", stdin);
55+
#endif
56+
57+
// cerr<<tick();
58+
return 0;
59+
}

0 commit comments

Comments
 (0)