{"id":125,"date":"2023-04-14T17:21:32","date_gmt":"2023-04-14T09:21:32","guid":{"rendered":"https:\/\/solost.cn\/?p=125"},"modified":"2023-04-14T17:21:32","modified_gmt":"2023-04-14T09:21:32","slug":"232","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=125","title":{"rendered":"Codeforces Round 578 (Div. 2) &#8211; E. Compress Words"},"content":{"rendered":"<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/codeforces.com\/contest\/1200\/problem\/E\">\u9898\u76ee\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u9898\u76ee\u7684\u610f\u601d\u662f\u628a\u5b57\u7b26\u4e32\u5220\u53bb\u8fde\u7eed\u7684\u4e24\u4e2a\u5b57\u6bcd\uff0c\u95ee\u5269\u4e0b\u7684\u5b57\u7b26\u4e32\u62fc\u8d77\u6765\u6709\u591a\u5c11\u79cd\uff1f<\/p>\n<h2>\u9898\u89e3<\/h2>\n<pre><code class=\"lang-cpp\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;unordered_set&gt;\n#include &lt;vector&gt;\n\nusing namespace std;\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007, P = 13331;\nconst int N = 2e5 + 10;\n\null h[N], p[N];\n\null get_hash(int l, int r)\n{\n    return h[r] - h[l - 1] * p[r - l + 1];\n}\n\nvoid solve()\n{\n    int n;\n    string s;\n    cin &gt;&gt; n &gt;&gt; s;\n    s = &#039; &#039; + s;\n    p[0] = 1;\n    for (int i = 1; i &lt;= n; i++) {\n        h[i] = h[i - 1] * P + s[i];\n        p[i] = p[i - 1] * P;\n    }\n    unordered_set&lt;ull&gt; q;\n    for (int i = 1; i &lt;= n; i++) {\n        if (i == 1)\n            q.insert(get_hash(i + 2, n));\n        else if (i == n)\n            q.insert(get_hash(1, n - 2));\n        else\n            q.insert(get_hash(i + 2, n) + get_hash(1, i - 1) * p[n - i - 1]);\n    }\n    cout &lt;&lt; q.size() &lt;&lt; endl;\n}\nint main()\n{\n    IOS;\n    int t = 1;\n    cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u9898\u76ee\u94fe\u63a5 \u9898\u76ee\u5927\u610f \u9898\u76ee\u7684\u610f\u601d\u662f\u628a\u5b57\u7b26\u4e32\u5220\u53bb\u8fde\u7eed\u7684\u4e24\u4e2a\u5b57\u6bcd\uff0c\u95ee\u5269\u4e0b\u7684\u5b57\u7b26\u4e32\u62fc\u8d77\u6765\u6709\u591a\u5c11\u79cd\uff1f \u9898\u89e3 #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;unordered_map&gt; #include &lt;unordered_set&gt; #include &lt;vector&gt; using namespace std; #define x first #define y second #define endl &#039;\\n&#039; #define IOS \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[23],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-solution","tag-hash"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}