SlideShare ist ein Scribd-Unternehmen logo
1 von 30
切り餅発見伝
(自分用メモ)
小山高専学内ミニプロコン
15/03/26
問題概要
• N行M列のマス目があり、
各マスは ”#”, ”.” のどちらかで構成されている。
• 各辺が ”#” からなる、
一辺の長さが3以上の長方形の総数を求めよ。
• 9 ≤ 𝑁𝑀 ≤ 1096
愚直な探索
• とりあえず全てのマスについて調べれば解は出そう。
N, M = 8
=> 6
愚直な探索
• #でなければ飛ばす
愚直な探索
• #から伸ばしていく
3以上
愚直な探索
• #から伸ばしていく
愚直な探索
• ダメな時点で打ち切る
(‘A`)ムリポ
愚直な探索
• 隣のマスに移る
愚直な探索
• 隣のマスに移る
愚直な探索
• 隣のマスに移る
愚直な探索
• 1周した → めでたしめでたし
愚直な探索
• 探索量が無駄に増えそうな場合
めっちょ長い
愚直な探索の考察
• 1マスずつ辿って見ると損失が大きい場合がある。
• もっと効率よく判断を行いたい。
• (長方形の頂点のように代表的な)
あるマスを見た時点で判断したい。
メモ化探索
• 事前にデータを集める。
• 例えば、あるマスから縦横に見て、連続する#の数
をカウントしておく。
x/y 0/0 0/0 0/0 0/0 0/0
0/0 5/5 4/1 3/4 2/1 1/3
0/0 1/4 0/0 1/3 0/0 1/2
0/0 5/3 4/1 3/2 2/2 1/1
0/0 1/2 0/0 2/1 1/1 0/0
0/0 1/1 0/0 0/0 0/0 0/0
メモ化探索
• 長方形の左上になり得るマスを選ぶ。
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
メモ化探索
• 0/0のマスは飛ばす。
0/0 0/0 0/0 0/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3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
メモ化探索
• ここで長方形の上、左の辺が保証される。
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
長方形になりそうな範囲
メモ化探索
• 右の辺を辿れるだけ辿って下の辺を調べていく。
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
(𝑥, 𝑦)
(𝑖, 𝑗)
x方向について、
𝑚𝑒𝑚𝑜 𝑥, 𝑗 ≥ 𝑖 − 𝑥 + 1
メモ化探索
• このマスを左上の頂点とする長方形は2コ。(sum: 2)
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
1コ目
2コ目
メモ化探索
• このマスを左上の頂点とする長方形は1コ。(sum: 3)
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
メモ化探索
• このマスを左上の頂点とする長方形は1コ。(sum: 4)
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
メモ化探索
• このマスを左上の頂点とする長方形は1コ。(sum: 5)
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
メモ化探索
• このマスを左上の頂点とする長方形は1コ。(sum: 6)
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
メモ化探索
• このマスを左上の頂点とする長方形は0コ。(sum: 6)
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/6 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/5 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/4 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/3 2/1 1/1 0/0 0/0
0/0 1/2 0/0 1/2 0/0 0/0 0/0 0/0
0/0 3/1 2/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
A. 6(コ)
実装時に仕込んだバグ
• 右の辺の探索を適切に打ち切れんかった。
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
4/2 3/6 2/3 1/4 0/0 3/4 2/1 1/3
6/1 5/5 4/2 3/3 2/1 1/3 0/0 1/2
0/0 3/4 2/1 1/2 0/0 3/2 2/1 1/1
0/0 1/3 0/0 3/1 2/1 1/1 0/0 0/0
0/0 1/2 0/0 0/0 0/0 0/0 0/0 0/0
0/0 2/1 1/1 1/1 0/0 0/0 0/0 0/0
0/0 0/0 0/0 0/0 0/0 0/0 0/0 0/0
(*゚∀゚)見つけた!
思ったこと
• バグを仕込んでしまったことが悔しい。
• 計算量が見積もれないのを改善したい。
O(𝑁𝑀…?)
ミニプロコン自分用メモ

Weitere ähnliche Inhalte

Empfohlen

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.pdfmarketingartwork
 
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 2024Neil 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 2024Albert 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 InsightsKurio // 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 2024Search 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 summarySpeakerHub
 
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 IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit 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 managementMindGenius
 
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 WorkGetSmarter
 

Empfohlen (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
 

ミニプロコン自分用メモ