Skip to content

Conversation

@docto-rin
Copy link
Owner

Copy link

@t9a-dev t9a-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

お疲れさまです。自分はまだ解いていないのと理解できていない問題なので、あほなコメントとして読んでもらえればと思います。

https://discord.com/channels/1084280443945353267/1196498607977799853/1238849107267948575

min_tails = []
# min_tails[i] is minimum of tail of length i + 1 subsequences
for num in nums:
next_length = bisect_left(min_tails, num) + 1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここで+1してnext_lengthを調整したあとに、227行目で-1しているのが気になりました。
今の自分には問題が難し過ぎて理解できていないので、読み流してもらって大丈夫です。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。

いえいえ、自分もその違和感は感じていて、どうしたものかと思いながら書いていました。

というのも、lengthは1-indexedな概念で、これを軸にまとめた方が条件分岐などが読みやすい気がするものの、bisectの結果やmin_tailsのアクセスは、length - 1の0-indexedだからです。

変数も0-indexedで扱い、"index"などの変数名にするか、それともmin_tailsなどの配列側を1-indexedで扱えるように、0番目に番兵を仕込んでおくのも手かなと思いますが、現状のコードがベストだと考えました。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

というのも、lengthは1-indexedな概念で、これを軸にまとめた方が条件分岐などが読みやすい気がするものの、bisectの結果やmin_tailsのアクセスは、length - 1の0-indexedだからです。

なるほど。そういった性質を持つ変数であれば、+1,-1による調整を明示的にしておくことで読み手に調整が必要な値であることを示せるという点で良いなと思いました。(無理に隠蔽してしまうと読み手が変更などの際に注意を払えないのでバグになりやすくなるなど。)
ありがとうございました。


### 実装3

- セグメント木を使ってみる。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

セグメント木はソフトウェアエンジニアの常識には含まれていないと思います。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

セグメントツリーは、50行以内で書け、いろいろな複雑なデータ構造の代用品として使えるので重宝されます。
https://discord.com/channels/1084280443945353267/1288758969522978847/1300830631512506448

# return []
return 0

min_tails = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自分なら length_to_min_tail または length_to_min_last_num とすると思います。コメントが書かれているので、 min_tails でも十分伝わると思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants