From da7e12d0b02e2c6dd3764c4ecc2b0853d16e8891 Mon Sep 17 00:00:00 2001 From: Rachit Jain <32428330+rachitiitr@users.noreply.github.com> Date: Sat, 16 Mar 2024 07:49:33 +0000 Subject: [PATCH] Codeforces Contest Runner and Debug Logger during Local --- .gitignore | 5 +- Library/Miscellanious/template2024.cpp | 41 +++++++++ Library/Utils/bits/stdc++.h | 117 +++++++++++++++++++++++++ Library/Utils/codeforces.sh | 30 +++++++ Library/Utils/logger.h | 108 +++++++++++++++++++++++ 5 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 Library/Miscellanious/template2024.cpp create mode 100644 Library/Utils/bits/stdc++.h create mode 100644 Library/Utils/codeforces.sh create mode 100644 Library/Utils/logger.h diff --git a/.gitignore b/.gitignore index d99efa9..aa1d2cc 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,7 @@ # Executables *.exe *.out -*.app \ No newline at end of file +*.app + +# Temp Codeforces Contest Env +CodeforcesContestRunner \ No newline at end of file diff --git a/Library/Miscellanious/template2024.cpp b/Library/Miscellanious/template2024.cpp new file mode 100644 index 0000000..8c129f4 --- /dev/null +++ b/Library/Miscellanious/template2024.cpp @@ -0,0 +1,41 @@ +#include +#ifndef ONLINE_JUDGE + #include "logger.h" +#else + #define deb(...) + #define deb(...) +#endif +using namespace std; +#define ll long long +#define all(x) x.begin(), x.end() +int mpow(int base, int exp); +//======================= +const int MOD = 1'000'000'007; +const int N = 2003, M = N; +vector g[N]; +int a[N]; + +void solve() { + +} + +int main() { + ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); + int t = 1; + cin >> t; + while(t--) { + solve(); + } + return 0; +} + +int mpow(int base, int exp) { + base %= MOD; + int result = 1; + while (exp > 0) { + if (exp & 1) result = ((ll)result * base) % MOD; + base = ((ll)base * base) % MOD; + exp >>= 1; + } + return result; +} \ No newline at end of file diff --git a/Library/Utils/bits/stdc++.h b/Library/Utils/bits/stdc++.h new file mode 100644 index 0000000..4886b92 --- /dev/null +++ b/Library/Utils/bits/stdc++.h @@ -0,0 +1,117 @@ +// C++ includes used for precompiling -*- C++ -*- + +// Copyright (C) 2003-2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file stdc++.h + * This is an implementation file for a precompiled header. + */ + +// 17.4.1.2 Headers + +// C +#ifndef _GLIBCXX_NO_ASSERT +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if __cplusplus >= 201103L +#include +#include +#include +// #include +#include +#include +#include +#include +#include +#endif + +// C++ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if __cplusplus >= 201103L +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif \ No newline at end of file diff --git a/Library/Utils/codeforces.sh b/Library/Utils/codeforces.sh new file mode 100644 index 0000000..444da0b --- /dev/null +++ b/Library/Utils/codeforces.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Get the root directory of the Git repository +GIT_ROOT=$(git rev-parse --show-toplevel) + +function enter() { + mkdir -p $GIT_ROOT/CodeforcesContestRunner; + cd $GIT_ROOT/CodeforcesContestRunner; + cp $GIT_ROOT/Library/Miscellanious/template2024.cpp a.cpp + cp $GIT_ROOT/Library/Miscellanious/template2024.cpp b.cpp + cp $GIT_ROOT/Library/Miscellanious/template2024.cpp c.cpp + cp $GIT_ROOT/Library/Miscellanious/template2024.cpp d.cpp + cp $GIT_ROOT/Library/Miscellanious/template2024.cpp e.cpp + echo '' > in.txt +} + +function build() { + problem=$1 + g++ -std=c++20 $problem.cpp -o run_$problem -isystem $GIT_ROOT/Library/Utils +} + +function run() { + problem=$1 + ./run_$problem +} + +function runtxt() { + problem=$1 + ./run_$problem < in.txt +} \ No newline at end of file diff --git a/Library/Utils/logger.h b/Library/Utils/logger.h new file mode 100644 index 0000000..593d3a7 --- /dev/null +++ b/Library/Utils/logger.h @@ -0,0 +1,108 @@ +#include +// #define cerr cout +namespace __DEBUG_UTIL__ +{ + using namespace std; + template + concept is_iterable = requires(T &&x) { begin(x); } && + !is_same_v, string>; + void print(const char *x) { cerr << x; } + void print(char x) { cerr << "\'" << x << "\'"; } + void print(bool x) { cerr << (x ? "T" : "F"); } + void print(string x) { cerr << "\"" << x << "\""; } + void print(vector &v) + { /* Overloaded this because stl optimizes vector by using + _Bit_reference instead of bool to conserve space. */ + int f = 0; + cerr << '{'; + for (auto &&i : v) + cerr << (f++ ? "," : "") << (i ? "T" : "F"); + cerr << "}"; + } + template + void print(T &&x) + { + if constexpr (is_iterable) + if (size(x) && is_iterable) + { /* Iterable inside Iterable */ + int f = 0; + cerr << "\n~~~~~\n"; + for (auto &&i : x) + { + cerr << setw(2) << left << f++, print(i), cerr << "\n"; + } + cerr << "~~~~~\n"; + } + else + { /* Normal Iterable */ + int f = 0; + cerr << "{"; + for (auto &&i : x) + cerr << (f++ ? "," : ""), print(i); + cerr << "}"; + } + else if constexpr (requires { x.pop(); }) /* Stacks, Priority Queues, Queues */ + { + auto temp = x; + int f = 0; + cerr << "{"; + if constexpr (requires { x.top(); }) + while (!temp.empty()) + cerr << (f++ ? "," : ""), print(temp.top()), temp.pop(); + else + while (!temp.empty()) + cerr << (f++ ? "," : ""), print(temp.front()), temp.pop(); + cerr << "}"; + } + else if constexpr (requires { x.first; x.second; }) /* Pair */ + { + cerr << '(', print(x.first), cerr << ',', print(x.second), cerr << ')'; + } + else if constexpr (requires { get<0>(x); }) /* Tuple */ + { + int f = 0; + cerr << '(', apply([&f](auto... args) + { ((cerr << (f++ ? "," : ""), print(args)), ...); }, + x); + cerr << ')'; + } + else + cerr << x; + } + template + void printer(const char *names, T &&head, V &&...tail) + { + int i = 0; + for (size_t bracket = 0; names[i] != '\0' and (names[i] != ',' or bracket != 0); i++) + if (names[i] == '(' or names[i] == '<' or names[i] == '{') + bracket++; + else if (names[i] == ')' or names[i] == '>' or names[i] == '}') + bracket--; + cerr.write(names, i) << " = "; + print(head); + if constexpr (sizeof...(tail)) + cerr << " ||", printer(names + i + 1, tail...); + else + cerr << "]\n"; + } + template + void printerArr(const char *names, T arr[], size_t N, V... tail) + { + size_t i = 0; + for (; names[i] and names[i] != ','; i++) + cerr << names[i]; + for (i++; names[i] and names[i] != ','; i++) + ; + cerr << " = {"; + for (size_t ind = 0; ind < N; ind++) + cerr << (ind ? "," : ""), print(arr[ind]); + cerr << "}"; + if constexpr (sizeof...(tail)) + cerr << " ||", printerArr(names + i + 1, tail...); + else + cerr << "]\n"; + } + +} +#define deb(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printer(#__VA_ARGS__, __VA_ARGS__) +#define debArr(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printerArr(#__VA_ARGS__, __VA_ARGS__) \ No newline at end of file