WSL&g++にて再帰関数でREするのはスタックサイズが原因 -fsplit-stackせよ

環境

--stackは使えなかった

$ g++ -Wl,--stack,10485760 answer.cpp
/usr/bin/ld: unrecognized option '--stack'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status

解決策

$ g++ -fsplit-stack answer.cpp
$ ./a.out
// 入力
1
500 250

// 出力
257950823 (答えが求まっている!)

$ g++ answer.cpp
$ ./a.out
// 入力
1
500 250

// 出力
Segmentation fault (core dumped) (オプション指定しないと再帰しすぎでRE)

参考

おまけ

  • AtCoderの場合、コードテストすればいいだろう