SlideShare a Scribd company logo
2022.03.24
Tomoki Yoshida
株式会社ディー・エヌ・エー + 株式会社 Mobility Technologies
AHC008振り返り
- Heuristic Contest初参戦 -
2
項目
01|はじめに
02|問題設定
03|最終解法
04|試したこと
05|上位解法
3
01 はじめに
4
●経歴
○ 名古屋工業大学 情報工学専攻 竹内烏山研究室
■ 凸最適化理論に基づいた機械学習高速化
■ 2018/8 DeNAインターン
■ 2019/2 SONYインターン
○ 2020/4 DeNA入社
●現在:DeNA
○ 社外の最適化案件を担当
●好きなこと
○ 野鳥撮影, カラオケ, お笑い, YouTube
●アカウント
○ Qiita: https://qiita.com/birdwatcher ※各種アカウントに飛べます
自己紹介:吉田 知貴
5
●2021/4からAtCoder参加
AtCoderと私
アルゴリズム ヒューリスティック
今回初参加
DeNA Advent Calendar 2021で
AtCoder Beginner Contestに必要な知識 ~解説と実装~
という記事を書きました
6
最適解がわからない問題でどれだけ良い解を出せるかを競う
ヒューリスティックコンテストとは
通常の競プロ(ABC, ARC) AHC
出力 想定された解と同一の結果(最適解) できるだけ良い解
出題数 6〜8問 1問
計算時間 2秒〜3秒 2秒〜5秒
開催回数 ABC: 244回, ARC: 137回 8回
考察時間 ABC:100分, ARC: 120分 4時間〜2週間
※2022/03/24時点
7
参加人数もまだ少ない
ヒューリスティックコンテストとは
200
100
アルゴリズム ヒューリスティック
8
02 問題設定
9
● オフィスサイズ 30 x 30マス
● ペットN匹(10~20)
○ 5種類
○ 種類ごとに動きが異なる(後述)
● 人間M人(5~10)
○ 行動:1マス移動、隣に柵を置く
● 人間を動かして、
300ターン終了後、
次ページのスコアを最大にせよ
問題設定:AHC008概要
https://atcoder.jp/contests/ahc008/tasks/ahc008_a
10
●スコア=
○ 人間のスコアの平均
●人間 i のスコア
○ |Ri|:人間 i がいる部屋のサイズ(到達可能なマス数)
○ ni:同じ部屋にいるペットの数
解釈:部屋サイズに線形で増加、ペット数に指数で減少
できるだけ...
● 人間がいる部屋のサイズは大きく
● ペットを部屋に入れない
○ 1匹入るとスコアが半分になる
問題設定:スコア
11
問題設定:ペットの動き
各ターン人間が動いたあとに、行動
1. ランダム移動1回
2. ランダム移動2回
3. ランダム移動3回
4. ターゲットの人間の方向へ1マ
ス移動し、ランダム移動1回※
5. ターゲットのマスの方向へ1マ
ス移動し、ランダム移動1回※
※ターゲットに到着/到達不可能なら、ターゲットを変える
12
問題設定:その他
● ペットの隣マスに柵を置いてはいけない
○ ペットから1マスは空けないといけない
● 人がいるマスに柵を置けない
○ ターン開始時に人がいるマス
○ ターン終了時に人がいるマス
● 開催期間:2週間
● 実行時間:3秒
● シード0のみ画像をTwitterで共有可能
13
03 最終解法
14
最終解法と結果
基本方針
●事前に決めた形の部屋を作る
●ペットが入ったら閉じ込める
結果
● 129/934(Top14%)
15
●部屋作成中にも閉じ込める
○ 画面左側中央上P5に注目
○ 人間は閉じ込められないようにする
●部屋の設計図
○ 青と緑は後から締める扉の候補
○ 優先度:青→緑
スコア改善の工夫
16
●真ん中の部屋を閉じ込めるのは
左右で2ステップ以内に閉じ込め
れるときだけにする
○ 画面中央下P1に注目
● キーポイント
○ 確実に閉じ込められるときだけ閉める
○ 片方の扉を閉めた後に
逃げられるパターンを減らす
○ 真ん中の扉を閉めすぎて左右別れて
しまうと、スコアが半分になる
スコア改善の工夫
17
● 各柵に対して置く人を選定
○ 置く予定の柵から最も近い人を割り当てる
■ PriorityQueueを使用
○ 単純な移動距離ではなく、目的地にたどり着くまでの柵配置のス
テップ数も雑に考慮した
○ 左の例
■ 移動5ステップ + 柵配置5ステップ
■ ターゲットにたどり着くまで10ステップ
スコア改善の工夫
18
●通路を使って閉じ込める
○ 画面右下のP1
○ 閉じ込めたマス数がX以下で、
人がいなければ閉じ込める
■ 250ターンまで、X=16
■ 250ターン以降、X=24
スコア改善の工夫
●最後の悪あがき
○ 300ターン目は最適な行動を取る
■ 最後の最適な行動は5通り
● なにもしない
● 上に柵配置
● 下に柵配置
● 右に柵配置
● 左に柵配置
■ 人間全体で5M通り
● 最悪ケース 510=108
○ 単純なループなら1秒程度
● 余裕を持って105ループで打ち切り
○ 閉じ込めれなかったときに効く
19
スコア改善の工夫
20
●周りを柵で囲う
○ 通常のアルゴリズムの問題でもよく使うテクニック
○ マップの端にいるかどうかを気にしなくてよくなる
○ 問題通り1-indexになる
●UnionFind
○ 連結判定によく使われるデータ構造(時間あれば説明します)
○ スコア計算に使用
●自作ビジュアライザ
○ ターミナルの標準出力で動作を見ながらやれる
○ "¥x1b[0;0H"を出力すると画面クリアができる
●最適化オプション -O3
実装上の工夫
21
04 試したこと
22
部屋の枠を作って一番ペットの少ない部屋に逃げ込む作戦
最終解法にたどり着くまでのトライ
扉を十字部分に
4.55409e+06
扉を各部屋の柵の中心に
6.05971e+06
手元の500ケース
平均スコア
ペットが同数の場合、
各々近い部屋に移動
→7.38278e+06
23
ペットを閉じ込める作戦
最終解法にたどり着くまでのトライ
部屋作成後通路で
待ち伏せ
1.30053e+07
部屋作成後いろんな部屋に
移動して誘導
1.63817e+07
柵の位置を
ペット位置に応じて決める
1.99895e+07
24
ペットを閉じ込める作戦(3分割)
最終解法にたどり着くまでのトライ
● 3分割
○ 2.36249e+07
● 中心の両扉はペットからの距離近いときだけ閉める
○ 2.85221e+07
● 扉位置は1つめり込んでも良い
○ 2.96927e+07
● 柵に人を対応つける
○ 3.25418e+07
● 最終ステップ最適化
○ 3.29763e+07
● 中心の両扉は2ステップ以内なら閉める
○ 3.65373e+07
25
やってみたがうまくいかなかったこと
● 部屋を考えずにペットを捕まえに行く
○ 全然捕まえられない
○ 知らない間に自分が身動き取れなくなった
● いろんな部屋を考える
● N, Mに対するスコアの可視化
最終解法にたどり着くまでのトライ
26
05 上位解法
27
1位,2位,5位の方は解説が見つからず...
● 3位: terry_u16さん
○ https://www.terry-u16.net/entry/ahc008
● 4位: simanさん
○ https://simanman.hatenablog.com/entry/2022/02/28/0748
38
● 6位:nejinejiさん
○ https://twitter.com/shift_neji/status/1497515949918134
272?cxt=HHwWgIDRhdC0n8gpAAAA
どの方も部屋を作ってペットを閉じ込める作戦
上位解法
28
柵の置き方
各柵を各人に割り当てて、
一番時間のかかる人の終了ターンを
できるだけ早くする最大値最小化問題
単純化
● ヘビ型の巡回経路 x 5本に限定
● 誰をヘビの開始地点に移動させるか
の最適化問題
上位解法:3位
https://www.terry-u16.net/entry/ahc008
柵を置き終えたら通りへ
最も遅く到着する人の到着時間を
早める最大値最小化のマッチング問題
min max{柵構築完了までのターン数
+通りへの移動までのターン数}
最大流問題として解く
29
上位解法:3位
https://www.terry-u16.net/entry/ahc008
ペットを捕まえる
どのペアで捕まえるかマッチング
tターン後に通路kに存在するペット数
をモンテカルロシミュレーション
● t:通路kまでのターン数
● マップが非連結になる関節点は除外
30
上位解法:3位
https://www.terry-u16.net/entry/ahc008
残りターンが少なくなったら、
全員でペットを捕まえる
最小カットで柵の位置決定
● source:通り
● sink:ペット周辺2マス
● 隣接マス同士結ぶ
柵を置く人の割り振り
最小費用流のマッチング問題を解く
31
上位解法:3位
https://www.terry-u16.net/entry/ahc008
フェーズ
1. 柵を配置する
2. 動物を捕まえる
方針
● チーム単位で動物の捕獲を行う
32
上位解法:4位
https://simanman.hatenablog.com/entry/2
022/02/28/074838
● チームは横軸を合わせて行動
● 犬、猫
○ 通路に入ろうとする→捕まえに行く
○ 通路から出ようとする→捕まえない
● 最後の1匹を無理やり捕まえる
○ 捕まえるパターンを用意
○ if文で無理やり
● 人数ごとにマップ切り替え
33
上位解法:4位
https://simanman.hatenablog.com/entry/2
022/02/28/074838
不定形に関する考察
● 犬、猫を捕まえるのが困難
● 犬、猫だけ例外扱いすれば可能かも
34
上位解法:4位
https://simanman.hatenablog.com/entry/2
022/02/28/074838
小部屋をたくさん作って挟み撃ち
● 先回りする
● なるべく人をばらけさせる
35
上位解法:6位
https://twitter.com/shift_neji/status/1497515949
918134272?cxt=HHwWgIDRhdC0n8gpAAAA
36
● ちゃんと定式化して取り組むことが重要
● ABCで出てくる技術を最大限活用すべし
○ フロー問題
○ DP
● 実装を面倒くさがらずに根気よくやる
振り返り

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

AHC008振り返り - Heuristic Contest初参戦 -