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
340
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
650
JOI2015-2016 春合宿 day 2 Sandwich 解説
snuke
0
280
JOI2015-sp-day4-walls-anothersolution
snuke
0
210
JOI2014 春合宿 day 2 スタンプラリー 解説
snuke
0
190
NPCA合宿きょーぷろ講義
snuke
0
350
CodeForces#162 Div1-E
snuke
0
280
CodeForces162 Div1-E
snuke
3
15k
SRM 555 Div 1 easy, Div 2 medium
snuke
1
420
SRM 555 Div 1 hard
snuke
1
490
Other Decks in Programming
See All in Programming
What we keep in mind when migrating from Serverless Framework to AWS CDK and AWS SAM
kasacchiful
1
140
『ドメイン駆動設計をはじめよう』中核の業務領域
masuda220
PRO
5
970
ブラウザ互換の重要性 - あらゆるユーザーに価値を届けるために必要なこと
yamanoku
0
110
エンジニア1年目で複雑なコードの改善に取り組んだ話
mtnmr
3
1.9k
Amazon Neptuneで始める初めてのグラフDB ー グラフDBを使う意味を考える ー
satoshi256kbyte
2
250
Prolog入門
qnighy
4
990
connect-go で面倒くささと戦う / 2024-08-27 #newmo_layerx_go
izumin5210
2
630
私のEbitengineの第一歩
qt_luigi
0
440
The Shape of a Service Object
inem
0
490
2024 컴포즈 정원사
jisungbin
0
150
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
180
GoのIteratorに詳しくなってしまう
inatonix
1
200
Featured
See All Featured
How GitHub (no longer) Works
holman
310
140k
KATA
mclloyd
27
13k
Why You Should Never Use an ORM
jnunemaker
PRO
53
8.9k
Principles of Awesome APIs and How to Build Them.
keavy
125
16k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
GitHub's CSS Performance
jonrohan
1029
450k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
45
4.8k
Gamification - CAS2011
davidbonilla
79
4.9k
Debugging Ruby Performance
tmm1
72
12k
Web Components: a chance to create the future
zenorocha
308
42k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.9k
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Λߦͬͨ༮ঁ͕શһղ์͞ΕΔ ͨͩ͠Ŋੴ૾ͷ࠷ॳͷ͖ෆ໌ͱ͢Δɻ·ͨɺͲͷ༮ঁेͳ࣌ؒΛͯඞͣબ ΕΔͷͱ͢Δɻ ͯ͞ɺ͜ͷͱ͖༮ঁୡͷશһ͕࣮֬ʹ༸͔ؗΒղ์͞ΕΔʹ ࣄલͷ͠߹͍ͰͲͷΑ͏ͳऔΓܾΊΛ͢Ε͍͍͔