Dc Prf-SPOJ-Classical.Ps
Total Page:16
File Type:pdf, Size:1020Kb
Archives of the Sphere Online Judge classical problemset Editors: 1 u.swarnaprakash NghiaHemant Nguyen Verma Hoang Blue Mary Andrés Leonardo Rojas LukasŁukasz Mai Kuszner Adrian Kosowski Duarte Stephenbalaji Merriman Adrian Kuegel Brian YashRahul Garg Camilo Andrés Varela León Spooky RobertNeal Zane Rychcicki Jin Bin Paritosh Aggarwal VOJChinh problem Nguyen setters Thanh-Vy Hua Le Đôn Khue ?????Paweł Dobrzycki Roman Sol Csaba Noszaly KonradPatryk Pomykalski Piwakowski Wanderley Guimaraes Analysis Mode (Bogardan ZhangFrank RafaelTaizhi Arteaga Michał Czuczman Hellkite) MauroMiorel PaliiPersano Jelani Nelson (Minilek) Abhilash I P.KasthuriTomek Czajka Rangan• Daniel Gómez Didier Paul Draper SebastianPripoae Toni Kanthak Ngô Minh Đu+’c Bobby Xiao BartłomiejReinier César Kowalski Mujica Neal Wu Darek Dereniowski IvanHdez Alfonso Prasanna Nguye^~n Ha Du+o+ng OlamendyRadu Grigore Piotr Łowiec Nguyen Minh Hieu MartinMark Gordon Bader Robin Nittka Qu Jun dqdLovro Puzar Ahmed Aly Fabio Avellaneda PiotrLordxfastx Piotrowski Adam Dzedzej Hoang Hong Quan TomaszRuslan Sennov Goluch Ajay Somani Nguyen Van Quang Huy Rahulabhijith reddy d Nikola P Borisov Tomas. Bob Diego Satoba Mir Wasi Ahmed Pawel Gawrychowski Luka Kalinovcic Matthew Reeder yandry pérez Rafal clemente Marco Gallotta Tomasz Niedzwiecki Pavel Kuznetsov Andrés Mejía-Posada Robert Gerbicz Andres Galvis Chen Xiaohong Slobodan Simon Gog Alfonso2 Peterssen Kashyap KBR Krzysztof Kluczek John Rizzo Jose Daniel Rdguez Race with time Abel Nieto Rodriguez Michał Małafiejski Bogusław K. Osuch Ivan Metelsky Gogu Marian Phenomenal Le Trong Dao Nguyen Dinh Tu Muntasir Azam Khan 2 Last updated: 2009-10-09 09:00:05 3 Preface This electronic material contains a set of algorithmic problems, forming the archives of the Sphere Online Judge (http://www.spoj.pl/), classical problemset. The document can be accessed at the following URLs: in PostScript format: http://www.spoj.pl/problems/classical.ps in Portable Document Format: http://www.spoj.pl/problems/classical.pdf These resources are constantly updated to synchronise with the ever-changing hypertext version of the problems, and to include newly added problems. If you have obtained this document from another source, it is strongly recommended that you should download the current version from one of the aforementioned URLs. Enjoy problem-solving at the Sphere Online Judge! Disclaimer from the Editors. Despite our best efforts, it is possible that this document contains errors or that some of the content differs slightly from its original hypertext form. We take no responsibility for any such faults and their consequences. We neither authorise nor approve use of this material for any purpose other than facilitating problem solving at the Sphere Online Judge site; nor do we guarantee its fitness for any purpose whatsoever. The layout of the problems in this document is the copyright of the Editors named on the cover (as determined by the appropriate footers in the problem description). The content is the copyright of the respective Editor unless the copyright holder is otherwise stated in the ’resource’ section. The document as a whole is not protected by copyright, and fragments of it are to be regarded independently. No responsibility is taken by the Editors if use or redistribution of this document violates either their or third party copyright laws. When referring to or citing the whole or a fragment of this document, please state clearly the aforementioned URLs at which the document is to be found, as well as the resources from which the problems you are referring to originally came. Remarks concerning this document should be sent to the following e-mail address: [email protected]. 4 Table of Contents 1. Problem TEST (1. Life, the Universe, and Everything) 2. Problem PRIME1 (2. Prime Generator) 3. Problem SBSTR1 (3. Substring Check (Bug Funny)) 4. Problem ONP (4. Transform the Expression) 5. Problem PALIN (5. The Next Palindrome) 6. Problem ARITH (6. Simple Arithmetics) 7. Problem BULK (7. The Bulk!) 8. Problem CMPLS (8. Complete the Sequence!) 9. Problem DIRVS (9. Direct Visibility) 10. Problem CMEXPR (10. Complicated Expressions) 11. Problem FCTRL (11. Factorial) 12. Problem MMIND (12. The Game of Master-Mind) 13. Problem HOTLINE (13. Hotline) 14. Problem IKEYB (14. I-Keyboard) 15. Problem SHPATH (15. The Shortest Path) 16. Problem TETRA (16. Sphere in a tetrahedron) 17. Problem CRYPTO1 (17. The Bytelandian Cryptographer (Act I)) 18. Problem CRYPTO2 (18. The Bytelandian Cryptographer (Act II)) 19. Problem CRYPTO3 (19. The Bytelandian Cryptographer (Act III)) 20. Problem CRYPTO4 (20. The Bytelandian Cryptographer (Act IV)) 21. Problem TRICENTR (22. Triangle From Centroid) 22. Problem PIR (23. Pyramids) 23. Problem FCTRL2 (24. Small factorials) 24. Problem POUR1 (25. Pouring water) 25. Problem BSHEEP (26. Build the Fence) 26. Problem SBANK (27. Sorting Bank Accounts) 27. Problem HMRO (28. Help the Military Recruitment Office!) 28. Problem HASHIT (29. Hash it!) 29. Problem BLINNET (30. Bytelandian Blingors Network) 30. Problem MUL (31. Fast Multiplication) 31. Problem NHAY (32. A Needle in the Haystack) 32. Problem TRIP (33. Trip) 33. Problem RUNAWAY (34. Run Away) 34. Problem EQBOX (35. Equipment Box) 35. Problem CODE1 (36. Secret Code) 36. Problem PROPKEY (37. The Proper Key) 37. Problem LABYR1 (38. Labyrinth) 38. Problem PIGBANK (39. Piggy-Bank) 39. Problem STONE (40. Lifting the Stone) 40. Problem WORDS1 (41. Play on Words) 41. Problem ADDREV (42. Adding Reversed Numbers) 42. Problem BOOKS1 (43. Copying Books) 43. Problem SCYPHER (44. Substitution Cipher) 44. Problem COMMEDIA (45. Commedia dell Arte) 45. Problem SCRAPER (47. Skyscraper Floors) 5 46. Problem BEADS (48. Glass Beads) 47. Problem HAREFOX (49. Hares and Foxes) 48. Problem INCARDS (50. Invitation Cards) 49. Problem TOUR (51. Fake tournament) 50. Problem JULKA (54. Julka) 51. Problem JASIEK (55. Jasiek) 52. Problem DYZIO (56. Dyzio) 53. Problem SUPPER (57. Supernumbers in a permutation) 54. Problem PICAD (58. Crime at Piccadily Circus) 55. Problem BIA (59. Bytelandian Information Agency) 56. Problem DANCE (60. The Gordian Dance) 57. Problem BRCKTS (61. Brackets) 58. Problem IMP (62. The Imp) 59. Problem SQRBR (63. Square Brackets) 60. Problem PERMUT1 (64. Permutations) 61. Problem BALL1 (65. Ball) 62. Problem CRSCNTRY (66. Cross-country) 63. Problem CUTOUT (67. Cutting out) 64. Problem EXPR1 (68. Expression) 65. Problem MOULDS (69. Moulds) 66. Problem RELATS1 (70. Relations) 67. Problem TREE1 (71. Tree) 68. Problem BAC (73. Bacterial) 69. Problem DIVSUM (74. Divisor Summation) 70. Problem EDIT1 (75. Editor) 71. Problem EDIT2 (76. Editor Inverse) 72. Problem BRICKS (77. New bricks disorder) 73. Problem MARBLES (78. Marbles) 74. Problem EASYPIE (82. Easy Problem) 75. Problem BUNDLE (83. Bundling) 76. Problem SHORTCUT (84. Shortcut) 77. Problem DICE1 (85. Dice Contest) 78. Problem RAIN1 (86. November Rain) 79. Problem FOOTBALL (87. Football) 80. Problem TREE2 (88. Which is Next) 81. Problem HANGLET (89. Hang or not to hang) 82. Problem MINIMAX (90. Minimizing maximizer) 83. Problem TWOSQRS (91. Two squares or not two squares) 84. Problem CUTSQRS (92. Cutting off Squares) 85. Problem MAYA (94. Numeral System of the Maya) 86. Problem STPAR (95. Street Parade) 87. Problem SHOP (96. Shopping) 88. Problem PARTY (97. Party Schedule) 89. Problem DFLOOR (98. Dance Floor) 90. Problem BUS (99. Bus) 91. Problem BABTWR (100. Tower of Babylon) 92. Problem FISHER (101. Fishmonger) 6 93. Problem LITEPIPE (102. GX Light Pipeline Inc) 94. Problem HIGH (104. Highways) 95. Problem ALICEBOB (105. Alice and Bob) 96. Problem BINSTIRL (106. Binary Stirling Numbers) 97. Problem MAYACAL (107. Calendar of the Maya) 98. Problem MORSE (108. Decoding Morse Sequences) 99. Problem EXCHNG (109. Exchanges) 100. Problem CISTFILL (110. Fill the Cisterns) 101. Problem SEGVIS (112. Horizontally Visible Segments) 102. Problem FAMILY (115. Family) 103. Problem INTERVAL (116. Intervals) 104. Problem RHOMBS (118. Rhombs) 105. Problem SERVERS (119. Servers) 106. Problem SOLIT (120. Solitaire) 107. Problem TTABLE (121. Timetable) 108. Problem STEVE (122. Voracious Steve) 109. Problem PAYING (123. Paying in Byteland) 110. Problem RENT (130. Rent your airplane and make money) 111. Problem SQDANCE (131. Square dance) 112. Problem HELPR2D2 (132. Help R2-D2!) 113. Problem PHONY (134. Phony Primes) 114. Problem MAWORK (135. Men at work) 115. Problem TRANS (136. Transformation) 116. Problem PARTIT (137. Partition) 117. Problem POSTERS (138. Election Posters) 118. Problem MAZE (139. The Long and Narrow Maze) 119. Problem LONER (140. The Loner) 120. Problem GLUE (142. Johnny and the Glue) 121. Problem ALIENS (145. Aliens) 122. Problem MULTIPLY (146. Fast Multiplication Again) 123. Problem TAUT (147. Tautology) 124. Problem MLAND (148. Land for Motorways) 125. Problem FSHEEP (149. Fencing in the Sheep) 126. Problem PLONK (150. Where to Drink the Plonk?) 127. Problem COURIER (151. The Courier) 128. Problem SCALES (153. Balancing the Stone) 129. Problem ROCK (154. Sweet and Sour Rock) 130. Problem PALSEC (160. Choosing a Palindromic Sequence) 131. Problem PAINTTMP (174. Paint templates) 132. Problem POLY1 (175. Polygon) 133. Problem SUM1SEQ (176. Sum of one-sequence) 134. Problem ABWORDS (177. AB-words) 135. Problem ROADNET (178. Road net) 136. Problem WORDEQ (179. Word equations) 137. Problem CONTPACK (180. How to pack containers) 138. Problem SCUBADIV (181. Scuba diver) 139. Problem WINDOW1 (182. Window) 7 140.