0
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?

Atcoderのjava環境

0
Posted at

Atcoderのjava環境についてメモ。

2つの外部ライブラリが使用できる。

メモリ指定は問題文のメモリ制限$1={memory:mb}が以下のように計算される。
要は最大ヒープが90%、スタックは1GBということ。1

  • heap_size=$(($1 * 90 / 100))
  • stack_size=min(1024, $1)
  • -Xmx"$heap_size"M -Xss"$stack_size"M

システムプロパティが定義される。
デバッグ出力をこれをスイッチに使うと、ローカル環境とサーバー環境で切り替えできるはず。2

  • -DONLINE_JUDGE=true

コンパイルはシンプル。

  • javac -cp ac_library.jar:bifurcan.jar Main.java

OpenJDKと2つのライブラリの入手URL。


# SPDX-License-Identifier: CC0-1.0

language = 'Java'

display = 'Java24 (OpenJDK 24.0.2)'

license = [
    { name = 'GPL-2.0-or-later', url = 'https://openjdk.org/legal/gplv2+ce.html', exception = 'Classpath-exception-2.0' }
]

library.ac-library-java = { license = [
    { name = 'CC0-1.0', url = 'https://github.com/ocha98/ac-library-java/blob/main/LICENSE' },
], version = 'v2.0.0' }
library.bifurcan = { license = [
    { name = 'MIT', url = 'https://mvnrepository.com/artifact/io.lacuna/bifurcan/0.2.0-rc1' },
], version = '0.2.0-rc1' }

filename = 'Main.java'

install = '''
curl https://download.java.net/java/GA/jdk24.0.2/fdc5d0102fe0414db21410ad5834341f/12/GPL/openjdk-24.0.2_linux-x64_bin.tar.gz | sudo tar zx -C /usr/local --strip-components=1
wget -q -O ac_library.jar https://github.com/ocha98/ac-library-java/releases/download/v2.0.0/ac_library23.jar
wget -q -O bifurcan.jar https://repo1.maven.org/maven2/io/lacuna/bifurcan/0.2.0-rc1/bifurcan-0.2.0-rc1.jar
cat << 'EOF' > java.sh
#! /bin/sh
if [ "$1" -gt 1024 ]; then
    stack_size=1024
else
    stack_size="$1"
fi
heap_size=$(($1 * 90 / 100))
java -Xmx"$heap_size"M -Xss"$stack_size"M -DONLINE_JUDGE=true -cp ac_library.jar:bifurcan.jar: Main
EOF
'''

compile = '''
javac -cp ac_library.jar:bifurcan.jar Main.java
'''

object = 'Main.class'

execution = [
    'sh',
    'java.sh',
    '{memory:mb}',
]
  1. メモリが1024MiB未満の問題はないと思われ。

  2. 今はDEBUG=false,RELEASE=trueの変数を、バッチから起動するときにシステムプロパティで判定して書き換えていた。まあ、ONLINE_JUDGE=trueもやり方は同じ。

0
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
0
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?