Skip to content

Commit da7e12d

Browse files
committed
Codeforces Contest Runner and Debug Logger during Local
1 parent ca63481 commit da7e12d

File tree

5 files changed

+300
-1
lines changed

5 files changed

+300
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@
2929
# Executables
3030
*.exe
3131
*.out
32-
*.app
32+
*.app
33+
34+
# Temp Codeforces Contest Env
35+
CodeforcesContestRunner
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<bits/stdc++.h>
2+
#ifndef ONLINE_JUDGE
3+
#include "logger.h"
4+
#else
5+
#define deb(...)
6+
#define deb(...)
7+
#endif
8+
using namespace std;
9+
#define ll long long
10+
#define all(x) x.begin(), x.end()
11+
int mpow(int base, int exp);
12+
//=======================
13+
const int MOD = 1'000'000'007;
14+
const int N = 2003, M = N;
15+
vector<int> g[N];
16+
int a[N];
17+
18+
void solve() {
19+
20+
}
21+
22+
int main() {
23+
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
24+
int t = 1;
25+
cin >> t;
26+
while(t--) {
27+
solve();
28+
}
29+
return 0;
30+
}
31+
32+
int mpow(int base, int exp) {
33+
base %= MOD;
34+
int result = 1;
35+
while (exp > 0) {
36+
if (exp & 1) result = ((ll)result * base) % MOD;
37+
base = ((ll)base * base) % MOD;
38+
exp >>= 1;
39+
}
40+
return result;
41+
}

Library/Utils/bits/stdc++.h

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// C++ includes used for precompiling -*- C++ -*-
2+
3+
// Copyright (C) 2003-2015 Free Software Foundation, Inc.
4+
//
5+
// This file is part of the GNU ISO C++ Library. This library is free
6+
// software; you can redistribute it and/or modify it under the
7+
// terms of the GNU General Public License as published by the
8+
// Free Software Foundation; either version 3, or (at your option)
9+
// any later version.
10+
11+
// This library is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
16+
// Under Section 7 of GPL version 3, you are granted additional
17+
// permissions described in the GCC Runtime Library Exception, version
18+
// 3.1, as published by the Free Software Foundation.
19+
20+
// You should have received a copy of the GNU General Public License and
21+
// a copy of the GCC Runtime Library Exception along with this program;
22+
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23+
// <http://www.gnu.org/licenses/>.
24+
25+
/** @file stdc++.h
26+
* This is an implementation file for a precompiled header.
27+
*/
28+
29+
// 17.4.1.2 Headers
30+
31+
// C
32+
#ifndef _GLIBCXX_NO_ASSERT
33+
#include <cassert>
34+
#endif
35+
#include <cctype>
36+
#include <cerrno>
37+
#include <cfloat>
38+
#include <ciso646>
39+
#include <climits>
40+
#include <clocale>
41+
#include <cmath>
42+
#include <csetjmp>
43+
#include <csignal>
44+
#include <cstdarg>
45+
#include <cstddef>
46+
#include <cstdio>
47+
#include <cstdlib>
48+
#include <cstring>
49+
#include <ctime>
50+
51+
#if __cplusplus >= 201103L
52+
#include <ccomplex>
53+
#include <cfenv>
54+
#include <cinttypes>
55+
// #include <cstdalign>
56+
#include <cstdbool>
57+
#include <cstdint>
58+
#include <ctgmath>
59+
#include <cwchar>
60+
#include <cwctype>
61+
#endif
62+
63+
// C++
64+
#include <algorithm>
65+
#include <bitset>
66+
#include <complex>
67+
#include <deque>
68+
#include <exception>
69+
#include <fstream>
70+
#include <functional>
71+
#include <iomanip>
72+
#include <ios>
73+
#include <iosfwd>
74+
#include <iostream>
75+
#include <istream>
76+
#include <iterator>
77+
#include <limits>
78+
#include <list>
79+
#include <locale>
80+
#include <map>
81+
#include <memory>
82+
#include <new>
83+
#include <numeric>
84+
#include <ostream>
85+
#include <queue>
86+
#include <set>
87+
#include <sstream>
88+
#include <stack>
89+
#include <stdexcept>
90+
#include <streambuf>
91+
#include <string>
92+
#include <typeinfo>
93+
#include <utility>
94+
#include <valarray>
95+
#include <vector>
96+
97+
#if __cplusplus >= 201103L
98+
#include <array>
99+
#include <atomic>
100+
#include <chrono>
101+
#include <condition_variable>
102+
#include <forward_list>
103+
#include <future>
104+
#include <initializer_list>
105+
#include <mutex>
106+
#include <random>
107+
#include <ratio>
108+
#include <regex>
109+
#include <scoped_allocator>
110+
#include <system_error>
111+
#include <thread>
112+
#include <tuple>
113+
#include <typeindex>
114+
#include <type_traits>
115+
#include <unordered_map>
116+
#include <unordered_set>
117+
#endif

Library/Utils/codeforces.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Get the root directory of the Git repository
4+
GIT_ROOT=$(git rev-parse --show-toplevel)
5+
6+
function enter() {
7+
mkdir -p $GIT_ROOT/CodeforcesContestRunner;
8+
cd $GIT_ROOT/CodeforcesContestRunner;
9+
cp $GIT_ROOT/Library/Miscellanious/template2024.cpp a.cpp
10+
cp $GIT_ROOT/Library/Miscellanious/template2024.cpp b.cpp
11+
cp $GIT_ROOT/Library/Miscellanious/template2024.cpp c.cpp
12+
cp $GIT_ROOT/Library/Miscellanious/template2024.cpp d.cpp
13+
cp $GIT_ROOT/Library/Miscellanious/template2024.cpp e.cpp
14+
echo '' > in.txt
15+
}
16+
17+
function build() {
18+
problem=$1
19+
g++ -std=c++20 $problem.cpp -o run_$problem -isystem $GIT_ROOT/Library/Utils
20+
}
21+
22+
function run() {
23+
problem=$1
24+
./run_$problem
25+
}
26+
27+
function runtxt() {
28+
problem=$1
29+
./run_$problem < in.txt
30+
}

Library/Utils/logger.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#include <bits/stdc++.h>
2+
// #define cerr cout
3+
namespace __DEBUG_UTIL__
4+
{
5+
using namespace std;
6+
template <typename T>
7+
concept is_iterable = requires(T &&x) { begin(x); } &&
8+
!is_same_v<remove_cvref_t<T>, string>;
9+
void print(const char *x) { cerr << x; }
10+
void print(char x) { cerr << "\'" << x << "\'"; }
11+
void print(bool x) { cerr << (x ? "T" : "F"); }
12+
void print(string x) { cerr << "\"" << x << "\""; }
13+
void print(vector<bool> &v)
14+
{ /* Overloaded this because stl optimizes vector<bool> by using
15+
_Bit_reference instead of bool to conserve space. */
16+
int f = 0;
17+
cerr << '{';
18+
for (auto &&i : v)
19+
cerr << (f++ ? "," : "") << (i ? "T" : "F");
20+
cerr << "}";
21+
}
22+
template <typename T>
23+
void print(T &&x)
24+
{
25+
if constexpr (is_iterable<T>)
26+
if (size(x) && is_iterable<decltype(*(begin(x)))>)
27+
{ /* Iterable inside Iterable */
28+
int f = 0;
29+
cerr << "\n~~~~~\n";
30+
for (auto &&i : x)
31+
{
32+
cerr << setw(2) << left << f++, print(i), cerr << "\n";
33+
}
34+
cerr << "~~~~~\n";
35+
}
36+
else
37+
{ /* Normal Iterable */
38+
int f = 0;
39+
cerr << "{";
40+
for (auto &&i : x)
41+
cerr << (f++ ? "," : ""), print(i);
42+
cerr << "}";
43+
}
44+
else if constexpr (requires { x.pop(); }) /* Stacks, Priority Queues, Queues */
45+
{
46+
auto temp = x;
47+
int f = 0;
48+
cerr << "{";
49+
if constexpr (requires { x.top(); })
50+
while (!temp.empty())
51+
cerr << (f++ ? "," : ""), print(temp.top()), temp.pop();
52+
else
53+
while (!temp.empty())
54+
cerr << (f++ ? "," : ""), print(temp.front()), temp.pop();
55+
cerr << "}";
56+
}
57+
else if constexpr (requires { x.first; x.second; }) /* Pair */
58+
{
59+
cerr << '(', print(x.first), cerr << ',', print(x.second), cerr << ')';
60+
}
61+
else if constexpr (requires { get<0>(x); }) /* Tuple */
62+
{
63+
int f = 0;
64+
cerr << '(', apply([&f](auto... args)
65+
{ ((cerr << (f++ ? "," : ""), print(args)), ...); },
66+
x);
67+
cerr << ')';
68+
}
69+
else
70+
cerr << x;
71+
}
72+
template <typename T, typename... V>
73+
void printer(const char *names, T &&head, V &&...tail)
74+
{
75+
int i = 0;
76+
for (size_t bracket = 0; names[i] != '\0' and (names[i] != ',' or bracket != 0); i++)
77+
if (names[i] == '(' or names[i] == '<' or names[i] == '{')
78+
bracket++;
79+
else if (names[i] == ')' or names[i] == '>' or names[i] == '}')
80+
bracket--;
81+
cerr.write(names, i) << " = ";
82+
print(head);
83+
if constexpr (sizeof...(tail))
84+
cerr << " ||", printer(names + i + 1, tail...);
85+
else
86+
cerr << "]\n";
87+
}
88+
template <typename T, typename... V>
89+
void printerArr(const char *names, T arr[], size_t N, V... tail)
90+
{
91+
size_t i = 0;
92+
for (; names[i] and names[i] != ','; i++)
93+
cerr << names[i];
94+
for (i++; names[i] and names[i] != ','; i++)
95+
;
96+
cerr << " = {";
97+
for (size_t ind = 0; ind < N; ind++)
98+
cerr << (ind ? "," : ""), print(arr[ind]);
99+
cerr << "}";
100+
if constexpr (sizeof...(tail))
101+
cerr << " ||", printerArr(names + i + 1, tail...);
102+
else
103+
cerr << "]\n";
104+
}
105+
106+
}
107+
#define deb(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printer(#__VA_ARGS__, __VA_ARGS__)
108+
#define debArr(...) std::cerr << __LINE__ << ": [", __DEBUG_UTIL__::printerArr(#__VA_ARGS__, __VA_ARGS__)

0 commit comments

Comments
 (0)