3
1

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 3 years have passed since last update.

AtCoderでREが出たら(C++er用)

Last updated at Posted at 2020-04-26

vectorの要素数多すぎ

// n = 10^5くらいがありえるとき
vector<int> pp(n);

これはメモリ確保できず,REが出ます.しかも気づきにくい...
vectorである必要がないなら,mainの外で配列にしましょう.

int pp[200000];
int main() {
    // do something
}

配列外参照

int a[4]; // a[0], a[1],...,a[3]からなる配列
a[4] = 1;

みたいに,定義されてないa[4]を参照すると実行時エラー.最適化時には未定義動作なので何が起こるかわからない
なおvectorでそのときのサイズより大きなnで[n]とすると,お節介から,n番目以下のところを勝手に0で埋めるという大惨事が起きるので,それはそれで気をつけましょう.

stringはmain()内に定義

これはTLEの原因になるものなのでちょっと違うのですが,stringの定義はmain()の外はやめたほうがいいです.(詳しくはないですし,環境依存かもしれないですが,長い文字列だとスタックからヒープへのコピーが重い??)

最後に

また失敗したら書き足していこうと思います.
競プロがんばりたい!

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?