Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
おしゃれなアルゴリズム
Search
eTakazawa
February 22, 2020
Programming
7
4.8k
おしゃれなアルゴリズム
本スライドは某LT用に作成しました.厳密性より,非競プロerに向けて面白さを重視しています.
過去問題の解説です.
eTakazawa
February 22, 2020
Tweet
Share
More Decks by eTakazawa
See All by eTakazawa
感動するアルゴリズム
etakazawa
0
170
Other Decks in Programming
See All in Programming
MCP with Cloudflare Workers
yusukebe
2
220
useSyncExternalStoreを使いまくる
ssssota
6
1k
return文におけるstd::moveについて
onihusube
1
1.1k
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
Recoilを剥がしている話
kirik
5
6.7k
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
760
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
910
php-conference-japan-2024
tasuku43
0
290
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
4
490
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
Featured
See All Featured
Thoughts on Productivity
jonyablonski
67
4.4k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
Facilitating Awesome Meetings
lara
50
6.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Making Projects Easy
brettharned
116
5.9k
Making the Leap to Tech Lead
cromwellryan
133
9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
How STYLIGHT went responsive
nonsquared
95
5.2k
The Invisible Side of Design
smashingmag
298
50k
Rails Girls Zürich Keynote
gr2m
94
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Transcript
͓͠ΌΕͳΞϧΰϦζϜ @utsubo_21 ※ ຊεϥΠυLT༻ʹ࡞͠·ͨ͠ ɹݫີੑΑΓɼඇڝϓϩerʹ͚ͯ໘ന͞Λॏࢹ͍ͯ͠·͢
ࠓ·Ͱղ͍ͨ ΞϧΰϦζϜͷͷத͔Β
ಛʹ͓͠Ζ͔ͬͨΛ pickup
• মΛ͍ͯ͠·͢ • ॏͳ͍ͬͯΔ෦͕ੜম͚ʹ • ͍͔ͭ͘ΛऔΓআ͘͜ͱͰ Ͱ͖Δ͚ͩ৯ΒΕΔ෦Λ͍ͨ͘͠ Question
* CODE FESTIVAL 2015 ຊઓ মͷୡਓ
• মΛ͍ͯ͠·͢ • ॏͳ͍ͬͯΔ෦͕ੜম͚ʹ • ͍͔ͭ͘ΛऔΓআ͘͜ͱͰ Ͱ͖Δ͚ͩ৯ΒΕΔ෦Λ͍ͨ͘͠ Question
* CODE FESTIVAL 2015 ຊઓ মͷୡਓ
• মΛ͍ͯ͠·͢ • ॏͳ͍ͬͯΔ෦͕ੜম͚ʹ • ͍͔ͭ͘ΛऔΓআ͘͜ͱͰ Ͱ͖Δ͚ͩ৯ΒΕΔ෦Λ͍ͨ͘͠ Question
* CODE FESTIVAL 2015 ຊઓ মͷୡਓ
• মΛ͍ͯ͠·͢ • ॏͳ͍ͬͯΔ෦͕ੜম͚ʹ • ͍͔ͭ͘ΛऔΓআ͘͜ͱͰ Ͱ͖Δ͚ͩ৯ΒΕΔ෦Λ͍ͨ͘͠ Question
* CODE FESTIVAL 2015 ຊઓ মͷୡਓ
Question • ೖྗ - (Ґஔɼ͞) × Nݸ ( N
≦ 10^5 ) - ͷ͞ M ( M ≦ 10^5 ) • త - ֤ʹ͍ͭͯম͔͘ম͔ͳ͍͔બͼɼ ͕ॏͳΒͣম͚Δ͞ͷ૯Λ࠷େԽ͠ग़ྗ 1 2 3
Question • ೖྗ - (Ґஔɼ͞) × Nݸ ( N
≦ 10^5 ) - ͷ͞ M ( M ≦ 10^5 ) • త - ֤ʹ͍ͭͯম͔͘ম͔ͳ͍͔બͼɼ ͕ॏͳΒͣম͚Δ͞ͷ૯Λ࠷େԽ͠ग़ྗ 1 2 3
Question • ೖྗ - (Ґஔɼ͞) × Nݸ ( N
≦ 10^5 ) - ͷ͞ M ( M ≦ 10^5 ) • త - ֤ʹ͍ͭͯম͔͘ম͔ͳ͍͔બͼɼ ͕ॏͳΒͣম͚Δ͞ͷ૯Λ࠷େԽ͠ग़ྗ 1 2 3
͏গ͠ෳࡶͳྫ ྫɽ
͏গ͠ෳࡶͳྫ ؒͷґଘ͕૿͑ɼ͍͠… ྫɽ
• ”͕ॏͳ͍ͬͯΔ” or ”Կͳ͍” ۠ؒ ͕͞Ք͛ͳ͍ • ”શମͷ͞M
ʔ ম͚ͳ͍۠ؒͷ͞” Ͱ͕͑ग़Δ ղ๏Λࢧ͑Δߟ͑ํ ম͚Δ෦Λ͘ → ম͚ͳ͍෦Λ͘
ղ๏ ͋ΔͷબͼํΛͨ࣌͠ͷ ম͚ͳ͍෦ͷ͞ΛΓ͍ͨ 1 2 3
ղ๏ ఱ࠽తͳͻΒΊ͖Ͱ ͷ͞ʹ߹ΘͤͯҹΛॻ͍ͯΈΔ
ղ๏ 1 2 3 ఱ࠽తͳͻΒΊ͖Ͱ ͷ͞ʹ߹ΘͤͯҹΛॻ͍ͯΈΔ
ղ๏ ͞Βʹఱ࠽తͳͻΒΊ͖Ͱ ”Կͳ͍” ෦Λද͢ҹΛՃ
ղ๏ ࠨ͔ΒӈҹΛḷͬͯΈΔ
ղ๏ ྫ͑ɼͷܦ࿏
ղ๏ ɹɹͷΈΛম͘߹Λදݱ ʢͱ”Կͳ͍”۠ؒ 4ͭʣ 1 1 ”Կͳ͍”۠ؒ
ղ๏ “Կͳ͍”۠ؒͷ͞ΛΓ͍ͨ ʢ㲎 શମͷ͞ʔম͚ͳ͍෦ͷ͞ʹম͚Δ͞ʣ
ղ๏ ҹʹίετΛ༩ 1 1 1 1 1 1
1 1 0 0 0
ղ๏ ܦ࿏্ͷҹͷίετͷ૯ ʹ ম͚ͳ͍෦(Կͳ͍෦)ͷ͞ ʹͳ͍ͬͯΔ 1 1 1
1 1 1 1 1 0 0 0
ղ๏ ”ॏͳ͍ͬͯΔ” ෦Ͳ͏දݱ͢Δ͔
ղ๏ ”ॏͳ͍ͬͯΔ” ෦Ͳ͏දݱ͢Δ͔ → ٯ͖ͷҹΛுΓ·͢ʢίετ1ʣ 1 1 1
ղ๏ ઌͱಉ༷ʹࠨ͔ΒӈҹΛḷΔ
ղ๏ ྫ͑ɼͷܦ࿏
ղ๏ 1 1 1 1 1 2 ɹɹͱɹɹΛম͘߹Λදݱ
1 2 ”Կͳ͍”۠ؒ ”ॏͳ͍ͬͯΔ”۠ؒ
ղ๏ 1 1 1 1 ম͚ͳ͍۠ؒͷ͞ 4 ”Կͳ͍”۠ؒ
”ॏͳ͍ͬͯΔ”۠ؒ
ղ๏ ·ͱΊ 1 1 1 1 1 1
1 1 1 1 1 ࠨ͔Βӈͷܦ࿏্ͷίετͷ૯ ʹ ম͚ͳ͍෦ͷ͞
ղ๏ ·ͱΊ 1 1 1 1 1 1
1 1 1 1 1 ͭ·Γɼࠨ͔Βӈͷ࠷ܦ࿏ ʹ ম͚ͳ͍෦ͷ͕͞࠷খͷͷબͼํ
ղ๏ ·ͱΊ 1 1 1 1 1 1
1 1 1 1 1 ͭ·Γɼ࠷ܦ࿏͕͔Εྑ͍ → ؆୯ʂ
ղ๏ ·ͱΊ 1 1 1 1 1 1
1 1 1 1 1 ͭ·Γɼ࠷ܦ࿏͕͔Εྑ͍ → ؆୯ʂ ܭࢉྔతʹɿ શ୳ࡧ O(2^N) → ຊख๏ O((M+N)logM)
͋ͱ͕͖ • ࠷ܦ࿏ʹؼணͰ͖ͯ࠷ߴʹ͓͠ΌΕ - মʹߦ͘ͱ͖ࢥ͍ग़ͯ͠Ͷ • ໘നΈΛײͨ͡ํڝϓϩ͍ͬͯͩ͘͞ • ࠷େԽΛ͢Δ࣌Կ͔ͷ࠷খԽʹ ஔ͖͑ΒΕͳ͍͔ߟ͑Δ
- “࠷େԽΛ࠷খԽʹมܗͯ͠ɼ࠷খΧοτʹؼண” ׂͱయܕΒ͍͠ʢࢀߟɿ೩͢ຒΊΔʣ https://www.slideshare.net/shindannin/project-selection-problem
͓·͚ • ൈ͚͍ͯΔେࣄͳߟ - ઌͷܦ࿏Ͱɼ3ຕҎ্͕ॏͳΔબͼํΛ දݱͰ͖ͳ͍ - ॏͳͬͨ෦Λ༨ܭʹίετͱͯ͠Χϯτͯ͠ ͠·͏ɽ͕ɼͦͦ3ຕҎ্ॏͳΔͷબͼํ ɼ࠷దղʹͳΓಘͳ͍
• ެࣜϖʔδͷղઆΛಡΜͰ͍ͩ͘͞ • ࢲ͕ॻ͍ͨίʔυͪ͜Β https://www.slideshare.net/chokudai/code-festival-2015-final https://code-festival-2015-final-open.contest.atcoder.jp/submissions/10197952