# Templates * Copy template : https://chrislaiisme.github.io/Copy_Template/ ## C++ Templates ### Defualt Code ```cpp= #include<bits/stdc++.h> #define IO cin.tie(0) -> sync_with_stdio(0) #define endl "\n" #define F first #define S second #define X first #define Y second #define pLL pair<LL, LL> #define mkp make_pair #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long using namespace std; const LL mod = 1e9 + 7, inf = numeric_limits<LL>::max() / 2, maxN = 0; LL T = 1; void solve() { } int main() { //\ IO; //\ cin >> T; while(T -- ) solve(); } ``` ### LeetCode ```cpp= #define F first #define S second #define X first #define Y second #define pLL pair<LL, LL> #define mkp make_pair #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long const LL mod = 1e9 + 7, inf = numeric_limits<LL>::max() / 2; ``` ### Task Cases Generating ```cpp= #pragma GCC optimize("O2") #include<bits/stdc++.h> #define endl "\n" #define F first #define S second #define X first #define Y second #define pLL pair<LL, LL> #define mkp make_pair #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long using namespace std; const LL mod = 1e9 + 7, inf = numeric_limits<LL>::max() / 2; void init(); struct file_name { string in_file, out_file; file_name(string name = "") { in_file = name + ".in"; out_file = name + ".out"; } } File; struct limits { /*VALUE LIMITS*/ struct range { LL mnm, mxm; range(LL _mnm = 0, LL _mxm = 0) { mnm = _mnm; mxm = _mxm; } }; range N; }; string problem_name = "a001"; /*PROBLEM NAME*/ constexpr LL number_of_cases = 1; /*NUMBER OF CASES*/ limits task_limits[number_of_cases]; vector<LL> skip = {}; /*SKIP TASKS*/ void update_file_name(LL num) { string test_case_number = to_string(num); if(test_case_number.length() == 1) test_case_number = "0" + test_case_number; string name = problem_name + "_" + test_case_number; File = file_name(name); } void generate_infile() { srand(time(0)); mt19937 mt(rand()); for(LL no = 0; no < number_of_cases; no ++ ) { bool skp = 0; for(auto &i : skip) { if(no == i) { skp = 1; break; } } if(skp) continue; update_file_name(no); freopen(File.in_file.c_str(), "w", stdout); cerr << "Generating Task Number " << no << "..." << endl; /*ALL DISTRIBUTIONS*/ #define UID uniform_int_distribution #define lim(X) task_limits[no].X.mnm, task_limits[no].X.mxm UID<LL> dis_N(lim(N)); /*GENERATE INFILE*/ /*****************/ fclose(stdout); } } void solve() { for(LL no = 0; no < number_of_cases; no ++ ) { bool skp = 0; for(auto &i : skip) { if(no == i) { skp = 1; break; } } if(skp) continue; update_file_name(no); cerr << "Solving Task Number " << no << "..." << endl; freopen(File.in_file.c_str(), "r", stdin); freopen(File.out_file.c_str(), "w", stdout); /*SOLVING PROBLEM*/ /*****************/ fclose(stdin), fclose(stdout); } } int main() { init(); cerr << "Initialization Complete" << endl; generate_infile(); cerr << "Infile Generation Complete" << endl; solve(); cerr << "Task Solving Complete" << endl; } void init() { cerr << "Initializing..." << endl; /*SETTING RANGES*/ #define lims task_limits lims[0] = {{0, 1}}; } ``` ### Task Cases Generating(Simple) ```cpp= #pragma GCC optimize("O2") #include<bits/stdc++.h> #define endl "\n" #define F first #define S second #define X first #define Y second #define pLL pair<LL, LL> #define mkp make_pair #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long #define UID uniform_int_distribution using namespace std; const LL mod = 1e9 + 7, inf = numeric_limits<LL>::max() / 2; int main() { srand(time(0)); mt19937 mt(rand()); UID<LL> dis_N(0, 1); fstream infile("a001_00.in", ios::out); fstream outfile("a001_00.out", ios::out); } ``` ### Match ```cpp= #pragma GCC optimize("O2") #include<bits/stdc++.h> #define endl "\n" #define F first #define S second #define X first #define Y second #define pLL pair<LL, LL> #define mkp make_pair #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long #define UID uniform_int_distribution using namespace std; const LL mod = 1e9 + 7, inf = numeric_limits<LL>::max() / 2; vector<string> vec, vec2; void generate_infile() { srand(time(0)); mt19937 mt(rand()); UID<LL> dis_N(0, 1); fstream cout("input.txt", fstream::out | fstream::trunc); /*GENERATE INFILE*/ /*****************/ } void solve1() { fstream cin("input.txt"), cout("output.txt", fstream::out | fstream::trunc); /*SOLVING PROBLEM*/ /****************/ cout.close(); string str; fstream f; f.open("output.txt", fstream::in); while(f >> str) vec.pb(str); } void solve2() { fstream cin("input.txt"), cout("output.txt", fstream::out | fstream::trunc); /*SOLVING PROBLEM*/ /****************/ cout.close(); string str; fstream f; f.open("output.txt", fstream::in); while(f >> str) vec2.pb(str); } bool match() { if(vec.size() != vec2.size()) return 1; for(LL i = 0; i < vec.size(); i ++ ) { if(vec[i] != vec2[i]) return 1; } vec.clear(), vec2.clear(); return 0; } int main() { LL T = 1; while(T -- ) { generate_infile(); solve1(); solve2(); if(match()) { fstream f("input.txt"); cout << "Input: " << endl; string str; while(f >> str) cout << str << " "; cout << endl; cout << "Answer1: " << endl; for(auto &i : vec) cout << i << " "; cout << endl; cout << "Answer2: " << endl; for(auto &i : vec2) cout << i << " "; cout << endl; } } } ``` ### Special Judge ```cpp= #include<bits/stdc++.h> #define IO cin.tie(0) -> sync_with_stdio(0) #define endl "\n" #define F first #define S second #define X first #define Y second #define pLL pair<LL, LL> #define mkp make_pair #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long using namespace std; int main(int argc, char* argv[]) { fstream infile(string(argv[1]).c_str(), ios::in); fstream outfile(string(argv[2]).c_str(), ios::in); fstream ansfile(string(argv[3]).c_str(), ios::in); } ``` ### .vimrc ```vim= set nu ci sw=4 ts=4 bs=2 set cursorline set guifont=Consolas:h18 filetype indent on inoremap {<S-CR> {<CR>}<Esc>ko inoremap {<CR> {<CR>}<Esc>ko nnoremap <F9> :w <bar> !g++ -std=c++11 % -o %:r<CR> nnoremap <F10> :!%:r<CR> ``` --- ## Problem Templates ### Input ${\begin{array}{l} T \\ N \\ a_1\ a_2\ \cdots\ a_N \\ \cdots \\ \end{array}}$ :::success ``` $\bk{\begin{array}{l} T \\ N \\ a_1\ a_2\ \cdots\ a_N \\ \cdots \\ \end{array}}$ ``` ::: ### Output ${\begin{array}{l} ans_1 \\ ans_2 \\ \cdots \\ ans_n \\ \end{array}}$ :::success ``` $\bk{\begin{array}{l} ans_1 \\ ans_2 \\ \cdots \\ ans_n \\ \end{array}}$ ``` ::: ### Limits ${\begin{array}{l} \bullet\ \ 1 \le N \le 10^6 \\ \bullet\ \ 1 \le T \le 10^2 \\ \bullet\ \ 1 \le a_i \le 10^9 \\ \bullet\ \ \forall variable \in \mathbb{N} \\ \end{array}}$ ${\begin{array}{ccc} \hline Subtask & Score & Extra\ Input\ Limits \\ \hline \#0 & 10 & N = 1 \\ \#1 & 20 & N \le 100 \\ \#2 & 30 & N \le 10^4 \\ \#3 & 40 & No\ extra\ limits \\ \hline \end{array}}$ :::success ``` $\bk{\begin{array}{l} \bullet\ \ 1 \le N \le 10^6 \\ \bullet\ \ 1 \le T \le 10^2 \\ \bullet\ \ 1 \le a_i \le 10^9 \\ \bullet\ \ \forall variable \in \mathbb{N} \\ \end{array}}$ $\bk{\begin{array}{ccc} \hline Subtask & Score & Extra\ Input\ Limits \\ \hline \#0 & 10 & N = 1 \\ \#1 & 20 & N \le 100 \\ \#2 & 30 & N \le 10^4 \\ \#3 & 40 & No\ extra\ limits \\ \hline \end{array}}$ ``` ::: ### Black Color :::success ``` $\def\bk{\color{#333333}}$ ``` ::: ### ByeBye Black Line ```cpp= #include<bits/stdc++.h> #define IO cin.tie(0) -> sync_with_stdio(0) #define endl "\n" #define F first #define S second #define pLL pair<LL, LL> #define pb emplace_back #define pf emplace_front #define ppb pop_back #define ppf pop_front #define LL lolita #define lolita long long using namespace std; void init(); const LL mod = 1e9 + 7, inf = 9e18; LL i = 0; bool bln = 0; string str, s1 = "<font color=white>", s2 = "</font>"; void one() { LL j = i + 1; while(j < str.length() && (str[j] != '$' || str[j - 1] == '\\')) j ++ ; if(j == str.length()) { bln = 1; return; } if(i >= s1.length() && j + s2.length() < str.length() && str.substr(i - s1.length(), s1.length()) == s1 && str.substr(j + 1, s2.length()) == s2) { i = j + s2.length() + 1; return; } str.insert(i, s1); str.insert(j + s1.length() + 1, s2); i = j + s1.length() + s2.length(); } void two() { LL j = i + 2; while(j + 1 < str.length() && (str[j] != '$' || str[j + 1] != '$')) j ++ ; if(j + 1 == str.length()) { bln = 1; return; } if(i >= s1.length() && j + 1 + s2.length() < str.length() && str.substr(i - s1.length(), s1.length()) == s1 && str.substr(j + 2, s2.length()) == s2) { i = j + s2.length() + 2; return; } str.insert(i, s1); str.insert(j + s1.length() + 2, s2); i = j + s1.length() + s2.length() + 1; } void solve() { init(); string tmp; cout << "Please enter your source code: " << endl << endl; while(getline(cin, tmp)) { if(tmp == "<EOF>") break; str += tmp + '\n'; } for(; i < str.length(); i ++ ) { if(str[i] != '$') continue; if(str[i + 1] == '$') two(); else one(); if(bln) break; } if(bln) { cout << "Hmmm... There's some wrong with your \'$\' of LaTeX" << endl; return; } cout << "Ok! Your code seems to have no problems. Here's your new source code: " << endl << endl; cout << str << endl; } int main() { // IO; solve(); } void init() { } ```