diff --git a/S2OJ/1139/1139.cpp b/S2OJ/1139/1139.cpp new file mode 100644 index 00000000..99466c10 --- /dev/null +++ b/S2OJ/1139/1139.cpp @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int k, nxt[15][1005]; +long long sum[15][1005], f[2][1005][(1 << 14) + 5], + ans = std::numeric_limits::min(); +std::string s; +std::vector a{""}; +int root, cnt; + +struct node { + int val; + int child[26], fail; + + node() + : val(0), fail(0) { + std::fill(std::begin(child), std::end(child), 0); + } +} tr[1005]; + +void insert(std::string s, const int& _val) { + int cur = root; + + for (char c : s) { + if (!tr[cur].child[c - 'a']) { + tr[cur].child[c - 'a'] = ++cnt; + } + + cur = tr[cur].child[c - 'a']; + } + + tr[cur].val += _val; +} + +void build() { + std::queue q; + + for (int i = 0; i < 26; i++) { + if (tr[root].child[i]) { + q.emplace(tr[root].child[i]); + } + } + + while (!q.empty()) { + int cur = q.front(); + q.pop(); + + for (int i = 0; i < 26; i++) { + if (tr[cur].child[i]) { + tr[tr[cur].child[i]].fail = tr[tr[cur].fail].child[i]; + q.emplace(tr[cur].child[i]); + tr[tr[cur].child[i]].val += tr[tr[tr[cur].child[i]].fail].val; + } else { + tr[cur].child[i] = tr[tr[cur].fail].child[i]; + } + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> k; + + for (int i = 1; i <= k; i++) { + std::string t; + int c; + + cin >> t >> c; + + insert(t, c); + } + + cin >> s; + + build(); + + for (char c : s) { + if (c == '?') { + a.emplace_back(""); + } else { + a.back().push_back(c); + } + } + + for (int i = 0; i < a.size(); i++) { + for (int j = 0; j <= cnt; j++) { + int cur = j; + + for (char c : a[i]) { + cur = tr[cur].child[c - 'a']; + sum[i][j] += tr[cur].val; + } + + nxt[i][j] = cur; + } + } + + memset(f, 0xc0, sizeof(f)); + + f[0][0][0] = 0; + + for (int i = 0, x = 0; i < a.size(); i++, x ^= 1) { + memset(f[x ^ 1], 0xc0, sizeof(f[x ^ 1])); + + for (int j = 0; j <= cnt; j++) { + for (int s = 0; s < 1 << 14; s++) { + if (f[x][j][s] < -0x3f3f3f3f3f3f3f3f) continue; + + int p = nxt[i][j]; + + if (i + 1 < a.size()) { + for (int k = 0; k < 14; k++) { + if (s & (1 << k)) continue; + + f[x ^ 1][tr[p].child[k]][s | (1 << k)] = std::max( + f[x ^ 1][tr[p].child[k]][s | (1 << k)], + f[x][j][s] + sum[i][j] + tr[tr[p].child[k]].val); + } + } else { + f[x ^ 1][p][s] = std::max(f[x ^ 1][p][s], f[x][j][s] + sum[i][j]); + } + } + } + } + + for (int i = 0; i <= cnt; i++) { + for (int s = 0; s < 1 << 14; s++) { + ans = std::max(ans, f[a.size() & 1][i][s]); + } + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1139/data/problem.conf b/S2OJ/1139/data/problem.conf new file mode 100644 index 00000000..7eb90e96 --- /dev/null +++ b/S2OJ/1139/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdffbae7be2c628eddd910f386f3dd2246dbc0f821e675d110ab7a48a43fa6e7 +size 211 diff --git a/S2OJ/1139/data/value1.in b/S2OJ/1139/data/value1.in new file mode 100644 index 00000000..11776cbc --- /dev/null +++ b/S2OJ/1139/data/value1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b26a053a973525e85bd4a98ed45bfe87b44006940bc7d7f3cdefb8bd98287ed1 +size 21 diff --git a/S2OJ/1139/data/value1.out b/S2OJ/1139/data/value1.out new file mode 100644 index 00000000..65493889 --- /dev/null +++ b/S2OJ/1139/data/value1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:084c799cd551dd1d8d5c5f9a5d593b2e931f5e36122ee5c793c1d08a19839cc0 +size 3 diff --git a/S2OJ/1139/data/value10.in b/S2OJ/1139/data/value10.in new file mode 100644 index 00000000..6230d857 --- /dev/null +++ b/S2OJ/1139/data/value10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:adaceab4cf6190dae32e03ed5e8bc06e63ab381ba3147f949c1f67214e2894c5 +size 401323 diff --git a/S2OJ/1139/data/value10.out b/S2OJ/1139/data/value10.out new file mode 100644 index 00000000..215d447c --- /dev/null +++ b/S2OJ/1139/data/value10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4e8443c67b210ea4b57fb135669f1ef45f1297671639480ccfc6bcffc83f5ea +size 10 diff --git a/S2OJ/1139/data/value11.in b/S2OJ/1139/data/value11.in new file mode 100644 index 00000000..270a98eb --- /dev/null +++ b/S2OJ/1139/data/value11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7420c22967f37989f1d437d806dc7a6d3e319d6532dc827486bb52b31445f6be +size 401173 diff --git a/S2OJ/1139/data/value11.out b/S2OJ/1139/data/value11.out new file mode 100644 index 00000000..fd98f34e --- /dev/null +++ b/S2OJ/1139/data/value11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1534bc0cdf7f849a7d23b69d264e54a7d735d26283e6faa752ca860e6d254dca +size 9 diff --git a/S2OJ/1139/data/value12.in b/S2OJ/1139/data/value12.in new file mode 100644 index 00000000..56f2cbd7 --- /dev/null +++ b/S2OJ/1139/data/value12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7ef328696906576a09ac251629e7833dba3543b09a8a2dee525cef6e410efc6 +size 401167 diff --git a/S2OJ/1139/data/value12.out b/S2OJ/1139/data/value12.out new file mode 100644 index 00000000..f1370de5 --- /dev/null +++ b/S2OJ/1139/data/value12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da19f2b7b1f38f88efe1085e52d273fbabb7bdbf1714f344bb1e44c33ac4013b +size 9 diff --git a/S2OJ/1139/data/value13.in b/S2OJ/1139/data/value13.in new file mode 100644 index 00000000..e5893ec2 --- /dev/null +++ b/S2OJ/1139/data/value13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8735eddcf6a307ab2751d8219dec806af62c6ecfa7ba59c35dd4117eb8984533 +size 401471 diff --git a/S2OJ/1139/data/value13.out b/S2OJ/1139/data/value13.out new file mode 100644 index 00000000..d4a38d46 --- /dev/null +++ b/S2OJ/1139/data/value13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a0e9f1e864fb0208f98ceb5beacd6d3de8baa3d3b4d072bcebb8fb894d086cf +size 11 diff --git a/S2OJ/1139/data/value14.in b/S2OJ/1139/data/value14.in new file mode 100644 index 00000000..d4354623 --- /dev/null +++ b/S2OJ/1139/data/value14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49d41ff8cf5556664abf11ee231ca0971ec157c1ea57da349180e391b64e880f +size 401476 diff --git a/S2OJ/1139/data/value14.out b/S2OJ/1139/data/value14.out new file mode 100644 index 00000000..b6c48dbd --- /dev/null +++ b/S2OJ/1139/data/value14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f20630a52bccd37e5b7dbec04482e88b7ded910d61515a906373eec0314ec663 +size 11 diff --git a/S2OJ/1139/data/value15.in b/S2OJ/1139/data/value15.in new file mode 100644 index 00000000..4f5bcafe --- /dev/null +++ b/S2OJ/1139/data/value15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e991c2abe327328b64e320750429d177e7a270c324c1c811d879e47b2e30384 +size 403412 diff --git a/S2OJ/1139/data/value15.out b/S2OJ/1139/data/value15.out new file mode 100644 index 00000000..4bd1255c --- /dev/null +++ b/S2OJ/1139/data/value15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27eb7a13fa45e3a9bbb57c3115515490333ee33873e0ec25a68825fbdd7c4506 +size 11 diff --git a/S2OJ/1139/data/value16.in b/S2OJ/1139/data/value16.in new file mode 100644 index 00000000..a32e62b5 --- /dev/null +++ b/S2OJ/1139/data/value16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d87715341b43abe8fe1f576061c1df451ae00c2ec3851e5ed6c68df7716cfa71 +size 402803 diff --git a/S2OJ/1139/data/value16.out b/S2OJ/1139/data/value16.out new file mode 100644 index 00000000..d4fc839d --- /dev/null +++ b/S2OJ/1139/data/value16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87af1b1b9209f63c76d23b19b15280a93783167c436a7f706129ccf938a01432 +size 10 diff --git a/S2OJ/1139/data/value17.in b/S2OJ/1139/data/value17.in new file mode 100644 index 00000000..71bdca5f --- /dev/null +++ b/S2OJ/1139/data/value17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bd9d739bb4acdb3fc4654e35bd7af3685faf1cbcdee8c3eb591982e46c17cb2 +size 403664 diff --git a/S2OJ/1139/data/value17.out b/S2OJ/1139/data/value17.out new file mode 100644 index 00000000..e3497a4b --- /dev/null +++ b/S2OJ/1139/data/value17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c244bf5a69da7b08e0e842c6cb872317efa24e1ff9df1e33205dc9f763361435 +size 11 diff --git a/S2OJ/1139/data/value18.in b/S2OJ/1139/data/value18.in new file mode 100644 index 00000000..2627d491 --- /dev/null +++ b/S2OJ/1139/data/value18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:062336844e97a2ff503bb3f4eb1aac18a01c4205483cdefcbba5ebff68ec7492 +size 402921 diff --git a/S2OJ/1139/data/value18.out b/S2OJ/1139/data/value18.out new file mode 100644 index 00000000..91a40769 --- /dev/null +++ b/S2OJ/1139/data/value18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:09c236420d4cfe563c280ee001ff83f7c28ef708cfdb741f0167a5128c016891 +size 11 diff --git a/S2OJ/1139/data/value19.in b/S2OJ/1139/data/value19.in new file mode 100644 index 00000000..f8cc2353 --- /dev/null +++ b/S2OJ/1139/data/value19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0791d896b7fc677048b121e9e7879361dc9f37919550aaad9d3a7bad538ced78 +size 402713 diff --git a/S2OJ/1139/data/value19.out b/S2OJ/1139/data/value19.out new file mode 100644 index 00000000..e059fe60 --- /dev/null +++ b/S2OJ/1139/data/value19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7228b6c1a578e5343f1208d9e2e6eab425b5a2b66c7b7df01bf2739607baefec +size 10 diff --git a/S2OJ/1139/data/value2.in b/S2OJ/1139/data/value2.in new file mode 100644 index 00000000..7e035355 --- /dev/null +++ b/S2OJ/1139/data/value2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b0d60e57c9d0bb5c9d223ee3a1ecc08af70f71eaaec11a5302f67bb19858a52 +size 29 diff --git a/S2OJ/1139/data/value2.out b/S2OJ/1139/data/value2.out new file mode 100644 index 00000000..aca84b3a --- /dev/null +++ b/S2OJ/1139/data/value2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f66561e21b0199b9062fd250073abd3285978f46e226f876467b3f749246434 +size 4 diff --git a/S2OJ/1139/data/value20.in b/S2OJ/1139/data/value20.in new file mode 100644 index 00000000..dd3a7801 --- /dev/null +++ b/S2OJ/1139/data/value20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4550f516940dab38b83c5130fd4a3541e61aa8095d5e6816bf088be57bc1c035 +size 402408 diff --git a/S2OJ/1139/data/value20.out b/S2OJ/1139/data/value20.out new file mode 100644 index 00000000..d6cd17aa --- /dev/null +++ b/S2OJ/1139/data/value20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48ae52a9ad37c80c782d6753bfc9a4cd88793485e9f31d57bda43120571deeb6 +size 10 diff --git a/S2OJ/1139/data/value3.in b/S2OJ/1139/data/value3.in new file mode 100644 index 00000000..cb10cd6a --- /dev/null +++ b/S2OJ/1139/data/value3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:130e6839a3675ec66cda991c9334bce23ab0a43cb961315b960ea31818a14d8a +size 69 diff --git a/S2OJ/1139/data/value3.out b/S2OJ/1139/data/value3.out new file mode 100644 index 00000000..284ce88e --- /dev/null +++ b/S2OJ/1139/data/value3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a468c076a2a0ff75141e1f0de7673c5b535639a213c64f35913b07852c86e10 +size 4 diff --git a/S2OJ/1139/data/value4.in b/S2OJ/1139/data/value4.in new file mode 100644 index 00000000..224c24bd --- /dev/null +++ b/S2OJ/1139/data/value4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ecfa18e6802c51a8bcf1a33ccfa1f546356818031614c7e330cf77e8aabcfb5 +size 72 diff --git a/S2OJ/1139/data/value4.out b/S2OJ/1139/data/value4.out new file mode 100644 index 00000000..dc051052 --- /dev/null +++ b/S2OJ/1139/data/value4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:afe825587584b44ccb6856b248841ab82630e86863b8deb83a98671c198afcbe +size 5 diff --git a/S2OJ/1139/data/value5.in b/S2OJ/1139/data/value5.in new file mode 100644 index 00000000..65bbbc16 --- /dev/null +++ b/S2OJ/1139/data/value5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2103126801c733e2a72caec8f9ace71db32143aee2cd85ead4d39ad4dbd475a9 +size 73 diff --git a/S2OJ/1139/data/value5.out b/S2OJ/1139/data/value5.out new file mode 100644 index 00000000..647a72b2 --- /dev/null +++ b/S2OJ/1139/data/value5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04ac70e5b43f47d205e6483b65209eb41e2e951aa57bf17e5b466112bbed9def +size 4 diff --git a/S2OJ/1139/data/value6.in b/S2OJ/1139/data/value6.in new file mode 100644 index 00000000..6b92ce3e --- /dev/null +++ b/S2OJ/1139/data/value6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f1175c5b862e7ddbf1047863cb0559fdd677da9f64c75c01d3ad288e957ab4a7 +size 81 diff --git a/S2OJ/1139/data/value6.out b/S2OJ/1139/data/value6.out new file mode 100644 index 00000000..6cbc3f83 --- /dev/null +++ b/S2OJ/1139/data/value6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0484e67e294385aa5303e36d90f2750b37bf9aec3c05c28afd14be1a82084ddc +size 5 diff --git a/S2OJ/1139/data/value7.in b/S2OJ/1139/data/value7.in new file mode 100644 index 00000000..6425347b --- /dev/null +++ b/S2OJ/1139/data/value7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6f52a61923f5a8180502e1fb2aadcbe30719569edbe4cc1a8d74bc5a94f0075 +size 400017 diff --git a/S2OJ/1139/data/value7.out b/S2OJ/1139/data/value7.out new file mode 100644 index 00000000..6d5a6650 --- /dev/null +++ b/S2OJ/1139/data/value7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5ebc5256f3aa2406c8d114e080650898e06da783031dd7c3dd9f9bb59368e22 +size 4 diff --git a/S2OJ/1139/data/value8.in b/S2OJ/1139/data/value8.in new file mode 100644 index 00000000..b025fed6 --- /dev/null +++ b/S2OJ/1139/data/value8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:28208a120a29cbdb39d315bd70b522674b3e14949b543f434700e0aa6a21ebd4 +size 400717 diff --git a/S2OJ/1139/data/value8.out b/S2OJ/1139/data/value8.out new file mode 100644 index 00000000..cc6c8f10 --- /dev/null +++ b/S2OJ/1139/data/value8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6a34568976c80f1c00b29fabd1458435d0e04ad281bfe3f8e94366fafa4b357 +size 5 diff --git a/S2OJ/1139/data/value9.in b/S2OJ/1139/data/value9.in new file mode 100644 index 00000000..18725019 --- /dev/null +++ b/S2OJ/1139/data/value9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f90452d4466e23c44c91be242889c3c2d641e58f0906c66f6294d080bbdf2ffa +size 401131 diff --git a/S2OJ/1139/data/value9.out b/S2OJ/1139/data/value9.out new file mode 100644 index 00000000..58506830 --- /dev/null +++ b/S2OJ/1139/data/value9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08deb395c31c7761aa14681715ad591032e316406c7aacfdafaedacde8e40eef +size 10