Presets for NOI series Algorithm Contests

Presets for NOI series Algorithm Contests

System Settings

1
2
3
gsettings set org.gnome.desktop.interface cursor-blink false
gsettings set org.gnome.desktop.wm.preferences focus-mode mouse
xset r rate 300 50 # X11 repeat rate

Editor Configuration

GNOME Terminal

Change color schemes to Tango dark.

Vim

in ~/.vimrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
syntax on
set expandtab softtabstop=2 shiftwidth=2
set ai cindent copyindent
set mouse=a
"set number relativenumber
autocmd BufWritePost *.cpp :!g++ -DMISAKA %:p -o %:p:r
autocmd BufNewFile *.cpp 0r ~/cpp.cpp
nmap S :s//g<left><left>
inoremap ' ''<left>
inoremap " ""<left>
inoremap { {}<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap "" "
inoremap '' '
inoremap [[ [
inoremap (( (
inoremap {{ {

Code::Blocks IDE Configuration (Debugging)

Reminder: debugging with Code::Blocks requires pasting original code to main.cpp then paste the modified version back, be careful!

  1. Create a new project

  2. choose Console application

  3. specify folder name (must done)

  4. copy code to main.cpp to start debugging;

Code Snippets/Templates

C++ main solution file

in ~/cpp.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int, int> pii;
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define FOR(i, j, k) for (int i = (j); i < (k); ++i)
#define ROF(i, j, k) for (int i = ((k) - 1); i >= j; --i)
template<typename T>
inline void chkmin(T &a, const T b) {
a = min(a, b);
}
template<typename T>
inline void chkmax(T &a, const T b) {
a = max(a, b);
}

const int N = ;

inline void solve() {

}

int main() {
#ifndef MISAKA
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
#endif
solve();
return 0;
}
/* Checklist:
* - data type
* - overflow
* - typo/logic
* - special cases
* - cleanup (multi-test)
* - bounds
* - memory usage
* - file IO
*/

C++ generator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int, int> pii;
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define FOR(i, j, k) for (int i = (j); i < (k); ++i)
#define ROF(i, j, k) for (int i = ((k) - 1); i >= j; --i)
template<typename T>
inline void chkmin(T &a, const T b) {
a = min(a, b);
}
template<typename T>
inline void chkmax(T &a, const T b) {
a = max(a, b);
}

typedef uniform_int_distribution<int> ui;
mt19937 gen;

const int N = ;

int main() {
gen = mt19937(chrono::steady_clock().now().time_since_epoch().count());

return 0;
}

checker script (random test cases batching)

Reminder: compile solution code without local flag.

one-liner validator script

1
2
3
4
for ((i=0; i < 10000; ++i)) {
echo "#$i"; ./gen > ex.in 2> ex.ans; ./ex;
diff ex.out ex.ans || break;
}

one-liner stress test script

1
2
3
for ((i=0;i<10000;++i)) {
echo "#$i"; ./gen > ex.in; time ./ex
}

other linux utilities

generate strings from /dev/urandom.

1
tr -dc "[a-z]" < /dev/urandom | head -c 1000

Reminders

Checklist

  • data type
  • overflow
  • typo/logic
  • special cases
  • cleanup (multi-test)
  • bounds
  • memory usage
  • file IO

Coding (Vim)

  • Since it's auto compile, never blindly :wq out of vim. Instead, see the compiler logs.

  • backup source file before massive modifications.

  • use vim with a calm mind to prevent disasters.

Update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void O(const T &x) { cout << x << '\n'; }
template <typename T, typename... W> inline void O(const T &x, const W &...b) {
cout << x << ' ';
O(b...);
}
#ifndef MISAKA
#define err(...)
#else
#define err(...) fprintf(stderr, __VA_ARGS__)
#endif
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef long double dbl;
typedef pair<int, int> pii;
typedef uniform_int_distribution<int> r32;
typedef uniform_int_distribution<i64> r64;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define shuf(L, R) shuffle((L), (R), rng)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define FOR(i, j, k) for (int i = (j); i <= (k); ++i)
#define ROF(i, j, k) for (int i = (k); i >= (j); --i)
template <typename T> inline void ckmin(T &a, const T &b) { a = min(a, b); }
template <typename T> inline void ckmax(T &a, const T &b) { a = max(a, b); }
//#define IOFILE "filename"
//#define MULTI
const int N = 0;

inline void sol() {
//
}

int main() {
#ifndef MISAKA
#ifdef IOFILE
freopen(IOFILE ".in", "r", stdin);
freopen(IOFILE ".out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
#endif
#ifdef MULTI
int T;
cin >> T;
while (T--)
#endif
sol();
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
syntax on
set expandtab softtabstop=2 shiftwidth=2
set ai cindent copyindent
set mouse=a
"set number relativenumber
autocmd BufWritePost *.cpp :!g++ -Wall -Wextra -Wconversion -fsanitize=undefined -g -DMISAKA %:p -o %:p:r
autocmd BufNewFile *.cpp 0r ~/misaka-cp/template/contest.cpp
nmap S :s//g<left><left>
inoremap ' ''<left>
inoremap " ""<left>
inoremap { {}<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap "" "
inoremap '' '
inoremap [[ [
inoremap (( (
inoremap {{ {

" extra
map <F5> :!xclip -selection c -o\|%:p:r<CR>
map <silent> <F6> :w !xclip -selection c<CR><CR>