{"id":181,"date":"2019-05-13T00:00:21","date_gmt":"2019-05-12T16:00:21","guid":{"rendered":"http:\/\/wwwwodddd.com\/?p=181"},"modified":"2019-05-22T00:24:47","modified_gmt":"2019-05-21T16:24:47","slug":"2019-51nod-noi3","status":"publish","type":"post","link":"https:\/\/wwwwodddd.com\/wordpress\/2019-51nod-noi3\/","title":{"rendered":"NOI2019\u5907\u6218\u4e4b\u7ec4\u5408\u8ba1\u6570\u7ec3\u4e60\u8d5b"},"content":{"rendered":"<p><!--more--><\/p>\n<h1>P1<\/h1>\n<p><a href=\"https:\/\/www.51nod.com\/Challenge\/Problem.html#!#problemId=2574\">51nod 2574 \u4e09\u89d2\u5f62\u8ba1\u6570<\/a><\/p>\n<pre><code class=\"language-cpp line-numbers\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\nchar s[1000020];\nint main() {\n    scanf(\"%s\", s);\n    int l = strlen(s);\n    long long ans = (long long)(l - 1) \/ 2 * l;\n    if (l % 2 == 1) {\n        long long cnt0 = 0;\n        long long cnt1 = 0;\n        for (int i = 0; i &lt; l; i++) {\n            if (s[i] == '1') {\n                cnt1++;\n            } else {\n                cnt0++;\n            }\n        }\n        ans -= cnt0 * cnt1 * 3 \/ 2;\n    } else {\n        long long cnt00 = 0, cnt01 = 0;\n        long long cnt10 = 0, cnt11 = 0;\n        for (int i = 0; i &lt; l; i += 2) {\n            if (s[i] == '1') {\n                cnt01++;\n            } else {\n                cnt00++;\n            }\n        }\n        for (int i = 1; i &lt; l; i += 2) {\n            if (s[i] == '1') {\n                cnt11++;\n            } else {\n                cnt10++;\n            }\n        }\n        ans -= (cnt00 * cnt01 + cnt10 * cnt11) * 2;\n        ans -= (cnt00 * cnt11 + cnt10 * cnt01);\n        for (int i = 0; i &lt; l \/ 2; i++) {\n            if (s[i] != s[(i + l \/ 2) % l]) {\n                ans++;\n            }\n        }\n    }\n    if (l % 3 == 0) {\n        ans -= l \/ 3 * 2;\n        for (int i = 0; i &lt; l; i++) {\n            if (s[i] != s[(i + (l \/ 3)) % l]) {\n                ans++;\n            }\n        }\n    }\n    printf(\"%lld\\n\", ans);\n    return 0;\n}\n<\/code><\/pre>\n<h1>P2<\/h1>\n<h1>P3<\/h1>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-181","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":0,"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"wp:attachment":[{"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wwwwodddd.com\/wordpress\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}