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
JOI 2013 春合宿 day4-1 messenger 解説
Search
snuke
March 23, 2013
Programming
0
350
JOI 2013 春合宿 day4-1 messenger 解説
情報オリンピック2013春合宿4日目1問目messengerの解説
snuke
March 23, 2013
Tweet
Share
More Decks by snuke
See All by snuke
puzzleLT.pdf
snuke
0
660
JOI2015-2016 春合宿 day 2 Sandwich 解説
snuke
0
290
JOI2015-sp-day4-walls-anothersolution
snuke
0
210
JOI2014 春合宿 day 2 スタンプラリー 解説
snuke
0
190
NPCA合宿きょーぷろ講義
snuke
0
360
CodeForces#162 Div1-E
snuke
0
290
CodeForces162 Div1-E
snuke
3
15k
SRM 555 Div 1 easy, Div 2 medium
snuke
1
420
SRM 555 Div 1 hard
snuke
1
500
Other Decks in Programming
See All in Programming
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
선언형 UI에서의 상태관리
l2hyunwoo
0
160
42 best practices for Symfony, a decade later
tucksaun
1
180
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
CSC305 Lecture 26
javiergs
PRO
0
140
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
150
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Embracing the Ebb and Flow
colly
84
4.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Facilitating Awesome Meetings
lara
50
6.1k
A designer walks into a library…
pauljervisheath
204
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
How GitHub (no longer) Works
holman
311
140k
Code Review Best Practice
trishagee
65
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Transcript
ୈ12ճ ຊใΦϦϯϐοΫय़߹॓ day4 Messenger ೋ֊ಊ ݐਓ (@the_nikaidoes/snuke)
֓ཁ A͞Μʹ͋Δ X ͕͑ΒΕΔɻ(1≤X≤10^9) A͞ΜͱB͞Μ̐×̐ͷϚεͱ͕ۨ͋Δ෦ʹ ϥϯμϜͳॱ൪Ͱݺͼग़͞ΕΔɻ ۨΛಈ͔͢͜ͱͷΈʹΑͬͯA͞ΜB͞Μʹ X ͷΛ͍͑ͨɻ
A B Kཧࣄͷ෦
X ͷใྔ̍ʹ͑Δʹେ͖͗͢Δɻ X ͷใΛ࠷খ୯Ґ·Ͱ۠Δɻ ʮใΛ࠷খ୯Ґʯʹʮyes/noʯʹ 1bit ͭ·ΓɺXΛ̎ਐʹܻͯ̍ͣͭ͑͠Δɻ جຊతͳํ
1bitΛ͑ΔʹͲ͏͢Εྑ͍͔ʁ 0,1ʹରԠ͢Δૢ࡞ΛܾΊ͓͖ͯɺA͕ͦͷૢ࡞ Λ࣮ߦͯ͠ɺB͕ͦͷૢ࡞͔Β1bitͷใΛಡΈ औΔɻ جຊతͳํ
A͞ΜͱB͞Μ͕ABABABABA...ͷॱͰަޓʹݺ ͼग़͞ΕΔɻ subtask1 (20pts)
0,1ʹରԠ͢Δૢ࡞ͷׂΓͯͷྫ ʮ0ͳΒॎɺ1ͳΒԣʹҠಈͤ͞Δɻʯ subtask1 (20pts)
A 101 B ??? Kཧࣄͷ෦
A 10- B ??? Kཧࣄͷ෦ A͕1Λ͑ΔͨΊʹɺۨΛԣʹಈ͔ͨ͠
A 10- B ??1 Kཧࣄͷ෦ B͕1ΛಡΈऔΓɺۨΛదʹҠಈͤͨ͞
A 1-- B ??1 Kཧࣄͷ෦ A͕0Λ͑ΔͨΊʹɺۨΛॎʹಈ͔ͨ͠
A 1-- B ?01 Kཧࣄͷ෦ B͕0ΛಡΈऔΓɺۨΛదʹҠಈͤͨ͞
A --- B ?01 Kཧࣄͷ෦ A͕1Λ͑ΔͨΊʹɺۨΛԣʹಈ͔ͨ͠
A --- B 101 Kཧࣄͷ෦ B͕1ΛಡΈऔΓɺۨΛదʹҠಈͤͨ͞
2^29 ≤ 10^9 ≤ 2^30 ͳͷͰɺ30ճͷΓऔ ΓΛ͢Ε X ͷΛ͑Δ͜ͱ͕ग़དྷΔɻ A͕ॎԣͲͪΒʹಈ͔ͨ͠ͷ͔ɺB͕ಈ͔ͨ͠ޙ
ͷۨͷҐஔΛهԱ͓͚ͯ͠ྑ͍ɻ ͨͩ̍͠λʔϯɺA͕Ͳ͏ಈ͔ͨ͠ͷ͔͕Bʹ ͔Βͳ͍ͷͰɺࣺͯΔɻ subtask1 (20pts)
جຊతͳํͦͷ̎ ͜ΕҎ߱ͷsubtaskͰɺAͱB͕ަޓʹݺͼग़͞ ΕΔͱݶΒͳ͍ɻ AAABAABBBBBBABAAA...Έ͍ͨͳͷ͋Γ͏Δ ʮࢭ·ͬͨ··ʯ͕ՄೳͳΒಉ͡ͳͷ͕ͩɾɾɾ
A B Kཧࣄͷ෦ B͕ۨΛ(2,3)ʹಈ͔ͨ͠
A B Kཧࣄͷ෦ A͕ۨΛ(2,2)ʹಈ͔ͨ͠
A B Kཧࣄͷ෦ A͕ۨΛ(2,3)ʹಈ͔ͨ͠
A B Kཧࣄͷ෦ B͕ۨ(2,3)ʹ͋Δ͜ͱΛΒ͞ΕΔ
جຊతͳํͦͷ̎ ͜ͷΑ͏ͳૢ࡞Λͯ͠͠·ͬͨ߹ɺBAABͱݺͼ ग़͞Εͨ࣌ͱɺBBͱݺͼग़͞Εͨ࣌ͷ۠ผ͕͔ͭ ͳ͍ɻ ૬ख͕ಈ͔ͨ͠ॴʹಈ͔͢ૢ࡞Λ͢ΔͱҋΔɻ ͭ·Γ
A B Kཧࣄͷ෦ B͕ۨΛ(2,3)ʹಈ͔ͨ͠
A B Kཧࣄͷ෦ A͕ۨΛ(2,2)ʹಈ͔ͨ͠
A B Kཧࣄͷ෦ A(2,3)Ҏ֎ʹۨΛಈ͔͢
جຊతͳํͦͷ̎ ࿈ଓͰݺΕΔͱʮ0ͳΒॎɺ1ͳΒԣʹҠಈͤ͞ Δɻʯͱ͍͏ํʹࢧো͕ग़Δ͔ʁ # ࣮ͦΜͳʹग़ͳ͍ɻ
0(ॎ)Λ͑Δ߹ͷྫ ্͕ۨɾԼʹ͋Δ߹ Kཧࣄͷ෦ Kཧࣄͷ෦ ͜ ͜ ͜ ͜ ͕ۨதԝͷஈʹ͋Δ߹ 1(ԣ)Λ͑Δ߹ಉ༷
ʮ͜͜ʯΛ͏Ζ͏Ζ͍ͯ͠Ε͍͍ɻ
جຊతͳํͦͷ̏ A͞ΜͱB͞ΜͷͲͪΒ͕࠷ॳʹݺͼग़͞ΕΔ͔͕ ͔Βͳ͍ɻ subtask1Ͱʮ̍λʔϯࣺͯΔʯͱ͍͏ઓུ ΛऔΔ͜ͱ͕Ͱ͖͕ͨɺࠓ͏·͍͔͘ͳ͍ɻ
جຊతͳํͦͷ̏ ABABAB... BABABA... Ͱࣔͨ͠ͱ͜ΖͷୡΛ͍ͯ͠Δ෦ʹͳΔ ͕ͣͩɺԼͷύλʔϯͩͱB͔Β࢝·͓ͬͯΓɺ ୡ͕͏·͍͔͘ͳ͍ɻ ͲͪΒ͔Β࢝·ͬͨͷ͔Λ͏·͍͑ͨ͘ɻ
ॳظঢ়ଶͰඞͣۨ(1,1)ʹ͋Δɻ subtask2 (20pts)
(1,1)ʹۨΛಈ͔͢͜ͱΛېࢭ͢Δɻ ͢Δͱ֤ϓϨΠϠʔɺ͕ࣗ࠷ॳʹݺΕͨͷ ͔Ͳ͏͔Λผ͢Δ͜ͱ͕ՄೳʹͳΔɻ -(1,1)ʹ͋Δ߹ɿ͕ࣗ࠷ॳʹݺΕͨ -(1,1)ʹͳ͍߹ɿࣗ࠷ॳʹݺΕ͍ͯͳ͍ subtask2 (20pts)
A 10 B ?? Kཧࣄͷ෦ A͔Βݺͼग़͢߹
A 10 B ?? Kཧࣄͷ෦ (1,1)ʹ͕ۨ͋ͬͨͷͰɺA͕ࣗ࠷ॳʹݺΕͨ͜ͱ͕͔Δ AۨΛదʹಈ͔ͨ͠
A 10 B ?? Kཧࣄͷ෦ A(1,1)Ҏ֎ͷϚεʹۨΛಈ͔ͨ͠
A 10 B ?? Kཧࣄͷ෦ (1,1)ʹ͕ۨͳ͔ͬͨͷͰɺBA͕࠷ॳʹݺΕͨ͜ͱ͕͔Δ BۨΛదʹಈ͔ͨ͠
A 10 B ?? Kཧࣄͷ෦ B(2,2)Ҏ֎ͷϚεʹۨΛಈ͔ͨ͠
A 1- B ?? Kཧࣄͷ෦ A͕0Λ͑ΔͨΊʹɺۨΛॎʹಈ͔ͨ͠
A 1- B ?0 Kཧࣄͷ෦ B͕0ΛಡΈऔΓɺۨΛదʹҠಈͤͨ͞
A -- B ?0 Kཧࣄͷ෦ A͕1Λ͑ΔͨΊʹɺۨΛԣʹಈ͔ͨ͠
A -- B ?0 Kཧࣄͷ෦ A͕1Λ͑ΔͨΊʹɺۨΛԣʹಈ͔ͨ͠
A -- B 10 Kཧࣄͷ෦ B͕1ΛಡΈऔΓɺۨΛదʹҠಈͤͨ͞
A 10 B ?? Kཧࣄͷ෦ B͔Βݺͼग़͢߹
A 10 B ?? Kཧࣄͷ෦ (1,1)ʹ͕ۨ͋ͬͨͷͰɺB͕ࣗ࠷ॳʹݺΕͨ͜ͱ͕͔Δ BۨΛదʹಈ͔ͨ͠
A 1- B ?? Kཧࣄͷ෦ (1,1)ʹ͕ۨͳ͔ͬͨͷͰɺAB͕࠷ॳʹݺΕͨ͜ͱ͕͔Δ A͕0Λ͑ΔͨΊʹɺۨΛॎʹಈ͔ͨ͠
A 1- B ?0 Kཧࣄͷ෦ B͕0ΛಡΈऔΓɺۨΛదʹҠಈͤͨ͞ ҎԼಉ༷
։࢝ॴ͢Β͔Βͳ͍ɻ subtask3 (60pts)
ͳΒແཧཧʮ։࢝ҐஔʯΛ࡞ͬͯΖ͏ʂ ֤ϓϨΠϠʔͷ࠷ॳ5λʔϯ(࿈ଓͯ͠ݺͼग़͞ΕΔͷΛ1λ ʔϯͱ͑Δ͜ͱʹ͠·͢)͘Β͍ͳ͔ͬͨ͜ͱʹ͠ɺ ͻͨ͢Β(1,1)ʹ͔ͬͯҠಈ͢Δɻ subtask3 (60pts)
ͦͷޙsubtask2ͱશ͘ಉ͡ɻ ABABABABABABAB... BABABABABABABA... AAABBBABAAABABBABBABABBB... ੨͍෦ͳ͔ͬͨ͜ͱʹ͞ΕΔ෦ɻ ͳ͔ͬͨ͜ͱʹ͞ΕΔ෦ඞͣ࿈ଓతɻ subtask3 (60pts)
subtask3 (60pts) ͳ͔ͬͨ͜ͱʹ͢Δλʔϯ͕ऴΘͬͨޙʹ(1,1) ʹࢭ·͍ͬͯͳ͍͜ͱ͋Δɻ ʮ(1,1)ʯΛʮ̍ߦʯʹ͢Δͱ͏·͍͘͘ɻ
A 0 B ? Kཧࣄͷ෦ ̑λʔϯͣͭ͘Β͍ͳ͔ͬͨ͜ͱʹͯ͠ɺ ʮॳظҐஔʯ(2,1)ͱͳͬͨɻ
A 0 B ? Kཧࣄͷ෦ ̍ߦʹ͕ۨ͋ͬͨͷͰɺA͕ࣗ࠷ॳʹݺΕͨ͜ͱ͕͔Δ AۨΛదʹಈ͔ͨ͠
A 10 B ?? Kཧࣄͷ෦ A1ߦҎ֎ͷϚεʹۨΛಈ͔ͨ͠ ΠΧུ
ؔݺͼग़͠ͷ߹ܭΛ3301ճʹ͑ΒΕ·͢ɻ 400ճͰॳظॲཧɺ2900ճͰͷୡɺ1ճͰΛ͑Δ subtask4 (͓·͚)
ୡphase A̍ճʹ2bit(0~3)Λ͑Δɻ BۨΛඞͣਅΜதͷ̐ͭͷ͍ͣΕ͔ʹಈ͔͢ɻ subtask4 (͓·͚)
Kཧࣄͷ෦ 00 10 01 11 ͍͑ͨ2bitʹରԠ͢ΔॴΛ͏Ζ͏Ζ͢Δɻ
ॳظॲཧphase Aͷ̍λʔϯɿ۱Ҏ֎ͷϚεʹҠಈ Aͷ̎λʔϯҎ߱ɿ B͕ʮmove1ʯΛͨ͠ͱ͖ɿ۱Ҏ֎ͷϚεʹҠಈ B͕ʮmove2ʯΛͨ͠ͱ͖ɿୡphaseʹҠߦ subtask4 (͓·͚)
ॳظॲཧphase Bͷ̍λʔϯɿmove1 Bͷ̎λʔϯɿmove2 move2ͷޙඞͣਅΜதͷ̐ͭͷ͍ͣΕ͔ͷϚ εʹ͕ۨ͋ΔΑ͏ʹ͢Δ subtask4 (͓·͚)
Kཧࣄͷ෦ move1 move2 ͕ۨதԝʹ͋Δ࣌ͷmove1ͱmove2ͷྫ
Kཧࣄͷ෦ move1 move2 ͕ۨลʹ͋Δ࣌ͷmove1ͱmove2ͷྫ
A ۱Ҏ֎ʹ B move1 A͔Βελʔτ B͔Βελʔτ A ۱Ҏ֎ʹ B move2
A ୡ B move1 A ۱Ҏ֎ʹ B move2 A ୡ
A ۱Ҏ֎ʹ A͔Βελʔτ B͔Βελʔτ B move1 A ۱Ҏ֎ʹ B move2
A ୡ
౷ܭ 0 2.143 4.286 6.429 8.571 10.714 12.857 15 0
10 20 30 40 50 60 70 80 90 100
༮ঁ ༮ঁ23ਓ͕ͱ͋Δ༸ؗʹด͡ࠐΊΒΕͨ ༮ঁؒʹूΊΒΕࠓޙʹ͍ͭͯ͠߹͏͜ͱ͕Ͱ͖Δ͕Ŋ͠߹͍͕͢ΜͩΒɺ Ұਓͣͭผʑͷ23ࣨͷ෦ʹ༓ด͞ΕͯͷίϛϡχέʔγϣϯऔΓ߹͑ͳ͍ɻ ͦͷޙ23ਓͷத͔ΒŽƃŦƄŷʹ1ਓ͕બΕΔŇ୭͕͍ͭબΕ͔ͨΛଞͷ༮ঁΔ͜ͱ ͕Ͱ͖ͳ͍ɻ બΕͨ༮ঁผʹ༻ҙ͞Εͨੴ૾ͷ෦ͰҎԼͷ2ͭͷ͏ͪͷͲͪΒ͔ΛඞͣߦΘͳ ͚ΕͳΒͳ͍ 1.෦ͷதԝͷੴ૾ͷ͖Λ90ӈ͔ࠨʹճసͤ͞Δ(ੴ૾౦ೆͷ͍ͣΕ͔Λ͍ ͍ͯΔ)
2.෦ͷதԝͷੴ૾Λഁյ͢Δ ༮ঁ͕1Λߦͬͨ߹Ŋ༮ঁ෦ʹ͞Ε࣍ʹŽƃŦƄŷʹબΕͨ༮ঁ͕ಉ༷ͷૢ࡞Λ͢ Δ(ҎԼ܁Γฦ͠) ༮ঁ͕2Λߦͬͨ߹ŊͦΕ·Ͱʹੴ૾ͷ෦Ͱ1Λߦͬͨ༮ঁ͕શһղ์͞ΕΔ ͨͩ͠Ŋੴ૾ͷ࠷ॳͷ͖ෆ໌ͱ͢Δɻ·ͨɺͲͷ༮ঁेͳ࣌ؒΛͯඞͣબ ΕΔͷͱ͢Δɻ ͯ͞ɺ͜ͷͱ͖༮ঁୡͷશһ͕࣮֬ʹ༸͔ؗΒղ์͞ΕΔʹ ࣄલͷ͠߹͍ͰͲͷΑ͏ͳऔΓܾΊΛ͢Ε͍͍͔