Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AHC041解説
Search
terry-u16
January 19, 2025
Programming
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AHC041解説
AtCoder Heuristic Contest 041(
https://atcoder.jp/contests/ahc041
)の解説放送で使用した解説スライドです。
terry-u16
January 19, 2025
More Decks by terry-u16
See All by terry-u16
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
410
TUNA Camp 2026 京都Stage ヒューリスティックアルゴリズム入門
terryu16
0
890
サンタコンペ2025完全攻略 ~お前らの焼きなましは遅すぎる~
terryu16
1
1.1k
[AI Engineering Summit Tokyo 2025] LLMは計画業務のゲームチェンジャーか? 最適化業務における活⽤の可能性と限界
terryu16
2
2.2k
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
1.3k
AtCoder Heuristic First-step Vol.1 講義スライド
terryu16
5
2.1k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
2
2.7k
AHC035解説
terryu16
0
2.7k
TOYOTA AHC 至高のアルゴリズム解説会 - Transit Warehouse 解説
terryu16
0
3.1k
Other Decks in Programming
See All in Programming
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
190
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
220
気持ちぃ〜角丸 Squircle
ryu1013
0
340
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
1
200
Seven New Principles of Software Engineering
yegor256
0
320
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
200
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.8k
AI-Powered Domain-Driven Design
ziobrando
0
320
ActionController meets Protocol Buffers
sorah
1
720
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
190
Jetpack Compose Mechanisms
skydoves
3
870
Kotlinの15年とServer-Side Kotlin
n_takehata
1
170
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
7k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
900
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
47k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Navigating Weather and Climate Data
rabernat
0
560
Large-scale JavaScript Application Architecture
addyosmani
516
110k
First, design no harm
axbom
PRO
2
1.4k
The Language of Interfaces
destraynor
162
27k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
340
Ethics towards AI in product and experience design
skipperchong
2
440
Faster Mobile Websites
deanohume
310
32k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Transcript
AHC041 解説 2025/1/19 writer : terry_u16
簡単な考察: どのような木が望ましいか 高い場所にあるほどスコアにかかる倍率が上がる できるだけ高い場所にたくさん頂点があるような木を作りたい ℎ = 0 ℎ = 1
ℎ = 2 ℎ = 3 低スコア 高スコア
解法例1 : DFSベース解法
① とりあえずACする 全ての頂点を根(-1)とする 7,584,268点 (本番954位相当)
② BFS木を作る まだ使われていない頂点を根として、BFS木を作る貪欲 55,988,632点 (本番741位相当) BFS中、頂点𝑢から頂点𝑣に 移動するときに辺を張ると 木ができる
③ DFS木を作る まだ使われていない頂点を根として、DFS木を作る貪欲 67,252,287点 (本番455位相当) DFS中、頂点𝑢から頂点𝑣に 移動するときに辺を張ると 木ができる
BFS木とDFS木 BFS木よりDFS木の方がスコアが高い BFSは近い頂点から順に訪れるが、DFSは遠い頂点から順に訪れるため 頂点の高さ ℎ𝑣 が大きくなりやすい ℎ𝑣 (BFS木) ℎ𝑣 (DFS木)
④ DFSの探索順を工夫する 𝐴𝑣 が大きい頂点はできるだけ ℎ𝑣 を高くしたい DFSで 𝑨𝒗 が小さい頂点から順に探索するようにするとスコアが上がる 69,853,969点
(本番322位相当) 10 × 1 + 90 × 2 +50 × 3 + 30 × 4 = 460点 10 × 1 + 30 × 2 +50 × 3 + 90 × 4 = 580点 𝐴𝑣 の降順に探索 𝐴𝑣 の昇順に探索 10 30 90 50 10 30 90 50
⑤ 根を全探索して貪欲 今まで根を適当に決めていたが、できるだけ効率良く頂点を使いたい 根を全探索して、 木のスコア÷木の頂点数 が最も大きい根を採用する貪欲 72,646,442点 (本番131位相当) 10 30
90 50 10 30 90 50 を根とする 520 ÷ 4 = 130点 を根とする 10 580 ÷ 4 = 145点 30
⑥ 根の順番を焼きなまし 採用する根を貪欲に決めていたが、焼きなましで決めることもできる 根の列を解とし、順番にDFSを行うことで森を構築する 74,282,453点 (本番64位相当) 10 30 90 50
10 30 90 50 210 + 30 = 240点 250 + 50 = 300点 90 50 30 10 10 90 50 30 10
解法例2 : 木を直接焼きなまし
⑦ 木を直接焼きなまし 各頂点の親の頂点を解として焼きなまし 頑張って高速化すると 𝑂 𝐻 + 部分木の大きさ くらいで差分更新が可能 76,105,950点
(本番19位相当) 10 30 90 50 10 30 90 50 0 1 2 3 −1, 0, 0, 2 → 400点 0 1 2 3 −1, 0, 3, 1 → 580点
⑦ 木を直接焼きなまし – 高速化 スコアの差分更新および木の高さ制限チェックに必要な情報を持つ 各頂点に 𝒉𝒗 ・親・子・部分木の𝑨𝒗 の和・部分木の最大𝒉𝒗 を持たせる
ℎ = 3 ℎ = 2 ℎ = 1 ℎ = 0 Δ = 𝑣∈𝑇 ℎ𝑣 ′ + 1 𝐴𝑣 − 𝑣∈𝑇 ℎ𝑣 + 1 𝐴𝑣 = Δℎ𝑟𝑜𝑜𝑡 𝑣∈𝑇 𝐴𝑣 スコア差分計算 max 𝑣∈𝑇 ℎ𝑣 + Δℎ𝑟𝑜𝑜𝑡 ≤ 𝐻 木の高さ制限チェック (部分木の𝑨𝒗 の和) (部分木の最大𝒉𝒗 ) ℎ𝑟𝑜𝑜𝑡
⑦ 木を直接焼きなまし – 高速化 焼きなましが受理されたら祖先と部分木の 𝒉𝒗 ・親・子・部分木の𝑨𝒗 の和・部分木の最大𝒉𝒗 を更新する ℎ
= 3 ℎ = 2 ℎ = 1 ℎ = 0
⑧ 高さ制限違反を許容 高さ制限を常に守るようにすると遷移が成功しづらい 高さ制限違反を許容し、違反量に応じたペナルティをかけるとスコアが伸びる 76,858,739点 (本番2位相当) ℎ = 3 ℎ
= 2 ℎ = 1 ℎ = 0 0 0.5 1 ペナルティ量 時刻 𝑠𝑐𝑜𝑟𝑒 = 1 + 𝑣 ℎ𝑣 + 1 𝐴𝑣 −𝛼1−𝑡𝛽𝑡 𝑣 max ℎ𝑣 − 𝐻, 0 ペナルティは時間とともに 少しずつ大きくする