Analyzing programming contest grandmasters' styles and tools - Gennady Korotkevich (tourist) vs Andrew He (ecnerwala) (2023-03-24)

This post is a commentary and analysis based on this video, which shows a competition between Gennady Korotkevich (tourist) and Andrew He (ecnerwala):

Watch the video here: https://www.youtube.com/watch?v=bBNIIg8REUU



Gena’s Code

ChatGPT 4 was used to recover the first 6 characters from Gena’s code snippet.
We see on the screen
image

So we know that "using " is missing in the first line of using namespace std; etc. (6 characters)
We also know that tourist tends to start his solutions with the following comment:

/**
 *    author:  tourist
 *    created: 16.03.2018 20:33:14       
**/
#include <bits/stdc++.h>
 
using namespace std;

Gena also has a template for his main function:

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  /* solution goes here */
  return 0;
}

So the code from the screenshot above is most likely this:

/**
 *    author:  tourist
 *    created: 10.05.2020 20:33:59       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    map<int, int> mp;
    long long ans = 0;
    
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        ans += mp[i - a];
        mp[i + a]++;
    }
    
    cout << ans << '\n';
    
    return 0;
}

Andrew’s code

image

#include <bits/stdc++.h>

int main() {
    using namespace std;
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    
    int N; cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    int64_t ans = 0;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        // H[i] + H[j] = i - j
        ans += mp[H[i] - i];
    }

    cout << ans << '\n';
    return 0;
}

Toolboxes (or Who Uses What to Compete)

What’s in Gena’s Toolbox

Lets find out what Gennady Korotkevich uses for programming competitions.
Here is what Gena uses and how he operates:

  • OS: Windows 10
  • browsers: Firefox, Chrome
  • no apparent version control (VCS) system
  • MinGW
  • C++ (GCC 9.2.1) (what atcoder.jp uses to evaluate)
  • IDE/Editor: Far Manager (version 3.0.4900 x64 (as of May 2020))
  • Gena does not have a shortcut for executing sol.exe with test input

Gena’s Setup:

  • has some automation to create the directories for the competition ahead of time:
    image
  • compiles with: C:\MinGW\MinGW\bin\g++.exe -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 !.! -o !.exe
  • executes the solution with: sol.exe <in1
  • based on the May 2020 video above there is no automation to submit the code. Gena copy/pastes from Far Manager to the competition website:

What’s in Andrew He’s toolbox

  • OS: macOS
  • IDE/Editor: NVIM / NeoVIM
    • NeoVIM Solarized Light Theme

Andrew uses automation download_prob.py to speed up the setup for the contest:

Andrew compiles with some iteration of:

g++ -std=c++17 -O2 -Wall -Wextra -pedantic -Wshadow -Wformat=2 \
  -Wfloat-equal -Wconversion -Wlogical-op -Wcast-qual -Wcast-align \
  -Wno-unused-result -Wno-sign-conversion \
  -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 \
  F.cpp -o F

What are all these flags?

  • -std=c++17 sets the C++ standard to C++17.
  • -O2 enables compiler optimizations.
  • -Wall enables all the warnings about constructions that are easy to avoid.
  • -Wextra enables extra warnings not covered by -Wall.
  • -pedantic ensures that the code adheres strictly to the standard.
  • -Wshadow warns whenever a local variable shadows another variable.
  • -Wformat=2 adds extra checks for printf/scanf, etc.
  • -Wfloat-equal warns if floating-point values are compared for equality.
  • -Wconversion warns for implicit conversions that may alter a value.
  • -Wlogical-op warns about suspicious uses of logical operators.
  • -Wcast-qual warns when a cast removes an attribute like const or volatile.
  • -Wcast-align warns where pointer casts increase alignment requirements.
  • -Wno-unused-result disables warnings for unused results.
  • -Wno-sign-conversion turns off warnings related to sign conversions.
  • -D_GLIBCXX_DEBUG enables macros for the debug version of the standard library.
  • -D_GLIBCXX_DEBUG_PEDANTIC is an even more pedantic version of the above.
  • -D_FORTIFY_SOURCE=2 adds security checks to detect buffer overflows.
  • F.cpp is the input source file to compile.
  • -o F specifies the output file name for the compiled executable.

It is interesting that Andrew keeps his competition solutions in a Dropbox folder → image

~/Dropbox/programming/AtCoder/ABC166/D

Andrew’s files are under git revision control → image

It is unclear from the video whether Andrew uses automation to submit his code to the judge or will do it manually (copy/paste from terminal?).


Far Manager

Configure Far Manager

  1. Create file associations in Far Manager.
  • Menu (F9) → Commands (C) → File associations (A)
  • Create a new file association (Insert):
    • mask: *.cc (or however you name your C++ files)
    • execute command for Enter: C:\MinGW\bin\g++.exe -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 !.! -o !.exe
    • execute command for Ctrl+PgDn: C:\MinGW\bin\g++.exe -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 !.! -o !.exe -DDEBUG -g

image

Press Enter on your sol.cc file to execute command g++ -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 sol.cpp -o sol.exe. This will compile the C++ code from sol.cc to an executable sol.exe. This assumes that you have C:\MinGW\bin\g++.exe. (Get MinGW from Nuwen.net)

Alternatively you can record the keystrokes necessary to do this operation and bind them to a hotkey (such as F9). Here are the instructions.


Far Manager Shortcuts

  • Ctrl-A - file attributes (equivalen* t to F9, F, A)
  • Alt-F9 - maximize window
  • Alt-Shift-F9 - configure plugins
  • Ctrl-Alt-Shift - hide windows while the keys are held
  • F4 on a folder - edit folders attributes (ctrl-a)
  • alt-left, right, home, end - scroll long names
  • ctrl-ins - copy names of the selected files into clipboard (command line empty, ctrl-shift-ins if not empty)
  • ctrl-alt-ins - copy network (unc) names into clipboard
  • alt-shift-ins - copy full (with path) names into clipboard
  • ctrl-f - full file name from the actve panel, crtl-: from passive (equiv to crtl-], ctrl-enter)
  • ctrl-end - command string completion from the history (press again to go to the next matching history line)
  • alt-f8 - command history
  • alt-f10 - find folder
  • alt-f11 - view and edit history
  • alt-f12 - folder history
  • shift-f1,f2,f3 - archive management commands
  • shift-f10 - show the last menu command
  • ctrl-\ - back to root
  • shift-enter in the drive menu - show root directory in explorer
  • ctrl-pgdn - enter in an archive/especially SFX
  • ctrl-g - run command on selected files, like “rar32 m !.!.rar !.!” to rar each file in its own archive
  • alt-ins - screen grabber
  • ctrl-“gray .” - record a keyboard macro
  • alt-del - wipe file, overwrite with 0, trunicate, rename to a temp name and delete.
  • ctrl-w - task list
  • ctrl-tab F12 - switch panes (screens) inside of far
  • ctrl-f full file name into the command line
  • alt shift ins full file name into clipboard for selected files
  • ctrl alt ins unc names into clipboard of the selected files
  • ctrl ins name into clipboard of the selected files if no cmd line
  • ctrl shift ins name into clipboard of the selected files always
  • ctrl m restore previous selection
  • ctrl enter in quick search (alt-letter) selects file and moves to the next
  • shift enter in history selects an item not changing its positions
  • In the drive menu - Shift - Del to disconnect Flash, Del remove a CD.
  • Ctrl-. to start recording macro. Ctrl-. again to end and assign a key
  • To erase a macro do Ctrl-. twice then use the key you want to erase.

FAR Shortcuts Printout

(source)


Links