{"id":128,"date":"2026-11-21T03:20:30","date_gmt":"2026-11-20T21:50:30","guid":{"rendered":"https:\/\/bhashitva.org\/index.php\/bhash-razorback-ziplines\/"},"modified":"2026-11-21T03:20:30","modified_gmt":"2026-11-20T21:50:30","slug":"bhash-razorback-ziplines","status":"publish","type":"page","link":"https:\/\/bhashitva.org\/index.php\/bhash-razorback-ziplines\/","title":{"rendered":"Razorback Ziplines"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bhashitva.org\/index.php\/bhash-problem-showcase\/\">\u0938\u092d\u0940 \u0938\u092e\u0938\u094d\u092f\u093e\u090f\u0901 \u00b7 Bhash Problem Showcase<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0938\u092e\u0938\u094d\u092f\u093e \u00b7 \u092a\u0947\u0921\u093c\u094b\u0902 \u0915\u0947 \u092c\u0940\u091a \u092e\u093e\u0930\u094d\u0917<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Read N (2\u201310), then the integer coordinates of N trees in the range 0\u2013999. A route visits every tree exactly once and may start and end anywhere. Round each Euclidean segment length to the nearest integer before adding it. Print the longest possible route length first and the shortest second.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0938\u092e\u093e\u0927\u093e\u0928 \u00b7 How the solution works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Round each individual segment to the nearest integer. For every subset of trees and possible last tree, retain the shortest and longest paths. Extending a smaller subset tries every possible predecessor in O(N\u00b2 \u00d7 2\u1d3a) time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u0909\u0926\u093e\u0939\u0930\u0923 \u00b7 Sample input<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>4\n10 10\n20 20\n10 20\n20 10<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0905\u092a\u0947\u0915\u094d\u0937\u093f\u0924 \u092a\u0930\u093f\u0923\u093e\u092e \u00b7 Expected output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>38 30<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u092d\u093e\u0937 \u0938\u094d\u0930\u094b\u0924 \u00b7 Complete Bhash program<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\u0906\u092f\u093e\u0924 \u092e\u093e\u0928\u0915.\u092a\u093e\u0920\u094d\u092f;\n\u092b\u0932\u0928 \u0938\u0902\u0916\u094d\u092f\u093e\u090f\u0901() -&gt; \u0938\u0942\u091a\u0940&lt;\u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915&gt; {\n    \u0938\u094d\u0925\u093f\u0930 \u092a\u0902\u0915\u094d\u0924\u093f: \u092a\u093e\u0920 = \u092a\u093e\u0920\u092a\u0922\u093c\u094b();\n    \u0938\u094d\u0925\u093f\u0930 \u092a\u0930\u093f\u0923\u093e\u092e: \u0938\u0942\u091a\u0940&lt;\u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915&gt; = \u0928\u092f\u093e \u0938\u0942\u091a\u0940&lt;\u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915&gt;();\n    \u092e\u093e\u0928 \u0938\u0902\u0916\u094d\u092f\u093e: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n    \u092e\u093e\u0928 \u091a\u093f\u0939\u094d\u0928: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 1;\n    \u092e\u093e\u0928 \u0938\u0915\u094d\u0930\u093f\u092f: \u0924\u093e\u0930\u094d\u0915\u093f\u0915 = \u0905\u0938\u0924\u094d\u092f;\n    \u092e\u093e\u0928 \u0938\u094d\u0925\u093e\u0928: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n    \u091c\u092c\u0924\u0915 (\u0938\u094d\u0925\u093e\u0928 &lt;= \u0932\u0902\u092c\u093e\u0908(\u092a\u0902\u0915\u094d\u0924\u093f)) {\n        \u092e\u093e\u0928 \u0905\u0915\u094d\u0937\u0930: \u092a\u093e\u0920 = &quot; &quot;;\n        \u092f\u0926\u093f (\u0938\u094d\u0925\u093e\u0928 &lt; \u0932\u0902\u092c\u093e\u0908(\u092a\u0902\u0915\u094d\u0924\u093f)) { \u0905\u0915\u094d\u0937\u0930 = \u0905\u0902\u0936(\u092a\u0902\u0915\u094d\u0924\u093f, \u0938\u094d\u0925\u093e\u0928, \u0938\u094d\u0925\u093e\u0928 + 1); }\n        \u0938\u094d\u0925\u093f\u0930 \u0905\u0902\u0915: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u092a\u093e\u0920\u094d\u092f.\u0916\u094b\u091c\u094b(&quot;0123456789&quot;, \u0905\u0915\u094d\u0937\u0930);\n        \u092f\u0926\u093f (\u0905\u0902\u0915 &gt;= 0) { \u0938\u0902\u0916\u094d\u092f\u093e = \u0938\u0902\u0916\u094d\u092f\u093e * 10 + \u0905\u0902\u0915; \u0938\u0915\u094d\u0930\u093f\u092f = \u0938\u0924\u094d\u092f; }\n        \u0905\u0928\u094d\u092f\u0925\u093e \u092f\u0926\u093f (\u0905\u0915\u094d\u0937\u0930 == &quot;-&quot;) { \u091a\u093f\u0939\u094d\u0928 = -1; }\n        \u0905\u0928\u094d\u092f\u0925\u093e \u092f\u0926\u093f (\u0938\u0915\u094d\u0930\u093f\u092f) { \u092a\u0930\u093f\u0923\u093e\u092e.\u091c\u094b\u0921\u093c\u094b(\u091a\u093f\u0939\u094d\u0928 * \u0938\u0902\u0916\u094d\u092f\u093e); \u0938\u0902\u0916\u094d\u092f\u093e = 0; \u091a\u093f\u0939\u094d\u0928 = 1; \u0938\u0915\u094d\u0930\u093f\u092f = \u0905\u0938\u0924\u094d\u092f; }\n        \u0938\u094d\u0925\u093e\u0928 = \u0938\u094d\u0925\u093e\u0928 + 1;\n    }\n    \u0932\u094c\u091f\u093e\u0913 \u092a\u0930\u093f\u0923\u093e\u092e;\n}\n\u092b\u0932\u0928 \u0926\u0936\u092e\u0932\u0935\u0932\u0947\u0916\u0928(\u092e\u093e\u0928\u0915: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915) -&gt; \u092a\u093e\u0920 {\n    \u092f\u0926\u093f (\u092e\u093e\u0928\u0915 &lt; 0) { \u0932\u094c\u091f\u093e\u0913 &quot;-&quot; + \u0926\u0936\u092e\u0932\u0935\u0932\u0947\u0916\u0928(-\u092e\u093e\u0928\u0915); }\n    \u0938\u094d\u0925\u093f\u0930 \u0905\u0902\u0915: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u092e\u093e\u0928\u0915 % 10;\n    \u0938\u094d\u0925\u093f\u0930 \u0905\u0915\u094d\u0937\u0930: \u092a\u093e\u0920 = \u0905\u0902\u0936(&quot;0123456789&quot;, \u0905\u0902\u0915, \u0905\u0902\u0915+1);\n    \u092f\u0926\u093f (\u092e\u093e\u0928\u0915 &lt; 10) { \u0932\u094c\u091f\u093e\u0913 \u0905\u0915\u094d\u0937\u0930; }\n    \u0932\u094c\u091f\u093e\u0913 \u0926\u0936\u092e\u0932\u0935\u0932\u0947\u0916\u0928(\u092e\u093e\u0928\u0915\/10) + \u0905\u0915\u094d\u0937\u0930;\n}\n\n\u092b\u0932\u0928 \u092e\u0941\u0916\u094d\u092f() -&gt; \u0936\u0942\u0928\u094d\u092f {\n    \u0938\u094d\u0925\u093f\u0930 \u0906\u0915\u093e\u0930: \u0938\u0942\u091a\u0940&lt;\u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915&gt; = \u0938\u0902\u0916\u094d\u092f\u093e\u090f\u0901();\n    \u0938\u094d\u0925\u093f\u0930 \u0928: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u0906\u0915\u093e\u0930[0];\n    \u0938\u094d\u0925\u093f\u0930 \u0915\u0941\u0932: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 1 &lt;&lt; \u0928;\n    \u0938\u094d\u0925\u093f\u0930 \u0926\u0942\u0930\u093f\u092f\u093e\u0901: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[][] = \u0928\u092f\u093e \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[\u0928][\u0928];\n    \u0938\u094d\u0925\u093f\u0930 \u0915\u094d\u0937: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[] = \u0928\u092f\u093e \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[\u0928];\n    \u0938\u094d\u0925\u093f\u0930 \u092f: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[] = \u0928\u092f\u093e \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[\u0928];\n    \u092e\u093e\u0928 \u0915: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n    \u091c\u092c\u0924\u0915 (\u0915 &lt; \u0928) {\n        \u0938\u094d\u0925\u093f\u0930 \u092c\u093f\u0902\u0926\u0941: \u0938\u0942\u091a\u0940&lt;\u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915&gt; = \u0938\u0902\u0916\u094d\u092f\u093e\u090f\u0901();\n        \u0915\u094d\u0937[\u0915] = \u092c\u093f\u0902\u0926\u0941[0]; \u092f[\u0915] = \u092c\u093f\u0902\u0926\u0941[1];\n        \u092e\u093e\u0928 \u091c: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n        \u091c\u092c\u0924\u0915 (\u091c &lt; \u0915) {\n            \u0938\u094d\u0925\u093f\u0930 \u0905: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u0915\u094d\u0937[\u0915]-\u0915\u094d\u0937[\u091c];\n            \u0938\u094d\u0925\u093f\u0930 \u092c: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u092f[\u0915]-\u092f[\u091c];\n            \u092e\u093e\u0928 \u0926: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n            \u091c\u092c\u0924\u0915 ((2*\u0926+1)*(2*\u0926+1) &lt; 4*(\u0905*\u0905+\u092c*\u092c)) { \u0926 = \u0926+1; }\n            \u0926\u0942\u0930\u093f\u092f\u093e\u0901[\u0915][\u091c] = \u0926; \u0926\u0942\u0930\u093f\u092f\u093e\u0901[\u091c][\u0915] = \u0926; \u091c = \u091c+1;\n        }\n        \u0915 = \u0915+1;\n    }\n    \u0938\u094d\u0925\u093f\u0930 \u091b\u094b\u091f\u0940: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[][] = \u0928\u092f\u093e \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[\u0915\u0941\u0932][\u0928];\n    \u0938\u094d\u0925\u093f\u0930 \u092c\u0921\u093c\u0940: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[][] = \u0928\u092f\u093e \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915[\u0915\u0941\u0932][\u0928];\n    \u092e\u093e\u0928 \u0928\u094d\u092f\u0942\u0928: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 99999;\n    \u092e\u093e\u0928 \u0905\u0927\u093f\u0915: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n    \u092e\u093e\u0928 \u0938\u092e\u0942\u0939: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 1;\n    \u091c\u092c\u0924\u0915 (\u0938\u092e\u0942\u0939 &lt; \u0915\u0941\u0932) {\n        \u0915 = 0;\n        \u091c\u092c\u0924\u0915 (\u0915 &lt; \u0928) {\n            \u0938\u094d\u0925\u093f\u0930 \u092c\u093f\u091f: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 1 &lt;&lt; \u0915;\n            \u092f\u0926\u093f ((\u0938\u092e\u0942\u0939 &amp; \u092c\u093f\u091f) != 0) {\n                \u0938\u094d\u0925\u093f\u0930 \u0936\u0947\u0937\u0938\u092e\u0942\u0939: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u0938\u092e\u0942\u0939-\u092c\u093f\u091f;\n                \u092f\u0926\u093f (\u0936\u0947\u0937\u0938\u092e\u0942\u0939 != 0) { \u091b\u094b\u091f\u0940[\u0938\u092e\u0942\u0939][\u0915] = 99999; }\n                \u092e\u093e\u0928 \u091c: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = 0;\n                \u091c\u092c\u0924\u0915 (\u091c &lt; \u0928) {\n                    \u092f\u0926\u093f ((\u0936\u0947\u0937\u0938\u092e\u0942\u0939 &amp; (1 &lt;&lt; \u091c)) != 0) {\n                        \u0938\u094d\u0925\u093f\u0930 \u0905: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u091b\u094b\u091f\u0940[\u0936\u0947\u0937\u0938\u092e\u0942\u0939][\u091c]+\u0926\u0942\u0930\u093f\u092f\u093e\u0901[\u091c][\u0915];\n                        \u0938\u094d\u0925\u093f\u0930 \u092c: \u092a\u0942\u0930\u094d\u0923\u093e\u0902\u0915 = \u092c\u0921\u093c\u0940[\u0936\u0947\u0937\u0938\u092e\u0942\u0939][\u091c]+\u0926\u0942\u0930\u093f\u092f\u093e\u0901[\u091c][\u0915];\n                        \u092f\u0926\u093f (\u0905 &lt; \u091b\u094b\u091f\u0940[\u0938\u092e\u0942\u0939][\u0915]) { \u091b\u094b\u091f\u0940[\u0938\u092e\u0942\u0939][\u0915] = \u0905; }\n                        \u092f\u0926\u093f (\u092c &gt; \u092c\u0921\u093c\u0940[\u0938\u092e\u0942\u0939][\u0915]) { \u092c\u0921\u093c\u0940[\u0938\u092e\u0942\u0939][\u0915] = \u092c; }\n                    }\n                    \u091c = \u091c+1;\n                }\n                \u092f\u0926\u093f (\u0938\u092e\u0942\u0939 == \u0915\u0941\u0932-1) {\n                    \u092f\u0926\u093f (\u091b\u094b\u091f\u0940[\u0938\u092e\u0942\u0939][\u0915] &lt; \u0928\u094d\u092f\u0942\u0928) { \u0928\u094d\u092f\u0942\u0928 = \u091b\u094b\u091f\u0940[\u0938\u092e\u0942\u0939][\u0915]; }\n                    \u092f\u0926\u093f (\u092c\u0921\u093c\u0940[\u0938\u092e\u0942\u0939][\u0915] &gt; \u0905\u0927\u093f\u0915) { \u0905\u0927\u093f\u0915 = \u092c\u0921\u093c\u0940[\u0938\u092e\u0942\u0939][\u0915]; }\n                }\n            }\n            \u0915 = \u0915+1;\n        }\n        \u0938\u092e\u0942\u0939 = \u0938\u092e\u0942\u0939+1;\n    }\n    \u0932\u093f\u0916\u094b(\u0926\u0936\u092e\u0932\u0935\u0932\u0947\u0916\u0928(\u0905\u0927\u093f\u0915)+&quot; &quot;+\u0926\u0936\u092e\u0932\u0935\u0932\u0947\u0916\u0928(\u0928\u094d\u092f\u0942\u0928));\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0938\u092d\u0940 \u0938\u092e\u0938\u094d\u092f\u093e\u090f\u0901 \u00b7 Bhash Problem Showcase \u0938\u092e\u0938\u094d\u092f\u093e \u00b7 \u092a\u0947\u0921\u093c\u094b\u0902 \u0915\u0947 \u092c\u0940\u091a \u092e\u093e\u0930\u094d\u0917 Read N (2\u201310), then the integer coordinates of N trees in the range 0\u2013999. A route visits every tree exactly once and may start and end anywhere. Round<span class=\"more-dots\">&#8230;<\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-128","page","type-page","status-publish","hentry","no-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/pages\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":0,"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/pages\/128\/revisions"}],"wp:attachment":[{"href":"https:\/\/bhashitva.org\/index.php\/wp-json\/wp\/v2\/media?parent=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}