diff --git a/S2OJ/1385/1385.cpp b/S2OJ/1385/1385.cpp new file mode 100644 index 00000000..cd612c02 --- /dev/null +++ b/S2OJ/1385/1385.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +void solve() { + std::vector st(3), ed(3); + std::string s; + + for (int i = 0; i < 3; i++) { + std::string t; + + cin >> t; + + st[i] = s.size(); + s += t; + ed[i] = s.size() - 1; + } + + std::function id = [&](int x) -> int { + return std::distance(std::begin(ed), std::lower_bound(std::begin(ed), std::end(ed), x)); + }; + + int n = s.size(); + std::vector> + f(n, std::vector(n)), + g(3, std::vector(n)), + h(3, std::vector(n)); + long long w = 0, ans = 0; + + for (int i = 0; i < n; i++) { + for (int j = n - 1; j > i; j--) { + if (s[i] != s[j]) continue; + + int id_i = id(i), + id_j = id(j); + + if (id_i == 0 && id_j == 2) { + f[i][j] = 1; + } + + f[i][j] += g[id_j][i]; // 加上右边块的贡献 + f[i][j] += h[id_i][j]; // 加上左边块的贡献 + + if (id_i == 1 && id_j == 1) { + f[i][j] += w; // 加上两边来的贡献 + } + + if (i != st[id_i] && j != ed[id_j]) { + f[i][j] += f[i - 1][j + 1]; // 还在块内,不跳到下一块 + } + + if (id_i == 0 && id_j == 2) { + w += f[i][j]; // 如果在两边的块,更新贡献 + } + + if (id_j != 0 && i != ed[id_i]) { + g[id_j - 1][i + 1] += f[i][j]; // 更新到左边块的贡献 + } + + if (id_i != 2 && j != st[id_j]) { + h[id_i + 1][j - 1] += f[i][j]; // 更新到右边块的贡献 + } + + if (id_i == id_j) { + if (j - i + 1 <= 3) { + // j - i + 1 == 2: i, j 相邻,总长度为偶数 + // == 3: i, j 之间还有一个字符,总长度为奇数 + ans += f[i][j]; + } + } else if (id_i + 1 == id_j) { // i 和 j 在相邻块中 + ans += static_cast( + 1 // i, j 之间不拼字符,总长度为偶数 + + (i != ed[id_i]) // 如果 i 不是块末尾,还可以在中间拼一个字符,总长度为奇数 + + (j != st[id_j]) // 如果 j 不是块开头,还可以在中间拼一个字符,总长度为奇数 + ) + * f[i][j]; + } + } + } + + ans += w * (ed[1] - st[1] + 1); + + cout << ans << endl; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) solve(); + + return 0; +} diff --git a/S2OJ/1385/data/pali1.ans b/S2OJ/1385/data/pali1.ans new file mode 100644 index 00000000..c2922ecd --- /dev/null +++ b/S2OJ/1385/data/pali1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be9109f87f481a73526dc7713dda8b524bd21d5ae15b905ca875b388197cf4aa +size 31 diff --git a/S2OJ/1385/data/pali1.in b/S2OJ/1385/data/pali1.in new file mode 100644 index 00000000..990d3653 --- /dev/null +++ b/S2OJ/1385/data/pali1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d61c4728264ca67314e8dbf5b3f8076fc2176497b79aa6af4de0df18b004e0df +size 212 diff --git a/S2OJ/1385/data/pali10.ans b/S2OJ/1385/data/pali10.ans new file mode 100644 index 00000000..04bb0333 --- /dev/null +++ b/S2OJ/1385/data/pali10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff954286940dde44927bcfc368ac03fabfc10fbaa4d32c847818bd43efdfd240 +size 83 diff --git a/S2OJ/1385/data/pali10.in b/S2OJ/1385/data/pali10.in new file mode 100644 index 00000000..c83e9da7 --- /dev/null +++ b/S2OJ/1385/data/pali10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b712e2eca40a2cc8aa64c3d08ffd10c54cec74d96828860de0b51528ef0c81b2 +size 5736 diff --git a/S2OJ/1385/data/pali11.ans b/S2OJ/1385/data/pali11.ans new file mode 100644 index 00000000..68a978b7 --- /dev/null +++ b/S2OJ/1385/data/pali11.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1e29f618ffba31ef9ab722971c3e5fff8877f680e121d9d341ff910f4ff7dfc +size 94 diff --git a/S2OJ/1385/data/pali11.in b/S2OJ/1385/data/pali11.in new file mode 100644 index 00000000..013d464d --- /dev/null +++ b/S2OJ/1385/data/pali11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85ffc08166a4ed34766305b6335068e47c0606b47f567c4103a8b280be12ac1d +size 5802 diff --git a/S2OJ/1385/data/pali12.ans b/S2OJ/1385/data/pali12.ans new file mode 100644 index 00000000..63f22b01 --- /dev/null +++ b/S2OJ/1385/data/pali12.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6f8a6ff87fe0c82e69184f95044c8f0e64a052ba2c70750831e8389d25d9a50 +size 88 diff --git a/S2OJ/1385/data/pali12.in b/S2OJ/1385/data/pali12.in new file mode 100644 index 00000000..78674b7e --- /dev/null +++ b/S2OJ/1385/data/pali12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:544e1d18895c660527f101c988b935b3d49db1b77df9a4d3d4bd31fae5adb7d6 +size 5728 diff --git a/S2OJ/1385/data/pali13.ans b/S2OJ/1385/data/pali13.ans new file mode 100644 index 00000000..2b102bb6 --- /dev/null +++ b/S2OJ/1385/data/pali13.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f2fb2e21b93aba524d6f82e247a04b81c20e6c580d1e2aca297f600276c6e5f +size 90 diff --git a/S2OJ/1385/data/pali13.in b/S2OJ/1385/data/pali13.in new file mode 100644 index 00000000..cbe8a34b --- /dev/null +++ b/S2OJ/1385/data/pali13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4341d46510a66e5aff94df7487a920810033ec7c4a0bd6a8c00d208c982280c7 +size 29754 diff --git a/S2OJ/1385/data/pali14.ans b/S2OJ/1385/data/pali14.ans new file mode 100644 index 00000000..cfeaae6e --- /dev/null +++ b/S2OJ/1385/data/pali14.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c20f48b6a75dbc1e5568fc1012d52208b299554bba731f8856647ce4a08ec160 +size 90 diff --git a/S2OJ/1385/data/pali14.in b/S2OJ/1385/data/pali14.in new file mode 100644 index 00000000..bfd847a6 --- /dev/null +++ b/S2OJ/1385/data/pali14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d0bbc77f0274b3d30d16bfdbbe6188ba6ed66571c747c6169a647a865c494f3 +size 29780 diff --git a/S2OJ/1385/data/pali15.ans b/S2OJ/1385/data/pali15.ans new file mode 100644 index 00000000..eac1d71f --- /dev/null +++ b/S2OJ/1385/data/pali15.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9b1c0e63ad3f127a119d74695dc3d19251c847dc478c744ef62f87b69ab01e5 +size 105 diff --git a/S2OJ/1385/data/pali15.in b/S2OJ/1385/data/pali15.in new file mode 100644 index 00000000..bbacc772 --- /dev/null +++ b/S2OJ/1385/data/pali15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:881f8023c2caa1a2c9680355f49255b6655221976f28e77e886b1fa3edf2f669 +size 29788 diff --git a/S2OJ/1385/data/pali16.ans b/S2OJ/1385/data/pali16.ans new file mode 100644 index 00000000..9f06a45e --- /dev/null +++ b/S2OJ/1385/data/pali16.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ab22971d54d440e070302a71ec3678bc1594fa0bd2593c700551570660a7a52 +size 121 diff --git a/S2OJ/1385/data/pali16.in b/S2OJ/1385/data/pali16.in new file mode 100644 index 00000000..914d2769 --- /dev/null +++ b/S2OJ/1385/data/pali16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca63e2ce94f0779288cad20a9f51bbe4abce90810863df893cd95edf15f6317c +size 29825 diff --git a/S2OJ/1385/data/pali17.ans b/S2OJ/1385/data/pali17.ans new file mode 100644 index 00000000..8b596514 --- /dev/null +++ b/S2OJ/1385/data/pali17.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42b61e4dbc1fbdb2e9e1f5b498108d96372090cca85c47192ba29934c7db43f5 +size 120 diff --git a/S2OJ/1385/data/pali17.in b/S2OJ/1385/data/pali17.in new file mode 100644 index 00000000..fb5eaed8 --- /dev/null +++ b/S2OJ/1385/data/pali17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0cc559c6631b30a636a66d8c5c6f2c8d8f49bdef2def8793490f44b18fb1410a +size 29778 diff --git a/S2OJ/1385/data/pali18.ans b/S2OJ/1385/data/pali18.ans new file mode 100644 index 00000000..434e23b8 --- /dev/null +++ b/S2OJ/1385/data/pali18.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4280059be66fd9bfab1c249da8f80c150356837922af2008bd1934d6280bac8 +size 116 diff --git a/S2OJ/1385/data/pali18.in b/S2OJ/1385/data/pali18.in new file mode 100644 index 00000000..014f0a56 --- /dev/null +++ b/S2OJ/1385/data/pali18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbef737558ef770b13e724f2ed506392301e3b40fc968bb84c2f51abbd43d37b +size 29771 diff --git a/S2OJ/1385/data/pali19.ans b/S2OJ/1385/data/pali19.ans new file mode 100644 index 00000000..1f11a202 --- /dev/null +++ b/S2OJ/1385/data/pali19.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f9e889b9bbda07ef8451f54b4ad9bc137b194658e7248c05072c6d4fdbc9eff +size 135 diff --git a/S2OJ/1385/data/pali19.in b/S2OJ/1385/data/pali19.in new file mode 100644 index 00000000..6e031c63 --- /dev/null +++ b/S2OJ/1385/data/pali19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e321174105e88698cc49a6026e517383292cafba416cfa8154185a7ff255f26d +size 29810 diff --git a/S2OJ/1385/data/pali2.ans b/S2OJ/1385/data/pali2.ans new file mode 100644 index 00000000..3ede59d2 --- /dev/null +++ b/S2OJ/1385/data/pali2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f25cbc8c9957c871e79f3df540c00b0d1a0c2647c455c640d9ee0ebf962ee50 +size 40 diff --git a/S2OJ/1385/data/pali2.in b/S2OJ/1385/data/pali2.in new file mode 100644 index 00000000..1c8091e8 --- /dev/null +++ b/S2OJ/1385/data/pali2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99a6993d38f4ea6e5c63f64504f7dc4bb57216ca8eab61d124bacda8df2204b1 +size 216 diff --git a/S2OJ/1385/data/pali20.ans b/S2OJ/1385/data/pali20.ans new file mode 100644 index 00000000..6c43534c --- /dev/null +++ b/S2OJ/1385/data/pali20.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d60fac4ac09adc2540af329b849cc28bb07e91d073ca1a62b78bcd4adf2e5a0 +size 114 diff --git a/S2OJ/1385/data/pali20.in b/S2OJ/1385/data/pali20.in new file mode 100644 index 00000000..f8d2f41a --- /dev/null +++ b/S2OJ/1385/data/pali20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6af7895cb0968d395f1480a3f2be1e8d929140e90fcfe33d83495bb2fb3d45da +size 29797 diff --git a/S2OJ/1385/data/pali3.ans b/S2OJ/1385/data/pali3.ans new file mode 100644 index 00000000..bfa57298 --- /dev/null +++ b/S2OJ/1385/data/pali3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1bdb63f5ae158052a7bf7d0cb3aecfee80d0a2a6a9cf7bafbcacb6639b194a9 +size 37 diff --git a/S2OJ/1385/data/pali3.in b/S2OJ/1385/data/pali3.in new file mode 100644 index 00000000..943c2870 --- /dev/null +++ b/S2OJ/1385/data/pali3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:768f69edd3080ef78058e9af5b583317b12fb71c4f41867f42b4e160d1233478 +size 211 diff --git a/S2OJ/1385/data/pali4.ans b/S2OJ/1385/data/pali4.ans new file mode 100644 index 00000000..888b4665 --- /dev/null +++ b/S2OJ/1385/data/pali4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:868b1e70126d1ab02aeb7f8fb5560746223eb98b0ae0ece7248409e9d3475049 +size 37 diff --git a/S2OJ/1385/data/pali4.in b/S2OJ/1385/data/pali4.in new file mode 100644 index 00000000..031f042f --- /dev/null +++ b/S2OJ/1385/data/pali4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8abece6d84e0c09bbed27f1d6c2dcdc6e0382816d5176d0cd3aff10c5b5b3445 +size 197 diff --git a/S2OJ/1385/data/pali5.ans b/S2OJ/1385/data/pali5.ans new file mode 100644 index 00000000..9012dbf2 --- /dev/null +++ b/S2OJ/1385/data/pali5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:01f7849114c5fba3e882753a8f7316545011c9684bb5de9e81ebb0d46691622c +size 85 diff --git a/S2OJ/1385/data/pali5.in b/S2OJ/1385/data/pali5.in new file mode 100644 index 00000000..d9d09d29 --- /dev/null +++ b/S2OJ/1385/data/pali5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bf81f06603acc517529f3026aef4ecb6e0c71d3baf01ad10072eacccb7f28c +size 2789 diff --git a/S2OJ/1385/data/pali6.ans b/S2OJ/1385/data/pali6.ans new file mode 100644 index 00000000..a560cdbb --- /dev/null +++ b/S2OJ/1385/data/pali6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f519a3ee448357ff3fa5a629ef3fdf94d6bb2db748622d5b6d37a9080d11bf50 +size 91 diff --git a/S2OJ/1385/data/pali6.in b/S2OJ/1385/data/pali6.in new file mode 100644 index 00000000..529d5d35 --- /dev/null +++ b/S2OJ/1385/data/pali6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5624d63fb80b3c0ba1efff70a9fb56c8baa8b133c89133a13312fbdd9a80135d +size 2824 diff --git a/S2OJ/1385/data/pali7.ans b/S2OJ/1385/data/pali7.ans new file mode 100644 index 00000000..24424c2a --- /dev/null +++ b/S2OJ/1385/data/pali7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:138820078914925dda71f2c8de9db930f40d412260c1fd4b6c8cbe10a2ee13e3 +size 73 diff --git a/S2OJ/1385/data/pali7.in b/S2OJ/1385/data/pali7.in new file mode 100644 index 00000000..ca8ba105 --- /dev/null +++ b/S2OJ/1385/data/pali7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f14a29334a3e32c8c75a693cd0788a2fd53febf719e1c2ec7fca4f8ff8da9215 +size 2773 diff --git a/S2OJ/1385/data/pali8.ans b/S2OJ/1385/data/pali8.ans new file mode 100644 index 00000000..191c41de --- /dev/null +++ b/S2OJ/1385/data/pali8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33e603cfb43eeab190310b5ad515d22c6297ecf11abbf768aaaaa8a605f99f91 +size 95 diff --git a/S2OJ/1385/data/pali8.in b/S2OJ/1385/data/pali8.in new file mode 100644 index 00000000..6c7499b5 --- /dev/null +++ b/S2OJ/1385/data/pali8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:474c0d6ef5bf684f23bc85815e5d2c7f47179a7d0a1437a59bc369c63c5a4f46 +size 2701 diff --git a/S2OJ/1385/data/pali9.ans b/S2OJ/1385/data/pali9.ans new file mode 100644 index 00000000..dce0615b --- /dev/null +++ b/S2OJ/1385/data/pali9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:029198682a0ee100008bd82ba540d318350d5afc610bf61b5a2c31a171b92853 +size 96 diff --git a/S2OJ/1385/data/pali9.in b/S2OJ/1385/data/pali9.in new file mode 100644 index 00000000..967cc05c --- /dev/null +++ b/S2OJ/1385/data/pali9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8057817f3dbba3c41fcc2b38cb47cc13cd09d8c1bf28d32740a4d2e31fec90ad +size 5774 diff --git a/S2OJ/1385/data/problem.conf b/S2OJ/1385/data/problem.conf new file mode 100644 index 00000000..82faa1f2 --- /dev/null +++ b/S2OJ/1385/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:603182f78441a20889b7a67b9f87ea47f3d26b714310f568708dc95a1ba9e78e +size 211