├── README.md ├── practical.cpp └── template.cpp /README.md: -------------------------------------------------------------------------------- 1 | # :collision: cpp14-template 2 | A general template for programming contests with implementations of most used functions such as gcd, lcm, etc. 3 | 4 | ## Why use template? 5 | - For faster execution of code (Faster versions of std::cin and std::cout) 6 | - Less time waste on easier portion of problem; easier focus on hard problems and logics of bigger problem. 7 | - It's nice to be organized. 8 | -------------------------------------------------------------------------------- /practical.cpp: -------------------------------------------------------------------------------- 1 | // File.cpp from PROBLEM+SETTER 2 | // AUTHOR: Jishan Shaikh 3 | // Approach: DP 4 | // Passed test cases: ? / ? 5 | 6 | #include 7 | 8 | using namespace std; 9 | 10 | #define int long long 11 | #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); 12 | 13 | // Predefined functions may be modular exponentiation, etc. 14 | 15 | __int128 main(){ // For safety side, will works for all type of C++ compilers 16 | FastIO() 17 | // Variable declarations 18 | // Your code goes here. 19 | // Main logic and STDOUT statements 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /template.cpp: -------------------------------------------------------------------------------- 1 | // Let's try something neww 2 | // Code *NAME_HERE* prepared for *auction* by Jishan Shaikh via template. 3 | // To be run by C++14 gcc compiler, not compatible for C++11 4 | 5 | #include // Be on safer side always! 6 | 7 | // Some handful definitions used frequently 8 | #define mod 1000000007 // Change it if there is any other requirements 9 | #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 10 | #define ll long long 11 | #define mp(x, y) make_pair(x, y) 12 | #define f first 13 | #define s second 14 | #define sd(x) scanf("%d", &x) 15 | #define sd2(x, y) scanf("%d%d", &x, &y) 16 | #define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z) 17 | #define sdl(x) scanf("%lld", &x) 18 | #define sdl2(x, y) scanf("%lld%lld", &x, &y) 19 | #define sdl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z) 20 | #define pb(x) push_back(x) 21 | 22 | // For definition of personal version of cin for int and string as gi and gs 23 | #define gc getchar_unlocked 24 | #ifndef getchar_unlocked 25 | #define getchar_unlocked getchar 26 | #endif 27 | 28 | using namespace std; 29 | // Its preferable NOT to use any element of std in harder, bigger, application level problems!!! 30 | 31 | // Utility functions 32 | string inttostr(ll str){ // Worst case time complexity: O(characters_in_str) 33 | stringstream stream; 34 | stream << str; 35 | return stream.str(); 36 | } 37 | 38 | ll modexpo(ll a,ll b,ll n){ 39 | ll d=1; 40 | while(b){ 41 | if(b&1) 42 | d=(d*a)%n; 43 | b>>=1; 44 | a=(a*a)%n; 45 | } 46 | return d; 47 | } 48 | 49 | ll expo(ll a, ll b){ 50 | ll d = 1; 51 | while(b){ 52 | if(b & 1) 53 | d *= a; 54 | b >>= 1; 55 | a *= a; 56 | } 57 | return d; 58 | } 59 | 60 | ll gcd(ll a, ll b){ // TODO: Recreate gcd function to handle larger inputs & removing recursion for avoiding stackoverflow. 61 | return b ? gcd(b, a%b) : a; 62 | } 63 | 64 | ll lcm(ll a, ll b){ 65 | return (a * b) / gcd(a, b); 66 | } 67 | 68 | ll inv(ll a, ll m){ 69 | return modexpo(a, m-2, m); 70 | } 71 | 72 | void parr(ll a[], ll n){ 73 | for(int i=0; i 80 | void gi(T &r){ // Integer version of cin/scanf but VERY FAST. 81 | r = 0; 82 | char input = gc(); 83 | int kl = 1; 84 | while(input < '0' || input > '9'){ 85 | if(input == '-') 86 | kl = -1; 87 | 88 | input = gc(); 89 | } 90 | while('0' <= input && input <= '9'){ 91 | r = (r << 3) + (r << 1) + (input - '0'), input = gc(); 92 | } 93 | if(kl < 1) 94 | r = -r; 95 | } 96 | 97 | void gs(string &r){ // String version of cin/scanf but VERY FAST for larger inputs. 98 | r.clear(); 99 | char input = gc(); 100 | while(!isgraph(input)) 101 | input = gc(); 102 | 103 | while(isgraph(input)){ 104 | r.push_back(input); 105 | input = gc(); 106 | } 107 | } 108 | 109 | // The main function, driver function required in cpp14 110 | // The driver (main) function can also be of __int128 return type for modern compilers such as C++17, so check it also. 111 | int main(){ 112 | fastio(); // Untie-ing the cin with stdio. 113 | int i, j, k; 114 | string s; 115 | gi(i); 116 | gi(j); 117 | gi(k); 118 | gs(s); 119 | cout << i << endl << j << endl << k << endl; 120 | cout << s; 121 | int t; 122 | cin >> t; // Please don't forgot to take input t; it hurts a lot. 123 | while(t--){ 124 | int n; 125 | cin >> n; 126 | vector arr(n, 0); 127 | for(int i = 0; i < n; i++){ 128 | cin >> arr[i]; 129 | } 130 | for(int i = 0; i < n; i++){ 131 | cout << arr[i] << " "; 132 | } 133 | cout << endl; 134 | } 135 | return 0; 136 | } 137 | --------------------------------------------------------------------------------