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?

ABC435 F - Cat Exercise 別解法

Last updated at Posted at 2025-12-07

問題概要

次の最大値に向かうように左右への分岐を繰り返すときに、最終的な移動距離の最大化をする
問題リンク

私の解法

  • 探索階層が十分に低いため、DFSで愚直しみゅれーしょん
  • 「max値セグ木と逆引配列の同時使用」で区間内の最大値の添え字を高速で求める

実行速度はO(N logN logN)ぐらい。
提出リンク (C++, 60ms)

公式解法

  • DFSで各頂点に訪問しみゅれーしょん
  • 「単調スタック」を用いて、現在地点より左/右の「次」に大きい添え字を定数時間で求める

実行速度はO(N)くらい。
提出リンク (C++, 40ms)

感想

ただ通すだけなら、私の解法の方が、発想が簡単。
コードの簡潔さや実行速度の観点でみると、将来的には公式解法も覚えておきたいです。

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?