1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

atcoder-libraryをdokcerfileに追加する(vscode, C++環境)

Last updated at Posted at 2022-09-30

前回の環境

AtCoderのコーディング環境の設定

今回の目的

atcoder-libraryを追加します。

dockerfile

git, python3-pip, pypy3, nodejs, npm, online-judge-tools, atcoder-cli, ac-libraryを使えるようにします。
imageは、「mcr.microsoft.com/vscode/devcontainers/cpp」を使用します。

dockerfile
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.134.0/containers/cpp/.devcontainer/base.Dockerfile
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
# インタラクティブモードにならないようにする
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install --no-install-recommends
# gitのインストール
RUN apt-get install -y git
# C++, Python3, PyPy3の3つの環境想定
RUN apt-get -y install python3-pip \
    pypy3 \
    nodejs \
    npm \
    && pip3 install online-judge-tools \
    && npm install -g atcoder-cli \
    && rm -rf /var/lib/apt/lists/* \
    && rm -rf ~/.cache/pip \
    && npm cache clean --force

# C++でAtCoder Library(ACL)を使えるようにする
RUN git clone https://github.com/atcoder/ac-library.git /lib/ac-library
ENV CPLUS_INCLUDE_PATH /lib/ac-library

launch.json

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++: Current File",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/a.out",
            "args": [
                "<input.txt"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build Main"
        },
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}",
            "args": [],
        }
    ]
}

tasks.json

ショートカットキーに登録する「CheckTestCase」、「SubmitCode」を追加しました。

tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Main",
            "type": "shell",
            "command": "g++",
            "args": [
                "-std=c++17",
                "-g",
                "${relativeFile}",
                "-o",
                "${fileDirname}/a.out"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "CheckTestCase",
            "type": "shell",
            "command": "cd ${fileDirname} && rm -f ${fileDirname}/${fileBasenameNoExtension} && g++ -std=gnu++17 ${fileBasename} -o a.out && oj test -c \"${fileDirname}/a.out\" -d ${fileDirname}/tests/",
            "presentation": {
                "reveal": "always",
                "focus": true,
                "panel": "shared",
            }
        },
        {
            "label": "SubmitCode",
            "type": "shell",
            "command": "cd ${fileDirname} && acc s ${fileBasename}",
            "presentation": {
                "reveal": "always",
                "focus": true,
                "panel": "shared",
            }
        },
    ]
}

ショートカットキー

vscodeの好きなキーに「CheckTestCase」、「SubmitCode」を追加します。

template

#include を記載してビルドできます。

C++
#include <bits/stdc++.h>
#include <atcoder/all>
 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define repx(i,x,n) for(int i=x; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9
 
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main(){

	return 0;
}

参考サイト

DockerでAtCoderができる環境を作る【Python・C++】

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?