Closed kmyk closed 3 years ago
std::endl を使うと TLE になりがち (e.g. Codeforces) です。これは std::endl が改行文字 ('\n') を出力するだけでなく出力の flush をしてしまうことに起因します。 https://en.cppreference.com/w/cpp/io/manip/endl これを防ぐため、現状の実装では std::endl は使わず、endl という名前のローカル変数を利用しています。 https://github.com/online-judge-tools/template-generator/blob/dd4d54356445ee0e01d1557e9715848eab5d553b/onlinejudge_template_resources/template/main.cpp#L65 しかしこのトリックは分かりにくいものである (例: https://tsutaj.hatenablog.com/entry/2020/10/24/112331) ため、単純に '\n' を使うようにした方がよい気がする (たぶん)。
std::endl
'\n'
endl
選択肢は
char endl = '\n'
ということで「char endl = '\n' を書いた上で '\n' を使う」 が最良だろうか。
このあたりをカスタマイズする方法がないのも問題なのだけど、面倒なのでカスタマイズについてはとりあえず後回しでいきたい。
Description
std::endl
を使うと TLE になりがち (e.g. Codeforces) です。これはstd::endl
が改行文字 ('\n'
) を出力するだけでなく出力の flush をしてしまうことに起因します。 https://en.cppreference.com/w/cpp/io/manip/endl これを防ぐため、現状の実装ではstd::endl
は使わず、endl
という名前のローカル変数を利用しています。 https://github.com/online-judge-tools/template-generator/blob/dd4d54356445ee0e01d1557e9715848eab5d553b/onlinejudge_template_resources/template/main.cpp#L65 しかしこのトリックは分かりにくいものである (例: https://tsutaj.hatenablog.com/entry/2020/10/24/112331) ため、単純に'\n'
を使うようにした方がよい気がする (たぶん)。Possible implementations and the analysis
選択肢は
char endl = '\n'
を消してしまうと TLE の危険がある (「よく分からないから勝手に消すぜ!」をするのはそういうことをする態度の方が危険そうではあるが)'\n'
に切り替えるendl
を使ってしまうと TLE の危険がある (これはよくない。「よく分かってないユーザでも TLE しない」を達成できないため)char endl = '\n'
を書いた上で'\n'
を使うstd::endl
に切り替えるということで「
char endl = '\n'
を書いた上で'\n'
を使う」 が最良だろうか。このあたりをカスタマイズする方法がないのも問題なのだけど、面倒なのでカスタマイズについてはとりあえず後回しでいきたい。