{"id":3258,"date":"2012-04-12T04:12:44","date_gmt":"2012-04-12T04:12:44","guid":{"rendered":"http:\/\/wp.binus.ac.id\/?p=3258"},"modified":"2012-04-12T04:12:44","modified_gmt":"2012-04-12T04:12:44","slug":"contoh-soal5128-to-add-or-to-multiply","status":"publish","type":"post","link":"https:\/\/simprug.binus.sch.id\/id\/2012\/04\/12\/contoh-soal5128-to-add-or-to-multiply\/","title":{"rendered":"[contoh soal]5128 &#8211; To Add or to Multiply"},"content":{"rendered":"<p>\t\t\t\tThe Industrial Computer Processor Company offers very fast, special purpose processing units tailored to customer needs. Processors of the\u00a0<em>a<\/em>-C-<em>m<\/em>\u00a0family (such as the 1-C-2 and the 5-C-3) have an instruction set with only two different operations:<br \/>\n<tt>A<\/tt>\u00a0add\u00a0<em>a<\/em><\/p>\n<p><tt>M<\/tt>\u00a0multiply by\u00a0<em>m<\/em><br \/>\nThe processor receives an integer, executes a sequence of\u00a0<tt>A<\/tt>\u00a0and\u00a0<tt>M<\/tt>\u00a0operations (the program) that modifies the input, and outputs the result. For example, the 1-C-2 processor executing the program\u00a0<tt>AAAM<\/tt>\u00a0with the input 2 yields the output 10 (the computation is\u00a02\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a03\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a04\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a05\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a010), while the 5-C-3 processor yields 51 with the same program and input (\u00a02\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a07\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a012\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a017\u00a0<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img1.png\" alt=\"$ rightarrow$\" width=\"22\" height=\"18\" align=\"BOTTOM\" border=\"0\" \/>\u00a051).<\/p>\n<p>You are an\u00a0<em>a<\/em>-C-<em>m<\/em>\u00a0programmer assigned to a top secret project. This means that you have not been told the precise computation your program should perform. But you are given particular values\u00a0<em>p<\/em>,\u00a0<em>q<\/em>,\u00a0<em>r<\/em>, and\u00a0<em>s<\/em>\u00a0and the following conditions:<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li>The input is guaranteed to be a number between\u00a0<em>p<\/em>\u00a0and\u00a0<em>q<\/em>.<\/li>\n<li>The output must be some number between\u00a0<em>r<\/em>\u00a0and\u00a0<em>s<\/em>.<\/li>\n<\/ol>\n<p>Given an\u00a0<em>a<\/em>-C-<em>m<\/em>\u00a0processor and the numbers\u00a0<em>p<\/em>,\u00a0<em>q<\/em>,\u00a0<em>r<\/em>, and\u00a0<em>s<\/em>, your job is to construct the shortest\u00a0<em>a<\/em>-C-<em>m<\/em>\u00a0program which, for every input\u00a0<em>x<\/em>\u00a0such that\u00a0<em>p<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>x<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>q<\/em>, yields some output<em>y<\/em>\u00a0such that\u00a0<em>r<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>y<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>s<\/em>. If there is more than one program of minimum length, choose the one that come first lexicographically, treating each program as a string of\u00a0<tt>A<\/tt>s and\u00a0<tt>M<\/tt>s.<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #ff0000;font-size: medium\"><a name=\"SECTION0001001000000000000000\"><\/a>Input\u00a0<\/span><\/h2>\n<p>The input contains several test cases. Each test case is given by a line with the six integers<em>a<\/em>,\u00a0<em>m<\/em>,\u00a0<em>p<\/em>,\u00a0<em>q<\/em>,\u00a0<em>r<\/em>, and\u00a0<em>s<\/em>\u00a0as described above (\u00a01<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>a<\/em>,\u00a0<em>m<\/em>,\u00a0<em>p<\/em>,\u00a0<em>q<\/em>,\u00a0<em>r<\/em>,\u00a0<em>s<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/>10<sup>9<\/sup>\u00a0,\u00a0<em>p<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>q<\/em>\u00a0and\u00a0<em>r<\/em><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/livearchive.onlinejudge.org\/external\/51\/5128img2.png\" alt=\"$ le$\" width=\"18\" height=\"31\" align=\"MIDDLE\" border=\"0\" \/><em>s<\/em>).<\/p>\n<p>The last test case is followed by a line with six zeros.<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #ff0000;font-size: medium\"><a name=\"SECTION0001002000000000000000\"><\/a>Output\u00a0<\/span><\/h2>\n<p>For each test case, display its case number followed by the best program as described above. Display the word &#8220;<tt>empty<\/tt>&#8221; if the best program uses no operations. Display the word &#8220;<tt>impossible<\/tt>&#8221; if there is no program meeting the specifications.<\/p>\n<p>Display the program as a sequence of space-separated strings, alternating between strings of the form &#8220;<em>n<\/em><tt>A<\/tt>&#8221; and strings of the form &#8220;<em>n<\/em><tt>M<\/tt>&#8220;, where\u00a0<em>n<\/em>\u00a0&gt; 0. Strings of the former type indicate\u00a0<em>n<\/em>\u00a0consecutive A operations, and strings of the latter type indicate\u00a0<em>n<\/em>consecutive\u00a0<em>M<\/em>\u00a0operations.<\/p>\n<p>Follow the format of the sample output.<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #ff0000;font-size: medium\"><a name=\"SECTION0001003000000000000000\"><\/a>Sample Input\u00a0<\/span><\/h2>\n<p>&nbsp;<\/p>\n<pre>1 2 2 3 10 20\n1 3 2 3 22 33\n3 2 2 3 4 5\n5 3 2 3 2 3\n0 0 0 0 0 0<\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #ff0000;font-size: medium\"><a name=\"SECTION0001004000000000000000\"><\/a>Sample Output\u00a0<\/span><\/h2>\n<p>&nbsp;<\/p>\n<pre>Case 1: 1A 2M\nCase 2: 1M 2A 1M\nCase 3: impossible\nCase 4: empty<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Industrial Computer Processor Company offers very fast, special purpose processing units tailored to customer needs. Processors of the\u00a0a-C-m\u00a0family (such as the 1-C-2 and the 5-C-3) have an instruction set with only two different operations: A\u00a0add\u00a0a M\u00a0multiply by\u00a0m The processor receives an integer, executes a sequence of\u00a0A\u00a0and\u00a0M\u00a0operations (the program) that modifies the input, and outputs [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3258","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/posts\/3258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/comments?post=3258"}],"version-history":[{"count":0,"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/posts\/3258\/revisions"}],"wp:attachment":[{"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/media?parent=3258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/categories?post=3258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/simprug.binus.sch.id\/id\/wp-json\/wp\/v2\/tags?post=3258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}