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?

More than 1 year has passed since last update.

vectorで凡ミスした話

Posted at

※「この記事は~」的な言い訳はめんどいので省略です。
正確な情報が必要な方は、ちゃんとした記事を参照ください。

2023/06/12 現在のpaiza IO の場合の話です。

動的計画法で解を求めたかったコード。
dpをvectorで宣言した時にサイズを指定せず、配列のようにアクセスしたら落ちた。。。

vectorは一度push_backをすると、542個分だけ自動的に領域が用意されるようです。
n が小さいうちは落ちなかったけど、提出したら大規模データで死んだ。。。:expressionless:


int main() {
    int n;

    cin >> n;
    __f(i,n) {
        int tmp;
        cin >> tmp;
        input.push_back(tmp);
    }

    vector<int> input;
    vector<int> dp;
    dp.push_back(input[0]);
    for (int i = 0; i < n; i++) {
        int tmp_1 = fugafuga(i);
        int tmp_2 = hogehoge(i);
        // ↓問題のコード
        dp[i] = max(tmp_1, tmp_2);
    }
    printf("%d\n", dp[n-1]);
    return 0;
}
0
0
1

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?