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
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
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
CSC509 Lecture 09
javiergs
PRO
0
140
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
110
CSC509 Lecture 12
javiergs
PRO
0
160
イベント駆動で成長して委員会
happymana
1
320
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Quine, Polyglot, 良いコード
qnighy
4
640
Ethereum_.pdf
nekomatu
0
460
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Featured
See All Featured
Become a Pro
speakerdeck
PRO
25
5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Building Your Own Lightsaber
phodgson
103
6.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
How to train your dragon (web standard)
notwaldorf
88
5.7k
RailsConf 2023
tenderlove
29
900
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
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Λߦͬͨ༮ঁ͕શһղ์͞ΕΔ ͨͩ͠Ŋੴ૾ͷ࠷ॳͷ͖ෆ໌ͱ͢Δɻ·ͨɺͲͷ༮ঁेͳ࣌ؒΛͯඞͣબ ΕΔͷͱ͢Δɻ ͯ͞ɺ͜ͷͱ͖༮ঁୡͷશһ͕࣮֬ʹ༸͔ؗΒղ์͞ΕΔʹ ࣄલͷ͠߹͍ͰͲͷΑ͏ͳऔΓܾΊΛ͢Ε͍͍͔