{"id":1409,"date":"2013-03-18T11:13:34","date_gmt":"2013-03-18T03:13:34","guid":{"rendered":"https:\/\/blog.rexdf.org\/?p=1409"},"modified":"2013-03-18T11:13:34","modified_gmt":"2013-03-18T03:13:34","slug":"codeforces-round-173-div-2-xor-and-or","status":"publish","type":"post","link":"https:\/\/blog.rexdf.org\/en\/2013\/03\/codeforces-round-173-div-2-xor-and-or\/","title":{"rendered":"Codeforces Round #173 (Div. 2) XOR and OR"},"content":{"rendered":"<p>&nbsp;<\/p>\n<div>\n<div>C. XOR and OR<\/div>\n<div>\n<div>time limit per test<\/div>\n<p>2 seconds<\/p><\/div>\n<div>\n<div>memory limit per test<\/div>\n<p>256 megabytes<\/p><\/div>\n<div>\n<div>input<\/div>\n<p>standard input<\/p><\/div>\n<div>\n<div>output<\/div>\n<p>standard output<\/p><\/div>\n<\/div>\n<div>\n<p>The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.<\/p>\n<p>A Bitlandish string is a string made only of characters &#8220;0&#8221; and &#8220;1&#8221;.<\/p>\n<p>BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string\u00a0<i>a<\/i>, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as\u00a0<i>x<\/i>\u00a0and the other one as\u00a0<i>y<\/i>. Then he calculates two values\u00a0<i>p<\/i>\u00a0and\u00a0<i>q<\/i>:\u00a0<i>p<\/i>\u2009=\u2009<i>x<\/i>\u00a0<i>xor<\/i>\u00a0<i>y<\/i>,\u00a0<i>q<\/i>\u2009=\u2009<i>x<\/i>\u00a0<i>or<\/i>\u00a0<i>y<\/i>. Then he replaces one of the two taken characters by\u00a0<i>p<\/i>\u00a0and the other one by\u00a0<i>q<\/i>.<\/p>\n<p>The\u00a0<i>xor<\/i>\u00a0operation means the bitwise excluding OR operation. The\u00a0<i>or<\/i>\u00a0operation is the bitwise OR operation.<\/p>\n<p>So for example one operation can transform string\u00a011\u00a0to string\u00a010\u00a0or to string\u00a001. String\u00a01\u00a0cannot be transformed into any other string.<\/p>\n<p>You&#8217;ve got two Bitlandish strings\u00a0<i>a<\/i>\u00a0and\u00a0<i>b<\/i>. Your task is to check if it is possible for BitHaval to transform string\u00a0<i>a<\/i>\u00a0to string\u00a0<i>b<\/i>\u00a0in several (possibly zero) described operations.<\/p>\n<\/div>\n<div>\n<div>Input<\/div>\n<p>The first line contains Bitlandish string\u00a0<i>a<\/i>, the second line contains Bitlandish string\u00a0<i>b<\/i>. The strings can have different lengths.<\/p>\n<p>It is guaranteed that the given strings only consist of characters &#8220;0&#8221; and &#8220;1&#8221;. The strings are not empty, their length doesn&#8217;t exceed\u00a010<sup>6<\/sup>.<\/p>\n<\/div>\n<div>\n<div>Output<\/div>\n<p>Print &#8220;YES&#8221; if\u00a0<i>a<\/i>\u00a0can be transformed into\u00a0<i>b<\/i>, otherwise print &#8220;NO&#8221;. Please do not print the quotes.<\/p>\n<\/div>\n<div>\n<div>Sample test(s)<\/div>\n<div>\n<div>\n<div>input<\/div>\n<pre>11 10<\/pre>\n<\/div>\n<div>\n<div>output<\/div>\n<pre>YES<\/pre>\n<\/div>\n<div>\n<div>input<\/div>\n<pre>1 01<\/pre>\n<\/div>\n<div>\n<div>output<\/div>\n<pre>NO<\/pre>\n<\/div>\n<div>\n<div>input<\/div>\n<pre>000 101<\/pre>\n<\/div>\n<div>\n<div>output<\/div>\n<pre>NO<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<pre class=\"brush: cpp; gutter: true\">\r\n#include &lt;iostream&gt;\r\n#include &lt;cstdio&gt;\r\n#include &lt;cstdlib&gt;\r\n#include &lt;cstring&gt;\r\n\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n\tchar c;\r\n\tint ones1=0,zero1=0,ones2=0,zero2=0;\r\n\tint fs=1;\r\n\twhile(c=getchar())\r\n\t{\r\n\t\tif(1==fs)\r\n\t\t{\r\n\t\t\tif(c==&#039;\\n&#039;)fs=2;\r\n\t\t\telse if(c==&#039;1&#039;)ones1++;\r\n\t\t\telse zero1++;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tif(c==&#039;\\n&#039;)break;\r\n\t\t\telse if(c==&#039;1&#039;)ones2++;\r\n\t\t\telse zero2++;\r\n\t\t}\r\n\t}\r\n\tif(((ones2 &amp;&amp; ones1) || ones2==ones1) &amp;&amp; ones1+zero1==ones2+zero2)\r\n\t  cout&lt;&lt;&quot;YES&quot;&lt;&lt;endl;\r\n\telse cout&lt;&lt;&quot;NO&quot;&lt;&lt;endl;\r\n\t\/\/system(&quot;pause&quot;);\r\n\treturn 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they &hellip; <a href=\"https:\/\/blog.rexdf.org\/en\/2013\/03\/codeforces-round-173-div-2-xor-and-or\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[125],"class_list":["post-1409","post","type-post","status-publish","format-standard","hentry","category-algorithm","tag-codeforces"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/posts\/1409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/comments?post=1409"}],"version-history":[{"count":0,"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/posts\/1409\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/media?parent=1409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/categories?post=1409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rexdf.org\/en\/wp-json\/wp\/v2\/tags?post=1409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}