Skip to content

Commit b6e71ff

Browse files
committed
Updated and added automater
1 parent e7cdade commit b6e71ff

7 files changed

+115
-126
lines changed

automate.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
g++ -std=c++11 inp_generator.cpp -o inputgen
3+
g++ -std=c++11 work.cpp -o work
4+
g++ -std=c++11 checker.cpp -o checker
5+
g++ -std=c++11 output_checker.cpp -o outputgen
6+
counter=5
7+
while [[ $counter -gt 0 ]]; do
8+
./inputgen
9+
./work
10+
./checker
11+
line=$(./outputgen)
12+
echo $line
13+
if [[ ${line:0:1} != 'S' ]]; then
14+
echo error
15+
break
16+
fi
17+
counter=`expr $counter - 1`
18+
done

check.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,32 @@ using namespace std;
66

77
typedef long long LL;
88
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;
9+
10+
const int MAX = 1e5 + 5;
11+
const int LIM = 3e5 + 5;
1612
const LD EPS = 1e-10;
1713
const double PI = acos(-1.0);
1814

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())
15+
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
16+
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";exit(1);}}
17+
#define unique(a) sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
18+
19+
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
20+
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
21+
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);}
3022

23+
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
24+
int ilog2(int n){return 31 - __builtin_clz(n);}
25+
int ilog2(LL n){return 63 - __builtin_clzll(n);}
26+
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
27+
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
3128
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
29+
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
3230
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)));}
31+
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
32+
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;}
33+
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
34+
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
3935

4036
int main() {
4137
#ifndef ONLINE_JUDGE

code_template.cpp

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,18 @@
88
using namespace std;
99

1010
typedef long long LL;
11-
typedef unsigned long long ULL;
1211
typedef long double LD;
13-
typedef pair<int,int> pii;
14-
typedef pair<int,pii> piii;
15-
16-
const int MAX = 1000005;
17-
const int LIM = 263005;
18-
const int INF = 1000000001;
19-
const LL INFL = 1000000000000000001LL;
20-
const LL MOD = 1000000007LL;
12+
13+
const int MAX = 1e5 + 5;
14+
const int LIM = 3e5 + 5;
2115
const LD EPS = 1e-10;
2216
const double PI = acos(-1.0);
2317

2418
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
25-
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";}}
19+
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";exit(1);}}
2620
#define inchar getchar//_unlocked
2721
#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())
22+
#define unique(a) sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
3923

4024
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
4125
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
@@ -44,29 +28,25 @@ template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg
4428
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
4529
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;}
4630
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');}
31+
inline void inStr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while (c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
32+
int ilog2(int n){return 31 - __builtin_clz(n);}
33+
int ilog2(LL n){return 63 - __builtin_clzll(n);}
34+
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
35+
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
4736
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
37+
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
4838
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;}
49-
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;}
50-
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;}
51-
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;}
52-
template<typename T> T InverseEuler(T a, T m){return (a==1?1:power(a,m-2,m));}
53-
template<typename T> T gcd(T a, T b){return (b==0?a:__gcd(a,b));}
54-
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
55-
56-
int a[MAX];
39+
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
40+
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;}
41+
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
42+
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
5743

5844
int main() {
5945
#ifndef ONLINE_JUDGE
60-
#define LOCAL 1
61-
#define DUBUG 1
6246
freopen("inp.txt", "r", stdin);
63-
#else
64-
#define LOCAL 0
65-
#define DEBUG 0
6647
#endif
6748

68-
if (LOCAL) {
69-
cerr<<"Execution time : "<<tick();
70-
}
49+
50+
// cout<<"Execution time : "<<tick()<<"\n";
7151
return 0;
7252
}

inp_generator.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
//Below code is used to generate some random test cases
22

3-
#include <bits/stdc++.h>
3+
#include <iostream>
4+
#include <cstdio>
5+
#include <cmath>
6+
#include <algorithm>
7+
#include <vector>
8+
#include <set>
9+
#include <map>
410
using namespace std;
511

612
typedef long long LL;
713

8-
const int mod = 1e9;
9-
const LL modl = 1e17;
14+
const int mod = 1e2;
15+
const int mod2 = 10;
16+
const LL modl = 1e18;
1017

1118
int main() {
1219
#ifndef ONLINE_JUDGE
1320
freopen("inp.txt", "w", stdout);
1421
#endif
1522
srand(unsigned(time(0)));
1623
int t;
17-
t = 10;
24+
t = 1000;
1825
printf("%d\n", t);
1926
while (t--) {
20-
LL n;
21-
n = (LL)rand() * (LL)rand() % modl + 1;
22-
// n = rand() % mod + 1;
23-
printf("%lld\n", n);
27+
int n, q, x, y, l, r;
28+
n = rand()%mod + 1;
29+
printf("%d\n", n);
30+
31+
// LL n;
32+
// n = (LL)rand() * (LL)rand() % modl + 1;
2433
}
2534
return 0;
26-
}
35+
}

output_checker.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#include <bits/stdc++.h>
1+
#include <iostream>
2+
#include <fstream>
3+
#include <cstdio>
4+
#include <cmath>
5+
#include <algorithm>
26
using namespace std;
37

48
int main() {
@@ -10,11 +14,11 @@ int main() {
1014
output2.open("res.txt", ios::in);
1115

1216
if (!output1) {
13-
cerr<<"Can't open output file 1\n";
17+
cout<<"Can't open output file 1\n";
1418
return 0;
1519
}
1620
if (!output2) {
17-
cerr<<"Can't open output file 2\n";
21+
cout<<"Can't open output file 2\n";
1822
return 0;
1923
}
2024

@@ -35,20 +39,20 @@ int main() {
3539
pos += 1;
3640
}
3741
if (c || a!=b) {
38-
cerr<<"Output differs at line number : "<<lines<<"\n";
39-
cerr<<"The characters diifer at position : "<<pos+1<<"\n";
42+
cout<<"Output differs at line number : "<<lines<<"\n";
43+
cout<<"The characters diifer at position : "<<pos+1<<"\n";
4044
if (a < b) {
41-
cerr<<"Output in file out.txt has shorter length\n";
45+
cout<<"Output in file out.txt has shorter length\n";
4246
}
4347
else if (b < a) {
44-
cerr<<"Output in file res.txt has shorter length\n";
48+
cout<<"Output in file res.txt has shorter length\n";
4549
}
4650
return 0;
4751
}
4852
lines += 1;
4953
}
50-
cerr<<"Scanned a total of "<<lines<<" lines from both files\n";
51-
cerr<<"Both output files are same\n";
54+
cout<<"Scanned a total of "<<lines<<" lines from both files\n";
55+
cout<<"Both output files are same\n";
5256
output1.close();
5357
output2.close();
5458
return 0;

stack_limit.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,14 @@
55
#include <bits/stdc++.h>
66
using namespace std;
77

8-
int main() {
9-
const rlim_t kStackSize = 8 * 1024 * 1024; // min stack size = 8 MB
10-
struct rlimit rl;
11-
int result;
12-
13-
result = getrlimit(RLIMIT_STACK, &rl);
14-
if (result == 0)
15-
{
16-
if (rl.rlim_cur < kStackSize)
17-
{
18-
rl.rlim_cur = kStackSize;
19-
result = setrlimit(RLIMIT_STACK, &rl);
20-
if (result != 0)
21-
{
22-
fprintf(stderr, "setrlimit returned result = %d\n", result);
23-
}
24-
}
25-
}
8+
#include <sys/resource.h>
269

27-
//write your code below
10+
int main() {
11+
const rlim_t Stack_size = 32L * 1024 * 1024;
12+
struct rlimit lim = {Stack_size, Stack_size};
13+
if(setrlimit(RLIMIT_STACK, &lim) == -1) assert(false);
2814

29-
return 0;
15+
//Write your code below
16+
17+
return 0;
3018
}

work.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,45 @@
99
using namespace std;
1010

1111
typedef long long LL;
12-
typedef unsigned long long ULL;
1312
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;
13+
14+
const int MAX = 1e5 + 5;
15+
const int LIM = 3e5 + 5;
2216
const LD EPS = 1e-10;
2317
const double PI = acos(-1.0);
2418

2519
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
20+
#define Assert(x) {if(!(x)){cerr<<"Assertion failed at line "<<__LINE__<<": "<<#x<<" = "<<(x)<<"\n";exit(1);}}
2621
#define inchar getchar//_unlocked
2722
#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())
23+
#define unique(a) sort((a).begin(), a.end()), (a).erase(unique((a).begin(), (a).end()),(a).end())
24+
25+
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
26+
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
27+
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);}
3928

4029
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;}
4130
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;}
4231
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');}
32+
inline void inStr(char *str){register char c=0;register int i=0;while(c<33)c=inchar();while (c!='\n'&&c!=' '&&c!=EOF){str[i]=c;c=inchar();++i;}str[i]='\0';}
33+
int ilog2(int n){return 31 - __builtin_clz(n);}
34+
int ilog2(LL n){return 63 - __builtin_clzll(n);}
35+
template<typename T> T gcd(T a, T b){return (b?__gcd(a,b):a);}
36+
template<typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
4337
template<typename T> T mod(T a, T b) {return (a<b ? a : a%b);}
38+
template<typename T> T mod_neg(T a, T b) {return ((a%b)+b)%b;}
4439
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)));}
40+
template<typename T> T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
41+
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;}
42+
template<typename T> T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
43+
template<typename T> T mod_inverse(T a, T n){T x,y;T d = extended_euclid(a, n, x, y);return (d>1?-1:mod_neg(x,n));}
5144

5245
int main() {
5346
#ifndef ONLINE_JUDGE
5447
freopen("inp.txt", "r", stdin);
5548
#endif
5649

57-
// cerr<<tick();
50+
51+
// cout<<"Execution time : "<<tick()<<"\n";
5852
return 0;
5953
}

0 commit comments

Comments
 (0)