├── .devcontainer ├── .config │ └── online-judge-tools │ │ └── prepare.config.toml ├── Dockerfile ├── devcontainer.json ├── reinstall-cmake.sh └── setup.sh ├── .gitattributes ├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── README.md └── doc ├── donwloaded_problems.png ├── download_code.png ├── login.png └── open_dev_container.png /.devcontainer/.config/online-judge-tools/prepare.config.toml: -------------------------------------------------------------------------------- 1 | contest_directory = "/home/vscode/coding/contest/{service_domain}/{contest_id}/{problem_id}" 2 | problem_directory = "." 3 | 4 | [templates] 5 | "main.cpp" = "main.cpp" 6 | "generate.py" = "generate.py" 7 | -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/cpp/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Debian / Ubuntu version (use Debian 11, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-11, debian-10, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 4 | ARG VARIANT="bullseye" 5 | FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT} 6 | 7 | # [Optional] Install CMake version different from what base image has already installed. 8 | # CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https://cmake.org/download/ 9 | ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="none" 10 | 11 | # Optionally install the cmake for vcpkg 12 | COPY ./reinstall-cmake.sh /tmp/ 13 | RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ 14 | /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \ 15 | fi \ 16 | && rm -f /tmp/reinstall-cmake.sh 17 | 18 | COPY .config/online-judge-tools /home/vscode/online-judge-tools 19 | 20 | # [Optional] Uncomment this section to install additional vcpkg ports. 21 | # RUN su vscode -c "${VCPKG_ROOT}/vcpkg install " 22 | 23 | # [Optional] Uncomment this section to install additional packages. 24 | RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 25 | && apt-get -y install --no-install-recommends lv vim -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.224.2/containers/cpp 3 | { 4 | "name": "cpp-programming-contest-environment", 5 | "workspaceMount": "source=${localWorkspaceFolder},target=/home/vscode/coding,type=bind", 6 | "workspaceFolder": "/home/vscode/coding", 7 | "build": { 8 | "dockerfile": "Dockerfile", 9 | // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 10 | // Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon 11 | "args": { 12 | "VARIANT": "ubuntu-20.04" 13 | } 14 | }, 15 | "runArgs": [ 16 | "--cap-add=SYS_PTRACE", 17 | "--security-opt", 18 | "seccomp=unconfined" 19 | ], 20 | // Set *default* container specific settings.json values on container create. 21 | "settings": { 22 | "macros": { 23 | "commentLine": [ 24 | "editor.action.commentLine", 25 | "cursorDown" 26 | ], 27 | "copyWithoutNewLine": [ 28 | "cursorHome", 29 | "cursorEndSelect", 30 | "editor.action.clipboardCopyAction", 31 | "cancelSelection" 32 | ] 33 | }, 34 | }, 35 | // Add the IDs of extensions you want installed when the container is created. 36 | "extensions": [ 37 | "geddski.macros", 38 | "ms-vscode.cpptools", 39 | "ms-vscode.cmake-tools" 40 | ], 41 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 42 | // "forwardPorts": [], 43 | // Use 'postCreateCommand' to run commands after the container is created. 44 | "postCreateCommand": "./.devcontainer/setup.sh", 45 | // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 46 | "remoteUser": "vscode", 47 | "features": { 48 | "git": "latest", 49 | "node": "lts", 50 | "python": "latest" 51 | } 52 | } -------------------------------------------------------------------------------- /.devcontainer/reinstall-cmake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #------------------------------------------------------------------------------------------------------------- 3 | # Copyright (c) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. 5 | #------------------------------------------------------------------------------------------------------------- 6 | # 7 | set -e 8 | 9 | CMAKE_VERSION=${1:-"none"} 10 | 11 | if [ "${CMAKE_VERSION}" = "none" ]; then 12 | echo "No CMake version specified, skipping CMake reinstallation" 13 | exit 0 14 | fi 15 | 16 | # Cleanup temporary directory and associated files when exiting the script. 17 | cleanup() { 18 | EXIT_CODE=$? 19 | set +e 20 | if [[ -n "${TMP_DIR}" ]]; then 21 | echo "Executing cleanup of tmp files" 22 | rm -Rf "${TMP_DIR}" 23 | fi 24 | exit $EXIT_CODE 25 | } 26 | trap cleanup EXIT 27 | 28 | 29 | echo "Installing CMake..." 30 | apt-get -y purge --auto-remove cmake 31 | mkdir -p /opt/cmake 32 | 33 | architecture=$(dpkg --print-architecture) 34 | case "${architecture}" in 35 | arm64) 36 | ARCH=aarch64 ;; 37 | amd64) 38 | ARCH=x86_64 ;; 39 | *) 40 | echo "Unsupported architecture ${architecture}." 41 | exit 1 42 | ;; 43 | esac 44 | 45 | CMAKE_BINARY_NAME="cmake-${CMAKE_VERSION}-linux-${ARCH}.sh" 46 | CMAKE_CHECKSUM_NAME="cmake-${CMAKE_VERSION}-SHA-256.txt" 47 | TMP_DIR=$(mktemp -d -t cmake-XXXXXXXXXX) 48 | 49 | echo "${TMP_DIR}" 50 | cd "${TMP_DIR}" 51 | 52 | curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_BINARY_NAME}" -O 53 | curl -sSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_CHECKSUM_NAME}" -O 54 | 55 | sha256sum -c --ignore-missing "${CMAKE_CHECKSUM_NAME}" 56 | sh "${TMP_DIR}/${CMAKE_BINARY_NAME}" --prefix=/opt/cmake --skip-license 57 | 58 | ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake 59 | -------------------------------------------------------------------------------- /.devcontainer/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | set -x 5 | 6 | npm install -g atcoder-cli 7 | pip3 install online-judge-tools 8 | pip3 install online-judge-template-generator 9 | 10 | (mkdir -p ~/.config/online-judge-tools && cp ~/online-judge-tools/prepare.config.toml ~/.config/online-judge-tools/) 11 | 12 | (cd && \ 13 | mkdir -p ac-library && \ 14 | wget https://github.com/atcoder/ac-library/releases/download/v1.4/ac-library.zip && \ 15 | unzip ac-library.zip -d ac-library && \ 16 | rm ac-library.zip) -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://github.com/microsoft/vscode-remote-release/issues/302#issuecomment-492703011 2 | * -crlf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Generated by gibo (https://github.com/simonwhitaker/gibo) 2 | ### https://raw.github.com/github/gitignore/ce5da10a3a43c4dd8bd9572eda17c0a37ee0eac1/C++.gitignore 3 | 4 | # Prerequisites 5 | *.d 6 | 7 | # Compiled Object files 8 | *.slo 9 | *.lo 10 | *.o 11 | *.obj 12 | 13 | # Precompiled Headers 14 | *.gch 15 | *.pch 16 | 17 | # Compiled Dynamic libraries 18 | *.so 19 | *.dylib 20 | *.dll 21 | 22 | # Fortran module files 23 | *.mod 24 | *.smod 25 | 26 | # Compiled Static libraries 27 | *.lai 28 | *.la 29 | *.a 30 | *.lib 31 | 32 | # Executables 33 | *.exe 34 | *.out 35 | *.app 36 | *.out 37 | 38 | # ignore contest 39 | contest -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "/home/vscode/ac-library", 8 | ], 9 | "defines": [], 10 | "compilerPath": "/usr/bin/clang", 11 | "cStandard": "gnu17", 12 | "cppStandard": "c++17", 13 | "intelliSenseMode": "linux-clang-x64" 14 | } 15 | ], 16 | "version": 4 17 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "g++ - Build and debug active file", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${fileDirname}/a.out", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${fileDirname}", 15 | "environment": [], 16 | "externalConsole": false, 17 | "MIMode": "gdb", 18 | "setupCommands": [ 19 | { 20 | "description": "Enable pretty-printing for gdb", 21 | "text": "-enable-pretty-printing", 22 | "ignoreFailures": true 23 | }, 24 | { 25 | "description": "Set Disassembly Flavor to Intel", 26 | "text": "-gdb-set disassembly-flavor intel", 27 | "ignoreFailures": true 28 | } 29 | ], 30 | "preLaunchTask": "build code", 31 | "miDebuggerPath": "/usr/bin/gdb" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.xml.rels": "xml", 4 | "any": "cpp", 5 | "array": "cpp", 6 | "atomic": "cpp", 7 | "bit": "cpp", 8 | "*.tcc": "cpp", 9 | "bitset": "cpp", 10 | "cctype": "cpp", 11 | "cfenv": "cpp", 12 | "charconv": "cpp", 13 | "chrono": "cpp", 14 | "cinttypes": "cpp", 15 | "clocale": "cpp", 16 | "cmath": "cpp", 17 | "codecvt": "cpp", 18 | "complex": "cpp", 19 | "condition_variable": "cpp", 20 | "csetjmp": "cpp", 21 | "csignal": "cpp", 22 | "cstdarg": "cpp", 23 | "cstddef": "cpp", 24 | "cstdint": "cpp", 25 | "cstdio": "cpp", 26 | "cstdlib": "cpp", 27 | "cstring": "cpp", 28 | "ctime": "cpp", 29 | "cuchar": "cpp", 30 | "cwchar": "cpp", 31 | "cwctype": "cpp", 32 | "deque": "cpp", 33 | "forward_list": "cpp", 34 | "list": "cpp", 35 | "map": "cpp", 36 | "set": "cpp", 37 | "unordered_map": "cpp", 38 | "unordered_set": "cpp", 39 | "vector": "cpp", 40 | "exception": "cpp", 41 | "algorithm": "cpp", 42 | "functional": "cpp", 43 | "iterator": "cpp", 44 | "memory": "cpp", 45 | "memory_resource": "cpp", 46 | "numeric": "cpp", 47 | "optional": "cpp", 48 | "random": "cpp", 49 | "ratio": "cpp", 50 | "regex": "cpp", 51 | "string": "cpp", 52 | "string_view": "cpp", 53 | "system_error": "cpp", 54 | "tuple": "cpp", 55 | "type_traits": "cpp", 56 | "utility": "cpp", 57 | "fstream": "cpp", 58 | "future": "cpp", 59 | "initializer_list": "cpp", 60 | "iomanip": "cpp", 61 | "iosfwd": "cpp", 62 | "iostream": "cpp", 63 | "istream": "cpp", 64 | "limits": "cpp", 65 | "mutex": "cpp", 66 | "new": "cpp", 67 | "ostream": "cpp", 68 | "scoped_allocator": "cpp", 69 | "shared_mutex": "cpp", 70 | "sstream": "cpp", 71 | "stdexcept": "cpp", 72 | "streambuf": "cpp", 73 | "thread": "cpp", 74 | "typeindex": "cpp", 75 | "typeinfo": "cpp", 76 | "valarray": "cpp", 77 | "variant": "cpp", 78 | "scc": "cpp" 79 | } 80 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "shell", 5 | "label": "download code", 6 | "command": "oj-prepare", 7 | "args": [ 8 | "${input:url}", 9 | ], 10 | "problemMatcher": [] 11 | }, 12 | { 13 | "type": "cppbuild", 14 | "label": "build code", 15 | "command": "/usr/bin/g++", 16 | "args": [ 17 | "-fdiagnostics-color=always", 18 | "-std=gnu++17", 19 | "-g", 20 | "-Wall", 21 | "${file}", 22 | "-I", 23 | "~/ac-library", 24 | "-o", 25 | "${fileDirname}/a.out" 26 | ], 27 | "options": { 28 | "cwd": "${fileDirname}" 29 | }, 30 | "problemMatcher": [ 31 | "$gcc" 32 | ], 33 | "group": { 34 | "kind": "none" 35 | }, 36 | "presentation": { 37 | "reveal": "always", 38 | "panel": "shared", 39 | "focus": true, 40 | "clear": true 41 | } 42 | }, 43 | { 44 | "type": "shell", 45 | "label": "run code", 46 | "command": "./a.out", 47 | "options": { 48 | "cwd": "${fileDirname}" 49 | }, 50 | "group": { 51 | "kind": "none", 52 | "isDefault": true 53 | }, 54 | "problemMatcher": [], 55 | "dependsOn": [ 56 | "build code" 57 | ], 58 | "presentation": { 59 | "reveal": "always", 60 | "panel": "shared", 61 | "focus": true 62 | } 63 | }, 64 | { 65 | "type": "shell", 66 | "label": "login", 67 | "command": "oj", 68 | "args": [ 69 | "login", 70 | "${input:url}", 71 | "-u", 72 | "${input:user}", 73 | "-p", 74 | "${input:password}", 75 | ], 76 | "problemMatcher": [], 77 | "options": {}, 78 | }, 79 | { 80 | "type": "shell", 81 | "label": "test code", 82 | "command": "oj", 83 | "args": [ 84 | "t" 85 | ], 86 | "options": { 87 | "cwd": "${fileDirname}" 88 | }, 89 | "group": { 90 | "kind": "test", 91 | "isDefault": true 92 | }, 93 | "problemMatcher": [], 94 | "dependsOn": [ 95 | "build code" 96 | ], 97 | "presentation": { 98 | "reveal": "always", 99 | "panel": "shared", 100 | "focus": true 101 | } 102 | }, 103 | { 104 | "type": "shell", 105 | "label": "submit code", 106 | "command": "oj", 107 | "args": [ 108 | "s", 109 | "-y", 110 | "${fileBasename}" 111 | ], 112 | "options": { 113 | "cwd": "${fileDirname}" 114 | }, 115 | "group": { 116 | "kind": "build" 117 | }, 118 | "problemMatcher": [], 119 | "dependsOn": [ 120 | "test code" 121 | ], 122 | "presentation": { 123 | "reveal": "always", 124 | "panel": "shared", 125 | "focus": true 126 | } 127 | } 128 | ], 129 | "inputs": [ 130 | { 131 | "id": "url", 132 | "description": "url:", 133 | "type": "promptString" 134 | }, 135 | { 136 | "id": "user", 137 | "description": "user:", 138 | "type": "promptString" 139 | }, 140 | { 141 | "id": "password", 142 | "description": "password:", 143 | "type": "promptString" 144 | } 145 | ], 146 | "version": "2.0.0" 147 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 2-Click C++ Programming Contest Environment 2 | 3 | This repository make it possible for programmers to create C++ programming contest environment by 2-Click. 4 | 5 | ## Why is it useful? 6 | 7 | It is very tedious job to install all necessary compilers and tools to local computer. There might be some errors to overcome to submit C++ program to programming contest service. What programmers want to do is not developping environment but developping program. 8 | 9 | This repository uses [VSCode Dev Container](https://code.visualstudio.com/docs/remote/containers) to create the environment with 2-Click. 10 | 11 | ## Tested Environments 12 | 13 | * Windows 10 14 | * Mac with Intel Chip 15 | * Mac with Apple Chip 16 | 17 | ## Getting started 18 | 19 | ### Requirements 20 | 21 | Install the following applications. 22 | 23 | * [Docker Desktop](https://www.docker.com/products/docker-desktop) 24 | * [VSCode](https://code.visualstudio.com/) 25 | 26 | ### Setup environment 27 | 28 | Open this repository with VSCode. 29 | Click left bottom corner of the VSCode window as follows, then choose "Reopen in Container". 30 | 31 | ![doc/open_dev_container.png](doc/open_dev_container.png) 32 | 33 | Wait for a while. After builds and setups, you can write code in dev container environment. 34 | (First time, it takes for long time, but next time, it's quick to open the environment.) 35 | 36 | This environment contains the following tools. 37 | 38 | * [online-judge-tools](https://github.com/online-judge-tools/oj) 39 | * [online-judge-template-generator](https://github.com/online-judge-tools/template-generator) 40 | * [atcoder-cli](https://github.com/Tatamo/atcoder-cli) 41 | 42 | ### Solve programming content problem 43 | 44 | For example, let's solve [AtCoder Library Practice Contest 45 | ](https://atcoder.jp/contests/practice2). 46 | 47 | There are three tasks to do. 48 | 49 | 1. Login (Once) 50 | 2. Download problem 51 | 3. Solve and submit 52 | 53 | First, login to the contest page to submit code afterwards. 54 | 55 | To login/download/submit problem, the dev container uses `oj` tool. 56 | In this repository, there is the specific VSCode task to login contest site. 57 | 58 | Choose `Terminal -> Run Task` from VSCode menu, then choose `login`. 59 | You should enter, `https://atcoder.jp/contests/practice2` as url, `your atcoder username` as password and `your atcoder password` as password. If you haven't created account, please create it for [register](https://atcoder.jp/register). 60 | 61 | ![doc/login.png](doc/login.png) 62 | 63 | Second, choose `Terminal -> Run Task` from VSCode menu, then choose `download code`. 64 | 65 | ![doc/download_code.png](doc/download_code.png) 66 | 67 | Enter the problem URL `https://atcoder.jp/contests/practice2` to the input and click enter. 68 | Inside the task, `oj-prepare https://atcoder.jp/contests/practice2` is executed, automatically problem set is donwloaded to under `contest/atcoder.jp/practice2` directory. 69 | 70 | ![doc/donwloaded_problems.png](doc/donwloaded_problems.png) 71 | 72 | Open, `contest/atcoder.jp/practice2/practice2_a/main.cpp` in VSCode, then solve the problem. 73 | 74 | Lastly, you can submit the code to AtCoder. 75 | Choose `Terminal -> Run Task` from VSCode menu while opening the solved `main.cpp` code, then choose `submit code`. 76 | 77 | Boom! The code is tested and submitted to the contest. If it has any error, you can see it on Terminal. 78 | 79 | ## Tips 80 | 81 | ### Use debugger 82 | 83 | To debug code, click `Run start Debugging` in menu while opening code. 84 | Then, input should be put in terminal. The following shows how to debug the code. 85 | 86 | https://user-images.githubusercontent.com/5561944/158003876-9c6bf878-61c0-45de-9993-80b875f7fc8b.mp4 87 | 88 | ### Use git to commit problem codes. 89 | 90 | Any file under `content` directory, it is ignored by `.gitignore`. 91 | You can delete `contest` line from `.gitignore` to commit these files. 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /doc/donwloaded_problems.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wapa5pow/cpp-programming-contest-environment/a85913805f9cf07d755cc277ab8ee995c90c5744/doc/donwloaded_problems.png -------------------------------------------------------------------------------- /doc/download_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wapa5pow/cpp-programming-contest-environment/a85913805f9cf07d755cc277ab8ee995c90c5744/doc/download_code.png -------------------------------------------------------------------------------- /doc/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wapa5pow/cpp-programming-contest-environment/a85913805f9cf07d755cc277ab8ee995c90c5744/doc/login.png -------------------------------------------------------------------------------- /doc/open_dev_container.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wapa5pow/cpp-programming-contest-environment/a85913805f9cf07d755cc277ab8ee995c90c5744/doc/open_dev_container.png --------------------------------------------------------------------------------