From b0db86725cc650d67360bb48fb494c2f1a3ee47d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Wed, 28 Sep 2022 16:21:40 +0800 Subject: [PATCH] =?UTF-8?q?#574.=20=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=88str?= =?UTF-8?q?ings=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/58180 --- S2OJ/574/574.cpp | 84 ++++++++++++++++++++++++++++++++++++ S2OJ/574/data/ex_string1.in | 3 ++ S2OJ/574/data/ex_string1.out | 3 ++ S2OJ/574/data/problem.conf | 3 ++ S2OJ/574/data/string1.in | 3 ++ S2OJ/574/data/string1.out | 3 ++ S2OJ/574/data/string10.in | 3 ++ S2OJ/574/data/string10.out | 3 ++ S2OJ/574/data/string2.in | 3 ++ S2OJ/574/data/string2.out | 3 ++ S2OJ/574/data/string3.in | 3 ++ S2OJ/574/data/string3.out | 3 ++ S2OJ/574/data/string4.in | 3 ++ S2OJ/574/data/string4.out | 3 ++ S2OJ/574/data/string5.in | 3 ++ S2OJ/574/data/string5.out | 3 ++ S2OJ/574/data/string6.in | 3 ++ S2OJ/574/data/string6.out | 3 ++ S2OJ/574/data/string7.in | 3 ++ S2OJ/574/data/string7.out | 3 ++ S2OJ/574/data/string8.in | 3 ++ S2OJ/574/data/string8.out | 3 ++ S2OJ/574/data/string9.in | 3 ++ S2OJ/574/data/string9.out | 3 ++ 24 files changed, 153 insertions(+) create mode 100644 S2OJ/574/574.cpp create mode 100644 S2OJ/574/data/ex_string1.in create mode 100644 S2OJ/574/data/ex_string1.out create mode 100644 S2OJ/574/data/problem.conf create mode 100644 S2OJ/574/data/string1.in create mode 100644 S2OJ/574/data/string1.out create mode 100644 S2OJ/574/data/string10.in create mode 100644 S2OJ/574/data/string10.out create mode 100644 S2OJ/574/data/string2.in create mode 100644 S2OJ/574/data/string2.out create mode 100644 S2OJ/574/data/string3.in create mode 100644 S2OJ/574/data/string3.out create mode 100644 S2OJ/574/data/string4.in create mode 100644 S2OJ/574/data/string4.out create mode 100644 S2OJ/574/data/string5.in create mode 100644 S2OJ/574/data/string5.out create mode 100644 S2OJ/574/data/string6.in create mode 100644 S2OJ/574/data/string6.out create mode 100644 S2OJ/574/data/string7.in create mode 100644 S2OJ/574/data/string7.out create mode 100644 S2OJ/574/data/string8.in create mode 100644 S2OJ/574/data/string8.out create mode 100644 S2OJ/574/data/string9.in create mode 100644 S2OJ/574/data/string9.out diff --git a/S2OJ/574/574.cpp b/S2OJ/574/574.cpp new file mode 100644 index 00000000..48739ebd --- /dev/null +++ b/S2OJ/574/574.cpp @@ -0,0 +1,84 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +std::vector manacher(const std::string &_s) { + int n = _s.size(); + std::string s(n * 2 + 3, '#'); + + for (int i = 0; i < n; i++) { + s[i * 2 + 2] = _s[i]; + } + + s[0] = '^'; + s[n * 2 + 2] = '$'; + + std::vector p(s.size(), 1); + + for (int i = 1, mid = 0, r = 0; i <= n * 2 + 1; i++) { + p[i] = i < r ? std::min(p[mid * 2 - i], r - i) : 1; + + while (s[i - p[i]] == s[i + p[i]]) p[i]++; + + if (i + p[i] - 1 > r) { + r = i + p[i] - 1; + mid = i; + } + } + + for (int i = 0; i < n; i++) { + p[i] = p[i * 2 + 2] / 2; + } + + p.resize(n); + + return p; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) { + std::string s; + + cin >> s; + + int n = s.size(); + + if (n == 1) { + cout << 1 << endl; + + continue; + } + + auto p = manacher(s); + std::vector ans(n); + + for (int i = n - 1; i >= 0; --i) { + if (i * 2 < n) { + ans[i] = (p[i] >= i + 1) && ans[i * 2]; + } else { + ans[i] = p[i] >= n - i; + } + } + + for (int i = 0; i < n; ++i) { + if (ans[i]) { + cout << (i + 1) << ' '; + } + } + + cout << endl; + } + + return 0; +} diff --git a/S2OJ/574/data/ex_string1.in b/S2OJ/574/data/ex_string1.in new file mode 100644 index 00000000..b8e63555 --- /dev/null +++ b/S2OJ/574/data/ex_string1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc845d5ce7cba53b5c36446cad2d6e2c8c186fccf621552b4a296bd21ee2e9ec +size 23 diff --git a/S2OJ/574/data/ex_string1.out b/S2OJ/574/data/ex_string1.out new file mode 100644 index 00000000..38bb91eb --- /dev/null +++ b/S2OJ/574/data/ex_string1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:06dcd55d8824ae2f8b72cdc6f8972c69be759384d7c13c553df0c4f43a526862 +size 16 diff --git a/S2OJ/574/data/problem.conf b/S2OJ/574/data/problem.conf new file mode 100644 index 00000000..058bd0c0 --- /dev/null +++ b/S2OJ/574/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d2b06f428df0d45aef46f46a3150b05f8ccd37359dbd7ea8fc93cadcede73e1 +size 181 diff --git a/S2OJ/574/data/string1.in b/S2OJ/574/data/string1.in new file mode 100644 index 00000000..eda68724 --- /dev/null +++ b/S2OJ/574/data/string1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65ba6d4533646dea9b30efa9e8f5fde1f43d334ce12e3ee53e692b939c041d0d +size 41 diff --git a/S2OJ/574/data/string1.out b/S2OJ/574/data/string1.out new file mode 100644 index 00000000..78584db9 --- /dev/null +++ b/S2OJ/574/data/string1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62f6d46a97f1a5babab74f5148b9a4ca23cd37c28c4e41d2711670dfa89a8530 +size 24 diff --git a/S2OJ/574/data/string10.in b/S2OJ/574/data/string10.in new file mode 100644 index 00000000..b21742c5 --- /dev/null +++ b/S2OJ/574/data/string10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33281f6d8ff7631b4058e00cb0be8d7b264ab1e5a88ef054814574b02e394cc4 +size 5000001 diff --git a/S2OJ/574/data/string10.out b/S2OJ/574/data/string10.out new file mode 100644 index 00000000..82e5853b --- /dev/null +++ b/S2OJ/574/data/string10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68bc8947c88aa8008909c0b4b007f0eb0dddd4325357b9beff36385b2d76da47 +size 13777782 diff --git a/S2OJ/574/data/string2.in b/S2OJ/574/data/string2.in new file mode 100644 index 00000000..db8d5362 --- /dev/null +++ b/S2OJ/574/data/string2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af923cca0a1f7ba63568c177e2faa30c9ff932a4b81df24ef02359db19678433 +size 505 diff --git a/S2OJ/574/data/string2.out b/S2OJ/574/data/string2.out new file mode 100644 index 00000000..fc5ec298 --- /dev/null +++ b/S2OJ/574/data/string2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b9015a8c9fca3e15507e6333eceee90fc12e0d895342a9ee866df3177db37e1 +size 732 diff --git a/S2OJ/574/data/string3.in b/S2OJ/574/data/string3.in new file mode 100644 index 00000000..13419657 --- /dev/null +++ b/S2OJ/574/data/string3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f099617508b30b48dfc87d7ed1193bd7458e0ab7b266950c2b43f6f39bec40a +size 505 diff --git a/S2OJ/574/data/string3.out b/S2OJ/574/data/string3.out new file mode 100644 index 00000000..e1b5c0f6 --- /dev/null +++ b/S2OJ/574/data/string3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5b212681e33d245f237014ada6b4a77083a6eafd662f3f0b8faf9acbff8fa8da +size 732 diff --git a/S2OJ/574/data/string4.in b/S2OJ/574/data/string4.in new file mode 100644 index 00000000..c588a965 --- /dev/null +++ b/S2OJ/574/data/string4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25c3f6b368d1e67e2cd9903084b8663e589d75c4b48f5efbaedbf109937cd231 +size 508 diff --git a/S2OJ/574/data/string4.out b/S2OJ/574/data/string4.out new file mode 100644 index 00000000..e0d05761 --- /dev/null +++ b/S2OJ/574/data/string4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27ccb546e0c506d91ba2744d1caec4b0dd157afa361d1d051346f2c2790de933 +size 830 diff --git a/S2OJ/574/data/string5.in b/S2OJ/574/data/string5.in new file mode 100644 index 00000000..56885be5 --- /dev/null +++ b/S2OJ/574/data/string5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e2090ec89bf1e0452fa6c1461ea8c1d1b85dbcd38a77c8aacb6017620d17b21 +size 5008 diff --git a/S2OJ/574/data/string5.out b/S2OJ/574/data/string5.out new file mode 100644 index 00000000..dcf679d6 --- /dev/null +++ b/S2OJ/574/data/string5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8f0debca6a0cf36322311a85f7cc04e8ceaaf6ce75a44828e131625b96878f2 +size 14921 diff --git a/S2OJ/574/data/string6.in b/S2OJ/574/data/string6.in new file mode 100644 index 00000000..aff9b39d --- /dev/null +++ b/S2OJ/574/data/string6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8583b0060d3e11c888712bdcd7ab8130ff82e82abfff70521098e113edd5455 +size 5008 diff --git a/S2OJ/574/data/string6.out b/S2OJ/574/data/string6.out new file mode 100644 index 00000000..a60dbf3a --- /dev/null +++ b/S2OJ/574/data/string6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f00270440636a0a1fc415e3c7991e067eede1bd398680e0ab5710a928643efd +size 11035 diff --git a/S2OJ/574/data/string7.in b/S2OJ/574/data/string7.in new file mode 100644 index 00000000..b21742c5 --- /dev/null +++ b/S2OJ/574/data/string7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33281f6d8ff7631b4058e00cb0be8d7b264ab1e5a88ef054814574b02e394cc4 +size 5000001 diff --git a/S2OJ/574/data/string7.out b/S2OJ/574/data/string7.out new file mode 100644 index 00000000..82e5853b --- /dev/null +++ b/S2OJ/574/data/string7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68bc8947c88aa8008909c0b4b007f0eb0dddd4325357b9beff36385b2d76da47 +size 13777782 diff --git a/S2OJ/574/data/string8.in b/S2OJ/574/data/string8.in new file mode 100644 index 00000000..74612936 --- /dev/null +++ b/S2OJ/574/data/string8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3146345a25734a491f304d6a699c7bd36153ac0d0f4b964aca2e1c0afdd6e9c +size 5000005 diff --git a/S2OJ/574/data/string8.out b/S2OJ/574/data/string8.out new file mode 100644 index 00000000..8f5bfb25 --- /dev/null +++ b/S2OJ/574/data/string8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e827d627361206ab09fb14d6c80ac7d4286b1fa05eb1ec163e2c5227503e4e5 +size 500035 diff --git a/S2OJ/574/data/string9.in b/S2OJ/574/data/string9.in new file mode 100644 index 00000000..c2854f75 --- /dev/null +++ b/S2OJ/574/data/string9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4945d10741a7a16ba8c1376150e7258eb3f1f67e98dab00a300bdd7d11a8c5b3 +size 5000001 diff --git a/S2OJ/574/data/string9.out b/S2OJ/574/data/string9.out new file mode 100644 index 00000000..1257f177 --- /dev/null +++ b/S2OJ/574/data/string9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a06d86ba10e9e7e0d91edb396d5b22dcc4360c9b69a8dd673f94c9a7a04af26c +size 171552